c语言按行读取文件

c语言按行读取文件,第1张

一、介绍
在做项目需要配置的参数一般保存在文件,读取文件配置比较简单的方法就是按行读取

二、程序

#include 

int main()
{
	FILE *fp=NULL;
	unsigned int tmp = 0;
		
	fp = fopen("config.txt", "r");
	while(!feof(fp))
	{
		fscanf(fp, "%x\r\n", &tmp);
		printf("tmp:%x\n",tmp);
	}
	fclose(fp);
	
	return 0;
}

测试文件
config.txt

1234
1234

编译

gcc testfile.c -o testfile

测试

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1325545.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-12
下一篇 2022-06-12

发表评论

登录后才能评论

评论列表(0条)

保存