// Problem 14: Write a C program that reads in words until // Ctrl+D, and checks whether a word read // in as a command line argument appears in the main word. // If it appears, print it again. #include #include #define MAX 100 void find_substring(char main_word[MAX], char word[MAX]); int main(int argc, char *argv[]) { char word[MAX]; while (fgets(word, MAX, stdin) != NULL) { word[strlen(word) - 1] = '\0'; find_substring(argv[1], word); } // PUT YOUR CODE HERE return 0; } void find_substring(char main_word[MAX], char word[MAX]) { int main_length = strlen(main_word); int length = strlen(word); int found = 0; for(int i = 0; i < main_length; i++) { found = 1; for (int j = 0; j < length; j++) { if (main_word[i + j] != word[j]) { found = 0; break; } } if (found) { printf("String found\n"); return; } } printf("String not found\n"); }