I'm trying to write an Excel archive(input) into an empty archive. The aim is to write a new Excel without the dates, but when I try, the new archive is erasing some lines in the excel and not erasing the dates as I wanted to. Is it something with the code?
Input
1760
02/20/18,11403.7
02/19/18,11225.3
02/18/18,10551.8
02/17/18,11112.7
02/16/18,10233.9
02/15/18,10166.4
02/14/18,9494.63
02/13/18,8598.31
Actual Output
1760
02/20/18
11403.7
02/19/18
11225.3
02/18/18
10551.8
02/17/18
11112.7
02/16/18
10233.9
02/15/18
10166.4
02/14/18
9494.63
02/13/18
8598.31
Expected Output
1760
11403.7
11225.3
10551.8
11112.7
10233.9
10166.4
9494.63
8598.31
This is my code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main(int argc,char **argv){
FILE *btc;
FILE *out;
if((out = fopen("new.csv", "w")) == NULL ){
printf("not found new\n");
exit(1);
}
if((btc = fopen("BTC.csv", "r")) == NULL ){
printf("not found btc\n");
exit(1);
}
long int a;
char linha[256];
char *token = NULL;
while (!feof(btc))
{
fgets(linha, 256, btc);
token = strtok(linha, ",\n");
while ((token != NULL) && (!feof(btc)))
{
a++;
fprintf(out, "%s\n", token);
token = strtok(NULL, " \n");
}
}
fclose(btc);
fclose(out);
return 0;
}