Monday, 30 November 2015

File handling program for B.Tech(CSE) students

#include<stdio.h>
#include<conio.h>

void main()
{
FILE* fp;
char ch;
fp=fopen("ABC.txt","w");
if(fp==NULL)
{
printf("File Doesn't exist");
exit(1);
}
fputs("Hello World",fp);
fclose(fp);
fp=fopen("ABC.txt","r");
if(fp==NULL)
{
printf("File Doesn't exist");
exit(1);
}
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
{
break;
}
printf("%c",ch);
}
fclose(fp);
getch();
}

No comments:

Post a Comment