Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <sys/file.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <limits.h>
- #include <ctype.h>
- #include <dirent.h>
- #include <string.h>
- char buf[10000];
- int ans;
- int
- main(int argc, char **argv)
- {
- FILE *f;
- char c;
- int cnt;
- int N = atoi(argv[1]), i;
- for (i = 0; i + 2 < argc && i < N; i++) {
- f = fopen(argv[i + 2], "r");
- cnt = 0;
- while (fscanf(f, "%c", &c) > 0) {
- if (c == '\n') {
- buf[cnt] = '\0';
- break;
- }
- buf[cnt++] = c;
- }
- fclose(f);
- if (!fork()) {
- execlp(buf, buf, NULL);
- exit(1);
- }
- }
- int status;
- while (wait(&status) > 0) {
- if (WIFEXITED(status) && !WEXITSTATUS(status)) {
- ans++;
- }
- }
- for (i = N + 2; i < argc; i++) {
- f = fopen(argv[i], "r");
- cnt = 0;
- while (fscanf(f, "%c", &c) > 0) {
- if (c == '\n') {
- buf[cnt] = '\0';
- break;
- }
- buf[cnt++] = c;
- }
- fclose(f);
- if (!fork()) {
- execlp(buf, buf, NULL);
- exit(1);
- } else {
- wait(&status);
- if (WIFEXITED(status) && !WEXITSTATUS(status)) {
- ans++;
- }
- }
- }
- printf("%d\n", ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement