2014-09-22 67 views
-2
printf("%c Trying to forget someone you love is like trying to remember someone you never knew \n\n",3); 

變得像在vb.net:如何在此C代碼中創建新行?

printf("%c Trying to forget someone you love is like trying to" & 
"remember someone you never knew \n\n",3); 

我們添加下一個串上新的生產線....如何在C語言中的字符串連接。

+5

只是忽略了&符。兩個並置的字符串文字將成爲一個。 (雖然這不會打印換行符,並將「粘貼到」和「記住」在您的案例中)。 – 2014-09-22 05:40:01

+0

另請參閱[這裏](http://stackoverflow.com/questions/797318/how-to-split -a-string-literal-across-multiple-lines-in-c-objective-c)以獲得更詳細的答案,這也給出了另一種選擇。 – 2014-09-22 05:43:12

+0

謝謝!我是C新手... – user3658777 2014-09-22 05:44:28

回答

2

兩種方式:

printf("%c Trying to forget someone you love is like trying to " 
     "remember someone you never knew \n\n",3); 

字符串字面可以這樣寫,與多個引用部分。它仍然只是一個字符串。這種方式可以在兩者之間進行縮進和評論。


printf("%c Trying to forget someone you love is like trying to \ 
remember someone you never knew \n\n",3); 

您可以通過具有反斜槓作爲行最後字符分割字符串文字。如果你想在最後使用\n\,那麼在結果字符串中將不會有換行符。此外,如果您縮進第二行,則該空格將進入字符串中,通常不是您想要的。

0

只需將字符串放在一起,而不需要任何操作符。

printf("%c Trying to forget someone you love is like trying to " 
     "remember someone you never knew \n\n", 3); 

它將被編譯器視爲一個長字符串。

0

你只需要編寫

printf("%c Trying to forget someone you love is like trying " 
     "to remember someone you never knew \n\n",3); 

兩個並列的字符串文本將成爲一體。