The problem of string cross-line writing in C language

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.