i am writing this code for a school poject it gives mee segmentation fault .please help
it scans iput of the form


struct time{
int hh,mm;

struct date{
int day,month,year;

struct student{
char firstname[20];
char lastname[20];
struct time entry;
struct time leavetime;
struct date dt;
int bno;
int rno;

int main(void)
    struct student stu1;
    FILE *file;
    file = fopen("inpt.txt", "r");

    fscanf(" %s %s %2d:%2d %2d:%2d %2d/%2d/%4d %3d %3d",
    printf("%s %s %d:%d %d:%d %d/%d/%d %d %d",


Alex Smith 10:00 12:00 24/08/2012 342 618

At line 28 you open a file, so presumably you want to read from file.

But at line 30 you use fscanf, and the first parameter should be the file, not the string.

file = fopen("inpt.txt", "r");
fscanf(file," %s %s %2d:%2d %2d:%2d %2d/%2d/%4d %3d %3d",etc etc etx

And make sure that the file includes the text and numbers in the correct order...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.