質問編集履歴
1
ファイル名のタイプミスがありました。getputch\.hのコードを追加しました
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -3,10 +3,113 @@
|
|
|
3
3
|
getputch.h:22:21: fatal error: curses.h: No such file or directory
|
|
4
4
|
compilation terminated.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
のようなエラーが出てデバッグできないのですが、
|
|
7
7
|
ファイルkadai8-5.cはchap08にあり、getputch.hとpdcurses.aとcurses.hも
|
|
8
8
|
chap08にあります。
|
|
9
|
-
$gcc -I. -o kadai8-5
|
|
9
|
+
$gcc -I. -o kadai8-5 kadai8-5.c pdcurses.aでコンパイルは成功します。実行もできるのですが、
|
|
10
|
-
$gcc -g -okadai8-5
|
|
10
|
+
$gcc -g -okadai8-5 kadai8-5.cを実行すると、最初に挙げたエラーが出てしまいます。
|
|
11
11
|
プログラムを理解するために、stepで実行を見たいのですが。
|
|
12
|
-
どなたか教えていただけますか。``
|
|
12
|
+
どなたか教えていただけますか。``
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
getputch.hのコードは以下のとおりです。
|
|
16
|
+
|
|
17
|
+
/* getch/putch用ヘッダ "getputch.h" */
|
|
18
|
+
|
|
19
|
+
#if !defined(__GETPUTCH)
|
|
20
|
+
|
|
21
|
+
#define __GETPUTCH
|
|
22
|
+
|
|
23
|
+
#if defined(_MSC_VER) || (__TURBOC__) || (LSI_C)
|
|
24
|
+
|
|
25
|
+
/* MS-Windows/MS-DOS(Visual C++, Borland C++, LSI-C 86 etc ...) */
|
|
26
|
+
|
|
27
|
+
#include <conio.h>
|
|
28
|
+
|
|
29
|
+
static void init_getputch(void) { /* 空 */ }
|
|
30
|
+
|
|
31
|
+
static void term_getputch(void) { /* 空 */ }
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
#else
|
|
35
|
+
|
|
36
|
+
/* Cursesライブラリが提供されるUNIX/Linux/OS X */
|
|
37
|
+
|
|
38
|
+
#include <curses.h>
|
|
39
|
+
|
|
40
|
+
#undef putchar
|
|
41
|
+
#undef puts
|
|
42
|
+
#undef printf
|
|
43
|
+
static char __buf[4096];
|
|
44
|
+
|
|
45
|
+
/*--- __putchar:putchar関数と同等(改行を[改行+復帰]で出力)---*/
|
|
46
|
+
static int __putchar(int ch)
|
|
47
|
+
{
|
|
48
|
+
if (ch == '\n')
|
|
49
|
+
putchar('\r');
|
|
50
|
+
return (putchar(ch));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/*--- putch:1文字表示してバッファを掃き出す ---*/
|
|
54
|
+
static int putch(int ch)
|
|
55
|
+
{
|
|
56
|
+
int result = putchar(ch);
|
|
57
|
+
|
|
58
|
+
fflush(stdout);
|
|
59
|
+
return (result);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/*--- __printf:printf関数と同等(改行を[改行+復帰]で出力)---*/
|
|
63
|
+
static int __printf(const char *format, ...)
|
|
64
|
+
{
|
|
65
|
+
va_list ap;
|
|
66
|
+
int count;
|
|
67
|
+
|
|
68
|
+
va_start(ap, format);
|
|
69
|
+
vsprintf(__buf, format, ap);
|
|
70
|
+
va_end(ap);
|
|
71
|
+
|
|
72
|
+
for (count = 0; __buf[count]; count++) {
|
|
73
|
+
putchar(__buf[count]);
|
|
74
|
+
if (__buf[count] == '\n')
|
|
75
|
+
putchar('\r');
|
|
76
|
+
}
|
|
77
|
+
return (count);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/*--- __puts:puts関数と同等(改行を[改行+復帰]で出力)---*/
|
|
81
|
+
int __puts(const char *s)
|
|
82
|
+
{
|
|
83
|
+
int i, j;
|
|
84
|
+
|
|
85
|
+
for (i = 0, j = 0; s[i]; i++) {
|
|
86
|
+
__buf[j++] = s[i];
|
|
87
|
+
if (s[i] == '\n')
|
|
88
|
+
__buf[j++] = '\r';
|
|
89
|
+
}
|
|
90
|
+
return (puts(__buf));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/*--- ライブラリ初期処理 ---*/
|
|
94
|
+
static void init_getputch(void)
|
|
95
|
+
{
|
|
96
|
+
initscr();
|
|
97
|
+
cbreak();
|
|
98
|
+
noecho();
|
|
99
|
+
refresh();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/*--- ライブラリ終了処理 ---*/
|
|
103
|
+
static void term_getputch(void)
|
|
104
|
+
{
|
|
105
|
+
endwin();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
#define putchar __putchar
|
|
109
|
+
#define printf __printf
|
|
110
|
+
#define puts __puts
|
|
111
|
+
|
|
112
|
+
#endif
|
|
113
|
+
|
|
114
|
+
#endif
|
|
115
|
+
```
|