-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLecture25 FileOperationss.c
121 lines (74 loc) · 2.03 KB
/
Lecture25 FileOperationss.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <stdio.h>
#include <stdlib.h>
//Written by Bunyamin Yavuz Fri Apr 15 22:38:09 2022
//File operations
int main()
{
/*
<-----Fundamental File Operations----->
"a" add
"r" read
"w" write
fopen() opens new or existing file
fclose closes the file
fprintf() write data into the file
fscanf() reads data from the file
fputc() writes a character into the file
fgetc() reads data from the file
fgets() read batch data into file
fputs() write batch from the file
EOF End Of File
*/
// Declaration as a file pointer
//FILE *file1;
/*
fopen to open the file.
"C:\\Users\\BunyaminYavuz\\OneDrive\\Masaüstü\\dosya2" is location of the file.
"w" is write command
.txt is textbox type
*/
//file1 = fopen("C:\\Users\\BunyaminYavuz\\OneDrive\\Masaüstü\\file1.txt","w");
/*
<-----Writing my name inside the file----->
// Prints Bunyamin
yavuz
fputc('B',file1);
fputc('u',file1);
fputc('n',file1);
fputc('y',file1);
fputc('a',file1);
fputc('m',file1);
fputc('i',file1);
fputc('n',file1);
fputc('\n',file1);
fputc('y',file1);
fputc('a',file1);
fputc('v',file1);
fputc('u',file1);
fputc('z',file1);
*/
/*
<-----Reading the file by using fgetc() function----->
FILE *file1Read;
char character;
file1Read = fopen("C:\\Users\\BunyaminYavuz\\OneDrive\\Masaüstü\\file1.txt","r");
do{
character = fgetc(file1Read);
printf("%c",character);
}
// End of file (EOF) it gets till the last end of file character
while(character != EOF);
// Close the file
fclose(file1Read);
*/
/*
<----- Reading the file by using fgets() function----->
FILE *file1Read2;
char character2[100];
file1Read2 = fopen("C:\\Users\\BunyaminYavuz\\OneDrive\\Masaüstü\\file1.txt","r");
fgets(character2,100,file1Read2);
puts(character2);
fclose(file1Read2);
*/
return 0;
}