2017-04-07 127 views
-1

私はこの種の質問が以前に尋ねられていることを理解しています。私はNotePad ++を使ってコードを書いていました。コンパイルしようとしたとき(コンパイルするためにcc lab7.c -o test1を使いました)、stray \ 342、stray \ 200、stray \ 234 errors以下。ここで"エラー:Cコンパイルでstray ' 342'"、 "stray ' 200'"、 "stray ' 234'"

は私のコードです:

#include <stdio.h> 
#include <string.h> 


char inbase, dummy, outbase; 
char response; 
int inputNum; 
char bin [32]; 

int main(void) 
{ 


// perform for yes response 
while (response == 'y' || response == 'Y') 
{ 

    // prompt to read in char for base of input 
    printf("Enter a base to read in (b for binary, d for decimal,\n h for hexidecimal, or o for octal: "); 
    scanf("%c", &inbase); 

    // if binary is inbase 
    if (inbase == 'b' || inbase == 'B') 
    { 
     printf ("Enter a binary number to read: "); 
     scanf ("%c", &dummy); 
     scanf ("%s", bin); 
     inputNum = binary(bin); 
    } 

    // if inbase is anything else, read 
    else 
    { 
     printf ("Enter an integer to read: "); 
     scanf ("%c", &dummy); 
     scanf ("%i", &inputNum); 
    } 

    // output the number 

    printf ("Enter a base to output as: "); 
    scanf ("%c", &dummy); 
    scanf ("%c", &outbase); 

    // decimal output 
    if (outbase == 'd' || outbase == 'D') 
    { 
     printf("The integer %i in decimal is %d" inputNum, inputNum); 
    } 

    // hexidecimal output 
    if (outbase == 'h' || outbase == 'H') 
    { 
     printf("The integer %i in hexidecimal is %h" inputNum, inputNum); 
    } 

    // octal output 
    if (outbase == 'o' || outbase == 'O') 
    { 
     printf("The integer %i in octal is %o" inputNum, inputNum); 
    } 

    // check to see if user wants to run again 
    printf (“Do you want to …”); 
    scanf (“%c”, &dummy); 
    scanf (“%c”, &response); 
    scanf (“%c”, &dummy); 

} 

int binary(char* inString) 
{ 
    int sum=0; 
    int i; 

    for (i=0; i < strlen(inString); i++) 
    { 
     sum = sum * 2 + (inString[i] - 48); 
    } 

    return sum; 
} 

return 0; 

} 

// END OF CODE 

そして、ここでエラーメッセージが私が取得していますされています

lab7.c: In function ‘main’: 

lab7.c:58:45: error: expected ‘)’ before ‘inputNum’ 
printf("The integer %i in decimal is %d" inputNum, inputNum); 
             ^

lab7.c:64:49: error: expected ‘)’ before ‘inputNum’ 
printf("The integer %i in hexidecimal is %h" inputNum, inputNum); 
              ^

lab7.c:70:43: error: expected ‘)’ before ‘inputNum’ 
printf("The integer %i in octal is %o" inputNum, inputNum); 
            ^

lab7.c:74:3: error: stray ‘\342’ in program 
printf (“Do you want to …”); 
^ 

lab7.c:74:3: error: stray ‘\200’ in program 

lab7.c:74:3: error: stray ‘\234’ in program 

lab7.c:74:14: error: ‘Do’ undeclared (first use in this function) 
printf (“Do you want to …”); 
     ^

lab7.c:74:14: note: each undeclared identifier is reported only once for     each function it appears in 

lab7.c:74:17: error: expected ‘)’ before ‘you’ 
printf (“Do you want to …”); 
      ^

lab7.c:74:17: error: stray ‘\342’ in program 

lab7.c:74:17: error: stray ‘\200’ in program 

lab7.c:74:17: error: stray ‘\246’ in program 

lab7.c:74:17: error: stray ‘\342’ in program 

lab7.c:74:17: error: stray ‘\200’ in program 

lab7.c:74:17: error: stray ‘\235’ in program 

lab7.c:75:3: error: stray ‘\342’ in program 
scanf (“%c”, &dummy); 
^ 

lab7.c:75:3: error: stray ‘\200’ in program 

lab7.c:75:3: error: stray ‘\234’ in program 

lab7.c:75:13: error: expected expression before ‘%’ token 
scanf (“%c”, &dummy); 
     ^

lab7.c:75:13: error: stray ‘\342’ in program 

lab7.c:75:13: error: stray ‘\200’ in program 

lab7.c:75:13: error: stray ‘\235’ in program 

lab7.c:76:3: error: stray ‘\342’ in program 
scanf (“%c”, &response); 
^ 

lab7.c:76:3: error: stray ‘\200’ in program 

lab7.c:76:3: error: stray ‘\234’ in program 

lab7.c:76:13: error: expected expression before ‘%’ token 
scanf (“%c”, &response); 
     ^

lab7.c:76:13: error: stray ‘\342’ in program 

lab7.c:76:13: error: stray ‘\200’ in program 

lab7.c:76:13: error: stray ‘\235’ in program 

lab7.c:77:3: error: stray ‘\342’ in program 
scanf (“%c”, &dummy); 
^ 

lab7.c:77:3: error: stray ‘\200’ in program 

lab7.c:77:3: error: stray ‘\234’ in program 

lab7.c:77:13: error: expected expression before ‘%’ token 
scanf (“%c”, &dummy); 
     ^

lab7.c:77:13: error: stray ‘\342’ in program 

lab7.c:77:13: error: stray ‘\200’ in program 

lab7.c:77:13: error: stray ‘\235’ in program 
+0

私はduskwuffの変更を提案し、char応答を変更しました。応答するにはchar = "y";それは動作します。ありがとう! – teddymv

答えて

1

はあなたのコードに問題がいくつかあります:

lab7.c:58:45: error: expected ‘)’ before ‘inputNum’ 
printf("The integer %i in decimal is %d" inputNum, inputNum); 
             ^

指定された場所の直前にカンマがありません。それに続くいくつかの同様の行にあります。私が示さきた場所で

printf (“Do you want to …”); 
     ^   ^

引用符は、両方の「スマート引用符」(“/”)ではなく、通常の引用符です。それらを再入力してください。

同じ問題は、“%c”に関する次のエラーのそれぞれに当てはまります。

+0

ありがとう、私はそれらを置き換え、それらのほとんどを取り除いた。 /tmp/ccvLZ92d.o: 'main '関数内: lab7.c :(。テキスト+ 0x84):未定義のバイナリへの参照 collect2:エラー:ldが1を返しました終了ステータス – teddymv

+0

私の答えをもう一度読んでください。最初の回答のパターンは、コード内の複数の行に適用されます。 – duskwuff

+0

申し訳ありませんが、私はもう一度編集しました。それらを取り除いてから新しいエラーが発生しました – teddymv

関連する問題