I've wrote this short code to read a text file and copy its information to a new txt file, but doing some character substitution in the process.
My problem is, the code does all the job it is supposed to do but it doesnt end. It cant find the EOF special character at the end of file (arq1) that would tell it to finish processing.
What is the problem?
#include<stdio.h>
#include<stdlib.h>
typedef enum {false, true} Boolean;
int main(){
FILE *arq1, *arq2;
char filename[30];
char first = '*' , second = '*';
Boolean f_use = false, s_use = false;
char aux;
printf("Filename: ");
scanf("%s", filename);
arq1 = fopen(filename, "r");
arq2 = fopen("Codes_out.txt", "w");
while(fscanf(arq1, "%c", &aux) != EOF && aux != '\n')
fprintf(arq2, "%c", aux); /*Copy first line*/
fprintf(arq2, "\n");
while(aux != EOF){ //#
printf("Processing new line\n"); // TEST
f_use = false;
s_use = false;
while(aux != '\t' && aux != ' ' && aux != EOF){ /* Copy locus ID*/
printf("%c", aux);//TEST
fscanf(arq1, "%c", &aux);
fprintf(arq2, "%c", aux);
printf("Copying ID\n");//TEST
}
printf("ID copied\n");//TEST
while(fscanf(arq1, "%c", &aux) != EOF && aux != '\n'){ //##
/*If a code for nitrogen base is found, identify
as first or second state and substitute
for a numeric code (1 or 2)*/
if(aux == 'C' || aux == 'G' || aux == 'A' || aux == 'T' ||
aux == 'c' || aux == 'g' || aux == 'a' || aux == 't'){
if(f_use == false){
/*First base not yet identified*/
first = aux;
f_use = true;
printf("OK 6a\n\n"); //TEST
printf("first = %c\n", first); //TEST
}
else if(s_use == false && aux != first){
/*second base not yet identified
and aux different from first base*/
second = aux;
s_use = true;
printf("OK 6b\n\n"); //TEST
printf("second = %c\n", second); //TEST
}
if(aux == first){
fprintf(arq2, "1");
printf("OK 5a\n\n"); //TEST
}
else if(aux == second){
fprintf(arq2, "2");
printf("OK 5b\n\n"); //TEST
}
}
else if(aux == ' ')
fprintf(arq2, "%c", aux);
else if(aux == 'N' || aux == 'n')
fprintf(arq2, "%c", aux);
else
fprintf(arq2, "3");
} //##
printf("%c ", aux);
fprintf(arq2, "\n"); /*add line break*/
printf("OK 7\n\n"); // //TEST
} //#
printf("Processing finished\n"); //Control
fclose(arq1);
fclose(arq2);
return 0;
}