|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 zwj.123 于 2022-11-26 18:06 编辑
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #pragma pack(1)
- typedef struct Link{
- int id;
- char name[30];
- char gender[20];
- char role[50];
- int age;
- char skill[50];
- }Node;
- void _input(Node *,int n);
- Node* _add(Node *,int n,int *);
- void _print(Node a[],int n);
- void _alter(Node *);
- Node * _delete(Node *,int n);
- void _quit();
- int main()
- {
- int i=0,n=0,m=0;
- int *p = &m;
- char order;
- Node *a;
- printf("Now you can do these things\n");
- printf("if you want to add ,input the order :a\n");
- printf("if you want to look,input the order :l\n");
- printf("if you want to alter,input the order :e\n");
- printf("if you want to delete,input the order :d\n");
- printf("if you want to quit,input the order :q\n");
-
- order=getchar();
- begin:
- switch(order)
- {
- case 'a': a= _add(a,n,p); break;
- case 'l': n=n+*p; _print(a,n);break;
- case 'e': _alter(a); break;
- case 'd':a= _delete(a,n); break;
- case 'q': _quit(); break;
- default : printf("you enter the wrong order\n");break;
- }
- if(order!='q')
- {
- printf("You not input the q,so enter the order again:\n");//第一次提问,有很多不会,如果做的不好希望见谅,抱歉,
- fflush(stdin);
- order=getchar();
- fflush(stdin);
- goto begin;
- }
- free(a);
-
-
- return 0;
- }
- Node * _add(Node *a,int n,int *p)
- {
- int i;
- printf("how much do you want to add? Please input the number:\n");
- scanf("%d",p);
- Node * b=(Node*)malloc((*p+n)*sizeof(Node));
- for(i=0;i<n;i++)
- {
- b[i].id=a[i].id;
- b[i].age=a[i].age;
- strcpy(b[i].name,a[i].name);
- strcpy(b[i].gender,a[i].gender);
- strcpy(b[i].skill,a[i].skill);
- }
- printf("Please input the people's information again\n");
- printf("including id,name,gender,role,age,skill\n");
- for(i=n;i<*p+n;i++)
- {
- scanf("%d %s %s %s %d %s",&b[i].id,b[i].name,b[i].gender,b[i].role,&b[i].age,b[i].skill);
- }
-
- return b;
- }
- }
复制代码
order=getchar(); // 你输入1个字符,其实有2个,(1个可见字符,1个回车)
getchar(); // 加getchar() 吃掉回车
|
|