This is what I have so far, just the only part I was unsure about was the copy the string if and only if it is 10 characters long. As of yet, I have it just copy every string over.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MaxStringLength 512
int main( int argc, char **argv )
{
FILE *fileFrom, *fileTo;
char fileNameFrom[MaxStringLength+1], fileNameTo[MaxStringLength+1];
int holdingTank;
printf( "Enter the name of a file to scan and sort from: " );
fgets( fileNameFrom, sizeof( fileNameFrom ), stdin );
if( fileNameFrom[strlen( fileNameFrom ) - 1] == '\n' )
fileNameFrom[strlen( fileNameFrom ) - 1] = '\0';
else
while( getchar() != '\n' );
fileFrom = fopen( fileNameFrom, "r" );
if( fileNameFrom == NULL )
{
printf( "Unable to open file: %s\n", fileNameFrom );
exit( 1 );
}
printf( "Enter the name of a file to copy the data to: " );
fgets( fileNameTo, sizeof( fileNameTo ), stdin );
if( fileNameTo[strlen( fileNameTo ) - 1] == '\n' )
fileNameTo[strlen( fileNameTo ) - 1] = '\0';
else
while( getchar() != '\n' );
fileTo = fopen( fileNameTo, "w" );
while( 1 )
{
holdingTank = fgetc( fileFrom );
if( holdingTank == EOF || holdingTank == 0 )
break;
fprintf( fileTo, "%c", holdingTank );
}
fclose( fileFrom );
fclose( fileTo );
return( 0 );
}
Just a little bit confused with the copy only string size of 10 over to a new file. Though, thanks for all the help so far!