何故かエラーOSXで

このQ&Aのポイント
  • プログラム実行時にエラーが発生する事例を、OSX環境でのものについて質問しています。
  • エラーメッセージには、conio.hファイルが存在しないことやプログラム内の文法エラーが示されています。
  • 他のプログラミング参考書を参照しても同様のエラーが発生しており、ソースコード自体が間違っていないことを指摘しています。
回答を見る
  • ベストアンサー

何故かエラーOSXで

int main() { int a=15, b=20; printf ("a=15?n b=20?n"); printf ("a+b=%d?n",a+b); printf ("NANIKAkeyWOOSITE"?n"); getch(); printf("end"); return 0; } 猫でもわかるプログラミングを参考にして書いたんですが 何故かエラーがでます OSXではできないのでしょうか? エラー内容は test.c:2:19: error: conio.h: No such file or directory test.c: In function 'main': test.c:10: error: stray '?' in program test.c:10: error: parse error before "n" test.c:10: error: missing terminating " character です ソースも間違ってないはずです  どなたか教えて下さい!

noname#35759
noname#35759

質問者が選んだベストアンサー

  • ベストアンサー
回答No.1

本当にこの通りのソースだとすると、 > printf ("NANIKAkeyWOOSITE"?n"); は、間違っています。 ?n の前に、" があるために、test.c:10 で始まる3つのエラーが出ています。 ・こんなところに?はおかしい ・nの前のところで、構文がおかしい ・文字列を閉じる " がない あと、おそらくは、?は、何かの文字が化けたものだと思います。 最初のエラーの test.c:2:19: error: conio.h: No such file or directory は、conio.h というヘッダファイルが探せないということなので、もしかしたら、conio.h というファイルがないのかもしれません。

関連するQ&A

  • C言語、コンパイルエラーの原因?

    いつも大変お世話になり誠にありがとうございます。 標記の件。 shift jifでコンパイルしているのですが コンパイルエラーが発生します。 下記にコードとエラーメッセージを書きます。 コード #include <stdio.h> int main(void) { printf("8進数101の文字コードをもつ文字は%cです。\n", '\101'); printf("16進数61の文字コードをもつ文字は%cです。\n", '\x61');      return 0; } コンパイルエラー gcc text4.c -o text4 text4.c: In function 'main': text4.c:7:1: error: stray '\201' in program    ^ text4.c:7:2: error: stray '@' in program    ^ text4.c:7:3: error: stray '\201' in program    ^ text4.c:7:4: error: stray '@' in program    ^ text4.c:8:1: error: stray '\201' in program   return 0; ^ text4.c:8:2: error: stray '@' in program   return 0; ^ text4.c:8:3: error: stray '\201' in program   return 0; ^ text4.c:8:4: error: stray '@' in program   return 0; 上記のようになります。 どうすればいいでしょうか? ご多忙中申し訳ございません。 ご回答の程宜しくお願い申し上げます。           高橋耕造

  • C言語 どこがコンパイルエラーか解りません。

    いつも大変お世話になっております。 標記の件。 どこがエラーなのか解りません。 2時間くらい、にらめっこが続いています。 どこがエラーなのか教えて下さい。 ご回答のほどよろしくお願い申し上げます。 コード #include <stdio.h> int a = 0; void func(void) { int c = 2; printf("func関数では変数aとcが使えます。¥n”); printf("変数aの値は%dです。\n",a); /*printf("変数bの値は%dです。\n",b);*/ printf("変数cの値は%dです。\n",c); } int main(void) { int b = 1; printf("main関数では変数aとbが使えます。\n"); printf("変数aの値は%dです。\n", a); printf("変数bの値は%dです。\n", b); /*printf("変数cの値は%dです。\n", c); */ func(); return 0; } コンパイルエラー printf("func関数では変数aとcが使えます。¥n”); ^ text10.c:9:8: error: missing terminating " character printf("func関数では変数aとcが使えます。¥n”); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ text10.c:10:34: error: expected ')' before ';' token printf("変数aの値は%dです。\n",a); ^ text10.c:10:1: warning: passing argument 1 of 'printf' makes pointer from integer without a cast [-Wint-conversion] printf("変数aの値は%dです。\n",a); ^~~~~~ In file included from text10.c:1:0: c:\mingw\include\stdio.h:454:38: note: expected 'const char *' but argument is of type 'int' _CRTIMP __cdecl __MINGW_NOTHROW int printf (const char *, ...); ^~~~~~ text10.c:13:1: error: expected ';' before '}' token } どうかよろしくお願いいたします。

  • コンパイルエラーについて

    #include <stdio.h> int main(void){ char a[8],b[7],c[6]; printf("a[8]のアドレスは%pです。\n",&a[8]); //a[8]のメモリアドレスを表示 printf("\n"); printf("b[7]のアドレスは%pです。\n",&b[7]); //b[7]のメモリアドレスを表示 printf("\n"); printf("c[6]のアドレスは%pです。\n",&c[6]); //c[6]のメモリアドレスを表示 printf("\n"); char *c1 ="abcde"; printf("c1=%s\n",c1); //abcdeを表示 printf("c1[2]=%c\n",*(c1+2)); //先頭アドレスの2つ先のアドレスに格納されている値(c)を表示 char c2[] ="abcde"; char *pc2; printf("c2=%s\n",c2); //abcdeを表示 pc2=&c2[2]; //変数c2[2]のアドレスを格納 printf("c2[2]=%c\n",*pc2); //c2[2]アドレスに格納されている値(c)を表示 char *c="abcdefghijklmn"; char cc[]="opqrstuvwxyz"; printf("%c\n", *(c+7)); printf("%c\n", *(cc+2)); return 0; } としてコンパイルした所、 test.c: In function ‘main’: test.c:31: error: conflicting types for ‘c’ test.c:4: note: previous declaration of ‘c’ was here と出てしまいました。原因が良く分からないのですが教えて頂けますでしょうか?

  • error C2143: 構文エラー : ';' が '{' の前にありません。

    #include <stdio.h> int main(void) {   int in;   printf("20以上の数字を入力してください\n");   scanf("%d", &in);   if(in >= 20){     printf("20以上の数字です。\n");     printf("終了します\n\n");}   else if(in <= 5){     printf("5以下の数字が入力されました\n");     printf("20には程遠いです\n\n");}   else(in <= 19){     printf("20以上の数字ではありません\n");     printf("20以上の数字を入力してください\n\n");}   return 0; } C言語でVisual C++ Expressを使っています このコードでビルドすると (16) : error C2143: 構文エラー : ';' が '{' の前にありません。 と表示されてしまいます。何がいけないのでしょうか?

  • エラーが出てコンパイルができません…

    #include<stdio.h> void main(void) { int i; i=0; while(i<3){ printf("おーい\n\"); printf(" やっほー\n\n\"); i=i+1; } printf("プログラムを終了します\"); } と本に書いてあった通りに入力したら、下のようなエラーが出てきました。 7: 文法エラー before \"i\" 9: stray \'\\\' in program 10: stray \'\\\' in program 10: 文法エラー before \"n\" 11: stray \'\\\' in program 11: 文法エラー before \"n\" 12: `i\' undeclared (first use in this function) 12: (Each undeclared identifier is reported only once 12: for each function it appears in.) トップレベル: 15: error: 文法エラー before string constant 15: conflicting types for built-in function `printf\' 15: data definition has no type or storage class 16:2: ファイル末尾に改行がありません 解決策と原因を教えて下さい。 宜しくお願い致します。

  • 分割コンパイルについて

    現在分割コンパイルが分からずに苦戦しています。 下記のリストは構造体を使わなければコンパイラを通すことができましたが、 使うとなぜか通りません。 あれこれ試しましたがどうしても分かりません。 何がおかしいのでしょうか? *define.hで全てのファイルへの定義や宣言を行わせています。 ////////////// //Main.cpp ////////////// #include <stdio.h> #include <conio.h> #include "define.h" int main( void ){ Tmp[0].c = 15; printf("a: %d\n", a); printf("b: %d\n", b); printf("c: %d\n", Tmp[0].c); printf("NUM:%d\n", NUM); aaa(); bbb(); getch(); return 0; } ////////////////// // A.cpp ///////////////// #include <stdio.h> #include "define.h" void aaa( void ){ printf("a: %d\n", a); printf("b: %d\n", b); printf("c: %d\n", Tmp[0].c); printf("NUM:%d\n", NUM); } ////////////////// // B.cpp ///////////////// #include <stdio.h> #include "define.h" void bbb( void ){ printf("a: %d\n", a); printf("b: %d\n", b); printf("c: %d\n", Tmp[0].c); printf("NUM:%d\n", NUM); } ////////////////// // define.cpp ///////////////// #include "define.h" int a = 10; int b = 20; struct Parameter { int c; }; struct Parameter Tmp[NUM]; ////////////////// // define.h ///////////////// #define NUM 100 extern int a; extern int b; extern struct Parameter Tmp[NUM]; void aaa( void ); void bbb( void );

  • MacのターミナルでC言語コンパイルエラー

    Macのターミナルで"HelloWorld.c"のコンパイルで以下のエラーが出ます。 HelloWorld.c:1: error: expected identifier or ‘(’ before ‘{’ token HelloWorld.c:1: error: stray ‘\’ in program HelloWorld.c:1: error: stray ‘\’ in program HelloWorld.c:1: error: stray ‘\’ in program HelloWorld.c:1: error: stray ‘\’ in program HelloWorld.c:1: error: stray ‘\’ in program HelloWorld.c:2: error: stray ‘\’ in program HelloWorld.c:2: error: stray ‘\’ in program HelloWorld.c:2: error: stray ‘\’ in program HelloWorld.c:2: error: stray ‘\’ in program HelloWorld.c:3: error: stray ‘\’ in program HelloWorld.c:3: error: stray ‘\’ in program HelloWorld.c:3: error: stray ‘\’ in program HelloWorld.c:3: error: stray ‘\’ in program HelloWorld.c:4: error: stray ‘\’ in program HelloWorld.c:4: error: stray ‘\’ in program HelloWorld.c:4: error: stray ‘\’ in program HelloWorld.c:4: error: stray ‘\’ in program HelloWorld.c:4: error: stray ‘\’ in program HelloWorld.c:4: error: stray ‘\’ in program HelloWorld.c:4: error: stray ‘\’ in program HelloWorld.c:5: error: stray ‘\’ in program HelloWorld.c:6: error: stray ‘\’ in program HelloWorld.c:6: error: stray ‘\’ in program HelloWorld.c:6: error: stray ‘\’ in program HelloWorld.c:6: error: stray ‘\’ in program HelloWorld.c:8: error: stray ‘\’ in program HelloWorld.c:8: error: stray ‘\’ in program HelloWorld.c:8: error: stray ‘\’ in program HelloWorld.c:8: error: stray ‘#’ in program HelloWorld.c:8:24: warning: backslash-newline at end of file HelloWorld.c:8: error: stray ‘\’ in program HelloWorld.c:8: error: stray ‘\’ in program ソースは以下 #include int main(void) { printf("Hello, World!¥n"); return 0; } どなたかお助けを!! まだ、プログラム超初心者です。よろしくお願いします。

  • 超初心者ですが><

    C言語でCygwinを使っていますが #include <stdio.h> main() { int test; test = 100; printf("テストの数字は%d"test); } と入力して実行しましたが ファイル名.c: In function `main': ファイル名.c:9: parse error before `test' と表示されてしまいます。 intは宣言になってないのでしょうか? もし原因わかればお願いします

  • C言語、度々すいません。コンパイルエラーです。

    いつも大変お世話になり誠にありがとうございます。 下記コードがコンパイルエラーになり色々と 変えてみたのですが、どうしてもコンパイルエラー となります。 度々すいません。 ご回答の程宜しくお願い申し上げます。      記 1.コード #include <stdio.h> int main(void) { char ch; printf("アルファベットの最初の文字は何ですか?\n"); ch = getchar(); printf("アルファベットの最初の文字は%cです。\n" ch); return 0; } 2.コンパイルエラー C:\MinGW>gcc test8.c -o test8 test8.c: In function 'main': test8.c:9:51: error: expected ')' before 'ch' printf("アルファベットの最初の文字は%cです。\n" ch); 上記の通りエラーメッセージが出ます。 どうしたらいいでしょうか? ご回答の程宜しくお願い申し上げます。

  • 関数でエラー

    #include<stdio.h> int func(int, int); int main() { int a, b, c; a = 10; b = 20; c = func(a, b); printf("%d x %d" = %d\n", a, b, c) return 0; } int func(int a, int b) { int c; c = a * b; return c; } エラーが出てしまうのですが、どうしてエラーが出るのか教えて頂けないでしょうか? エラー一覧です。 ------------------------------------------------------------------------------------------------------------------------------- 配列型 const char[8]を割り当てることはできません。 14行目 ;がreturnの前にありません              16行目 式は変更可能な左辺値である必要があります      14行目 ;が必要です                     16行目 よろしくお願いします。

専門家に質問してみよう