Search Sub String individual

Q. Write a C program to accept two string from user, first is main string and second is searching sub string from main string, and count how many times its repeat individual in main string.
Q. WAP to accept two string and find out how many times individual sub-string found in main string.

For example:

First main string: This is a good program
Second search string: is
Result: 1


/*c program for search sub string from main string and counting how many times its repeat individual*/
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++)
  if(str[i-1]==' ')
    for(j=0; str[i]==fstr[j] && fstr[j]!='\0'; i++,j++);
 return 0;


Output of search individual sub string from main string C program
Screen shot for search sub-string individual from main string

Related Programs:

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

No comments:

Post a Comment