编写以下代码以从一个文件中选择一些数据并复制到另一个文件中,但我在通知位置收到错误“分配中的类型不兼容”。我无法弄清楚导致此错误的原因。我很高兴得到您的帮助。
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *myfile;
myfile=fopen("write.txt","a");
char *name;
int id,i=0,check,*w,n=0;
if(myfile)
{
do
{
printf("Enter ID and Name of the student\n");
scanf("%d%s",&id, name);
fprintf(myfile,"%d$ %s@", id, name);
printf("Are there any more students [y/n]");
}while(getch()=='y');
fclose(myfile);
}
printf("Do you want to shortlist the students [y/n]?");
if(getch()=='y')
{
myfile=fopen("write.txt","r");
while(check!=EOF)
{
check=getc(myfile);
i++;
if(check=='%')
n++;
}
fclose(myfile);
myfile=fopen("write.txt","r");
int x[i-1];
char car[n][20];
int yolo,y=0,q=0,j,h,temp;
for(j=0;j<i;j++)
{
x[j]=getc(myfile);
if(x[j]=='$')
{
w[q]=x[j-1];
yolo=temp=j;
q++;
}
else
if(x[j]=='@')
{
yolo++;
for(h=0;h<j-temp;h++)
car[y]=(char)x[yolo]; // ERROR
y++;
}
}
fclose(myfile);
//char data= new char[i++];
//fscanf();
myfile=fopen("shortlisted.txt","a");
if(myfile)
{
printf("Type the ID of the student you want to shortlist:\n");
scanf("%d",id);
}
}
else
printf("The file you specified doesn't exists");
printf("Hello world!\n");
return 0;
}
这段代码目前需要做一些工作,但我想在完成代码之前删除所有可能的错误
问候