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

二、程序

#include <stdio.h>

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

测试

更多推荐

c语言按行读取文件