fgets 函数
来源:互联网 发布:linux安装jenkins配置 编辑:程序博客网 时间:2024/05/20 06:28
fgets函数用来从文件中读入字符串。
fgets函数的调用形式如下:fgets(str,n,fp);
此处,fp是文件指针;str是存放在字符串的起始地址;
n是一个int类型变量。
函数的功能是从fp所指文件中读入n-1个字符放入str为起始地址的空间内;
如果在未读满n-1个字符之时,已读到一个换行符或一个EOF(文件结束标志),则结束本次读操作,读入的字符串中最后包含读到的换行符。
因此,确切地说,调用fgets函数时,最多只能读入n-1个字符。读入结束后,系统将自动在最后加'\0',并以str作为函数值返回。
#include <string.h>
#include <stdio.h>
int main(void)
{
FILE *stream;
char string[] = "This is a test";
char msg[20];
/* open a file for update */
stream = fopen("DUMMY.FIL", "w+");
/* write a string into the file */
fwrite(string, strlen(string), 1, stream);
/* seek to the start of the file */
fseek(stream, 0, SEEK_SET);
/* read a string from the file */
fgets(msg, strlen(string)+1, stream);
/* display the string */
printf("%s", msg);
fclose(stream);
return 0;
}
- fgets函数
- fgets函数
- fgets函数
- fgets 函数
- fgets函数
- fgets函数
- fgets函数
- fgets()函数
- fgets函数
- fgets函数
- fgets()函数
- fgets函数
- fgets函数
- fgets函数
- fgets函数
- fgets函数
- fgets()函数
- fgets()函数
- [整理]ECMAScript版本和主流浏览器对它们的支持
- highcharts与ajax的应用
- 并查集(Union-Find)算法介绍
- 向GOOGLE产品经理学习
- alttiff.ocx文件的用处
- fgets 函数
- ASP.NET AJAX服务器端控件官方视频教程 下载--英文
- html5 svg
- 低配高效的唯一优势就是成本低
- 由于现在在看QT 所以,转载写文章 -- QT focusInEvent 事件
- IP工具类v1.0
- ★ Eclipse Debug 界面应用详解——Eclipse Debug不为人知的秘密
- 批量替换 MySQL 指定字段中的字符串
- FPGA开发流程及步骤含义