Line wrapping problem when string constants are defined if we place a backslash at the end of a line of code, the C compiler ignores line breaks at the end of lines and counts the contents of the next line as our content. Here the backslash acts as a continuation of the line.
If we do not use backslashes, the C language compiler will issue a warning when we try to initialize a string that spans multiple lines. As shown in the following statement:
Char letters[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ
Abcdefghijklmnopqrstuvwxyz "};
But we use backslashes at the end of the line, so we can write string constants across lines as follows:
Char letters[] = {"Abcdefghijklmnopqrstuvwxyz\
Abcdefghijklmnopqrstuvwxyz "};Enter a string from the beginning of the continuation line to avoid adding more spaces to the entire string。 In summary, the above statement defines a character array letters,
and initialize it to the following initial value: "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
There is also a way to split a string in C, which is to write multiple adjacent strings. These strings are separated by 0 or more whitespace, a producer, and a newline character. The C language compiler will automatically connect these strings together. Therefore, the following expression: "One" "Two" "three" is actually equivalent to "onetwothree". Therefore, the initialization statement of the preceding cross-line can also be done in the following form:
Char letters[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
An example is given under "abcdefghijklmnopqrstuvwxyz", and the following three printf statements actually accept only the parameters, printf ("programing in C is fun\n"); Programing in C are funprintf ("Programming in C", "is fun\n"); Programing in C was funprintf ("Programming" "" In C "" was fun "\ n);//programing in C was fun to understand is that this function of the C language string is borrowed from the shell. , so for the shell command line, the following two command execution results are equivalent when writing shell scripts:
[Email protected]:/etc# pwd/etc[email protected]:/etc# pw> d/Etc[email Protected]:
Reprint: http://blog.csdn.net/pachonghanya/article/details/6972632
The problem of string cross-line writing in C language