structure problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shardul316
    New Member
    • Jan 2007
    • 20

    structure problem

    i have done the following program of student information.
    when we run the program we enter details of all the 10 students
    and get output details of all the 10students.
    now if we come out of the program i.e execution of program is completed and again we come to the sourse code of the program.
    now my question is what should i do if i have to view the details of
    all the 10 students whose information i have entered earlier?
    is this information (details of 10 students) get stored anywhere?
    Code:
    #include<stdio.h>
    #include<conio.h>
    struct student
       {
       char name[20];
       int roll,age;
       };
    main()
       {
       int i;
       struct student S[10];
       clrscr();
       for(i=0;i<3;i++)
          {
          printf("\nEnter the details of the student : ");
          scanf("%s %d %d",S[i].name,&S[i].roll,&S[i].age);
          }
       clrscr();
       printf("\nThe details of the student are\n");
       for(i=0;i<3;i++)
          {
          printf("\n%s \n%d \n%d\n\n",S[i].name,S[i].roll,S[i].age);
          }
       getch();
       return 0;
       }
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    you need to open an output file and write the records to it, e.g.using fwrite()
    http://www.cplusplus.c om/reference/clibrary/cstdio/fwrite.html

    then you can use fread() to read them back later
    http://www.cplusplus.c om/reference/clibrary/cstdio/fread.html

    Comment

    Working...