質問編集履歴

1

ファイル名のタイプミスがありました。getputch\.hのコードを追加しました

2017/07/23 11:59

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -8,16 +8,222 @@
8
8
 
9
9
 
10
10
 
11
- C:\MinGW\users\chap08>のようなエラーが出てデバッグできないのですが、
11
+ のようなエラーが出てデバッグできないのですが、
12
12
 
13
13
  ファイルkadai8-5.cはchap08にあり、getputch.hとpdcurses.aとcurses.hも
14
14
 
15
15
  chap08にあります。
16
16
 
17
- $gcc -I. -o kadai8-5 ksai8-5.c pdcurses.aでコンパイルは成功します。実行もできるのですが、
17
+ $gcc -I. -o kadai8-5 kadai8-5.c pdcurses.aでコンパイルは成功します。実行もできるのですが、
18
-
18
+
19
- $gcc -g -okadai8-5 ksai8-5.cを実行すると、最初に挙げたエラーが出てしまいます。
19
+ $gcc -g -okadai8-5 kadai8-5.cを実行すると、最初に挙げたエラーが出てしまいます。
20
20
 
21
21
  プログラムを理解するために、stepで実行を見たいのですが。
22
22
 
23
23
  どなたか教えていただけますか。``
24
+
25
+
26
+
27
+
28
+
29
+ getputch.hのコードは以下のとおりです。
30
+
31
+
32
+
33
+ /* getch/putch用ヘッダ "getputch.h" */
34
+
35
+
36
+
37
+ #if !defined(__GETPUTCH)
38
+
39
+
40
+
41
+ #define __GETPUTCH
42
+
43
+
44
+
45
+ #if defined(_MSC_VER) || (__TURBOC__) || (LSI_C)
46
+
47
+
48
+
49
+ /* MS-Windows/MS-DOS(Visual C++, Borland C++, LSI-C 86 etc ...) */
50
+
51
+
52
+
53
+ #include <conio.h>
54
+
55
+
56
+
57
+ static void init_getputch(void) { /* 空 */ }
58
+
59
+
60
+
61
+ static void term_getputch(void) { /* 空 */ }
62
+
63
+
64
+
65
+
66
+
67
+ #else
68
+
69
+
70
+
71
+ /* Cursesライブラリが提供されるUNIX/Linux/OS X */
72
+
73
+
74
+
75
+ #include <curses.h>
76
+
77
+
78
+
79
+ #undef putchar
80
+
81
+ #undef puts
82
+
83
+ #undef printf
84
+
85
+ static char __buf[4096];
86
+
87
+
88
+
89
+ /*--- __putchar:putchar関数と同等(改行を[改行+復帰]で出力)---*/
90
+
91
+ static int __putchar(int ch)
92
+
93
+ {
94
+
95
+ if (ch == '\n')
96
+
97
+ putchar('\r');
98
+
99
+ return (putchar(ch));
100
+
101
+ }
102
+
103
+
104
+
105
+ /*--- putch:1文字表示してバッファを掃き出す ---*/
106
+
107
+ static int putch(int ch)
108
+
109
+ {
110
+
111
+ int result = putchar(ch);
112
+
113
+
114
+
115
+ fflush(stdout);
116
+
117
+ return (result);
118
+
119
+ }
120
+
121
+
122
+
123
+ /*--- __printf:printf関数と同等(改行を[改行+復帰]で出力)---*/
124
+
125
+ static int __printf(const char *format, ...)
126
+
127
+ {
128
+
129
+ va_list ap;
130
+
131
+ int count;
132
+
133
+
134
+
135
+ va_start(ap, format);
136
+
137
+ vsprintf(__buf, format, ap);
138
+
139
+ va_end(ap);
140
+
141
+
142
+
143
+ for (count = 0; __buf[count]; count++) {
144
+
145
+ putchar(__buf[count]);
146
+
147
+ if (__buf[count] == '\n')
148
+
149
+ putchar('\r');
150
+
151
+ }
152
+
153
+ return (count);
154
+
155
+ }
156
+
157
+
158
+
159
+ /*--- __puts:puts関数と同等(改行を[改行+復帰]で出力)---*/
160
+
161
+ int __puts(const char *s)
162
+
163
+ {
164
+
165
+ int i, j;
166
+
167
+
168
+
169
+ for (i = 0, j = 0; s[i]; i++) {
170
+
171
+ __buf[j++] = s[i];
172
+
173
+ if (s[i] == '\n')
174
+
175
+ __buf[j++] = '\r';
176
+
177
+ }
178
+
179
+ return (puts(__buf));
180
+
181
+ }
182
+
183
+
184
+
185
+ /*--- ライブラリ初期処理 ---*/
186
+
187
+ static void init_getputch(void)
188
+
189
+ {
190
+
191
+ initscr();
192
+
193
+ cbreak();
194
+
195
+ noecho();
196
+
197
+ refresh();
198
+
199
+ }
200
+
201
+
202
+
203
+ /*--- ライブラリ終了処理 ---*/
204
+
205
+ static void term_getputch(void)
206
+
207
+ {
208
+
209
+ endwin();
210
+
211
+ }
212
+
213
+
214
+
215
+ #define putchar __putchar
216
+
217
+ #define printf __printf
218
+
219
+ #define puts __puts
220
+
221
+
222
+
223
+ #endif
224
+
225
+
226
+
227
+ #endif
228
+
229
+ ```