Hi, I'm new to the forum, and really new to C, but I'd like to get better...
I'm trying to read information from a text file with headers and info as well.
The header is printing fine, but the info is not. The strings comes out perfectly, but the integers aren't.
Any help would be appreciated.
Here's the code:
Everythings inside of a function and the main only contains the call to those function
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define text 200
#define inti 200
void printSummary()
int main()
{
printSummary();
}
void printSummary() {
char month[text];
char date[text];
char day[text];
char activity[text];
char repetitions[text];
FILE *fptr;
char filename[20];
int i;
int dater2[inti];
int reps[inti];
printf("Please enter filename [.txt]: ");
scanf("%s", filename);
fptr = fopen(filename,"r");
if (fptr != NULL)
{
printf("\n");
fscanf(fptr,"%s %s %s %s %s", month, date, day, activity, repetitions);
printf ("%s %s %s %s %s\n", month, date, day, activity, repetitions);
for (i=0; i<8; i++)
{
fscanf(fptr, "%s %d %s %s %d", month, dater2, day, activity, reps);
printf("%s %d %s %s %d\n", month, dater2, day, activity, reps);
}
}
else
{
printf("File cannot be opened");
}
}
Yes, I know the for loop initializes the i, but somehow the compiler gave me an error stating the i wasn't initialized, even though it was in the for loop :S
Any help would be appreciated, if you need any more info feel free to ask!
Oh and here's the ouput
http://img444.imageshack.us/img444/8535/capturell.png