Techhgeekz ™

Tuesday 10 September 2013

strchr and strrchr functions in c

C - strrchr function

#include <stdio.h> 

int main()

 { 

 char *s; 

 char buf [] = "This is a testing";

s = strrchr (buf, 't');

if (s != NULL)

printf ("found a 't' at %s\n", s); 

return 0;

}

It will produce following result:

found a 't' at ting

Explanation:-

The strrchr function searches string for the last occurrence of c. The null character terminating string is included in the search.

C - strchr function

#include <stdio.h>

int main() 

{

char *s;

char buf [] = "This is a testing";

s = strchr (buf, 't');

if (s != NULL)

printf ("found a 't' at %s\n", s);

return 0;

}

It will produce following result:

found a 't' at testing

Explanation:-

The strchr function searches string for the first occurrence of c. The null character terminating string is included in the search.

No comments:

Post a Comment