回答編集履歴

2

追記

2016/10/05 04:35

投稿

cateye
cateye

スコア6851

test CHANGED
@@ -17,3 +17,83 @@
17
17
  [たとえば・・・]
18
18
 
19
19
  文字列から空白と改行を取り除く関数を作って、fgets()で一行読んで処理をさせ書き出すようにします
20
+
21
+
22
+
23
+ 時間があったので作ってみました。(stdin→stdoutです)
24
+
25
+ ```C
26
+
27
+ ~/test/ctst >cat tst08.c
28
+
29
+ #include <stdio.h>
30
+
31
+ #include <ctype.h>
32
+
33
+
34
+
35
+ void DelSpace(char *strp);
36
+
37
+
38
+
39
+ int main()
40
+
41
+ {
42
+
43
+ char buf[1024];
44
+
45
+ //
46
+
47
+ while(fgets(buf, sizeof buf, stdin)){
48
+
49
+ DelSpace(buf);
50
+
51
+ fputs(buf, stdout);
52
+
53
+ }
54
+
55
+ //
56
+
57
+ return 0;
58
+
59
+ }
60
+
61
+
62
+
63
+
64
+
65
+ void DelSpace(char *strp)
66
+
67
+ {
68
+
69
+ char *sop= strp;
70
+
71
+ char *dip= strp;
72
+
73
+ //
74
+
75
+ while(*sop){
76
+
77
+ if(!isspace(*sop)){
78
+
79
+ *dip++= *sop;
80
+
81
+ }
82
+
83
+ sop++;
84
+
85
+ }
86
+
87
+ *dip= '\0';
88
+
89
+ }
90
+
91
+
92
+
93
+ ~/test/ctst >./a.out <tst08.c
94
+
95
+ #include<stdio.h>#include<ctype.h>voidDelSpace(char*strp);intmain(){charbuf[1024];//while(fgets(buf,sizeofbuf,stdin)){DelSpace(buf);fputs(buf,stdout);}//return0;}voidDelSpace(char*strp){char*sop=strp;char*dip=strp;//while(*sop){if(!isspace(*sop)){*dip++=*sop;}sop++;}*dip='\0';}~/test/ctst >
96
+
97
+
98
+
99
+ ```

1

加筆

2016/10/05 04:35

投稿

cateye
cateye

スコア6851

test CHANGED
@@ -11,3 +11,9 @@
11
11
  >エラーが出ない書き方はどのようなものか
12
12
 
13
13
  fscanf()の戻り値を確認しましたか?・・・EOF(-1)あるいは読み取った項目数です。
14
+
15
+
16
+
17
+ [たとえば・・・]
18
+
19
+ 文字列から空白と改行を取り除く関数を作って、fgets()で一行読んで処理をさせ書き出すようにします