做兼职那个网站比较好,哔哩哔哩推广平台,建网站步骤,软文推广软文营销函数声明#xff1a;char *fgets(char *str,int n,FILE *stream) 函数介绍#xff1a;从指定的stream流中读取一行#xff0c;并把它存储在str所指向的字符串中。当读取到#xff08;n-1#xff09;个字符时#xff0c;获取读取到换行符时#xff0c;或者到达文件末尾时… 函数声明char *fgets(char *str,int n,FILE *stream) 函数介绍从指定的stream流中读取一行并把它存储在str所指向的字符串中。当读取到n-1个字符时获取读取到换行符时或者到达文件末尾时他会停止。具体视情况而定。 函数参数 l str –- 这是一个指向字符数组的指针该数组存储了要读取的字符串。 l n – 这是读取的最大的字符数包括最后面的空字符通常是使用str传递的数组长度。 l stream – 这是指向FILE对象的指针该FILE对象标识了要从中读取的字符串。 返回值如果成功该函数返回相同的str参数如果到达文件末尾或者没有读取到任何字符str内容保持不变并返回一个空指针。 实例 /*
fgets.c
*/
int main()
{FILE *fp;char str[60];fp fopen(file.txt,r);if(NULL fp){perror(open the file error);return 0;}while(NULL ! fgets(str,60,fp)){puts(str);}fclose(fp);return 0;
} /*
file.txt
*/
this is first line
this is second linethis is three line 输出结果 exbotubuntu:~/wangqinghe/Transducer/20190712/01$ ./fgets this is first line this is second line this is three line exbotubuntu:~/wangqinghe/Transducer/20190712/01$ gedit fgets.c file.txt puts(str);//自带“\n” 改为printf(“%s”,str); 运行结果 exbotubuntu:~/wangqinghe/Transducer/20190712/01$ ./fgets this is first line this is second line this is three line 转载于:https://www.cnblogs.com/wanghao-boke/p/11176790.html