我试图运行此代码,并且在任何这些命令中都会出现运行时错误:
strcpy( memories[i].name, "file");
memories[i].name[4]=i+48;
memories[i].name[5]='\0';
我试图在很长一段时间内理解这个原因但却无法找到它。特别是当这个命令工作时:
strcpy( mm.name, "working file");
完整代码:
struct Memory {
char name[50]; //the name of the file
char storage[8000]; //the storage of the file
uint32_t address;
int sizeInUse; //bytes that are used
int memory_id;
};
//void initialMemory (struct Memory mm, struct Memory memories[]);
struct Memory mm; //working file
struct Memory memories[10];
//initialMemory ( mm ,memories);
strcpy( mm.name, "working file");
mm.address=&mm.storage;
mm.memory_id=-1;
mm.sizeInUse=0;
int i,j;
for(i=0; i<10; i++){
strcpy( memories[i].name, "file");
memories[i].name[4]=i+48;
memories[i].name[5]='\0';
memories[i].address= &memories[i].storage;
memories[i].memory_id=i;
int index=(i+1)*2; //we will fill (i+1)*200 places of memory i.
memories[i].sizeInUse= index;
for(j=0; j<index; j++){
memories[i].storage[j]=j+48;
}
memories[i].storage[index+1]='~';
}