有时候,串太长,一行写不下,怎么办,当然你可以用反斜杠换行符,但是程序有点丑陋,比如:
#include <stdio.h>
#include <string.h>
int main()
{
// 下面程序不能缩进,否则串将改变。好丑陋。
char str1[] =
"a = 1\n\
b = 2\n\
c = 3\n\
d = 4\n\
e = 5\n\
f = 6";
char str2[] = "a = 1\nb = 2\nc = 3\nd = 4\ne = 5\nf = 6";
if(0 == strcmp(str1, str2))
{
printf("yes\n");
}
return 0;
}
有没有更好的办法呢?有的,如下:
#include <stdio.h>
#include <string.h>
int main()
{
char str1[] =
"a = 1\n"
"b = 2\n"
"c = 3\n"
"d = 4\n"
"e = 5\n"
"f = 6";
char str2[] = "a = 1\nb = 2\nc = 3\nd = 4\ne = 5\nf = 6";
if(0 == strcmp(str1, str2))
{
printf("yes\n");
}
return 0;
}