When the user selected this option, your program should be able to accept a character from the user and search for this character from the phrase. Your program should be able to identify the location of the character in the phrase
i already found this code of program
/* strchr example */
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] = "This is a sample string";
char * pch;
printf ("Looking for the 's' character in \"%s\"...\n",str);
pch=strchr(str,'s');
while (pch!=NULL)
{
printf ("found at %d\n",pch-str+1);
pch=strchr(pch+1,'s');
}
return 0;
}
but the main problem that my lecturer want is, he want me to search an alphabet and display the location.
the result is the same, but i must make the code as an input from user.
please help me ASAP as i must send this program to him by 11 am.
{
char str[] = "This is a sample string";
char * pch;
printf ("Looking for the 's' character in \"%s\"...\n",str);
pch=strchr(str,'s');
while (pch!=NULL)
{
printf ("found at %d\n",pch-str+1);
pch=strchr(pch+1,'s');
}
return 0;
}
We have started the second iteration of the loop that will be infinite until you will try to do something yourself.
I am not going to write the code instead of you.