Skip to content

Instantly share code, notes, and snippets.

@Riateche
Last active December 10, 2015 04:08
Show Gist options
  • Save Riateche/4378812 to your computer and use it in GitHub Desktop.
Save Riateche/4378812 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
int main() {
int fd[2], kol = 0, i;
char instr[30], outstr[30], symb;
pid_t childpid;
pipe(fd);
if ((childpid = fork()) == -1) {
perror("fork");
exit(1);
} else if (childpid == 0) {
FILE *fil;
fil = fopen("fil.txt", "r");
while (fgets(instr, 30, fil) != NULL) {
write(fd[1], instr, sizeof(char) * strlen(instr));
}
close(fd[0]);
exit(0);
} else {
close(fd[1]);
printf("Введите букву: \n");
scanf("%c", &symb);
while(read(fd[0], outstr, 30) != 0) {
for (i = 0; i < strlen(outstr); i++) {
if (outstr[i] == symb) { kol++; }
}
}
printf("result = %i\n", kol);
}
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment