info@thistimebd.com

Saturday 27th of April 12:53:34am

Write a program that will read your personal information such as name, student id, and home district from the keyboard and save it into a file name myinfo.txt. Then write another program to read information from this txt file and display it as output of your program.

Write a program that will read your personal information such as name, student id, and home district from the keyboard and save it into a file name myinfo.txt. Then write another program to read information from this txt file and display it as output of your program.


Solution:


#include<stdio.h>

int main()

{

FILE *file;

char name[30];

int id,num,i;

char district[15];


file=fopen("myinfo.txt","a");

if(file==NULL)

printf("not");

else

{

printf("File is open ");

printf("Enter of integer number of student ");

scanf("%d",&num);


for(i=0; i<num; i++)

{

printf("Enter student name ");

scanf("%s",&name);

printf("Enter student ID ");

scanf("%d",&id);

printf("Enter student district ");

scanf("%s",&district);

fprintf(file,"%s %d %s ",name,id,district);

}

fclose(file);

}

}