OUTPUT (after running):
Enter 8 numbers:
11
22
33
44
55
66
77
88
Solution 4(b):
#include
#include
void main( )
{
struct
{
char name[30];
int age;
float sal;
} emp;
FILE * fp;
char ch = ‘y’;
if ((fp = fopen(“test.dat”, “wb”)) = =NULL)
{
printf(“\n Cannot open file”);
exit(1);
}
while (ch = = ‘y’)
{
printf(“\n Enter name, age and salary:”);
scanf(“ %s %d %f”, emp.name, &emp.age, &emp.sal);
fwrite(&emp, sizeof(emp), 1, fp);
printf(“\n More records (y/n)?”);
ch = tolower (getche( ));
}
fclose(fp);
}
Do'stlaringiz bilan baham: |