I'm trying to make a program for my 101 class that reads from a file using functions for each struct type and prints the file out to the screen. Unfortunately, I don't know how to make it continuously read from the file when I'm using fscanf in different functions. Sorry I know, not a very good explanation of my problem, but hopefully you'll understand from my code.

Open the file in main, and pass the FILE pointer around to each function.

And the warning means just what it says: the official 1990 standard for the C language forbids variable declarations mixed in with code.

12-03-2008

matsp

If production date and purchase date are part of the car itself, perhaps you want to put those into the autoT type. I would also use a struct with year, month, day in it, and not have the two dates in one structure - that way, you could have ONE function that reads a date, and call it twice, instead of repeating the same bit of code twice in the same function.

awesome! i didn't know (didn't even try for some reason) that you could pass the FILE pointer. Thanks a bunch! Program works like a charm now, except for some minor cleaning up to do.

12-03-2008

slingerland3g

If you are familiar with how the "infile.txt" is structured there is no need to then create a FILE handle within each of your function calls. Just pass a reference to the input FILE handle variable to each of your function calls. You will need to redefine your prototypes for the functions though.

This way you are not needing to start reading from the file from the beginning each time.

12-03-2008

bchan90

i actually had to change that part of my code cause it wasn't looping correctly...i had to run the scan functions before checking for EOF so my while loop ends up looking like this