如何在我的C code返回一个字符串? [英] How to return a string in my C code?
本文介绍了如何在我的C code返回一个字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一个C初学者,这是我的C code:
I am a C beginner and this is my C code:
#include <stdio.h>
#include <stdlib.h>
main()
{
printf("Hello world !\n");
return 'sss';
}
这将显示一个错误,
因此,如何在C code返回一个字符串?
so how to 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\n");
printf("%s\n", getString());
return 0;
}
const char * getString()
{
const char *x = "abcstring";
return x;
}
这篇关于如何在我的C code返回一个字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文