Okay, here is some low hanging fruit.
I have a text file with a million rows (1 record per row). Each record is a string consisting of numbers, followed by an asterisk, followed by a single space. Each row is terminated with a carriage return+Line Feed. I need to create a second file that consists of all these records on one row.
Here is what I have so far. The best I have been able to figure out is how to copy the contents of the source file into the new file.
Thanks for the help!!
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#define ARSIZE 16
#define SRCNAME "C:\\ValidCust.txt"
#define DSTNAME "C:\\newcust.txt"
int main()
{
FILE *readfile;
FILE *writefile;
char buffer[ARSIZE];
errno = 0;
readfile = fopen( SRCNAME, "r" );
writefile = fopen( DSTNAME, "w" );
if( readfile == NULL || writefile == NULL )
fprintf(stderr,
"Open file error: %d, \"%s\"\n",
errno,
strerror( errno )
);
while( fgets( buffer, sizeof( buffer ), readfile ) != NULL )
{
fputs( buffer, writefile );
}
fclose( readfile );
fclose( writefile );
return EXIT_SUCCESS;
}