如何用C语言写日记?
How do I make a Diary in C language?
这里是第一个计时器;我正在尝试按照 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时,它returns这个错误信息
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.
这里有什么我遗漏的吗?我在我的 OS 中安装了 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)
我被难住了
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);
^
此错误意味着您无法将 "What is your name?\n"
传递给 GetString
。
Diarytest.c:11:22: warning: more '%' conversions than data arguments
[-Wformat]
printf("Hello there %s, name\n");
~^
此错误意味着您必须在此处向 printf
提供另一个参数(可能是 name
)。
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);
^
类似上面的问题,不能把"What is your age?\n"
传给GetInt
。
Diarytest.c:15:18: warning: more '%' conversions than data arguments
[-Wformat]
printf("You are %i, old\n");
~^
2 warnings and 2 errors generated.
再一次,你必须在这里为 printf
提供另一个参数(可能是 age
)。
这里是第一个计时器;我正在尝试按照 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时,它returns这个错误信息
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.
这里有什么我遗漏的吗?我在我的 OS 中安装了 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)
我被难住了
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);
^
此错误意味着您无法将 "What is your name?\n"
传递给 GetString
。
Diarytest.c:11:22: warning: more '%' conversions than data arguments
[-Wformat]
printf("Hello there %s, name\n");
~^
此错误意味着您必须在此处向 printf
提供另一个参数(可能是 name
)。
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);
^
类似上面的问题,不能把"What is your age?\n"
传给GetInt
。
Diarytest.c:15:18: warning: more '%' conversions than data arguments
[-Wformat]
printf("You are %i, old\n");
~^
2 warnings and 2 errors generated.
再一次,你必须在这里为 printf
提供另一个参数(可能是 age
)。