函數原型
char* fgets(char* s, int size, FILE* fp)
用法
函數會讀取最多size大小的數據到s中,當遇到EOF或者新行時也會停止,並將換行符“\n”保存在s中。
示例代碼:
1 #include <stdio.h>
2 #include <stdlib.h>
3 void main()
4 {
5 FILE *fp = fopen("test.in","r");
6 char in[100],in2[100];
7 fgets(in,sizeof(in),fp);
8 fgets(in2,sizeof(in2),fp);
9 printf("%s%s",in,in2);
10 }
test.in
1 this is a test!
2 hello world!
3 god bless me!
4
運行結果:
this is a test!
hello world!