【发布时间】:2020-11-30 19:58:51
【问题描述】:
这里是第一个计时器;我正在尝试按照cs50参考在c中制作一个日记程序
#include <cs50.h>
#include <stdio.h>
#include <unistd.h>
int main(void)
{
//Program ask user for their name
string name = GetString("What is your name?\n");
printf("Hello there %s, name\n");
//Program ask user for their age
int age = GetInt("What is your age?\n");
printf("You are %i, old\n");
}
当我使用 clang 运行代码时,它会返回此错误消息
Diarytest.c:10:25: error: too many arguments to function call, expected 0,
have 1
string name = GetString("What is your name?\n");
~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/cs50.h:106:1: note: 'GetString' declared here
string GetString(void);
^
Diarytest.c:11:22: warning: more '%' conversions than data arguments
[-Wformat]
printf("Hello there %s, name\n");
~^
Diarytest.c:14:18: error: too many arguments to function call, expected 0,
have 1
int age = GetInt("What is your age?\n");
~~~~~~ ^~~~~~~~~~~~~~~~~~~~~
/usr/local/include/cs50.h:87:1: note: 'GetInt' declared here
int GetInt(void);
^
Diarytest.c:15:18: warning: more '%' conversions than data arguments
[-Wformat]
printf("You are %i, old\n");
~^
2 warnings and 2 errors generated.
这里有什么我遗漏的吗?我在我的操作系统中安装了 cs50 库,我什至尝试链接它,它返回了相同的错误消息。谢谢你的帮助!干杯。
更新:代码在下方用户的帮助下进行了更新(感谢 David Cullen),现在代码如下所示。
#include <cs50.h>
#include <stdio.h>
#include <unistd.h>
int main(void)
{
//Program ask user for their name
string name = GetString();
printf("Hello there, %s\n", name);
//Program ask user for their age
int age = GetInt();
printf("You are, %i\n", age);
}
但是,当我使用 clang 运行程序时,我收到一条新的错误消息。
/usr/bin/ld: /tmp/Diarytest-862733.o: in function `main':
Diarytest.c:(.text+0x9): undefined reference to `GetString'
/usr/bin/ld: Diarytest.c:(.text+0x2a): undefined reference to `GetInt'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我被难住了
【问题讨论】:
-
您打算使用
get_int吗?见cs50.stackexchange.com/questions/28698/… -
2016年,CS50课程的学员将函数接口由
GetString()改为get_string()。您不应该仍然尝试使用带有大写字母的名称。令人惊讶的是,您发现了对旧名称的引用。