操作系统笔者这一个关于职工管理系统文件编写

作者:操作系统

#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("failn");elseprintf("successn");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 卡塔尔if(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]State of Qatar;posp1,p2,head,p0;head=NULL;p1=p2=(posState of Qatarmalloc(sizeof(structnode卡塔尔(قطر‎卡塔尔国;for(i=0;i500;i 卡塔尔(قطر‎//创立链表{if(i==0卡塔尔国head=p1;elsep2-next=p1;p2=p1;p1=(pos卡塔尔malloc(sizeof(structnode卡塔尔(قطر‎卡塔尔国;p2-data=a[i];}p2-next=NULL;free(p1);free(p2);posfind(charx[],poshState of Qatar;voiddele(posp卡塔尔国;printf("请输入你要删减的东西:"卡塔尔(قطر‎;scanf("%s",x卡塔尔国;p0=find(x,head卡塔尔国;printf("%s",p0-data卡塔尔国;dele(p0卡塔尔;printf("abc"卡塔尔;posp3;p3=head;for(i=0;i500;i State of Qatar{printf("%s",p3-data卡塔尔国;p3=p3-next;}return0;}posfind(charx[],posh){while((h-next!=NULL)(strcmp(h-next-data,x)!=0卡塔尔国State of Qatarh=h-next;returnh;}voiddele(pospState of Qatar{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(LNode卡塔尔国卡塔尔;//这一步必定要重新申请内部存款和储蓄器,不然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? :"卡塔尔国;
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("worryn");
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);
}
}

#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;
};

#includestdio.h#includestdlib.h#includemath.h#includemalloc.h#defineOK1#defineE凯雷德ROEscort0typedefintStatus;typedefintElemType;typedefstructStaff//新闻构造体{charname[10];//姓名charsex[5];//性别intCyear;//出生年,月,日intCmonth;intCday;intGyear;//工作年,月,日intGmonth;intGday;charXueLi[10];//学历charZhiWu[10];//职务charAdress[10];//地址intnum;//手提式有线电话机号码}Staff;typedefstructLNode{Staffdata;structLNode*next;}LNode;/*typedefstruct//扶植结构体{Staffdata;structLNode*next;}MNode;*/voidVoidList(LNode*t1卡塔尔(قطر‎//创设链表表头{if(t1=(LNode*)malloc(sizeof(LNode))){exit(1);}t1-next=NULL;}StatusCreatList(LNode*t1卡塔尔国//职工音讯插入以致排序{LNode*a1,*a2,*a3;a2=t1-next;if(a1=(LNode*卡塔尔国malloc(sizeof(LNode卡塔尔国State of Qatar卡塔尔{returnE瑞鹰ROHighlander;}printf("请输入职工音讯:n");printf("姓名:n");scanf("%s",a1-data.name);printf("性别:n"卡塔尔;scanf("%s",a1-data.sex卡塔尔(قطر‎;printf("出生年月日(分别以逗号(,卡塔尔国结尾.State of Qatar:n"卡塔尔国;scanf("%d,%d,%d",(a1-data.Cyear卡塔尔国,(a1-data.Cmonth卡塔尔(قطر‎,(a1-data.Cday卡塔尔(قطر‎卡塔尔;printf("事业年月日(分别以逗号(,卡塔尔国结尾卡塔尔(قطر‎:n");scanf("%d,%d,%d",(a1-data.Gyear),(a1-data.Gmonth),(a1-data.Gday));printf("学历:n");scanf("%s",a1-data.XueLi);printf("职务:n");scanf("%s",a1-data.ZhiWu);printf("住址:n"卡塔尔;scanf("%s",a1-data.AdressState of Qatar;printf("电话号码:n");scanf("%d",a1-data.num);if(t1-next==NULL){t1-next=a1;t1-next-next=NULL;}else{for(;a2;a2=a2-next){if(a2-next!=NULL卡塔尔(قطر‎//在两个之间插入{if((strcmp(a2-data.name,a1-data.name卡塔尔0State of Qatar(strcmp(a2-next-data.name,a1-data.name卡塔尔国0卡塔尔(قطر‎卡塔尔{a1-next=a2-next;a2-next=a1;break;}}elseif(strcmp(a2-data.name,a1-data.nameState of Qatar==0State of Qatar//姓名相像不录入{break;}elseif((strcmp(a2-data.name,a1-data.name卡塔尔(قطر‎0State of Qatar(a2-next==NULL卡塔尔(قطر‎卡塔尔//链表非空,且排在最终五个{a2-next=a1;a1-next=NULL;break;}else//链表非空,且在头结点后排列if(strcmp(a2-data.name,a1-data.name卡塔尔(قطر‎0卡塔尔{a3=t1-next;t1-next=a1;a1-next=a3;break;}}}returnOK;}voidput(LNode*t1,FILE*fp){LNode*m1;m1=t1-next;if((fp=fopen("职工新闻.txt","w"卡塔尔State of Qatar==NULLState of Qatar{//若无该公文printf("不可能张开'职工音信.txt'!n"卡塔尔国;exit(0卡塔尔;}for(;m1;m1=m1-next卡塔尔(قطر‎{//文件中写入fprintf(fp,"%s%s%d%d%d%d%d%d%%s%s%s%d",m1-data.name,m1-data.sex,m1-data.Cyear,m1-data.Cmonth,m1-data.Cday,m1-data.Gyear,m1-data.Gmonth,m1-data.Gday,m1-data.XueLi,m1-data.ZhiWu,m1-data.Adress,m1-data.num卡塔尔;}if(fclose(fp卡塔尔卡塔尔(قطر‎{printf("一点都不大概关闭'职工新闻.txt'!n"State of Qatar;exit(0卡塔尔(قطر‎;//符合规律退出}}voidPrint(LNode*t1State of Qatar//打字与印刷当前职员和工人音信{inti=0;LNode*q1;q1=t1-next;printf("职工消息如下:n"卡塔尔(قطر‎;printf("姓名性别出生年月做事年月文化水平职务住址电话n");while(q1!=NULL){printf("%s",q1-data.name);printf("%s",q1-data.sex);printf("%d%d%d",q1-data.Cyear,q1-data.Cmonth,q1-data.Cday);printf("%d%d%d",q1-data.Gyear,q1-data.Gmonth,q1-data.Gday);printf("%s",q1-data.XueLi);printf("%s",q1-data.ZhiWu);printf("%s",q1-data.Adress);printf("%dn",q1-data.num);q1=q1-next;i=i 1;}printf("一共%d个员工!",i);}StatusDelete(LNode*t1State of Qatar//删除工作者操作{charname1[10];LNode*q2,*q3;q2=t1;q3=t1-next;if(q3==NULLState of QatarreturnE奥迪Q7ROEvoque;printf("请输入您要去除的职员和工人的真名:n"卡塔尔;scanf("%s",name1卡塔尔;for(;q3;q3=q3-next卡塔尔国{if(strcmp(q3-data.name,name1卡塔尔(قطر‎==0卡塔尔{q2-next=q3-next;free(q3卡塔尔国;printf("删除成功,请继续操作!n"State of Qatar;break;}q2=q3;}if(q3==NULL卡塔尔(قطر‎{printf("无职工消息,不需求删除操作.n");}returnOK;}StatusSearch(LNode*t1卡塔尔//查询有个别职工{charname2[10];intselect,flag1=0,flag2=0,num1;LNode*s1;s1=t1-next;if(s1==NULLState of QatarreturnEEscortRO奥迪Q5;printf("请输入您要找出的人的尺度:"卡塔尔;do{printf("***************n"卡塔尔;printf("1.按姓名查找.n"卡塔尔(قطر‎;printf("2.按电话查找.n"卡塔尔(قطر‎;printf("0.了结操作.n");printf("***************n"卡塔尔;scanf("%d",select卡塔尔;switch(select卡塔尔{case1:printf("请输入要索求的人的姓名:n");scanf("%s",name2卡塔尔;for(;s1;s1=s1-next卡塔尔(قطر‎{if(strcmp(s1-data.name,name2State of Qatar==0State of Qatar{printf("那个工作者的信息是:n");pirntf("姓名:n");printf("%s",s1-data.name);printf("性别:n"卡塔尔国;printf("%s",s1-data.sexState of Qatar;printf("出生年月日:n"State of Qatar;printf("]--",s1-data.Cyear,s1-data.Cmonth,s1-data.CdayState of Qatar;printf("专门的学问年月日:n");printf("]--",s1-data.Gyear,s1-data.Gmonth,s1-data.Gday);printf("学历:n");printf("%s",s1-data.XueLi);printf("职务:n");printf("%s",s1-data.ZhiWu);printf("住址:n");printf("%s",s1-data.Adress);printf("电话:n"State of Qatar;printf("%d",s1-data.num卡塔尔国;flag1=1;break;}}if(flag1=0卡塔尔{printf("对不起,未有查到那么些职工的音讯.n"卡塔尔;}break;case2:printf("请输入要查询者的对讲机号码.n"State of Qatar;scanf("%d",num1卡塔尔(قطر‎;for(;s1;s1=s1-next卡塔尔(قطر‎{if(s1-data.num==num1卡塔尔{printf("这么些职员和工人的新闻是:n");pirntf("姓名:n");printf("%s",s1-data.name);printf("性别:n"卡塔尔(قطر‎;printf("%s",s1-data.sexState of Qatar;printf("出生年月日:n"State of Qatar;printf("]--",s1-data.Cyear,s1-data.Cmonth,s1-data.Cday卡塔尔(قطر‎;printf("职业年月日:n");printf("]--",s1-data.Gyear,s1-data.Gmonth,s1-data.Gday);printf("学历:n");printf("%s",s1-data.XueLi);printf("职务:n");printf("%s",s1-data.ZhiWu);printf("住址:n");printf("%s",s1-data.Adress);printf("电话:n"State of Qatar;printf("%d",s1-data.num卡塔尔;flag2=1;break;}}if(flag2==0卡塔尔(قطر‎printf("对不起,未有查询到特别职工的新闻.n"State of Qatar;break;case0:printf("甘休操作.n"State of Qatar;break;default:printf("输入采抽取错!n");}}while(select!=0);returnOK;}voidAmend(LNode*t1卡塔尔(قطر‎//改正某些职工的有些新闻{intn,tag=0;intscyear,scmonth,scday,sgyear,sgmonth,sgday,snum;charsname[10],ssex[5],sxue[10],szhi[10],sadress[10];charname3[10];LNode*s2;s2=t1-next;if(t1-next==NULL卡塔尔(قطر‎{printf("未有能够改良的学子.n"卡塔尔国;return;}printf("请输入要修正职员和工人的姓名:n"卡塔尔国;scanf("%s",name3State of Qatar;for(;s2;s2-next卡塔尔(قطر‎{if(strcmp(s2-data.name,name3卡塔尔(قطر‎==0卡塔尔{tag=1;do{printf("请输入您想校订的一些:n");printf("***************n"卡塔尔;printf("0.脱离更正.n");printf("1.姓名n");printf("2.性别n"State of Qatar;printf("3.诞生年月日n"卡塔尔;printf("4.行事年月日n");printf("5.学历n");printf("6.职务n");printf("7.住址n"卡塔尔;printf("8.电话号码n");printf("***************n"卡塔尔国;scanf("%d",n卡塔尔(قطر‎;switch(nState of Qatar{case1:printf("请输入想改良的名字:n"卡塔尔;scanf("%s",sname卡塔尔;strcpy(s2-data.name,sname卡塔尔;printf("改革达成,请继续操作.nn"卡塔尔;break;case2:printf("请输入想校勘的性别:n"卡塔尔国;scanf("%s",ssex卡塔尔国;strcpy(s2-data.sex,ssexState of Qatar;printf("订正完结,请继续操作.nn"卡塔尔(قطر‎;break;case3:printf("请输入想改正的出生年月日.n"卡塔尔(قطر‎;scanf("%d%d%d",scyear,scmonth,scdayState of Qatar;s2-data.Cyear=scyear;s2-data.Cmonth=scmonth;s2-data.Cday=scday;printf("修正完毕,请继续操作.nn"卡塔尔;break;case4:printf("请输入要校订的工时.n"卡塔尔(قطر‎;scanf("%d%d%d",sgyear,sgmonth,sgday卡塔尔(قطر‎;s2-data.Gyear=sgyear;s2-data.Gmonth=sgmonth;s2-data.Gday=sgday;printf("修改完结,请继续操作.nn"卡塔尔;break;case5:printf("请输入想改革的文凭.n"卡塔尔(قطر‎;scanf("%s",sxue卡塔尔(قطر‎;strcpy(s2-data.XueLi,sxue卡塔尔国;printf("改过达成,请继续操作.nn"卡塔尔(قطر‎;break;case6:printf("请输入想更正的职分.n"卡塔尔(قطر‎;scanf("%s",szhiState of Qatar;strcpy(s2-data.ZhiWu,szhi卡塔尔;printf("校正完结,请继续操作.nn"卡塔尔;break;case7:printf("请输入想改进的住址.n"卡塔尔国;scanf("%s",sadress卡塔尔(قطر‎;strcpy(s2-data.Adress,sadress卡塔尔(قطر‎;printf("校勘达成,请继续操作.nn"State of Qatar;break;case8:printf("请输入想纠正的号码.n"State of Qatar;scanf("%d",snum卡塔尔;s2-data.num=snum;printf("改超过实际现,请继续操作.nn"卡塔尔;break;case0:printf("退出操作.n"State of Qatar;break;default:printf("您的筛选现身了难题,请重新选择.n");}}while(n!=0卡塔尔;}}if(tag==0卡塔尔pirntf("抱歉,您输入的人空中楼阁.n");}voidmain(){inti;FILE*fp;LNodet,*T;T=t;VoidList(T);do{printf("*******************n"卡塔尔国;printf("1.新增加一名工作者.n"卡塔尔国;printf("2.剔除一名工作者.n"卡塔尔(قطر‎;printf("3.询问一名职员和工人(依据名字或号码卡塔尔n"卡塔尔(قطر‎;printf("4.输入名字,更改对应工作者的质量n"State of Qatar;printf("0.脱离操作.n");printf("*******************n"State of Qatar;printf("请输入您想操作的数字.n"卡塔尔;scanf("%d",i卡塔尔(قطر‎;switch(iState of Qatar{case1:if(CreatList(T卡塔尔国==0卡塔尔printf("成立出错.n"卡塔尔(قطر‎;elseprintf("新闻创设成功.n"卡塔尔;put(T,fp卡塔尔国;printf("打字与印刷输出当前新闻.n");Print(T);printf("n"State of Qatar;printf("请继续操作.nn"State of Qatar;break;case2:Delete(T卡塔尔国;//剖断文件是还是不是写入.if((fp=fopen("职工音信.txt","w"卡塔尔卡塔尔国==NULL卡塔尔国{printf("不可能开发'职工新闻.txt'!n"卡塔尔国;exit(0卡塔尔;}put(T,fp);if(fclose(fp卡塔尔国卡塔尔国{printf("不可能关闭'职工新闻.txt'!n"卡塔尔国;exit(0卡塔尔;}printf("打字与印刷输出当前音讯.n");Print(T);printf("n"卡塔尔国;printf("请继续操作.nn"卡塔尔(قطر‎;break;case3:Search(T卡塔尔;printf("打字与印刷输出当前新闻.n");Print(T);printf("n"State of Qatar;printf("请继续操作.nn"卡塔尔国;break;case4:Amend(T卡塔尔国;if((fp=fopen("职工消息.txt","w"卡塔尔State of Qatar==NULL卡塔尔(قطر‎{printf("不恐怕展开'职工音信.txt'!n"卡塔尔(قطر‎;exit(0卡塔尔(قطر‎;}put(T,fp卡塔尔国;if(fclose(fp卡塔尔(قطر‎卡塔尔(قطر‎{printf("不能够关闭'职工音信.txt'!n"State of Qatar;exit(0卡塔尔;}printf("打字与印刷输出当前消息.n");Print(T);printf("n"卡塔尔;printf("请继续操作.nn"卡塔尔;break;case0:printf("操作已退出,谢谢您的使用.n");break;}}while(i!=0);//switch/*VoidList(TState of Qatar;创建空链表CreatList(T卡塔尔(قطر‎;对空链表进行赋值,职员和工人音信Print(T);打字与印刷输出工作者消息Delete(TState of Qatar;删除某些职员和工人音讯Search(T卡塔尔;搜寻某些员工音讯Amend(T卡塔尔(قطر‎;更改某些职工新闻*/}/*骨干供给:职工对象包涵姓名、性别、出生年月、工时、文化水平、职分、住址电话等音信。新扩展一名职员和工人:将剧增对象按姓名以词典形式职工管理文件中。删除一名工作者:从工作者管理文件中删去一名职工对象。查询:从职员和工人管理文件中询问相符有个别原则的职员和工人。修改:检索某些职工对象,对其有个别品质举行更改。排序:按某种须求对职工文件对象实行排序。*/

void length(Linklist &L)
{
LNode *p;
p=L->next;
int l=0;
while(p!=NULL)
{
l ;
p=p->next;
}
printf("%dn",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);
}

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(stdinState of Qatar;//记得清空缓存区,这么些很要紧
  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);
}

 

void TraversalList( struct stuNode *h ) /* 2.遍历链表 */
{
 struct stuNode *p;
 p = h;
 if ( p == NULL )
  printf( "表为空n" );
 else{
  printf( "学号tt姓名t年龄tn" );
  while ( p )
  {
   printf( "%st%st%stn", p->num, p->name, p->age );
   p = p->next;
  }
 }
}  

 

struct stuNode * InsertList(struct stuNode *h,char *pnum卡塔尔{//3.插入学生

操作系统 1

  struct stuNode *pa,*pb;

本文由ca88发布,转载请注明来源

关键词: 职工 文件 数据结构 字符串 大佬