Im a newby to programing 2 months exp.. I am trying to write code in C to take a input string from the user and then the input substring. I wish to compare the substring to the string and count the number of times it apears and print this to the user. After many hours of frustration i have gotten this far any help or derection would be aprieciated [code=c]
# include<stdio.h >
# include<math.h>
# include<stdlib. h>
# include<string. h>
int main(void)
{
char s1[200], s2[200];
char count;
int count2;
int run;
int i;
int j;
int strstrcnt(const char *s1,const char *s2);
char s[200];
printf("\nThis is a program to find certian occurances of words in a user inputed sentence\n");
printf("\nIt will display the number of times the word is found.\n");
printf("\nTo run this program and input the word to find and the sentence to search hit 1,\n\n Hit 2 to exit.\n");
scanf("%d",&run );
fflush(stdin);
while (run==1)
{printf("\nPlea se input the sentence you wish to hae searched.\n");
gets(s1);
printf("\nPleas e enter the word or term you wish to have found in the sentence.\n");
gets(s2);
strstrcnt(s1,s2 );
printf("%d",s1[0]);
}
return(0);}
int strstrcnt(const char *s1,const char *s2)
{
char * strstr(const char *s1, const char *s2);
return (0);}
[/code]
I know gets() is generally bad and know i am missing some code to compleate this just hoping for some derection and clarification.
# include<stdio.h >
# include<math.h>
# include<stdlib. h>
# include<string. h>
int main(void)
{
char s1[200], s2[200];
char count;
int count2;
int run;
int i;
int j;
int strstrcnt(const char *s1,const char *s2);
char s[200];
printf("\nThis is a program to find certian occurances of words in a user inputed sentence\n");
printf("\nIt will display the number of times the word is found.\n");
printf("\nTo run this program and input the word to find and the sentence to search hit 1,\n\n Hit 2 to exit.\n");
scanf("%d",&run );
fflush(stdin);
while (run==1)
{printf("\nPlea se input the sentence you wish to hae searched.\n");
gets(s1);
printf("\nPleas e enter the word or term you wish to have found in the sentence.\n");
gets(s2);
strstrcnt(s1,s2 );
printf("%d",s1[0]);
}
return(0);}
int strstrcnt(const char *s1,const char *s2)
{
char * strstr(const char *s1, const char *s2);
return (0);}
[/code]
I know gets() is generally bad and know i am missing some code to compleate this just hoping for some derection and clarification.
Comment