Skip to content

Commit e0e72bb

Browse files
file_read_all.c
1 parent a0bc313 commit e0e72bb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

file_read_all.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdio.h>
2+
3+
//https://stackoverflow.com/questions/3381080/reading-all-content-from-a-text-file-c
4+
5+
int main(int argc, char** argv) {
6+
FILE* fp = fopen("abc.txt", "r");
7+
8+
fseek(fp, 0, SEEK_END);
9+
long size = ftell(fp);
10+
fseek(fp, 0, SEEK_SET);
11+
12+
char* fcontent = (char*)malloc(size);
13+
fread(fcontent, 1, size, fp);
14+
fclose(fp);
15+
16+
printf("%s\n", fcontent);
17+
18+
return 0;
19+
}

0 commit comments

Comments
 (0)