#include<stdio.h>//header file
#include<conio.h>//header file
void main() //starting of the main() function
{
FILE *fp;
char s[100]; //declaration of the variables
clrscr();
printf("program that can create a file,can insert and read the data");
printf("\n\ncreating a file");
fp=fopen("abc.c","w");
if(fp=='\0')
{
printf("\n\n\n\t\t------------OUTPUT------------");
printf("\n\nfile cannot open"); //printing output
exit(1);
}
printf("\n\n\n\t\t------------INPUT-------------");
printf("\ninsert the data in the file");
printf("\n");
while(strlen(gets(s))>0) //taking input from the user
{
fputs(s,fp);
fputs("\n",fp);
}
fclose(fp);
fp=fopen("abc.c","r");
if(fp=='\0')
{
printf("\n\n\n\t\t------------OUTPUT------------");
printf("\n\ncannot open the file"); //printing output
exit(1);
}
printf("\n\n\n\t\t------------OUTPUT------------");
printf("\n\nthe data is read from the file:");
printf("\n\n");
while(fgets(s,79,fp)!='\0')
{
puts(s); //printing output
}
fclose(fp);
getch();
}