菜鸟问高手一个问题?关于字符串的输入问题!
在下面我编的小程序功能是利用链表将一组数据逆序(不另外增加空间),在原来链表的基础上做。我想将对整型操作变为对字符串操作。
#include <stdio.h>
#include <malloc.h>
#include "string.h"
struct list
{
int value;//char *value;
struct list *next;
}
main()
{
struct list *head,*track,*onforward,*onforward1;
int chr;//char *chr;
head=(struct list*)malloc(sizeof(struct list *));
track=head;
for(int i=0;i<10;i++)
{
onforward=(struct list*)malloc(sizeof(struct list *));
scanf("%d",&chr);//scanf("%s",&chr);
onforward->value=chr;//strcpy(onforward->value,chr);
track->next=onforward;
track=onforward;
}
onforward->next=NULL;
onforward=head->next;
track=onforward;
onforward1=onforward->next;
while(onforward1!=NULL)
{
onforward->next=onforward1->next;
onforward1->next=head->next;
head->next=onforward1;
track=head->next;
onforward1=onforward->next;
}
onforward=head->next;
while(onforward!=NULL)
{
printf("%d ",onforward->value);//printf("%s ",onforward->value);
onforward=onforward->next;
}
}
注意://为我所改动得操作!但效果不行。
我想输入:
dsdsf fdfdsfd oo dsd ewew oop wewer kl qw ere
结果:与上面正好相反!
我的算法没问题,就是对字符串的操作有问题。请问高手我怎么解决?