69,373
社区成员
发帖
与我相关
我的任务
分享
【学生成绩信息】
姓名:张三
性别:男
年龄:22
姓名:李四
性别:男
年龄:21
姓名:王丽
性别:女
年龄:20
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LENGTH 20
typedef struct Student
{
char name[MAX_LENGTH];
char gender[3];
int age;
} Student;
int main(void)
{
int i = 0;
char buf[100];
char *tmp = NULL, *content;
char *delim = ":";
FILE *fp = fopen("stu.txt", "r");
if (fp == NULL)
{
printf("file error!\n");
return -1;
}
fscanf(fp, "%s", buf);
while (EOF != fscanf(fp, "%s", buf))
{
printf("%s\n", buf);
tmp = strtok(buf, delim);
do
{
content = tmp;
/*printf("%s\n", tmp);*/
} while (NULL != (tmp = strtok(NULL, delim)));
/* 此时content指向的就是分割结果的最后一个(即字段的数据字符串)*/
/* 后面的处理暂时我也想不起来 */
printf("\n");
}
fclose(fp);
return 0;
}