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

Popular posts from this blog

Write a program to accept numerator and denominator and find the remainder without using modulus (%) operator using do..while loop.