C++ File Input in Xcode
#include <stdio.h>
#include <string.h>
struct student
{
char studentID [4+1];
char firstname [25+1];
char lastname [25+1];
int grade;
char dob [10+1];
};
struct course
{
char code [5+1];
char name [50+1];
int grade;
float credit;
};
int main (void)
{
student people[4];
int x;
x=0;
FILE *fp;
fp=fopen ("Student.txt", "r");
if (fp!=NULL)
{
printf("Got here");
while (x<5)
{
printf ("hi");
fscanf (fp, "%s, %s, %s, %d, %s", people[x].studentID, people[x].firstname, people[x].lastname, people[x].grade, people[x].dob);
printf("ID: %s, Name: %s, %s, Grade: %d, DOB: %s", people[x].studentID, people[x].lastname, people[x].firstname, people[x].grade, people[x].dob);
x++;
}
fclose (fp);
}
}
2 GHz Intel Macbook White, Mac OS X (10.5.3)