C LAB‎ > ‎(Sem1) Introduction to C‎ > ‎

WAP to enter and retrieve a character from a file.

posted Nov 18, 2010, 4:39 AM by Neil Mathew   [ updated Nov 18, 2010, 4:45 AM ]

SOURCE CODE:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
#include <stdio.h>
main()
{
     char ch;
     FILE *file;
     file = fopen("abc.txt", "w");
 
     printf("\nEnter any character into FILE: ");
     scanf("%c", &ch);
 
     putc(ch, file);
     fclose(file);
 
     file = fopen("abc.txt", "r");
 
     ch = getc(file);
     printf("\nEntered Character from FILE: %c", ch);
}
 
Comments