新手求助链表的问题
我的源程序是这样:
程序代码:#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct ST
{
int i;
char c;
struct ST *next;
}*tou,*wei,*yuanshi;
int main(void)
{
int i=0,j;
printf("键入‘*’符结束操作,其它健继续:\n");
while(1)
{
printf("%c\n",tou->c=getch());
if(tou->c=='*') break;
while(tou=(struct ST*)malloc(sizeof(struct ST)))
{
if(i==0)
{
tou=NULL;
yuanshi=tou;
wei=tou;
}
else
{
wei->next=tou;
wei=tou;
}
printf("OK!\n键入‘*’符结束,其它键继续:\n");
break;
}
tou->i=i;
i++;
}
tou=NULL;
for(j=0;j<i;j++)
{
printf("%5d%5c%5d\n",j,tou->c,tou->i);
tou=tou->next;
}
getch();
}
当我输入a b c d e f * 时,输出却是 b c d e f * ,不知道前面的 a 弄哪去了,怎么修改?还望各位帮下忙,谢谢。
再说几句题外话,近段时间太忙,每天高强度工作达十多个小时之久,所以把C的学习耽误了。但还是尽量抽出时间来学习,所以请朋友们不必拿我开涮,说我是“大个儿的牛”,大家就拿我当才学二个月的新手来对待就可以了(其实我也就是这个水平)。谢谢大家。









