[问题]c语言的小问题
发表于 : 2008-06-22 22:01
请高手看一下,为什么会不行,程序如下:
#include "stdio.h"
#include "malloc.h"
#define SIZE 10;
typedef struct node{
char data[10];
struct node *next;
}linknode;
typedef struct queueNode{
struct node *front,*rear;
}linkqueue;
linkqueue *q;
void creat(){
q->front=(linknode *)malloc(sizeof(linknode)); //这句显示出错
};
main(){
creat();
}
我是用netbeans写的c语言程序,编译器是gcc。
程序出输出的结果是 : Segmentation fault
为什么会这样啊。。我在xp里面用turbo c就可以运行。。
是不是ubuntu下的c语言跟xp下的有差别啊。。[/img]
#include "stdio.h"
#include "malloc.h"
#define SIZE 10;
typedef struct node{
char data[10];
struct node *next;
}linknode;
typedef struct queueNode{
struct node *front,*rear;
}linkqueue;
linkqueue *q;
void creat(){
q->front=(linknode *)malloc(sizeof(linknode)); //这句显示出错
};
main(){
creat();
}
我是用netbeans写的c语言程序,编译器是gcc。
程序出输出的结果是 : Segmentation fault
为什么会这样啊。。我在xp里面用turbo c就可以运行。。
是不是ubuntu下的c语言跟xp下的有差别啊。。[/img]