Thanks Quzah and Koni
I will attempt writing the function prototypes and post what I come up with.
Thanks again for all the help you guys are awesome
DMKanz07
Printable View
Thanks Quzah and Koni
I will attempt writing the function prototypes and post what I come up with.
Thanks again for all the help you guys are awesome
DMKanz07
Code:
/* Fopen opens file; exits program if file cannot be opened */
if ( ( cfPtr = fopen( "unsorted_file.txt", "r" ) ) == NULL ) {
printf( "File could not be opened\n" );
} /* End if */
Does anyone know if it is possible to replace "unsorted_file.txt" in the IF statement with a file name that the user would be prompted for?
i.e Enter the name of the unsorted file?
Thanks
DMKanz07
Of course. the first argument of fopen() is a char pointer. You can either write the filename hardcorded or ask the user to enter the filename and try to open it by giving the string as argument.
would the syntax be fopen ( "%s", filename, '"r" )...
Thanks
DMKanz07
just drop the first argument:Code:FILE* f = fopen (filename, "r" ); // use user-defined (in variable 'filename') filename
// or:
FILE* f = fopen ("myFile.dat", "r" );// use hardcoded one