我試圖用新節點更新全局鏈接列表。我做了一個指向結構體的指針,每次我嘗試爲它分配一個新的成員值時,我得到一個總線錯誤10.我很喜歡這個,所以任何幫助將不勝感激。更新全局結構的成員
的代碼:
typedef struct alarmItem
{
pthread_t id; //id of the thread to block/unblock
int delay; //initial delay time set by user for this alarm item
int realdelay; //adjusted delay time for this item in the queue
char function[256]; //function for this item to execute once alarm goes off
char args[256]; //arguments to pass into function, sql query or null
time_t calltime; //stores the time that this alarm item was introduced
struct alarmItem* next; //stores the next node in the linked list of alarm items
} alarmItem ;
typedef struct LinkedList
{
alarmItem* head;
} LinkedList;
LinkedList *alarmq; //empty linkedlist of alarm items
void initList()
{
if(alarmq == NULL)
printf("List is null.\n\n");
else
alarmq->head = NULL;
}
void entry_point(char **arguments)
{
char **args = (char **)arguments;
//create a new alarm item
alarmItem *new;
int d;
sscanf(args[0], "%d", &d);
new->delay = d;
strcpy(new->args, args[3]);
strcpy(new->function, args[4]);
initList();
}
的入口點函數只是被從與字符串的命令的標準列表的主要方法調用。
這使得絕對沒有感覺'char ** args =(char **)參數;'。 – 2015-02-09 23:39:39
'alarmItem * new;'你沒有爲你的變量分配內存,例如使用malloc - 最好避免保留的C++單詞,比如新的,即使在純c中 – 2015-02-09 23:39:41
@Lashane如果OP沒有使用C++,沒有理由這麼說。事實上,它可以防止錯誤地用C++編譯器編譯。 – 2015-02-09 23:40:07