実現したいこと
以下のプログラムがコンパイルを通るようにしたいです。
c
1#include <curses.h> 2#include <string.h> 3#include <stdbool.h> 4#include <conio.h> 5 6int main() 7{ 8 int x, y, w, h; 9 char *str = "Hello World"; 10 int key; 11 12 initscr(); 13 noecho(); 14 cbreak(); 15 keypad(stdscr, TRUE); 16 17 getmaxyx(stdscr, h, w); 18 y = h / 2; 19 x = (w - strlen(str)) / 2; 20 21 while (1) 22 { 23 erase(); 24 move(y, x); 25 addstr(str); 26 refresh(); 27 28 // key = getch(); 29 if (_kbhit()) 30 { 31 key = _getch(); 32 break; 33 } 34 35 if (key == 'q') 36 break; 37 switch (key) 38 { 39 case KEY_UP: 40 y--; 41 break; 42 case KEY_DOWN: 43 y++; 44 break; 45 case KEY_LEFT: 46 x--; 47 break; 48 case KEY_RIGHT: 49 x++; 50 break; 51 } 52 } 53 endwin(); 54 return (0); 55}
前提
c言語でテトリスを作っています。ミノの定期的な落下処理と入力待ちの相性が悪く、入力をとる部分だけ別スレッドに分けることができないか考えていましたところ_kbhit()を見つけました。この使用例も見つけて
c
1#include <stdio.h> 2#include <stdbool.h> 3#include <conio.h> 4#include <windows.h> 5 6int main(void) 7{ 8 int key; 9 printf("Please input any key\n"); 10 11 while (true) 12 { 13 14 if (_kbhit()) 15 { 16 key = _getch(); 17 printf("key = '%c'(%d)\n", key, key); 18 } 19 Sleep(1000); 20 printf("a\n"); 21 } 22 23 return 0; 24}
をコンパイルしたところきちんと通るのですが、一番上にあるような形で入力部分を置き換えたときコンパイルでエラーが図れるようになりました。
発生している問題・エラーメッセージ
In file included from memo.c:4: C:/pg/mingw64/x86_64-w64-mingw32/include/conio.h:272:25: error: macro "getch" passed 1 arguments, but takes just 0 272 | int __cdecl getch(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005; | ^ In file included from memo.c:1: C:\pg\PDCurses-master/curses.h:1371: note: macro "getch" defined here 1371 | #define getch() wgetch(stdscr) |
補足情報(FW/ツールのバージョンなど)
gcc version 12.2.0 (x86_64-win32-seh-rev0, Built by MinGW-W64 project)
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2023/04/10 22:17