Untitled
unknown
plain_text
2 years ago
792 B
4
Indexable
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fptr;
char name[30];
int roll;
char address[50];
float marks;
fptr=fopen("D:\\student.txt","w");
if(fptr==NULL) {
printf("Unable to create or open the file.\n");
exit(0);
}
printf("Enter name of the student: \t");
gets(name);
fflush(stdin);
printf("Enter roll of %s: \t",name);
scanf("%d",&roll);
fflush(stdin);
printf("Enter address of %s: \t",name);
gets(address);
fflush(stdin);
printf("Enter marks of %s: \t",name);
scanf("%f",&marks);
fflush(stdin);
printf("Writing data to file....\n");
fprintf(fptr,"Name=%s \nRoll = %d\n Address=%s\nMarks=%.2f\n",name,roll,address,marks);
printf("\nWriting data to the file completed.");
fclose(fptr);
}
Editor is loading...
Leave a Comment