Problems creating CSV file with column of numbers as input
I'm trying to create a CSV file with my input file being 400 numbers, one on each line. When I run the program I get strange output in my CSV file. Any help would be appreciated. Thank you very much!
Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *inputFile;
FILE *CSVFile;
char buff[400];
int i=0;
int c=0;
inputFile= fopen("pix.txt", "r");
CSVFile= fopen("csv.txt", "w");
if(inputFile==NULL)
printf("File not found");
else
while(c<400){
buff[c]=getc(inputFile);
c++;
}
i=0;
c=0;
while(c<400){
putc(buff[c],CSVFile);
c++;
i++;
if(i<20)
{
putc(',',CSVFile);
}
else
{
putc('\n',CSVFile);
i=0;
}
}
system("PAUSE");
return 0;
}