如何在我的 C 代码中将字符串返回给操作系统? [英] How can I return a string to the operating system in my C code?
本文介绍了如何在我的 C 代码中将字符串返回给操作系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 C 初学者,这是我的 C 代码:
#include <stdio.h>#include <stdlib.h>主要的(){printf("你好,世界!
");返回'ss';}
这将显示一个错误.那么如何在 C 代码中返回一个字符串呢?
解决方案
如果您希望从函数(main
除外)返回字符串,您应该这样做.
p>
#include <stdio.h>const char * getString();主函数(){printf("你好,世界!
");printf("%s
", getString());返回0;}const char * getString(){const char *x = "abcstring";返回 x;}
I am a C beginner and this is my C code:
#include <stdio.h>
#include <stdlib.h>
main()
{
printf("Hello, World!
");
return 'sss';
}
That will show an error. So how can I return a string in C code?
解决方案
If you are looking to return a string from a function (other than main
), you should do something like this.
#include <stdio.h>
const char * getString();
int main()
{
printf("Hello, World!
");
printf("%s
", getString());
return 0;
}
const char * getString()
{
const char *x = "abcstring";
return x;
}
这篇关于如何在我的 C 代码中将字符串返回给操作系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文