我是C语言的新手,所以请原谅我的一些错误。我想知道是否有可能在一个字符串中存储多个字符串/数组值?这是一个示例,可让您大致了解我要做什么。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const char *lister[] = {"H", "E", "LL", "O"}; //forgot brackets, fixed now
int main()
{
char *mystring[] = ("%s%s", lister[1], lister[2]);
printf ("%s\n", mystring);
return 0;
}
不知道这是否有意义,但正在寻找将字符串值存储到另一个字符串或数组中的方法。谢谢!:)编辑:strncat解决了此问题,如果您遇到相同的问题,请访问http://www.tutorialspoint.com/c_standard_library/c_function_strncat.htm了解更多信息,这要归功于computerfreaker建议strncat!
您也可以使用sprintf将多个字符串转换为具有自己格式的一个字符串。
sprintf(destination_string, "%s----%s", source_string1,source_string2);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句