I have a file In this format:
link (link to download the file read);
[105][32][55][10][32][32][32][32][32][32][32][32][32][32][32][32][32][32][32][32][32][82][101][108][101][97][115][101]...
I need to read the data in this format:
105 32 55 10 32 32 32 32 32...[32][32][32][32][32][32][32][32][32][32][32][32][82][101][108][101][97][115][101]...
I'm using the code trick:
while( c != EOF) {
fscanf(ler, "%c", &c);
fscanf(ler, "%d", &num);
fscanf(ler, "%c", &a);
fprintf(traduzido, "%d ", num);
}
But looping never closes, I'm also using this:
while(fscanf(ler, "%c", &c) && fscanf(ler, "%d", &num) && fscanf(ler, "%c", &a) != EOF) {
fprintf(traduzido, "%d ", num);
}
But it does not stop reading the file, it always goes from two to three lines.
What is the error and why of the error? How can I read this file and leave it as I want, if I have an easier way?
Look at the code completely:
int main(void)
int num;
char c;
FILE *ler;
FILE *traduzido;
ler = fopen("readme.code.txt", "r");
traduzido = fopen("traduzido.txt", "w");
if(ler == NULL || traduzido == NULL) {
printf("Erro Na aberura do Arquivo");
}
while(1) {
if (fscanf(ler, "%c", &c) <= 0){
break;
}
fscanf(ler, "%d", &num);
fscanf(ler, "%c", &c);
fprintf(traduzido,"%d ", num);
}
while(fscanf(traduzido, "%d", &num) != EOF) {
printf("%c", num);
}
system("pause");