链表菜单轻便版 纯C

#includestdio.h#includestring.h#includestdlib.h#includestdbool.htypedefstructnode*pos;structnode//成立布局体{char*data;posnext;};intmain(intargc,char*argv[]){inti,j,k,m;charc,x[19]={0};FILE*p;chara[500][19];p=fopen("F:\\500.txt","r");if(p==NULL)printf("fail\n");elseprintf("success\n");for(i=0;i500;i++){for(j=0;j18;j++){a[i][j]=fgetc(p);}a[i][18]=0;}//将文件中多少存到数组a中fclose(p卡塔尔;for(i=0;i500;i++卡塔尔(قطر‎for(j=i;j500;j++State of Qatarif(strcmp(a[i],a[j])0){for(m=0;m18;m++){k=a[i][m];a[i][m]=a[j][m];a[j][m]=k;}}//排序for(j=0;j500;j++)printf("%s",a[j]卡塔尔;posp1,p2,head,p0;head=NULL;p1=p2=(pos卡塔尔(قطر‎malloc(sizeof(structnode卡塔尔卡塔尔;for(i=0;i500;i++卡塔尔国//创设链表{if(i==0卡塔尔(قطر‎head=p1;elsep2-next=p1;p2=p1;p1=(pos卡塔尔(قطر‎malloc(sizeof(structnode卡塔尔(قطر‎State of Qatar;p2-data=a[i];}p2-next=NULL;free(p1);free(p2);posfind(charx[],posh卡塔尔国;voiddele(posp卡塔尔;printf("请输入你要去除的东西:"卡塔尔;scanf("%s",x卡塔尔(قطر‎;p0=find(x,head卡塔尔(قطر‎;printf("%s",p0-data卡塔尔(قطر‎;dele(p0卡塔尔国;printf("abc"State of Qatar;posp3;p3=head;for(i=0;i500;i++卡塔尔(قطر‎{printf("%s",p3-data卡塔尔(قطر‎;p3=p3-next;}return0;}posfind(charx[],posh){while((h-next!=NULL)(strcmp(h-next-data,x)!=0卡塔尔国卡塔尔国h=h-next;returnh;}voiddele(posp卡塔尔国{p-next=p-next-next;}那几个顺序正是有500行字符串每一种字符串都是18列,先读入文件取得了,然后排个序,接着遵照相排版序结果营造链表,要达成输入某一行将那一行对应的字符串删除。dele死了链表删除,find是找到该行字符串前一行对应的位置,作者gets输入的x明确就是那本来的500行之一,然则为啥find函数里面strcmp就是不起成效呢,每一趟小编试都以间接把while循环试行到了最后二个链表单元,真的是找错找疯了。。。。求大佬指教。。。难点就出在while循环这几个strcmp上,不过笔者不明白怎么错了,为何相比较不出来0的结果。

#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<string.h>
int cmd;
typedef struct Lnode
{
int data;
struct Lnode *next;
}LNode, *Linklist;
void creatList(Linklist &L)
{
LNode *p;
int n,m;
printf(" 先输入一个n,在输入n个数: "State of Qatar;
scanf("%d",&n);
//p = (Linklist)malloc(sizeof(LNode));
L = p;
while(n--)
{
LNode *q;
q = (LNode*卡塔尔(قطر‎malloc(sizeof(LNodeState of Qatar卡塔尔(قطر‎;//这一步一定要双注重建议请内部存款和储蓄器,不然q的针对永世不会变,
//招致三个单节点q=p,且小编的next指向小编;
scanf("%d",&m);
q->data = m;
p->next = q;
p = q;
}
p->next = NULL;
}
void Print(Linklist &L)
{
LNode *p;
p=L->next;
printf(" 链表输出为"卡塔尔国;
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
printf(" 是不是继续 yes 0r no? :"State of Qatar;
char str[4];
scanf("%s",str);
if(strcmp(str,"yes"))
return ;
}
void Listinert(Linklist &L, int i, int e)
{
Linklist head = L;
int j = 0;
Linklist p = head;
while (p != NULL&&j < i - 1)
{
j++; p = p->next;
}
if (!p || j > i - 1)
printf("worry\n");
else
{
Linklist s=new LNode; //= (Linklist)malloc(sizeof(LNode));
s->data = e;
s->next = p->next;
p->next = s;
}
}
void Listdelete(Linklist &L, int i)
{
int j=0;
Linklist p = L;
Linklist q;
while(p->next&&j<i-1)
{
p=p->next;j++;
}
if(!p->next||(j>i-1))
j=j;
else
{
q=p->next;p->next=q->next;
free(q);
}
}

  }
  }

void length(Linklist &L)
{
LNode *p;
p=L->next;
int l=0;
while(p!=NULL)
{
l++;
p=p->next;
}
printf("%d\n",l);
printf(" 是还是不是继续 yes 0r no? :"卡塔尔(قطر‎;
char str[4];
scanf("%s",str);
if(strcmp(str,"yes")||strcmp(str,"YES")||strcmp(str,"Yes"))
int w;
}
void menu()
{ //打字与印刷图形分界面
printf(" -------MENU------ ");
printf("\n");
printf(" ================= ");
printf("\n");
printf(" Linklist operation \n");
printf(" 1. creat \n");
printf(" 2. insert \n");
printf(" 3. delete \n");
printf(" 4. print \n");
printf(" 5. length \n");
printf(" 6. reverse \n");
printf(" 0. exit \n");
printf(" ================= ");
printf("\n");
printf(" Choice(0,1,2,3,4,5,6): ");
scanf("%d",&cmd);
}
int main()
{
int flag=1,pos,num;
Linklist L1;
do
{ system("cls");
menu();
switch(cmd)
{
case 0:
flag=0;break;
case 1:
creatList(L1); break;
case 2:
printf(" 输入插入的职位和对象: "卡塔尔国;
scanf("%d %d",&pos,&num);
Listinert(L1,pos,num);
break;
case 3:
printf(" 输入删除的岗位: "卡塔尔(قطر‎;
scanf("%d",&pos);
Listdelete(L1,pos);break;
case 4:
Print(L1);break;
case 5:
printf(" 链表的尺寸为: "卡塔尔;
length(L1);
}
}while(flag==1);
}

 }

 

   if(!strcmp(pa->next->num,pnum)){
   pb=(struct stuNode *)malloc(sizeof(struct stuNode));
   fflush(stdin);
   printf("请输入待插入学子的信息\n");
   printf("请输入学子的学号:\n");
   gets(pb->num);
  printf("请输入学子的全名:\n");
   gets(pb->name);
   printf("请输入学子的年龄:\n");
   scanf("%s",pb->age);
   printf("插入学子音信成功\n");
   pb->next=pa->next;
   pa->next=pb;
   return h;
   }
   else
   pa=pa->next;
  }
  printf("未找到插入地方:\n");
  return h;  

 

struct stuNode *CreateList( int n ) /* 1.创建链表 */
{
 struct stuNode *pb, *pf;
 int  i;
 int count=1;
 for ( i = 0; i < n; i++ )
 {  
  pb = (struct stuNode *) malloc( sizeof(struct stuNode) );
  fflush(stdin卡塔尔;//记得清空缓存区,那些很首要
  printf( "请输入第%d个学子的学号:\n",count );
  gets(pb->num);
  printf( "请输入学子的真名:\n" );
  gets(pb->name);
  printf( "请输入学子的年龄:\n" );
     gets(pb->age);
  count++;
  pb->next = NULL;
  if ( i == 0 )
   head = pb;
  else
   pf->next = pb;
  pf = pb;
 }
 printf( "表已开立完结\n" );
 return(head);
}

 

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static struct stuNode *head=NULL;
struct stuNode {
 char  num[16];
 char  name[8];
 char  age[4];
 struct stuNode *next;
};

图片 1

  struct stuNode *pa,*pb;