gpt4 book ai didi

c - 结构中的二维整数数组 - C

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

我在 main 之前声明结构:

struct roomData
{
float widthFeet, widthInch;
float lengthFeet, lengthInch;
char roomName[100];
int roomNumberOfType;
char roomType[6]; //char of room type
int roomStock[101][6]; //for storing each room stock types
int roomHasStock; //if the room has a stock avaliable
int roomStockCount; //how many stocks the room has
float area; // sq ft
float rentalRate;
float profitsPerRoom;
float netProfit;
float grossProfit;
};

在 main 中,我用这个声明结构:

int main(void)
{
struct roomData rooms[MAXROOMS+1] = {0}; //struct for rooms(+1 for temp swapping in sorts)
}

稍后,我将结构和一些其他变量传递给在 main 中使用以下代码的函数:

        fillRoomData(n, x, array, rooms, 1);

fillRoomData 函数是这样的:

    void fillRoomData(int n, int x, struct fileInput array[300], struct roomData rooms[MAXROOMS], int check)//NEED TO ERROR CHECK
{
if(check == 1) //for stock values in room
{
char * word4; //for strTok
word4 = strtok(array[n].input," "); //stockType
rooms[x].roomStock[a][0] = atoi(word4); //sores stock number
word4 = strtok(NULL, " "); //stockCount
rooms[x].roomStock[a][1] = atoi(word4); //sores stock inventory
....

}

这是我在 rdb 之后从 GCC 得到的错误

    Program received signal SIGSEGV, Segmentation fault.
0x000000338f23473a in ____strtoll_l_internal () from /lib64/libc.so.6
(gdb) backtrace
#0 0x000000338f23473a in ____strtoll_l_internal () from /lib64/libc.so.6
#1 0x000000338f231bf2 in atoi () from /lib64/libc.so.6
#2 0x0000000000406ed9 in fillRoomData (n=29, x=0, array=0x7ffffffefcc0,
rooms=0x7ffffffd2fe0, check=1) at amp6572Lab4.c:1420
#3 0x0000000000400fde in main () at amp6572Lab4.c:279
(gdb) frame 2
#2 0x0000000000406ed9 in fillRoomData (n=29, x=0, array=0x7ffffffefcc0,
rooms=0x7ffffffd2fe0, check=1) at amp6572Lab4.c:1420
1420 rooms[x].roomStock[a][b] = atoi(word4); //stores

非常感谢所有帮助!

最佳答案

尝试将您的 main 更改为:

struct roomData rooms[MAXROOMS+1];

关于c - 结构中的二维整数数组 - C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13584773/

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