C Programming Code Examples C > Strings Code Examples C Program to Check if the Substring is present in the given String C Program to Check if the Substring is present in the given String This C Program checks the substring is present in the given string. The program accepts both string and substring. Then checks whether the substring is present in the given string. #include<stdio.h> void main() { char str[100], search[10]; int count1 = 0, count2 = 0, x, j, flag; printf("Enter a string:"); gets(str); printf("Enter search substring:"); gets(search); while (str[count1] != '?') count1++; while (search[count2] != '?') count2++; for (x = 0; x <= count1 - count2; x++) { for (j = x; j < x + count2; j++) { flag = 1; if (str[j] != search[j - x]) { flag = 0; break; } } if (flag == 1) break; } if (flag == 1) printf("SEARCH SUCCESSFUL!"); else printf("SEARCH UNSUCCESSFUL!"); }