【发布时间】:2019-09-18 11:40:39
【问题描述】:
我对 C 编程非常陌生,我正在编写一个基本代码,它收集名字和姓氏、工作时间、小时工资,然后返回姓氏、名字和小时 * 工资:
char first_name;
char last_name;
printf("\n%s, %s: %.2lf\n", last_name, first_name, total_payment);
我在编译时收到的错误是:
payroll.c:22:13: warning: format '%s' expects argument of type char *' but argument 2 has type 'int' [-Wformat=]
printf("\n%s, %s: %.2lf\n", last_name, first_name, total_payment);
^
payroll.c:22:13: warning: format '%s' expects argument of type char *' but argument 3 has type 'int' [-Wformat=]
printf("\n%s, %s: %.2lf\n", last_name, first_name, total_payment);
^
我不明白这个错误。 char * 是指针吗?为什么它不返回列出的第一个 char 变量,然后返回 .2 浮点 int 之前的第二个?我也在使用 nano,因此无法像往常一样进行调试。 (推荐的 IDE 也会非常有帮助。)
【问题讨论】:
-
first_name和last_name是单个字符。它们不能保存以 null 结尾的字节字符串。看来您可能需要退后一步来阅读您的书或教程。 -
%s用于字符串。你传递一个字符。单个字符不是字符串。字符串有一个零字符作为终止符。 -
免费的 Visual Studio 版本非常适合调试,如果您在 Windows 上,imo 通常是一个令人愉快的 IDE。也许有人推荐适用于 Linux 和 Mac 的 IDE?
-
在阅读和考虑编译器警告方面得到了我的意见。这甚至超过了许多有经验的程序员可以做到的。
-
谢谢大家。我来自 Java,所以这在某些方面非常陌生。我感谢您的帮助,并确实通过建议和我的资源解决了问题。 (通常我需要几个小时或几天,但这是即时的。)
标签: c console-application