我在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)
}
稍后我将struct和一些其他变量传递给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
非常感谢所有人的帮助!
答案 0 :(得分:0)
尝试将您的主页更改为:
struct roomData rooms[MAXROOMS+1];