c語言輸出最長字符串 C語言:四個字符串的輸入輸出?
C語言:四個字符串的輸入輸出?Scanf();將在緩存中存儲“回車”;執(zhí)行Scanf后,使用fflush(stdin)清理緩存。get(s)函數(shù)類似于scanf(%s“,&s),但并不完全相同。
C語言:四個字符串的輸入輸出?
Scanf();將在緩存中存儲“回車”;執(zhí)行Scanf后,使用fflush(stdin)清理緩存。get(s)函數(shù)類似于scanf(%s“,&s),但并不完全相同。使用scanf(%s“,&s)函數(shù)輸入字符串時出現(xiàn)問題,即如果輸入了空格,則輸入字符串將被視為結束,空格后的字符將作為下一個輸入處理,但gets()函數(shù)將接收整個輸入字符串,直到回車為止。get(s)函數(shù)中的變量s是一個字符串。如果是單個字符,則編譯連接時不會出錯,但運行后會出現(xiàn)“空指針為內(nèi)存”的錯誤。#include “stdio.h”define max 100int main(){ char s1[max],s2[max],s3[max],s4[max] printf(“Input s1:”) scanf(“%s”,&1) Flush(stdin) printf(“Input s2:”))scanf(“%s”,&2) Flush(stdin) printf(“Input s3:”) gets(s3) printf(“Input s4:”) gets(s4) puts(s1) puts(s3) puts(s4) return 0}