Methods and file pointers
I am pretty confident that I wrote my requestFileName correctly, but my program crashes every time I run it, so I am assuming I wrote out fileScan incorrectly.
Code:
void requestFileName(FILE **fp)
{
char inputFilename[30]; // Character Array to hold the users specified input file name
printf("Enter the name of the file to be scanned: ");
scanf("%s", inputFilename); // Scans the input file specified by the user
printf("\n"); // adds a space in between file names and file statistics
*fp = fopen(inputFilename, "r"); // open the file as read-only
}
/* Stores values from the input file into the variables cityName, population, squareMileafe, pollution,
crime, expense, and highways. */
void fileScan(FILE **fp, char cityName, int population, int squareMileage, int pollution, int crime, int expense, int highways)
{
fscanf(fp, "%s %d %d %d %d %d %d", cityName, population, squareMileage, pollution, crime, expense, highways);
}
In my main method I call fileScan like:
Code:
while(fileScan(&fp, cityName, population, squareMileage, pollution, crime, expense, highways) != EOF) // get next char from input file until we reach EOF
{
//...
}
What am i doing incorrectly?