Write a program to write and read a file using byte-level access.
/* Write a program to write and read a file using byte-level access.*/
#include
<stdio.h>
void main()
{
char ch;
FILE *fp;
fp=fopen("a.txt","w");
printf("Enter the contents (End with
Ctrl+Z):\n");
while((ch=getchar())!=EOF)
{
fputc(ch,fp);
}
fclose(fp);
fp=fopen("a.txt","r");
printf("Contents of the file
:\n");
ch=fgetc(fp);
while(!feof(fp))
{
putch(ch);
ch=fgetc(fp);
}
fclose(fp);
getch();
}
Comments
Post a Comment