Write a program to create a file, perform READ & WRITE operations on it
Program
#include <stdio.h>void main(){ FILE *fp; char c; printf("Type the content to store in hello.txt ... (Press CTRL+D to trigger EOF)\n\n"); fp = fopen("hello.txt", "w"); while ((c = getchar()) != EOF) { putc(c, fp); } fclose(fp); fp = fopen("hello.txt", "r"); while ((c = getc(fp)) != EOF) { putchar(c); } fclose(fp); printf("\n");}
Result
Type the content to store in hello.txt ... (Press CTRL+D to trigger EOF)
Testing write oprtn in a file...
1 2 3
Testing new lines
Last line...Testing write oprtn in a file...
1 2 3
Testing new lines
Last line...