读取文本数据或参数到构造体
读取文本数据或参数到结构体
我定义了这样一组结构:
我想将文本中的一组数据:
(score3由score1、score2计算得出)读取到结构中,我下面是这么定义函数的:请给指点一下
------解决方案--------------------
你怎么写入文本STUDENT_FILE的,就怎么读出来呗
------解决方案--------------------
推荐使用WinHex软件查看硬盘或文件或内存中的原始字节内容。
不要把
fopen("...","...");fscanf,fprintf,fclose //读时把\r\n替换成\n,写时把\n替换成\r\n;读到\x1a就设置EOF;读写的内容当字符看待
和
fopen("...","...b");fread,fwrite,fclose //不作以上替换,遇到\x1a仍继续读;读写的内容当字节看待
弄混了
------解决方案--------------------
vs下用GetPrivateProfileInt函数读取ini文件中的数据到int
如果是linux下,自己找个读ini文件的源代码
------解决方案--------------------
没实际编译链接调试,不保证对,仅供参考:
我定义了这样一组结构:
typedef struct student //学生数据结构体声明
{
int number; //学号
int score[3]; //平时、期末和总评成绩
}STUDENT;
我想将文本中的一组数据:
[studentinfo]
stuudentsum=3
[student1]
number=00001
score1=88
score2=99
[student2]
number=00002
score1=99
score2=86
[student3]
number=00003
score1=78
score2=65
[student4]
number=00004
score1=78
score2=56
[student5]
number=00005
score1=35
score2=78
[student6]
number=00006
score1=98
score2=76
[student7]
number=00007
score1=78
score2=65
(score3由score1、score2计算得出)读取到结构中,我下面是这么定义函数的:请给指点一下
void readinfo(int student_sum, int student_number, int student_score[]) //从文本读取
{
FILE *pRF;
if(NULL == (pRF=fopen(STUDENT_FILE, "rb")))
{
printf("open false!");
return;
}
//下面不知道怎么分类读取里面的数据到结构了。
}
C
数据结构
------解决方案--------------------
你怎么写入文本STUDENT_FILE的,就怎么读出来呗
------解决方案--------------------
推荐使用WinHex软件查看硬盘或文件或内存中的原始字节内容。
不要把
fopen("...","...");fscanf,fprintf,fclose //读时把\r\n替换成\n,写时把\n替换成\r\n;读到\x1a就设置EOF;读写的内容当字符看待
和
fopen("...","...b");fread,fwrite,fclose //不作以上替换,遇到\x1a仍继续读;读写的内容当字节看待
弄混了
------解决方案--------------------
vs下用GetPrivateProfileInt函数读取ini文件中的数据到int
如果是linux下,自己找个读ini文件的源代码
------解决方案--------------------
没实际编译链接调试,不保证对,仅供参考:
//in.txt:
//[studentinfo]
//stuudentsum=3
//
//[student1]
//number=00001
//score1=88
//score2=99
//
//[student2]
//number=00002
//score1=99
//score2=86
//
//[student3]
//number=00003
//score1=78
//score2=65
//
//[student4]
//number=00004
//score1=78
//score2=56
//
//[student5]
//number=00005
//score1=35
//score2=78