HELP! Search for a character from the phrase

closed account (DL35Djzh)
hey, can someone make a code for this question.

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've try the arrays but still can't go

There is already such a standard C function that is named strchr.
closed account (DL35Djzh)
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.
closed account (DL35Djzh)
i must change the code of
char str[]="This is a sample string";
to an input from the user.

when i change it, there will be too many error occur.

i am totally lost it to this program.

please help me.
I do not see your code so I can say nothing about your errors. I am not going to write the code instead of you.
closed account (DL35Djzh)
/* 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;
}


can u see the code now?
It is the code that you found somewhere. Does it have errors? I do not take into account that main in C shall be declared as

int main( void )
By the way I think that you should not use the standard function strchr but write it yourself.:)
Good luck!
closed account (DL35Djzh)
im still studying in visual studio c, still a newbie. so i haven't learned to make that advance code. can u help?
I could halp but as I said I do not see your code.
closed account (DL35Djzh)
please give me your email. i'll send my code to you there
lol this is funny :)
closed account (DL35Djzh)
lol me too, wht else cn i do :/
learn lol ;)
closed account (DL35Djzh)
ok lol
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.
closed account (DL35Djzh)
ok guys, pardon fr the weird attitude. i'll try my best
Topic archived. No new replies allowed.