- #1
Spectre32
- 136
- 0
Loading a File in C
Ok here is my code:
Yeah I know its on the large size but I'm kinda confused. My professor gave us that whole File loading thing,a nd i created a data file from notepad. When i run to the program It just sits there and does nothing. So i started to debug and added printf's in those lines. the last line that the printf worked on was the one prior to the return statement, now perhpas my data format is incorrect, but I'm pretty sure I'm straight with that. Does anyone have any Ideas?
Ok here is my code:
Code:
FILE *fReadOpen( void )
/*
purpose: open file for reading
goal state: fReadOpen returns pointer to file
*/
{ /* begin fReadOp */
/* data object declarations */
char FileName[80]; /* input file name */
FILE *pInFile; /* file pointer */
int NoSuchFile; /* logical check for FileName existence */
/* algorithm */
printf( "\nPlease enter the file name to open for reading.\n ==> " );
do
{ /* get FileName */
fflush( stdin );
scanf( "%[^\n]", FileName );
fflush( stdin );
/* check for existence */
NoSuchFile = ( (pInFile = fopen( FileName, "r" ) ) == NULL );
/* print message if file not found */
if ( NoSuchFile )
{ /* begin if NoSuchFile */
printf( "\n%s not found."
"\nPlease input valid file name.\n ==> ", FileName );
} /* end if NoSuchFile */
}
while ( NoSuchFile );
return( pInFile );
} /* end fReadOpen */
//********************************************************************
void get_data( double input_val[], int *parray_int)
/*
purpose: continue on with file opening process
goal state: return an array with via the point array_int
*/
{ // begin get_data
// variable dictionary
double acquire; // being read by fscanf
double value = 0; // "value" for the fscanf statement
FILE *pInfile; // file from above function
// algorithm
// open file for reading
pInfile = fReadOpen();
// loop for reading values
*parray_int = 0;
do
{
acquire = fscanf(pInfile,"%f", &value);
if (acquire == 1)
{
input_val[*parray_int] = value;
*parray_int = *parray_int + 1;
}
} while (acquire == 1);
// close file
fclose( pInfile );
} // end get_data
Yeah I know its on the large size but I'm kinda confused. My professor gave us that whole File loading thing,a nd i created a data file from notepad. When i run to the program It just sits there and does nothing. So i started to debug and added printf's in those lines. the last line that the printf worked on was the one prior to the return statement, now perhpas my data format is incorrect, but I'm pretty sure I'm straight with that. Does anyone have any Ideas?
Last edited: