秦斩大魔王 2016-12-20 07:27 采纳率: 33.3%
浏览 907
已采纳

C语言,一个语句问题。

```#include "stdafx.h"

define MAXNUM 70

define FALSE 0

define TRUE 1

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
typedef struct Qnode {char data[MAXNUM]; struct Qnode next;
}Qnodetype;
/
定义队列的结点*/
typedef struct
{
Qnodetype front;/头指针*/
Qnodetype rear; /尾指针*/
int number;/*短信数量*/
}Lqueue;
int initLqueue(Lqueue **q) {
/*创建一个空链队列q*/

if (((*q)->front = (Qnodetype*)malloc(sizeof(Qnodetype))) == NULL)
    return FALSE;
(*q)->rear = (*q)->front;
strcpy((*q)->front->data, "head"); 
(*q)->front->next = NULL;
(*q)->number = 0; 
return TRUE;

}
int LInQueue(Lqueue q, char x[])
{
/
将元素x插入到链队列q中,作为q的新队尾*/

Qnodetype *p;

if ((p = (Qnodetype*)malloc(sizeof(Qnodetype))) == NULL) 

return FALSE;

strcpy(p->data, x);

p->next = NULL;   /*置新结点的指针为空*/

q->rear->next = p;   /*将链队列中最后一个结点的指针指向新结点*/ 


q->rear = p;  /*将队尾指向新结点*/

return TRUE;
}

char * LOutQueue(Lqueue *q){

/*若链队列q不为空,则删除队头元素,返回其元素值*/ 
char  x[MAXNUM]; Qnodetype *p;

    if (q->front->next == NULL) return NULL;  /*空队列*/

    p = q->front->next;            /*取队头*/

q->front->next = p->next;           /*删除队头结点*/

if (p->next == NULL) q->rear = q->front;strcpy(x, p->data); 

    free(p); 
        return x;

}
void get(Lqueue q, char x[]) { /接受短信*/

int n;
if (q->number == 20)
{
    LOutQueue(q);q->number--;
} LInQueue(q, x); q->number++;

}
void deleteall(Lqueue q) { /删除所有短信*/
while (q->front != q->rear)

LOutQueue(q);
q->number = 0;
}
void deleteone(Lqueue q, int n) {/删除第n条短信*/
Lqueue p;Qnodetype *s;
int i;
p = q;
i = 1;
while (i {
p->front = p->front->next; i = i + 1;
}
s = p->front->next;
p->front->next = p->front->next->next; free(s);
q->number--;
}
void displayall(Lqueue *q) {/
显示所有短信*/
Lqueue p;char x[MAXNUM]; p = q;
while (p->front != q->rear) {
p->front = p->front->next;
printf("%s\n", p->front->data);
} printf("\n");
}
void displayone(Lqueue *q, int n) {/
显示第n条短信*/ Lqueue *p;Qnodetype *s; int i; p = q;i = 1; while (i {
p->front = p->front->next; i = i + 1;
}
s = p->front->next;
printf("%s\n", s->data);
}
void main()
{
Lqueue *Lp;
int i;
Qnodetype *headnode;
char command,ch[MAXNUM];
initLqueue(&Lp);
headnode = Lp->front;
while (1)
{
printf("Get information(%d),please enter R\n", Lp->number);
printf("Display one information(%d),please enter L\n", Lp->number);
printf("Display all information(%d),please enter A\n", Lp->number);
printf("Delete one information(%d),please enter D\n", Lp->number);
printf("Delete all information(%d),please enter U\n", Lp->number);
printf("Quit,please enter Q\n");
printf("please input command:");
scanf("%c", &command);
switch (command) {
case 'r'://case 'R': get(ch);Lp->front = headnode;get(Lp, ch);break;
case 'l':case 'L':printf("enter No.:"),
scanf("%d", &i);
Lp->front = headnode;displayone(Lp, i);
break;
case 'a':case 'A':Lp->front = headnode;displayall(Lp)
;break;
case 'd':case 'D':printf("enter No.:"), scanf("%d", &i);
Lp->front = headnode;deleteone(Lp, i);
break;
case 'u':case 'U':Lp->front = headnode;deleteall(Lp);break;
case 'q':case 'Q':printf("quit!");
}
if (command == 'q' || command == 'Q')
break;
}
}



initLqueue方法里
if (((*q)->front = (Qnodetype*)malloc(sizeof(Qnodetype))) == NULL)

总是报错,访问位置冲突。怎么解决?
  • 写回答

3条回答 默认 最新

  • shen_wei 2016-12-20 08:06
    关注

    http://www.cnblogs.com/renyuan/archive/2013/05/21/3091506.html
    参考这个全面的去对比看看吧。。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?