簡體   English   中英

C-printf錯誤

[英]C - printf error

我正在嘗試在24小時內匯編Sam的Learn C中的示例。

當我嘗試編譯以下代碼時,出現錯誤:

/* 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

提前致謝。

您在程序中對字符串使用了錯誤的引號。 您有應有的狀態"

您只是誤了引號字符,將其更改為:

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

我不知道您使用的是哪種鍵盤,但是通常情況下,“”字符位於“ 2”字符上方(我使用的是意大利語鍵盤,因此可能因您所在的國家/地區而有所不同)。
當然,您會在某個地方找到該角色。
如果我沒記錯的話,ASCII表中的數字是34,因此在Windows上,您可以通過按alt + 34來獲取它。

由於錯誤的雙qoute

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

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

不要在代碼中使用“智能引號”! 對於字符串定界符,請使用普通的舊引號。 這里(“”“”“”“”“”“”“”)是一些(這里的單引號:“''''''''''''),您可以復制/粘貼:)

我看到您的錯誤, 因為字符相同 查看您的代碼

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

嘗試更改為:

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

你能看到差異嗎? Qoute“一定是”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM