字串處理函式問題

2021-09-29 09:47:51 字數 820 閱讀 9640

在使用字串處理函式的學習中,發現了書中的gets()和puts()函式報錯。

/* string"a" might be zero-terminated. */

以下是部分處理函式報錯的處理方法:

/*gets()原寫法*/

char str1[

100]

;gets

(str1)

;/*報錯:identifier "gets"is undefined*/

/*解決修改方案*/

char str1[

100]

;fgets

(str1,

sizeof

(str1)

,stdin)

;

/*puts()原寫法*/

char str1[

100]

;puts

(str1)

;/*修改解決方案*/

char str1[

100]

;fputs

(str1,stdout)

;

/*strcat()原寫法*/

char str1[

100]

;strcat

(str1,str2)

;/*修改解決方案*/

char str1[

100]

;strncat

(str1,str2,

int size)

;

字串處理函式

1 puts 向顯示器輸出字串 原型 int puts const char s 標頭檔案 include 返回值 成功返回輸出的字元數,失敗返回eof puts 函式與printf 輸出字串的區別 1.puts在輸出字串時,遇到 0 會自動終止輸出,並將 0 轉換為 n 來輸出 2.printf在...

字串處理函式

puts 函式 用來向標準輸出裝置 螢幕 寫字串並換行,其呼叫格式為 puts s 其中s為字串變數 字串陣列名或字串指標 puts 函式的作用與語printf s n s 相同,將緩衝區的字元輸出到標準輸出,遇到空字元截至,並且在末尾新增乙個換行符。gets 函式用來從標準輸入裝置 鍵盤 讀取字串...

字串處理函式

下面介紹幾個最常用的字串函式。格式 puts 字元陣列名 功能 把字元陣列中的字串輸出到顯示器。即在螢幕上顯示該字串。例7 12 include stdio.h main 從程式中可以看出puts函式中可以使用轉義字元,因此輸出結果成為兩行。puts函式完全可以由printf函式取代。當需要按一定格...