•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,530 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,812 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 293 | Replies: 1
![]() |
•
•
Join Date: Oct 2007
Posts: 4
Reputation:
Rep Power: 0
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.
//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
struct inFile
{
char itemNumber[32];
int timeToFinish;
int elapsedMinutes;
};
typedef struct inFile inFile;fscanf(fn, "%s, %d, %d,", inFile.itemNumber[i], inFile.timeToFinish[i], inFile.elapsedMinutes[i]);
char itemNumber[10];
int timeToFinish = 0;
int elapsedMinutes = 0; At the very moment that I find myself in the side of the mayority, I will know that I need to re-think my ideas. ~ In my book.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
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



Linear Mode