为什么会打印出两个printf()呢,

来源:百度知道 编辑:UC知道 时间:2024/05/30 12:52:45
#include"stdio.h"
#include"stdlib.h"
typedef struct queue{
char data;
struct queue *next;
}queue,*pqueue;
pqueue first,last;
int all;
first=last=NULL;

main()
{ int m;

printf("qing shu ru da xiao:");
scanf("%d",&m);
void insert(m);
while(last!=first)
{printf("%c",first->data);
first=first->next;}
printf("%c",first->data);
}
void insert(int n)
{ pqueue s,t;
for(i=1;i<=m;i++)
{ getqueue(t,i)
if(first==NULL)
{first=last=t;
s=t;}
else
{last=t;
s->next=t;
s=s->next;
}
}
}
getnode(pqueue *t,int i)
{

帮你改了一下。

#include<stdio.h>
#include<stdlib.h>
typedef struct queue
{
char data;
struct queue *next;
}queue,*pqueue;

pqueue first,last;

int all;

void getnode(pqueue t,int i)
{

printf("qing shu ru di %d de zhi\n",i);
scanf(" %c",&t->data); ////////////////////////原因在这里,因为你输入的是c单个
//字符,它会接收你上次输入大小时的 回车符,你可以在debug下看见
//在前面加一个空格,或scanf("\n%c",&t->data);可以吃掉那个回车
return ;
}

void insert(int n)
{
pqueue s=NULL,t=NULL;
int i;
for(i=1;i<=n;i++)
{
t=(pqueue)malloc(sizeof(queue));// t在这里申请空间

if(!t) exit(-2);
t->next=NULL;
getnode(t,i) ;// 传入后相当于对t的操作
if(first==NULL) // 一般的链表
{
first=last=t;
s=t;
}
else
{
last=t;
s->next=t;
s=s->next;