gpt4 book ai didi

c - 将数据传递到结构时出错

转载 作者:太空宇宙 更新时间:2023-11-04 08:49:46 25 4
gpt4 key购买 nike

我在函数内部的结构调用中遇到错误。在代码中,我将两个字节的数据转换为一个 16 位数据,我想将其存储到我的一个结构变量中。但是,我收到一个无法查明的错误。编译器告诉我错误在 unsigned int fat.sector_size = combinedBytes; 行中。我在这里做错了什么?提前致谢!

编辑:我得到的错误是

main.c:62:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token

main.c:62:19: error: expected expression before ‘.’ token`


struct fileSystem_info{
unsigned int sector_size; //Sector size
int cluster_size_in_sectors; //Cluster size in sectors
int entries_in_root_directory; //Number of entries in root directory
int sectors_per_fat; //Sectors per file allocation table
int reserved_sectors; //Number of reserved sectors on the disk
int hidden_sectors; //Number of hidden sectors on the disk
int sector_number_of_first_copy_of_fat; //Sector number of the first copy of the file allocation table
int sector_number_of_first_sector_of_root_directory; //Sector number of the first sector of the root directory
int sector_numner_of_first_sector_of_first_usable_data_cluster; //Sector number of the first sector of the first usable data cluster
};

//Converts two 8 bit data to one 16 bit data
unsigned converter(unsigned mostSignificant_bit, unsigned leastSignificant_bit){
uint16_t value = (uint16_t)(mostSignificant_bit << 8) | leastSignificant_bit;
//return((mostSignificant_bit * 256) + leastSignificant_bit);
return (value);
}

unsigned int sectorSize (){
struct fileSystem_info fat;
unsigned char first_byte = buffer[11];
printf("%hhu \n", first_byte);
unsigned char second_byte = buffer[12];
printf("%hhu \n", second_byte);
unsigned int combinedBytes = converter ((int)second_byte, (int)first_byte);
unsigned int fat.sector_size = combinedBytes;
return (combinedBytes);
}

最佳答案

这里

unsigned int fat.sector_size = combinedBytes;

删除类型

fat.sector_size = combinedBytes;

(……或许可以休息一下……;-)


在下面的评论中提到关于版本信息的问题:

做这样的事情:

#define VERSION_MAJOR (0)  /* \                                          */
#define VERSION_MINOR (1) /* +--<-- adjust those for upcoming releases. */
#define VERSION_MICRO (42) /* / */

struct fileSystem_info
{
unsigned int version;
unsigned int sector_size; //Sector size

...

当初始化一个struct fileSystem_info的实例时,做:

struct fileSystem_info fsi = {0};
fsi.version = (VERSION_MAJOR << 24) | (VERSION_MINOR << 16) | VERSION_MICRO};

这样做允许您的最大版本号为 255.255.65535

因为您总是将 version 写入磁盘,您稍后可以通过从结构中读取第一个 unsigned int version 来确定您写入的版本,然后决定如何继续阅读。如果结构及其内容在version之后的解释方式在您的程序的不同版本中发生变化,这可能是相关的。

关于c - 将数据传递到结构时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20080907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com