|
|
|
|
File Input/Output
Most programs need to read and write data to disk-based storage systems. In the C language, all I/O operations are carried out using functions from the standard C library. This approach makes C a powerful and flexible. #include <stdio.h>main ( ) { FILE *fp; char ch=' '; if (( fp = fopen ("Tej","w")) == NULL) { printf("Cannot open file \n\n\n"); exit(1); } clrscr(); printf("Enter Characters ( ^ for Terminate) \n\n); ch=getche(); while(ch != ' ^ ' ) { fputc(ch,fp); ch=getche(); } fclose(fp); printf("\n\n Displaying Contents of File Tej \n\n\n"); if (( fp = fopen ("Tej","r")) == NULL) { printf("Cannot open file \n\n\n"); exit(1); } do { ch=fgetc(fp); putchar(ch); } while ( ch ! = EOF); fclose(fp); } |