C
- voluntas
- @ignis_fatuus
- ブン
- @Linda_pp
- 清楚なC++メイドBOT
- @tzik_tack
- 長谷川一輝
- wraith13
- @jj1bdx
- @cpp_akira
- 安藤敏彦
- @srz_zumix
- Siv3D
- @okdshin
- @hnokx
- @ishidakei
- @take_cheeze
- TAKEI Yuya
- @mumumu
- I (@wx257osn2)
- Tommy6
- わたやん
- @KorekaraSEDB
- @kariya_mitsuru
- @ciniml
- @beam2d
- @grafi_tt
- @nekketsuuu
- LouiS0616
- @volanja
- 大鎌広
- むてら
- ガチKGB
- 三重野賢人
x
35
1
2
3
4
5
6
7
8
int main(void)
9
{
10
char line[RSIZ][LSIZ];
11
char fname[20];
12
FILE *fptr = NULL;
13
14
int i = 0;
15
int tot = 0;
16
printf("\n\n Read the file and store the lines into an array :\n");
17
printf("------------------------------------------------------\n");
18
printf(" Input the filename to be opened : ");
19
scanf("%s",fname);
20
21
fptr = fopen(fname, "r");
22
while(fgets(line[i], LSIZ, fptr))
23
{
24
line[i][strlen(line[i]) - 1] = '\0';
25
i++;
26
}
27
tot = i;
28
printf("\n The content of the file %s are : \n",fname);
29
for(i = 0; i < tot; ++i)
30
{
31
printf(" %s\n", line[i]);
32
}
33
printf("\n");
34
return 0;
35
}
$ gcc prog.c -Wall -Wextra -std=gnu11
Stdin
file.txt
Start
Read the file and store the lines into an array : ------------------------------------------------------ Input the filename to be opened : The content of the file file.txt are : hogehoge aaa rwerae war wea ar ewrwaw wecrwev rcewrwerwec
0
Finish