This is my last C code:
int main(int argc, char *argv[]){
if(argc < 3 || argc > 3){ //Si no se le pasa el nombre del archivo
Uso(argv[0]); //Se muestra la ayuda de cómo usar el programa
exit(1);
}
//system("clear"); Limpiamos la consola
FILE *fps, *fpd;
int linea = 2, fin = 0, opswitch=0;
char temp1[80]="", temp2[80]="", temp3[80]="", apost[5]="’", punt[3]="·", opcion[5]="", paraula[20]="", etiqueta[10]="", generic[20]="";
if((fps = fopen(argv[1], "r")) == NULL){ //Si el archivo no se abre correctamente
return(-1);
}
if((fpd = fopen(argv[2], "w+")) == NULL){
return(-1);
}
fgets(temp1, 80, fps);
fgets(temp2, 80, fps);
fgets(temp3, 80, fps);
do{
//Tiene apóstrofe y marca de error Fz
if((strstr(temp2, apost)) != NULL && (strstr(temp2, "Fz")) != NULL){
//printf("%d******\n1[%c - %c] 3[%c - %c] \n",linea, temp1[0], temp1[1], temp3[0], temp3[1]);
//printf("%s\n%s\n%s\n", temp1, temp2, temp3);
//Apóstrofe delante
if(temp1[0]=='s' && temp1[1]=='\t'){ fprintf(fpd, "%s", "s’\tP0300000\tes\n");}
if(temp1[0]=='m' && temp1[1]=='\t'){ fprintf(fpd, "%s", "m’\tPP1CS000\tjo\n");}
if(temp1[0]=='d' && temp1[1]=='\t'){ fprintf(fpd, "%s", "d’\tSPS00\tde\n");}
if(temp1[0]=='t' && temp1[1]=='\t'){ fprintf(fpd, "%s", "t’\tPP2CS000\ttu\n");}
if(temp1[0]=='l' && temp1[1]=='\t'){
printf("- S'ha trobat una ela apostrofada a la linea %d\n", linea);
printf("La linea següent diu:\t%s\n", temp3);
//Elegir una de las opciones
printf("Tria una opció:\n\t1) l’\tDA0CS0\tel\n\t2) l’\tDA0FS0\tel\n\t3) l’\tPP3MSA00\tell\nOpció:");
do{
scanf("%d", &opswitch);
if(opswitch <1 || opswitch >3) printf("Trieu una de les opcións posibles. Opció:");
}while(opswitch !=1 && opswitch!=2 && opswitch !=3);
switch(opswitch){
case 1: fprintf(fpd, "%s", "l’\tDA0CS0\tel\n"); break;
case 2: fprintf(fpd, "%s", "l’\tDA0FS0\tel\n"); break;
case 3: fprintf(fpd, "%s", "l’\tPP3MSA00\tell\n"); break;
}
}
//Apóstrofe detrás
if(temp3[0]=='l' && temp3[1]=='\t'){ fprintf(fpd, "%s", "’l\tPP3MSA00\tell\n");}
if(temp3[0]=='t' && temp3[1]=='\t'){ fprintf(fpd, "%s", "’t\tPP2CS000\ttu\n");}
if(temp3[0]=='n' && temp3[1]=='\t'){ fprintf(fpd, "%s", "’n\tPP3CN000\ten\n");}
}
//Tiene punto medio y marca de error Fz
if((strstr(temp2, punt)) != NULL && (strstr(temp2, "Fz")) != NULL){
printf("- S'ha trobat una ela geminada a la linea %d\n", linea);
printf("La linea previa diu:\t%s", temp1);
printf("La linea següent diu:\t%s\n", temp3);
do{
//El usuario pone la línea manualmente
printf("\tFica la paraula:");
scanf("%s", paraula);
printf("\tFica l'etiqueta:");
scanf("%s", etiqueta);
printf("\tFica el genèric:");
scanf("%s", generic);
printf("\n%s\t%s\t%s\nVols agregar-la així?\t",paraula,etiqueta,generic);
scanf("%s", opcion);
}while(strcmp(opcion,"si"));
fprintf(fpd, "%s\t%s\t%s\n", paraula, etiqueta, generic);
}
else{
//TODO: Escribir la linea tal cual, cambiando el orden y quitando los números
fprintf(fpd, "%s", temp2);
}
strcpy(temp1,temp2);
strcpy(temp2,temp3);
if(fgets(temp3, 80, fps)==NULL) ++fin;
++linea;
}while(fin <= 3);
if(fps) fclose(fps); //Cerramos los 2 archivos si están abiertos
if(fpd) fclose(fpd);
}