C写的小程序,请大虾找错

来源:百度知道 编辑:UC知道 时间:2024/06/07 03:58:18
刚鞋C,现小菜阶段!大家帮看看我写的这代码问题在哪儿了,为啥到删除时总是"没有要删的那个"纳?
代码:
struct ab
{
char y[5];
char u[22];
int i[9];
struct ab *p;
};
struct ab *po()
{
char l[2];
int o,p;
o=1;
p=0;
l[0]='y';
struct ab *h,*g,*jk;
while(l[0]=='y')
{h=(struct ab *)malloc(sizeof(struct ab));
if(o)
{jk=g=h;
--o;}
if(p)
{g->p=h;
g=h;
--p;}
printf("种类:");
scanf("%s",&h->y);
printf("用户名:");
scanf("%s",&h->u);
printf("密码:");
scanf("%s",&h->i);
printf("继续吗?y\\n:");
scanf("%s",&l[0]);
p=1;}
h->p='\0';
return jk;
}
struct ab *pi(struct ab *pl)
{
struct ab *k;
k=pl;

不好意思 给你改面目全非了 不过你的思想应该改 要建立带头结点的结构体链表 你有可能不明白为什么 不过以后你编程多了 自然就知道了
#include <stdio.h>
#include <math.h>
#include <malloc.h>
#include <string.h> //字符串比较用包 strcmp()
struct ab
{
char y[5];
char u[22];
int i[9];
struct ab *p;
};
struct ab *po(struct ab *o)
{
char l[2];
l[0]='y';
struct ab *h,*g; //没有必要要那么多标志判断位
g=o;
h=o->p;
while(l[0]=='y')
{
g->p=h=(struct ab *)malloc(sizeof(struct ab));
printf("种类:");
scanf("%s",&h->y);
printf("用户名:");
scanf("%s",&h->u);
printf("密码:");
scanf("%s",&h->i);
printf("继续吗?y\\n:");
scanf("%s",&l[0]);
h->p=NULL; //表空值
g=h;
}
return o;
}
void pi(struct ab *pl)//没