-3

所以我写了这段代码并通过cygwin终端运行它!我清除了所有错误,但它只给我留下了最后一个警告,我无法修复。

#include <stdio.h>
int main (int argc, char *argv[]) {
        int phoneNumber;
        char firstName[11];
        char lastName[11];
        char eMail[20];

        printf("Please enter the user's first name:");
        scanf("%s", firstName);
        printf("Please enter the user's last name:");
        scanf("%s", lastName);
        printf("Please enter the user's phone number:");
        scanf("%i", phoneNumber);
        printf("Please enter the user's e-mail:");
        scanf("%s", eMail);
        printf("firstName, lastName, phoneNumber, eMail: %s, %s, %i, %s", firstName, lastName,
phoneNumber, eMail);
}

有代码。cygwin 错误告诉我:

警告:格式指定类型“int”,但参数的类型为“int *”[-Wformat]

这是指 %i 所在的最后一个 printf 行。

4

1 回答 1

1

尝试scanf("%d", &phoneNumber);并使用%dprintf在 C 及其衍生物中,函数都是按值传递的。为了让函数修改变量,您需要传入该变量的地址而不是其值。这就是为什么您使用前缀来&获取函数的地址。但是,您仅将用于参数,而不用于在本地声明或使用变量。phoneNumberscanf&scanf

于 2013-09-25T02:53:20.540 回答