【问题标题】:C - printf errorC - printf 错误
【发布时间】:2012-11-20 21:00:50
【问题描述】:

我正在尝试从 Sam's Learn C in 24 Hours 编译一个示例。

当我尝试编译以下代码时出现错误:

/* 03L02.c: Calculate an addition and print out the result */
#include <stdio.h>
/* This function adds two integers and returns the result */
int integer_add( int x, int y )
{
    int result;
    result = x + y;
    return result;
}
int main()
{
    int sum;
    sum = integer_add(5, 12);
    printf(“The addition of 5 and 12 is %d.\n”, sum);
    return 0;
}

这是我的编译器给出的错误:

In function main
stray "\147\' in program
The undeclared identifier is declared only once
for each function it appears in
syntax error before addition
stray "\' in program
stray "\148' in program

提前致谢。

【问题讨论】:

  • 看起来您的“引号”字符不正确。您使用的是“而不是默认的”
  • 看起来你从某个地方复制了代码..

标签: c function main


【解决方案1】:

我看到你的错误因为相同的字符。查看您的代码

printf(“The addition of 5 and 12 is %d.\n”, sum);

尝试更改为:

printf("The addition of 5 and 12 is %d.\n", sum);

你能看出区别吗? Qoute “它必须是”

【讨论】:

    【解决方案2】:

    你刚才把引号字符弄错了,改成这样:

    printf("The addition of 5 and 12 is %d.\n", sum);
    

    我不知道您使用的是什么键盘,但通常 " 字符在 '2' 字符上方(我使用的是意大利键盘,所以您所在国家/地区的键盘可能有所不同)。
    你肯定会在某个地方找到那个角色。
    如果我没记错的话它在 ASCII 表中是 34,所以在 windows 上你可以通过按 alt+34 来获取它。

    【讨论】:

      【解决方案3】:

      不要在代码中使用“智能引号”!!!!!!对于字符串分隔符,请使用普通的旧引号。这里 ("""""""""""""") 是几个(这里是单引号:'''''''''''''')你可能可以复制/粘贴:)

      【讨论】:

        【解决方案4】:

        因为双引号错误

        printf(“The addition of 5 and 12 is %d.\n”, sum);
        

        printf("The addition of 5 and 12 is %d.\n”, sum);
        

        【讨论】:

          【解决方案5】:

          您在程序中为字符串使用了错误的引号。你有,而它应该是"

          【讨论】:

            猜你喜欢
            • 2013-10-12
            • 2015-08-05
            • 2020-08-15
            • 1970-01-01
            • 1970-01-01
            • 2014-03-06
            • 2021-04-03
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多