Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- printf("Saved grandchild %d pid %dn", q,grandchild_pid[q]);
- ./cript_p -c 3 filein fileout
- void encriptarM(char message[], int inicio, int nc){
- int fin = inicio+nc;
- int aux = inicio;
- for (inicio; inicio<fin; inicio++){
- if(message[inicio]=='m' || message[inicio]=='M'){
- message[inicio]=48;
- }
- if(message[inicio]=='u' || message[inicio]=='U'){
- message[inicio]=49;
- }
- if(message[inicio]=='r' || message[inicio]=='R'){
- message[inicio]=50;
- }
- if(message[inicio]=='c' || message[inicio]=='C'){
- message[inicio]=51;
- }
- if(message[inicio]=='i' || message[inicio]=='I'){
- message[inicio]=52;
- }
- if(message[inicio]=='e' || message[inicio]=='E'){
- message[inicio]=53;
- }
- if(message[inicio]=='l' || message[inicio]=='L'){
- message[inicio]=54;
- }
- if(message[inicio]=='a' || message[inicio]=='A'){
- message[inicio]=55;
- }
- if(message[inicio]=='g' || message[inicio]=='G'){
- message[inicio]=56;
- }
- if(message[inicio]=='o' || message[inicio]=='O'){
- message[inicio]=57;
- }
- }
- }
- void encriptar(char message[], int inicio, int nc){
- int fin = inicio+nc;
- int aux = inicio;
- char ch;
- for(inicio; inicio<fin; inicio++){
- ch = message[inicio];
- if(ch >= 'a' && ch <= 'z'){
- ch = ch + 2;
- if(ch > 'z'){
- ch = ch - 'z' + 'a' - 1;
- }
- message[inicio] = ch;
- }
- else if(ch >= 'A' && ch <= 'Z'){
- ch = ch + 2;
- if(ch > 'Z'){
- ch = ch - 'Z' + 'A' - 1;
- }
- message[inicio] = ch;
- }
- }
- }
- void concatChildren(char message[], char salida[], pid_t children[], int niveles){
- FILE *fp;
- FILE *gc;
- char texto[1500];
- char name[50];
- fp = fopen(salida, "w");
- for(int inicio; inicio<niveles; inicio++){
- strcpy(name,"");
- sprintf(name, "%d", children[inicio]);
- strcat(name,".txt");
- gc = fopen(name, "r");
- while (!feof(gc)){
- fgets(texto, 1500, gc);
- }
- fclose(gc);
- fprintf(fp, "%s", texto);
- }
- fclose(fp);
- }
- void childFIle(char message[], pid_t child, int nc){
- int fin = nc;
- FILE *fp;
- char name [50];
- char texto [500];
- sprintf(name, "%d", child);
- strcat(name,".txt");
- fp = fopen(name, "r");
- while (!feof(fp)){
- fgets(texto, 500, fp);
- }
- encriptarM(texto,0,nc);
- fclose(fp);
- fp = fopen(name,"w");
- for(int inicio = 0; inicio<=fin; inicio++){
- fprintf(fp, "%c", texto[inicio]);
- }
- fclose(fp);
- }
- void concatGrandChildren(char message[], pid_t child, pid_t grandChildren[], int niveles){
- FILE *fp;
- FILE *gc;
- char name [50];
- char texto[50];
- sprintf(name, "%d", child);
- strcat(name,".txt");
- //printf("Nombre de archivo hijo es %sn", name);
- fp = fopen(name, "w");
- for(int inicio; inicio<niveles; inicio++){
- strcpy(name,"");
- sprintf(name, "%d", grandChildren[inicio]);
- strcat(name,".txt");
- gc = fopen(name, "r");
- while (!feof(gc)){
- fgets(texto, 50, gc);
- }
- fclose(gc);
- fprintf(fp, "%s", texto);
- }
- fclose(fp);
- }
- void grandChildFIle(char message[], pid_t grandChild, int inicio, int nc){
- int fin = inicio+nc;
- int aux = inicio;
- FILE *fp;
- char name [50];
- sprintf(name, "%d", grandChild);
- strcat(name,".txt");
- //printf("Nombre de archivo es %sn", name);
- fp = fopen(name, "w");
- for(inicio; inicio<=fin; inicio++){
- fprintf(fp, "%c", message[inicio]);
- }
- fclose(fp);
- }
- void llenarVector(FILE *e, char texto [], int n) {
- int l;
- while (!feof(e)){
- fgets(texto, 1000, e);
- }
- l = strlen(texto);
- printf("%sn", texto);
- printf("%dn", l);
- fclose(e);
- }
- void abrirArchivoEntrada (char * nombre, char texto[], int n){
- FILE *e;
- e = fopen(nombre, "r");
- if (e == NULL)
- {
- printf("errorn");
- }
- else {
- printf("successn");
- llenarVector(e,texto,n);
- }
- }
- void slice(char vector[], int length, int niveles, int inicio, int nc){
- }
- int removeSpace(char * vector, int length){
- // To keep track of non-space character count
- int count = 0;
- // Traverse the given string. If current character
- // is not space, then place it at index 'count++'
- for (int i = 0; vector[i]; i++)
- if (vector[i] != ' ')
- vector[count++] = vector[i]; // here count is
- // incremented
- vector[count] = '