i even made a code of my own, but i seem to be having trouble. it is a program to find a word in a string and print its no of occurences without using the find or any string library function.
could you please point me out where i am going to wrong, and help me sort it out.
i will really appreciate it.
#include <stdio.h>
#include <conio.h>
void main()
{
char s[50],ch;
int c=0;
char s2[20],th;
printf("Enter any string : ");
for(int i=0;ch!='\n';i++)
{
ch=getchar();
s[i]=ch;
}
s[i]='\0';
printf("enter word: ");
for(int k=0;th!='\n';k++)
{
th=getchar();
s2[k]=th;
}
s2[k]='\0';
for(i=0;s[i]!='\0';i++){
if (s[i]==s2[i])
while (s[i] !=' ')
{ c++;
while(s[i]==' ')
i++;
}
}
printf("\n\noccurences are %d",c+1);
getch();
}

New Topic/Question
Reply
MultiQuote









|