The problem is that the csv file has more things than numbers that you will not be able to read with %d
. Although I may try to change your algorithm for this case, for example with sscanf
I think it's easier follow another path.
Using the same idea as this my other answer can do so:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *in = fopen("BTH.csv", "r");
fseek (in, 0, SEEK_END); //posicionar-se no fim
long dimensao = ftell (in); //descobrir a dimensão
fseek (in, 0, SEEK_SET); //voltar ao inicio
//alocar espaço para ler tudo
char *dados = (char*) malloc(dimensao * sizeof(char));
if(dados){ //se conseguiu alocar
fread (dados, 1, dimensao, in); //ler tudo
FILE *out = fopen("novo.csv", "w"); //abrir o destino para escrita
fwrite(dados, dimensao, 1 , out); //escrever todo o conteudo
fclose(out);
}
fclose(in);
return 0;
}
You have several other alternatives, such as executing a file copy by the operating system with the appropriate command.
It would also be relevant to write its error messages either for when it was unable to allocate the required reading space, or for when the opening of any of the FILE*
was unsuccessful.