Sunday 12 January 2014

c-code to store student information in a text file

#include<stdio.h>
#include<stdlib.h>
struct student{
    int roll;
    int class_no;
    char name[80];
};
int prog9(){
    FILE *fp;
    struct student s;
    char str[120];
    fp = fopen("d:\\recd.text", "a");
    printf("\nenter the roll : ");
    scanf("%d", &s.roll);

    printf("\nenter the class : ");
    scanf("%d", &s.class_no);
   
    fflush(stdin);
    printf("\nenter the name : ");
    gets(s.name);
   
    sprintf(str, "%d    %d    %s", s.roll, s.class_no, s.name);
    fputs(str, fp);
    fclose(fp);
         
    return 0;
}

No comments:

Post a Comment