【问题标题】:How do I get input from user in the first problem set of cs50?如何在 cs50 的第一个问题集中获得用户的输入?
【发布时间】:2019-11-16 16:42:44
【问题描述】:

我需要实现get_string 方法才能要求用户输入,但我在运行程序时遇到了问题,尽管我认为我已经正确地执行了这些步骤。

这是我的代码:

#include <stdio.h>
#include <cs50.h>


int main(void)
{ string name = get_string("What is your name?\n");

   // string name= get_string("What is your name, huh? \n"); 
    printf("hello, %s\n", name);
}

现在要运行程序,我输入./hi(hi 是文件夹名称)进行编译,然后 ls.. 当我输入 clang hello.c ( hello.c 是我正在写入的文件的名称)时,我得到了错误.. 我不明白clang hello.c./hi 之间的区别..

【问题讨论】:

  • 错误信息是什么?请注意,clang hello.c 是编译代码的命令 - 如果它生成名为 hi (clang -o hi hello.c) 的可执行文件,则 ./hi 将运行该程序。如果hi 是一个目录名,那么./hi 不会做任何有用的事情。
  • 这里是错误信息:$ clang -o hi hello.c /tmp/hello-5cfed3.o: In function main': hello.c:(.text+0x19): undefined reference to get_string' clang: error: linker command failed with exit code 1 (use -v 查看调用) $

标签: java c cs50 edx


【解决方案1】:

尝试运行$ make hello.c,而不是运行clang,这应该会生成一个名为hello 的文件。终端还将显示 CS50 添加到 clang 的所有编译器参数。然后你应该可以使用$ ./hello运行了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-23
    • 2023-01-12
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多