2017-04-07 611 views
-1

我明白這個問題之前已經被問過了,請不要把它釘在十字架上。我用NotePad ++來編寫代碼,當我試圖編譯它時(我使用cc lab7.c -o test1來編譯它),我得到了一堆迷路的\ 342,stray \ 200,stray \ 234錯誤,正如所見下面。「錯誤:在C編譯時發生' 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 :(.text + 0x84):未定義的對'binary'的引用 collect2:error:ld返回1個出口狀態 – teddymv

+0

再次閱讀我的答案。第一個答案中的模式適用於代碼中的多行。 – duskwuff

+0

對不起,是啊,我再次編輯它。擺脫了那些,但後來得到了一個新的錯誤 – teddymv