我前主聲明的結構:2D int數組withing一個結構 - Visual C
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;
};
內部主,我聲明該結構與此:
int main(void)
{
struct roomData rooms[MAXROOMS+1] = {0}; //struct for rooms(+1 for temp swapping in sorts)
}
以後我通過結構和幾其它變量的函數與此代碼在主:
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
....
}
這是錯誤的IM從GCC獲得RDB
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
後
非常感謝所有幫助!
你沒有顯示此足夠的代碼是有用的。告訴我們這個結構是如何初始化和使用的;在代碼中發生seg故障。 – tillerstarr
@tillerstarr感謝您的快速回復 ,我發佈了一個答案,我自己的問題更多的代碼。 – user1856602
word4實際上有一個值嗎? – tillerstarr