techhipbettruvabetnorabahisbahis forumutaraftarium24edueduedueduseduseduedueduseduedu C Program To Find Last Occurrence Of A Character In A Given String
Latest :

C Program To Find Last Occurrence Of A Character In A Given String

C program to find the last occurrence of a character in a given string – In this article, we will describe the numerous means to find the last occurrence of a character in a given string in C programming.

Suitable examples and sample programs have also been added so that you can understand the whole thing very clearly. The compiler has also been added with which you can execute it yourself.

The means used in this piece are as follows:

  • Using Standard Method
  • Using Function
  • Using Recursion

A string is nothing but an array of characters. The value of a string is determined by the terminating character. Its value is considered to be 0.

In the image uploaded above, it is seen that you need to enter the string first up.

The string that has been entered here is as follows:

“Be yourself; everyone else is already taken”

After that, you need to enter the character that needs to be searched.

The character ‘e’ is assigned in the given example.

It is seen that the character ‘e’ last occurs at location 41.

Thus, doing the same in C programming is as follows:

Using Standard Method

  1. Read the entered string using gets(s).

2) Read the entered character to be searched and store that character into the variable c.

3)For loop iterate through string in reverse order  with the structure for(i=strlen(s)-1;i>=0;i–).

compare s[i] with the character c.if both are equal then initialize k=1 and break the loop.

4) If k=1 then print the location of the character where its last occurrence in the string. Otherwise, print the character is not available in the string.

Output:

Using Function

  1. The main() calls the check(char *s, char c) function to find the last occurrence of the given character in the string.

2) The for loop iterates through the string in reverse order with the structure for(i=length of the string-1; i>=0; i–).

comparing the given character with the elements of the string in reverse order.

a) If the character at s[i] matched with the given character then initialize k=1 and break the loop and return the i value.

b) Otherwise, decrease the i value.

Repeat this until finds the occurrence of the character.

3) Print the return value i which is the last occurrence of the character.

Output:

Using Recursion

  1. The main() calls the recursive function check(char *s, char c) to find the last occurrence of the character.

2) The function check(char *s,char c)

a) If the length of the string-1<0 then it returns i value.

b) Otherwise,

b.1) Compare the given character with the element at the last index “string length-1”.If matched then return ‘i’ value which is the last occurrence of the character.

b.2) If not matched then decrease the index value and call the function itself(go to step 2).

The function calls itself repeatedly until it finds the last occurrence of the character.

3) If the return value is >-1 then print the return value which indicates the last occurrence of the character in the string.

Output:

techhipbettruvabetnorabahisbahis forumutaraftarium24eduseduedueduedusedusedusedueduedus
x

Check Also

C Program To Input Any Alphabet And Check Whether It Is Vowel Or Consonant

C program to input any alphabet and check whether it is vowel or consonant – ...

cratosroyalbetgrandpashabetgrandpashabethttps://mobilebarhawaii.com/ballettea tropazhacklinkgrandpashabetonwinonwin girişselcuksportshdbahsegelatakoy escortatakoy escortcratosroyalbetonwinligobetkingroyal girişJojobetgrandpashabetİzmit escortbakırköy escortdeneme bonusu veren sitelerhalkali escortgrandpashabetonwinyurtiçi kargoesenyurt anal escortbets10starzbetmaltcasinomaltcasinojojobet girişfixbetkucukcekmece escortistanbul escortstarzbetjojobetfast creditsightcareİstanbul Escortantalya escortNorabahisfixbetmaltepe escortÜmraniye Escortholiganbetbets10takipçi satın aldeneme bonusu veren sitelerkingroyalnerobetetrabetcashback girişcasibomjojobetholiganbetsahabetcasibomcasibommariobetgrandpashabetGrandpashabetGrandpashabetholiganbetdeneme bonusu veren sitelermarsbahisGrandpashabetholiganbet güncel girişjojobet girişmarsbahisdeneme bonusu veren sitelermeritkingmatbethttps://markaescort.org/bolgeler/kartalartemisbet güncel girişescort kadıköyholiganbetsahabet girişonwin girişpusulabetmarsbahis giriş güncelmarsbahis güncel girişsahabetbahiscomkulisbetarnavutkoy escorttempobettarafbetsavoybettingsahabetsekabetmobilbahismadridbetbetturkeyholiganbet girişzbahismeritbetbets10ultrabetdinamobetbetkanyonstarzbetsuperbetinbetzulasuperbetinbetebetmilanobetbetturkey girişholiganbet girişmarsbahistempobetbetebetpusulabetonwin,onwin giriş,onwin güncel giriş,onwin giriş adresisahabetsekabet girişmatbet girişmarsbahis girişonwinmarsbahis girişsahabet girişsekabet girişmatbetbetturkey,betturkey girişimajbet,imajbet giriş,imajbet güncel giriş,imajbet resmi girişsahabetsahabetholiganbetkralbetmarsbahis,marsbahis güncel giriş , marsbahis giriş,marsbahis adresonwinsahabet,sahabet giriş,sahabet güncel giriş,sahabet resmi girişpusulabetmeritkingmavibetmobilbahiskingroyalbetebetnakitbahisMatbetholiganbetmetamaskmarsbahiskingroyalonwinmatbetpusulabetholiganbet girişmarsbahisgrandpashabetdinamobetbayconti girişGrandpashabetbetebetholiganbetsekabetbetsatholiganbetjojobetkingbettinggrandpashabet girişgrandpashabetjustin tv1xbethttps://canlicasino.shorthandstories.com/https://canlicasino.shorthandstories.com/deneme bonusu veren sitelerjojobetimajbet girişjojobet girişjojobet girişgamdomsahabetİzmit escortdeneme bonusukralbet güncel girişbetexperholiganbet girişjojobetsekabetsekabet girişpadişahbetistanbul escortgrandpashabetmarsbahistipobetmadridbetHoliganbet marsbahisholiganbetholiganbetimajbetjojobetistanbul, escortdumanbetcasibomjojobetdeneme bonusudeneme bonusu veren sitelerrestbetgrandpashabet girişgrandpashabet girişmadridbetLimanbetdeneme bonusu veren sitelerdeneme bonusu veren siteleronwinonwinonwinbetturkey girişholiganbetdinamobetmarsbahis