我试图用新节点更新全局链接列表。我做了一个指向结构体的指针,每次我尝试为它分配一个新的成员值时,我得到一个总线错误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