我是 C 初学者,这是我的 C 代码:
#include <stdio.h>
#include <stdlib.h>
main()
{
printf("Hello, World!\n");
return 'sss';
}
这将显示一个错误。那么如何在 C 代码中返回一个字符串呢?
最佳答案
如果您希望从一个函数(main
除外)返回一个字符串,您应该这样做。
#include <stdio.h>
const char * getString();
int main()
{
printf("Hello, World!\n");
printf("%s\n", getString());
return 0;
}
const char * getString()
{
const char *x = "abcstring";
return x;
}
关于c - 如何在我的 C 代码中将字符串返回给操作系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4929329/