Tuesday, April 7, 2015

37. Write a program to store std-no, name and marks of ‘n’ students in a data file. 'Display the records in appropriate format reading from the files.


#include <stdio.h>
#include <conio.h>
struct student
{
char name[30];
int marks;
}s[50];
void main()
{
int i,n;
FILE *ptr;
clrscr();
ptr=fopen("Student.txt","w+");
printf("\nHow many students:- ");
scanf(“%d",&n);
printf("\n Input following %d iinformation:- ",n);
for(i=0;i<n;i++)
{
fflush(stdin);
printf("\n Name[%d]:- “,i+l);
gets(s[i].name);
printf("\n Marks[%d]:- ",i+l);
scanf("%d",&s[i].marks);
}
for(i=0;i<n;i++)
fprintf(ptr,"\n%s\t%d",s[i].name,s[i].marks);
printf("\n Name \t Marks");
for(i=0;i<n;i++)
printf("\n%s\t%d",s[i].name,s[i].marks);
fclose(ptr);
getch();
}

No comments:

Post a Comment