I'm trying to read 400 numbers from a file with one single-digit number on each line. I need to read the numbers into a file with 20 on each line, separated by commas. When I run what I have now I get a bunch of garbage characters in my CSV file.
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *inputFile;
FILE *CSVFile;
char buff[800];
int i=0;
int c=0;
int byte=0;
inputFile= fopen("pix.txt", "r");
CSVFile= fopen("csv.txt", "w");
if(inputFile==NULL)
printf("File not found");
else
byte=fread(buff,sizeof(buff),800,inputFile);
printf("%d",byte);
while(c<800){
if(buff[c]=='\n')
{
buff[c]=',';
c++;
}
else
c++;
}
c=0;
while(c<800){
putc(buff[c],CSVFile);
c++;
}
system("PAUSE");
return 0;
}