1个回答
展开全部
拿作业给你说下
FILE *f;//设置文件指针
f = fopen("d:\\T\\inf.txt", "r");//打开指定文件
char a;
fseek(f, -50, 2);//设置文件指针位置
fread(&a, 1, 1, f);//将当前位置的n个字符串读到a开始的空间中这里只有一个字符
fclose(f);//关闭文件
if (a != '\0')
{
f = fopen("d:\\T\\inf.txt", "a+");
char kk[51] = { '\0' };
fwrite(kk, sizeof(char), 51, f);
fclose(f);
}
f = fopen("d:\\T\\inf.txt", "r");
Clist*L = (Clist*)malloc(sizeof(Clist)), *L1, *L2;
L2 = L; L->next = NULL;
int i = 0;
for (;; i++)
{
char *in = (char*)malloc(50 * sizeof(char));
fseek(f, i * 50 , 0);
fread(in,1, 50, f);
L1 = (Clist*)malloc(sizeof(Clist));
strcpy(L1->k, in);
L->next = L1;
L = L1;
L->next = NULL;
if (in[0]=='\0')
break;
}
fclose(f);
char*s = (char*)malloc(50 * i);
char*s1;s1 = s;
int cal = 0;
while (i>0) {
L2 = L2->next;
strcpy(s1, L2->k);
cal += 50;s1 = &s[cal];
i--;
}
return s;
FILE *f;//设置文件指针
f = fopen("d:\\T\\inf.txt", "r");//打开指定文件
char a;
fseek(f, -50, 2);//设置文件指针位置
fread(&a, 1, 1, f);//将当前位置的n个字符串读到a开始的空间中这里只有一个字符
fclose(f);//关闭文件
if (a != '\0')
{
f = fopen("d:\\T\\inf.txt", "a+");
char kk[51] = { '\0' };
fwrite(kk, sizeof(char), 51, f);
fclose(f);
}
f = fopen("d:\\T\\inf.txt", "r");
Clist*L = (Clist*)malloc(sizeof(Clist)), *L1, *L2;
L2 = L; L->next = NULL;
int i = 0;
for (;; i++)
{
char *in = (char*)malloc(50 * sizeof(char));
fseek(f, i * 50 , 0);
fread(in,1, 50, f);
L1 = (Clist*)malloc(sizeof(Clist));
strcpy(L1->k, in);
L->next = L1;
L = L1;
L->next = NULL;
if (in[0]=='\0')
break;
}
fclose(f);
char*s = (char*)malloc(50 * i);
char*s1;s1 = s;
int cal = 0;
while (i>0) {
L2 = L2->next;
strcpy(s1, L2->k);
cal += 50;s1 = &s[cal];
i--;
}
return s;
更多追问追答
追问
谢谢了
我那道题是要求:学生基本信息文件可以在磁盘建立,采用写文件的方式录入学生成绩基本信息,综合成绩计算得到。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询