循环中的小问题!~~~~
kialo 2004-10-06 09:42:47 我的代码如下:
#include <stdio.h>
#include <malloc.h>
#define DATATYPE2 char
typedef struct node{
DATATYPE2 data;
struct node *next;
}LINKLIST;
void main()
{
LINKLIST *t,*p,head;
char ch;
int i=0;
head.next=NULL;
while((ch=getchar())!='$'){
t=(LINKLIST*)malloc(sizeof(LINKLIST));
t->data=ch;
t->next=head.next;
head.next=t;
}
p=head.next;
while(p){
i++;
printf("%c",p->data);
p=p->next;
printf("\ni=%d\n",i);
}
}
编译通过了,可运行时,却打印两次i的语句,不知为何,请各位指教。^_^