gpt4 book ai didi

c - C编译时出现错误 "error: stray '\34 2' "、 "stray '\20 0' "、 "stray '\23 4' "

转载 作者:行者123 更新时间:2023-11-30 19:09:26 25 4
gpt4 key购买 nike

我用了Notepad++编写代码,当我尝试编译它时(我使用 cc lab7.c -o test1 来编译它),我得到了一堆杂散\342、杂散\200、杂散\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

最佳答案

您的代码存在几个问题:

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

您在指定位置之前以及后面的几行类似的行中缺少逗号。

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

我所指出的位置中的引号都是“智能引号”(“/”),而不是普通引号。重新输入它们。

同样的问题也适用于以下有关“%c”的每个错误。

关于c - C编译时出现错误 "error: stray '\34 2' "、 "stray '\20 0' "、 "stray '\23 4' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43268151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com