Le code suivant est écrit pour sélectionner des données d'un fichier et copier dans un autre, mais j'obtiens l'erreur "Types incompatibles dans l'affectation" à la position notifiée.Je n'arrive pas à comprendre Qu'est ce qui cause cette erreur. Je serai heureux de recevoir votre aide.Types incompatibles dans l'affectation C/C++
#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$ %[email protected]", 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;
}
Ce code a besoin d'un peu de travail pour le moment mais je veux supprimer toutes les erreurs possibles avant de finaliser le code
Cordialement
'car' est un tableau bidimensionnel, donc' car [y] 'est un tableau de char, et vous ne pouvez lui assigner un seul caractère. – DCoder
'scanf ("% d ", id);' devrait également être corrigé. – chris
Le code pourrait avoir besoin de plus de travail que ce que vous pensez. Le faire compiler est la partie facile. Le débogage prendra aussi du temps. –