Last active
October 21, 2021 16:03
-
-
Save DominusDrow/fd1b3a98e3f42b210f74ca3a4ca9782a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <signal.h> | |
#include <unistd.h> | |
#include <sys/types.h> | |
//variable para armar señal | |
char* nameFile; | |
void printResult(){ | |
printf("el resultado se guardo en el archivo %s\n",nameFile); | |
exit(0); | |
} | |
int main(int argc, char* argv[]){ | |
int pid; | |
char c; | |
if(argc > 1){ | |
pid = fork(); | |
if(pid == -1) | |
perror("no se pude crear hijo"); | |
else if(pid == 0){ | |
signal(SIGINT, printResult); | |
nameFile = (char*)malloc(10*sizeof(char)); | |
nameFile = "result.txt"; | |
FILE* fileR = fopen(argv[1],"r"); | |
FILE* fileW = fopen(nameFile, "w"); | |
while ((c = fgetc(fileR)) != EOF) | |
if( (c >= '0' && c<='9') || (c >= 'a' && c <= 'z')) | |
fprintf(fileW, "%c",c); | |
fclose(fileR); | |
fclose(fileW); | |
pause(); | |
} | |
else | |
sleep(1); | |
kill(pid, SIGINT); | |
} | |
else | |
printf("\nNo se ingreso nombre del archivo\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment