strchr, descripcion y ejemplo

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 /* strchr example */
00003 #include <stdio.h>
00004 #include <string.h>
00005 
00006 int main ()
00007 {
00008   char str[] = "This is a sample string";
00009   char * pch;
00010   printf ("Looking for the 's' character in \"%s\"...\n",str);
00011   pch=strchr(str,'s');
00012   while (pch!=NULL)
00013   {
00014     printf ("found at %d\n",pch-str+1);
00015     pch=strchr(pch+1,'s');
00016   }
00017   return 0;
00018 }
00019 
00020 /*
00021 Output:
00022 
00023 Looking for the 's' character in "This is a sample string"...
00024 found at 4
00025 found at 7
00026 found at 11
00027 found at 18
00028 */