string - Find the rightmost occurence of a character in C? -


O all, I am trying to find the numerical position of one character or the number of characters in a string. I am able to know where the character "a" is in the string "abcd", but if I put "abcda", then it is printed only 0, which means that it only calculates the first example I want to find the last or the topmost part of this string. Here's what I've done so far:

  #include & lt; Stdio.h & gt; Main () {Four S [20]; Four t [20]; Intestinal PP; Printf ("Enter a full string: \ n"); Scanf ("% s", s); Printf ("Enter what you want to find: \ n"); Scan ("% s", t); Pp = strandex (s, t); Printf ("% d", pp); } / * String index * / int strandend (four s [], four t []) {int i, j, k, c; For (i = 0; s [i]! = '\ 0'; i ++) {for (j = i, k = 0; t [k]! = '\ 0' and & amp; [h ] == T [K]; J ++, K ++); If (k & gt; 0 & amp; t [k] == '\ 0') comes back i; } Return -1; }  

It is probably very easy, but I am working on it and pushed my mind and nothing is coming out of it. Thanks a lot!

As soon as you get an event, instead of returning again, one more variable

that is Come back; with lastOccurence = i

The last action should be started for -1 at the beginning of the function, then finally returned.

In addition, your internal loop needs to check S [J]! = '\ 0' or you're going to the end of your input string when you search.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -