2012-02-23 70 views
0

我已經編寫了一個小應用程序,並像下面這樣:打印「」到C系統不工作?

sprintf(command, "......sending this string to system......{} \;" 
printf("%s\n",command); 
system(command); 
break; 

的問題是,不是整個字符串發送到系統,一切都出現在我的外殼除了「\」,這不因爲某些原因?我確信它確實是一個愚蠢的錯誤,我是一個新手。 謝謝

回答

5

\是一個轉義字符(你只是用它來打印使用\n換行符),所以如果你想打印一個反斜槓,你需要使用\\

sprintf(command, "......sending this string to system......{} \\;" 
//               ^^ 
//              take note here 
+0

謝謝你,這就是一個! – user1166981 2012-02-23 01:39:23

0

\是一個轉義字符。

使用\,你必須早\另一個\ 這樣的:

\\