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

#include<stdio.h>
#include<stdlib.h>

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",
                  stu1.firstname,stu1.lastname,&stu1.entry.hh,&stu1.entry.mm,&stu1.leavetime.hh,&stu1.leavetime.mm,
                  &stu1.dt.day,&stu1.dt.month,&stu1.dt.year,&stu1.bno,&stu1.rno);
fclose(file);
    printf("%s %s %d:%d %d:%d %d/%d/%d %d %d",
                  stu1.firstnamename,stu1.lastname,stu1.entry.hh,stu1.entry.mm,stu1.leavetime.hh,stu1.leavetime.mm
                  ,stu1.dt.day,stu1.dt.month,stu1.dt.year,stu1.bno,stu1.rno);

return(0);
}   

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, networking, learning, and sharing knowledge.