| | |
small error with structs
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2007
Posts: 4
Reputation:
Solved Threads: 0
I'm back and I 've changed my code around a bit. I almost have it compiling except for one error that says there is a syntax error before inFile my struct that will hold my arrays. It's in the second for loop. I think that I have my struct declared correctly and I think that it will actually hold each line from the text file as an array into my struct. Here's my code
So frustrated because I'm almost there! Just one little error and a couple of my friends couldn't figure it out either.
C Syntax (Toggle Plain Text)
//Struct representing the items in the file struct inFile { char itemNumber[32]; int timeToFinish; int elapsedMinutes; }; typedef struct inFile inFile; int main () { char fileName[100]; int itemAmount = 0; char itemNumber[10]; int timeToFinish = 0; int elapsedMinutes = 0; int i = 0; int readCounter = 0; int finishTime[20];//holds the finish items int counter = 0; // Prompt the user for a filename. printf ("Enter a filename to load: "); scanf ("%s" , &fileName); FILE *fn; fn = fopen(fileName, "r"); // Check to make sure that we opened the file successfully. if (fn != NULL) { fscanf (fn, "%d", &itemAmount);//Scan first line into variable int finishTime[15]; // Initialize it to NULLs /* for (i=0; i<15; i++) { finishTime[i] = NULL; } */ //Loading each item from the file into our array. //while (i <= itemAmount) for (i=0; i<itemAmount; i++) { fscanf(fn, "%s, %d, %d,", inFile.itemNumber[i], inFile.timeToFinish[i], inFile.elapsedMinutes[i]); //HERE I HAVE AN ERROR BEFORE INFILE finishTime[counter] = timeToFinish; counter++; } //Closes the file printf ("\nFile successfully loaded!\n"); fclose(fn); // Print out the array contents. for (readCounter = 0; readCounter < 15; readCounter++) { if (finishTime[readCounter] != 0) { printf("item%d %d %d\n", readCounter, finishTime[readCounter]); } } } else { printf("Error: The file you specified could not be found!"); } system ("PAUSE"); return 0; }
Last edited by Ancient Dragon; Oct 8th, 2007 at 10:39 pm. Reason: correct code tags
C Syntax (Toggle Plain Text)
struct inFile { char itemNumber[32]; int timeToFinish; int elapsedMinutes; }; typedef struct inFile inFile;
C Syntax (Toggle Plain Text)
fscanf(fn, "%s, %d, %d,", inFile.itemNumber[i], inFile.timeToFinish[i], inFile.elapsedMinutes[i]);
C Syntax (Toggle Plain Text)
char itemNumber[10]; int timeToFinish = 0; int elapsedMinutes = 0;
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
![]() |
Similar Threads
- JSP iterator error with structs (JSP)
- in over my head LOST welcha? wininet? (Viruses, Spyware and other Nasties)
- 98% done (C++)
- need help asap :) (Java)
- Need to Preload many Images (and show a wait screen) (JavaScript / DHTML / AJAX)
- Conver int Array into a String (Java)
- MERGED: Deleting duplicates in an array (plz help me out!!!!!!!) (C)
- Asus Mb Beeping!! (Motherboards, CPUs and RAM)
- Error in Wrox Book (Perl)
Other Threads in the C Forum
- Previous Thread: Information on function pointers
- Next Thread: pls help me about my project
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory drawing dynamic fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop interest kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming pyramidusingturboccodes radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab windows.h






