char filenames[1000];
memset(filenames, 0, 1000);
printf("Enter filenames:\n");
read(0, filenames, 1000);
char* part1 = "file ";
char* part2 = "| grep 'C source' | wc -1";
char* result = malloc(strlen(part1) + strlen(filenames) + strlen(part2) + 1);
memset(result, 0, strlen(part1) + strlen(filenames) + strlen(part2) + 1);
memcpy(result, part1, strlen(part1));
memcpy(result + strlen(part1), filenames, strlen(filenames));
memcpy(result + strlen(part1) + strlen(filenames), part2, strlen(part2));
printf(result);
system(result);
Enter filenames:
nginx.info abc.c
file nginx.info abc.c
nginx.info: ASCII text
abc.c: C source, ASCII text
sh: 2: Syntax error: "|" unexpected