#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp1;
int ch;
clrscr();
fp1=fopen("test1.txt","w");
if(fp1==NULL)
{
printf("file creation error\n");
getch();
exit();
}
else
{
printf("enter the character\n");
ch=getchar();
while(ch!=EOF)
{
fputc(ch,fp1);
ch=getchar();
}
}
fclose(fp1);
fp1=fopen("test1.txt","r");
if(fp1==NULL)
{
printf("file does not exist\n");
getch();
exit();
}
else
{
ch=fgetc(fp1);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(fp1);
}
}
fclose(fp1);
getch();
}
#include<conio.h>
void main()
{
FILE *fp1;
int ch;
clrscr();
fp1=fopen("test1.txt","w");
if(fp1==NULL)
{
printf("file creation error\n");
getch();
exit();
}
else
{
printf("enter the character\n");
ch=getchar();
while(ch!=EOF)
{
fputc(ch,fp1);
ch=getchar();
}
}
fclose(fp1);
fp1=fopen("test1.txt","r");
if(fp1==NULL)
{
printf("file does not exist\n");
getch();
exit();
}
else
{
ch=fgetc(fp1);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(fp1);
}
}
fclose(fp1);
getch();
}
No comments:
Post a Comment