-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadandwrite.c
60 lines (48 loc) · 957 Bytes
/
readandwrite.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
int main()
{
FILE *fp;
char fName[100];
printf("Enter file name to create :\n");
scanf("%s",fName);
fp=fopen(fName,"w");
if(fp==NULL)
{
printf("File was not created!!!");
return 0;
}
printf("File was created ");
putc('H',fp);
putc('e',fp);
putc('l',fp);
putc('l',fp);
putc('o',fp);
putc(' ',fp);
putc('W',fp);
putc('o',fp);
putc('r',fp);
putc('l',fp);
putc('d',fp);
printf("and data was written successfully.:\n");
fclose(fp);
fp=fopen(fName,"r");
if(fp==NULL)
{
printf("Can't open file!!! :\n");
return 0;
}
printf("Contents of file are :\n");
printf("%c",getc(fp));
printf("%c",getc(fp));
printf("%c",getc(fp));
printf("%c",getc(fp));
printf("%c",getc(fp));
printf("%c",getc(fp));
printf("%c",getc(fp));
printf("%c",getc(fp));
printf("%c",getc(fp));
printf("%c",getc(fp));
printf("%c",getc(fp));
fclose(fp);
return 0;
}