Hi! I've a problem with my code, please help me to undestand what is going on...
I open a file and I save all it's characters in an array, which I call "instruction_name". Then I close the file. Finally, I open a new file and I save all it's characters in an another array (register_name), and after this I close the file, as before. The problem is that after the open/read/close of the second file, the first two elements of the "instruction_name" array are being missed! For example let's say that the "instruction_name" array is like this: "NOPADDINC ...". After the second file the "instruction_name" array is "ασPADDINC ...". What is going on?
My code is like this
Code:
FILE *readinstructions;
printf("Loading the file which contains the instructions... ");
if ((readinstructions=fopen("instructions.txt","r"))==NULL){
printf("\nError: Cannot open the instructions.txt");
}
else printf("successful");
i=0;
while ((character=fgetc(readinstructions))!=EOF){
instruction_name[i]=character;
i++;
}
fclose(readinstructions);
FILE *readregisters;
printf("\nLoading the file which contains the registers...");
if ((readregisters=fopen("registers.txt","r"))==NULL){
printf("\nError: Cannot open the registers.txt");
}
else printf(" successful");
i=0;
while ((character=fgetc(readregisters))!=EOF){
register_name[i]=character;
i++;
}
fclose(readregisters);
PS: I use DEV C++