// Write a C program that reads in words from standard input until Ctrl+D, // and checks whether a word read in as a command line argument is a substring // in the word. If so, then the word that was read in should be printed again // Assume max length of strings read is is 100 characters // $./array_substring courage age bloom encourage // blooming // blooming // potato // encourage // encourage // rage // rage // egg #include #include #define MAX 100 int main(int argc, char *argv[]) { char line[MAX]; while (fgets(line, MAX, stdin) != NULL) { int len = strlen(line); if (len > 0 && line[len - 1] == '\n') { len--; } int found = 0; int i = 1; while (i < argc) { // is argv[i] a substring of line? int arg_len = strlen(argv[i]); int j = 0; while (j <= (len - arg_len)) { if (strncmp(&line[j], argv[i], arg_len) == 0) { found = 1; } j++; } i++; } if (found == 1) { printf("%s", line); } } return 0; }