Search Sub String

Q. Write a C program to accept two string from user and find sub string from main string.

For example:

main string: This is a good program
sub string: is
result: 2


/*c program to find how many times sub string found in main string*/
int main()
 int i,j,count=0;
 char str[40],fstr[10];
 printf("Enter main string: ");
 printf("Enter sub string: ");
 for(i=0; str[i]!='\0'; i++)
   for(j=0; str[i]==fstr[j] && fstr[j]!='\0'; i++,j++);
 return 0;


Output of search sub-string from main string C program
Screen shot of find sub-string in main string C program

Related programs:

  1. Reverse all string
  2. Reverse all words but not string
  3. Reverse each first character of word & add extra word
  4. Display string vertically
  5. Change title case of string
  6. Position and repetition of character in string
  7. Search sub string individual from main string

No comments:

Post a Comment