fgets()函數(shù)的第二個(gè)參數(shù)指明了讀入字符的最大數(shù)量,如果讀到一個(gè)換行符蘑斧,會(huì)把它存在字符串中,同時(shí)须眷,fgets()函數(shù)并不會(huì)自動(dòng)換行竖瘾,其第三個(gè)參數(shù)指明要讀入的文件,如果從鍵盤輸入花颗,則是stdin(標(biāo)準(zhǔn)輸入)作為參數(shù)捕传。
#include<stdio.h>
#define STLEN 10
int main()
{
char words[STLEN];
puts("enter string :");
while (fgets(words, STLEN, stdin) != NULL&&words[0] != '\n')
{
fputs(words, stdout);
}
puts("done.");
return 0;
}
輸出示例:
enter string :
by the way,the gets() function
by the way,the gets() function
done.