c - 在多行上定义一个字符串

标签 c syntax

请采取以下措施:

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/

相关文章:

c++ - 我可以从 Visual Studio 即时窗口调用 Win32 API 吗?

c - 中止数组连接函数中的陷阱 6

c - 为什么在调用strcat时添加\001

c++ - 使用范围解析运算符时的语法错误

mysql - 如何修复 MySQL 错误 #1064?

C:处理 HTTP 请求和响应

c - 程序没有在 scanf ("%c", &ch) 行停止,为什么?

swift 字典 : join key and value into string

javascript - 为什么使用 )( 在 Node.js REPL 中调用函数?

javascript - new MyFunction() 与 new(MyFunction)