正确使用cs50库中的’get_string’函数而不遇到错误的方式是什么?

huangapple go评论86阅读模式
英文:

What should be the correct way to use 'get_string' function from cs50 library without encountering errors?

问题

使用cs50库时,get_string函数无法正常工作。

错误消息中指出了问题:get_string函数缺少参数。要解决此问题,您需要提供正确的参数。

以下是修复的代码:

string name = get_string("hey? ");

这样就可以正常使用get_string函数了。希望这有助于解决您的问题。

英文:

When using cs50 library, get_string function doesn't work properly.

uppercase.c:6:19: error: too few arguments to function 'get_string'
     string name = get_string("hey? ");
                   ^~~~~~~~~~
In file included from uppercase.c:2:0:
c:\mingw\include\cs50.c:78:8: note: declared here
 string get_string(va_list *args, const char *format, ...)
        ^~~~~~~~~~

How can I make this work?

答案1

得分: 3

错误信息建议在uppercase.c中包含#include <cs50.c>。 正确的用法是包含头文件#include <cs50.h>并在构建程序时链接实现库-lcs50。 文档说:

> 如果在编译程序时看到/usr/bin/ld: cannot find -lcs50:请将export LIBRARY_PATH=/usr/local/lib添加到您的.bashrc中。

通常,您可以使用-L/usr/local/lib或您安装库的路径来指定库搜索路径。

英文:

The error message suggest that in uppercase.c you #include <cs50.c>. The correct usage is to include the header file #include <cs50.h> and link the implementation library -lcs50 when you build your program. The documentation says:

> If, when compiling a program, you see /usr/bin/ld: cannot find -lcs50: Add export LIBRARY_PATH=/usr/local/lib to your .bashrc.

You normally specify the library search path with -L/usr/local/lib or whatever path you installed the library to.

huangapple
  • 本文由 发表于 2023年6月5日 12:05:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76403446.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定