Thursday, 21 June 2012

write a c program to store the record of student (stud_no,stud_name, address,percentages) in the file using structure


/*write a c program to store the record of student (stud_no,stud_name,
address,percentages) in the file using structure */
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fs;
char an='y';
struct stud
{
int stud_no;
char stud_name[20];
char stud_addr[20];
float per;
};
struct stud s;
clrscr();
fs=fopen("a.txt","w");
if(fs==NULL)
{
printf("source file cannot open");
exit();
}
while(an=='y')
{
printf("\nenter the rollno, number,address,percentages");
scanf("%d%s%s%f",&s.stud_no,&s.stud_name,&s.stud_addr,&s.per);
fprintf(fs,"%d %s %s %f",s.stud_no,s.stud_name,s.stud_addr,s.per);
printf("add another record(y/n)");
fflush(stdin);
an=getch();
}
fclose(fs);
}
/*

enter the rollno, number,address,percentages1 peer sdfa 35                    
add another record(y/n)                                                        
enter the rollno, number,address,percentages4 san sde 89                      
add another record(y/n)                                                        
Type EXIT to return to Turbo C++. . .Microsoft(R) Windows DOS                  
(C)Copyright Microsoft Corp 1990-2001.                                        
                                                                               
C:\TC\BIN>type a.txt                                                          
1 peer sdfa 35.000000
4 san sde 89.000000                                      
C:\TC\BIN>                                                                    
C:\TC\BIN>exit                                                                
*/

No comments: