我必须创建这个学生数据程序.有这个警告我只是想不通

  • 本文关键字:想不通 警告 程序 创建 数据 c
  • 更新时间 :
  • 英文 :


所以我写出了这段代码并通过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错误告诉我:

警告:format 指定类型"int",但参数的类型为"int *" [-Wformat]

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

尝试scanf("%d", &phoneNumber);并将%d也用于printf。 在 C 及其导数中,函数都是按值传递的。 为了使函数修改变量,您需要传入该变量的地址而不是其值。 这就是为什么您在前缀上加上&,以将phoneNumber的地址放入scanf函数中。 但是,您只能将 & 用于 scanf 参数,而不用于在本地声明或使用变量。

最新更新