Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2008
    Location
    delhi
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question file handling in c

    hi...i tried a simple code in file handling that inputs name roll no. and cgpa of a student in a structure and saves it in a file and then displays it
    but the progarm is not giving the desired output.pls help..i m new in the programing scene.
    here is the code:
    Code:
    #include<stdio.h>
     #include<conio.h>
     struct student
     {
     int rolno;
     char name[20];
     float cgpa;
     }s[10];
     void main()
     {
     struct student s[10];
     FILE *fp;
     int i;
     clrscr();
     for(i=0;i<10;i++)
     {
     printf("enter rolno");
     scanf("%d",&s[i].rolno);
     printf("name");
     gets(s[i].name);
     printf("cgpa");
     scanf("%f",&s[i].cgpa);
     }
     fopen("c:\\S.DAT","w+");
     fwrite(s,sizeof(struct student),10,fp);
     rewind(fp);
     for(i=0;i<10;i++)
     {
     fprintf(fp,"%d %s %f \n" , s[i].rolno,s[i].name,s[i].cgpa);
     }
     fclose(fp);
     }
    Last edited by Millenia; 11-16-2008 at 08:10 PM.

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Lost in Localhost...
    Posts
    702
    Thanks
    3
    Thanked 43 Times in 42 Posts
    Can you be more specific about you're problem? In more detail
    Also can you wrap you're code in [code] tags please
    Thanks

  • #3
    New Coder
    Join Date
    Nov 2008
    Location
    delhi
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the problem is tht i m trying to print wotevr is stored in the file but actually it is nt diaplayed on the screen


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •