为什么我的 Struct char 成员没有被分配值 'F' 而是保留默认的初始化值?
Why isn't my Struct char member being assigned the value 'F' and instead is staying the default initialization value?
我正在从磁盘映像中读取二进制数据,当 buffer[0] 等于 3 时,RootDirectory[j] 的状态成员应该是 'F'。然而,当我 运行 代码值为 0 时。if 语句 (chartest == 3) 在每次应该输入时都会输入。
typedef struct{
char Status;
int StartingBlock;
int BlockNumbers;
int FileSize;
int CreateTime;
int ModifyTime;
char FileName[31];
}RootDirectory;
RootDirectory *Dir = (RootDirectory*)malloc(sizeof(RootDirectory)* RootNum);
char buffer1[50];
int chartest;
int j = 0;
int RootBytes = Info.RootDirectoryBlocks * Info.BlockSize;
int DirectoryEntries = RootBytes/64;
for(int i = 0; i < DirectoryEntries; i++){
int statusread = fread(buffer1, 1,1, fp);
if((int) buffer1[0] == 0){
fseek(fp, 63, SEEK_CUR);
}
else{
chartest = (int)buffer1[0];
if(chartest == 3){
Dir[j].Status = 'F';
}
fseek(fp, 63, SEEK_CUR);
j++;
}
}
for(int i = 0; i < j; i++){
printf("%c\n", Dir[j].Status);
}
在最后一个循环中会是printf("%c\n", Dir[i].Status);
。不是 Dir[j].Status
我正在从磁盘映像中读取二进制数据,当 buffer[0] 等于 3 时,RootDirectory[j] 的状态成员应该是 'F'。然而,当我 运行 代码值为 0 时。if 语句 (chartest == 3) 在每次应该输入时都会输入。
typedef struct{
char Status;
int StartingBlock;
int BlockNumbers;
int FileSize;
int CreateTime;
int ModifyTime;
char FileName[31];
}RootDirectory;
RootDirectory *Dir = (RootDirectory*)malloc(sizeof(RootDirectory)* RootNum);
char buffer1[50];
int chartest;
int j = 0;
int RootBytes = Info.RootDirectoryBlocks * Info.BlockSize;
int DirectoryEntries = RootBytes/64;
for(int i = 0; i < DirectoryEntries; i++){
int statusread = fread(buffer1, 1,1, fp);
if((int) buffer1[0] == 0){
fseek(fp, 63, SEEK_CUR);
}
else{
chartest = (int)buffer1[0];
if(chartest == 3){
Dir[j].Status = 'F';
}
fseek(fp, 63, SEEK_CUR);
j++;
}
}
for(int i = 0; i < j; i++){
printf("%c\n", Dir[j].Status);
}
在最后一个循环中会是printf("%c\n", Dir[i].Status);
。不是 Dir[j].Status