Thread: menu driven program using file

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    1

    menu driven program using file

    Hi!
    i am told to write a program using file,nd structures that contain student database usin add,modify,search,display functions.
    i wrote add function but unable to write modify,serach,display.plz help its urgent
    insert
    Code:
    #include<stdio.h>
    struct student3
     {
      int age;
      int marks;
      char name[11];
     int roll;
      };
      add();
    main()
     {
       add();
      } 
      
      
      add()
       {
        FILE *fp;
        int i,n;
        struct student3 s[100];
        printf("enter no. of students");
        scanf("%d",&n);
        printf("name,roll,marks,age");
        for(i=0;i<n;i++)
        scanf("%s %d %d %d",s[i].name,&s[i].roll,&s[i].marks,&s[i].age);
        fp=fopen("student4.dat","w");
        fwrite(s,sizeof(struct student3),n,fp);
        fclose(fp);
       }

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    At first, a typical main structure is like this
    Code:
    int main(void)
    {
         ....
         return 0;
    }
    For the display , use fread function, to fetch data from the file into a buffer and then print them with printf.
    An alternative solution would be to use fprintf to print directly from the file.The first approach is more simple in my mind.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    An alternative solution would be to use fprintf to print directly from the file
    No, fprintf will write formatted output to a file, not from a file. Printing from a file describes something that the C standard library doesn't really provide in a single function.

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    .plz help its urgent
    I don't care if its urgent mate - thats your problem alone. This board is not for people that cannot manage their time and do the required study - you have no chance of succeding at programming if you cannot get a grip on the above.
    Last edited by rogster001; 11-18-2012 at 07:16 AM. Reason: typo
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by whiteflags View Post
    No, fprintf will write formatted output to a file, not from a file. Printing from a file describes something that the C standard library doesn't really provide in a single function.
    Correct.My mistake

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. menu driven program
    By tgarrisoniv in forum C Programming
    Replies: 14
    Last Post: 03-06-2012, 01:47 PM
  2. Menu driven program
    By kenadams in forum C Programming
    Replies: 9
    Last Post: 10-27-2011, 01:38 AM
  3. menu driven program help
    By vallamrao in forum C Programming
    Replies: 2
    Last Post: 09-10-2010, 04:56 AM
  4. C menu driven program
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 04-25-2002, 08:56 AM

Tags for this Thread