请采取以下措施:
char buffer[512];
memset(buffer, 0, sizeof(buffer));
sprintf(&buffer[0],"This Is The Longest String In the World that in text goes on and..");
printf("Buffer:%s\r\n",buffer);
我希望能够在多行中创建此字符串,以便于进行故障排除和编辑。但是,当我使用 \
命令时,我的输出被似乎是制表符的东西分隔开?
示例:
sprintf(&buffer[0],"This Is The\
Longest String In the World\
that in text goes on and..");
产生以下输出:
Buffer:This Is The Longest String In the World that in text goes on and..
有什么想法吗?这只是一种尝试跨多行代码拆分字符串的错误方法吗?
最佳答案
换行符会考虑代码中的任何空格。
您可以利用字符串文字连接来提高可读性:
sprintf(buffer, "This Is The "
"Longest String In the World "
"that in text goes on and..");
使用 \
您需要在第 0 列开始继续您的字符串:
sprintf(buffer, "This Is The \
Longest String In the World \
that in text goes on and..");
关于c - 在多行上定义一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12694838/