eclipseで2つのファイルlist11_1.c,list12_2.cをリンクして実行したい、やり方を教えてください
プロジェクトは以下のようになっています。
一応自分なりにやってみましたが、実行するとエラーが出ています。
お願いいたします。
コード //list11_1.c //1文字入出力ライブラリ //main関数がないので実行できない #include <stdio.h> #define BUFSIZE 256 // バッファの大きさ char buffer[BUFSIZE]; // バッファ int buf_no = 0; // 現在の要素数 int front_ptr = 0; // 先頭要素カーソル int rear_ptr = 0; // 末尾要素カーソル //--- 1文字取り出す --- int getchr(void) { if (buf_no <= 0) // バッファが空であれば return (getchar()); // キーボードから読み込んで返す //getchar 関数は標準入力から 1 文字分文字を読み取ります //ライブラリ関数getcharは、実行されるとキーボードからの入力を待ち、 //エンターキーが押されると入力待ちを終了、 //入力したうちの1文字目を返り値として返します。 //getchar関数はあふれた入力をストックしておいて //自動でそれを入力として取得できる //getchar関数に渡す入力を決定する際のエンターキーは //改行コードとしてストックの最後に入る else { int temp; buf_no--; temp = buffer[front_ptr++]; if (front_ptr == BUFSIZE) front_ptr = 0; return (temp); } } //--- 1文字押し戻す --- int ungetchr(int ch) { if (buf_no >= BUFSIZE) // バッファが満杯であれば return (EOF); // これ以上押し戻せない else { buf_no++; buffer[rear_ptr++] = ch; if (rear_ptr == BUFSIZE) rear_ptr = 0; return (ch); } } // 1文字入出力ライブラリの利用例 //list11_2.c #include <ctype.h> #include <stdio.h> int getchr(void); int ungetchr(int ch); //--- 整数(数字の列)を読み込んで2倍の値を表示 --- int getnum(void) { int c = 0; int x = 0; int ch; while ((ch = getchr()) != EOF && isdigit(ch)) { x = x * 10 + ch - '0'; c++; } if (ch != EOF) ungetchr(ch); if (c) printf("%d\n", x * 2); return (ch); //--- 文字を読み込んでそのまま表示 --- int getnnum(void) { int ch; while ((ch = getchr()) != EOF && !isdigit(ch)) //getchar 関数は標準入力から 1 文字分文字を読み取ります putchar(ch); if (ch != EOF) ungetchr(ch); putchar('\n'); return (ch); } int main(void) { while (getnum() != EOF) if (getnnum() == EOF) break; return (0); } 実行結果 17:59:45 **** インクリメンタル・ビルド of configuration Debug for project Cproject **** Info: Internal Builder is used for build gcc -O0 -g3 -Wall -c -fmessage-length=0 -o "list11\list11_2.o" "..\list11\list11_2.c" ..\list11\list11_2.c: In function 'getnum': ..\list11\list11_2.c:53:5: warning: 'main' is normally a non-static function [-Wmain] int main(void) ^~~~ ..\list11\list11_2.c:60:1: error: expected declaration or statement at end of input } ^ At top level: ..\list11\list11_2.c:53:5: warning: 'main' defined but not used [-Wunused-function] int main(void) ^~~~ 17:59:45 Build Finished (took 932ms)
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/03/19 09:19