#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef struct PCB{
char name[32];
PCB* point;
int runtime;
int degree;
int status;
} PCB;
int main(int argc, char* argv[])
{
//打开文件
FILE * r=fopen("A.txt","r");
assert(r!=NULL);
FILE * w=fopen("B.txt","w");
assert(w!=NULL);
//读写文件
PCB a[5];
int i=0;
while(fscanf(r,"%s%d%d%d",a[i].name,&a[i].runtime,&a[i].degree,&a[i].status)!=EOF)//文本文件结束符
{
printf("%s\t%d\t%d\t%d\n",a[i].name,a[i].runtime,a[i].degree,a[i].status);//输出到显示器屏幕
fprintf(w,"%s\t%d\t%d\t%d\n",a[i].name,a[i].runtime,a[i].degree,a[i].status);//输出到文件B.txt
i++;
}
//关闭文件
fclose(r);
fclose(w);
system("pause");
return 0;
#include <stdlib.h>
#include <assert.h>
typedef struct PCB{
char name[32];
PCB* point;
int runtime;
int degree;
int status;
} PCB;
int main(int argc, char* argv[])
{
//打开文件
FILE * r=fopen("A.txt","r");
assert(r!=NULL);
FILE * w=fopen("B.txt","w");
assert(w!=NULL);
//读写文件
PCB a[5];
int i=0;
while(fscanf(r,"%s%d%d%d",a[i].name,&a[i].runtime,&a[i].degree,&a[i].status)!=EOF)//文本文件结束符
{
printf("%s\t%d\t%d\t%d\n",a[i].name,a[i].runtime,a[i].degree,a[i].status);//输出到显示器屏幕
fprintf(w,"%s\t%d\t%d\t%d\n",a[i].name,a[i].runtime,a[i].degree,a[i].status);//输出到文件B.txt
i++;
}
//关闭文件
fclose(r);
fclose(w);
system("pause");
return 0;
}
读取文件之后指向文件的读取指针会往后移动