如何在linux下编写大型c程序

如何在linux下编写大型c程序,第1张

linux终端下,编译C语言程序步骤为: 采用vi进行源代码编写,编写完成后,:wq存盘退出,如: vi test.c 在命令行下,运行gcc编译程序,生成执行码,如: gcc -o test test.c -o 表示指明生成的执行码名称 运行编译后的执行码 ./test

# include "stdio.h"

# include "stdlib.h"

# include "string.h"

# define NULL 0

struct xiangcun

{

char num[4]//乡村的编号

char name[20] //村名

int people //总人数

int relieve//救济人数

float amount //救济总金额

struct xiangcun *next

}

struct jiating

{

char num[10] //乡村编号

char candidate[20] //身份z号码

char fname[20]//户主名字

char sex[2] //性别

int fpeople //家庭人数

float insert //年收入

int time //接受救助次数

struct jiating * next

}

struct out

{

char candidate[20]//户主身份z号码

char goodsname[20] //商品名字

char date[15]//发放日期

char unit[10] //单位

float price //单价

int count//发放数量

float money //金额

struct out *next

}

struct xiangcun *h1,*tail1

struct jiating *h2,*tail2

struct out *h3,*tail3

struct xiangcun * rebuilt1() //构建乡村链表

{

int n1=0

struct xiangcun *p1,*p2,*head

p1=p2=(struct xiangcun *)malloc(sizeof(struct xiangcun))

printf("\n\n\n\n\n\n 请输入以下信息:\n 乡村的编号:\n 村名:\n 总人数:\n 救济人数:\n 就系总金额:\n")

scanf("%s%s%d%d%f",p1->num,p1->name,&p1->people,&p1->relieve,&p1->amount)

while(strcmp(p1->num,"0")!=0)

{

n1++

if(n1==1)

h1=p1

else

p2->next=p1

p2=p1

p1=(struct xiangcun *)malloc(sizeof(struct xiangcun))

scanf("%s%s%d%d%f",p1->num,p1->name,&p1->people,&p1->relieve,&p1->amount)

}

p2->next=NULL

return h1

}

struct jiating * rebuilt2() //构建家庭信息链表

{

int n2=0

struct jiating *p1,*p2,*head

p1=p2=(struct jiating *)malloc(sizeof(struct jiating))

printf("\n\n\n\n\n\n 请输入以下信息:\n乡村名字: \n户主身份z号码: \n 户主名字:\n 户主性别:\n 家庭人数:\n 年收入:\n 接受救助的次数:\n")

scanf("%s%s%s%s%d%f%d",p1->num,p1->candidate,p1->fname,p1->sex,&p1->fpeople,&p1->insert,&p1->time)

while(strcmp(p1->candidate,"0")!=0)

{

n2++

if(n2==1)

h2=p1

else

p2->next=p1

p2=p1

p1=(struct jiating *)malloc(sizeof(struct jiating))

scanf("%s%s%s%s%d%f%d",p1->num,p1->candidate,p1->fname,p1->sex,&p1->fpeople,&p1->insert,&p1->time)

}

p2->next=NULL

return h2

}

struct out * rebuilt3() //构建物资信息链表

{

struct out *p1, *p2,*head

int n3=0

p1=p2=(struct out *)malloc(sizeof(struct out))

printf("\n\n\n\n\n\n 请输入以下信息:\n 户主身份z号码:\n 商品名字:\n 发放日期:\n 单位:\n 单价:\n 发放数量:\n 金额:\n")

scanf("%s%s%s%s%f%d%f",p1->candidate,p1->goodsname,p1->date,p1->unit,&p1->price,&p1->count,&p1->money)

while(strcmp(p1->candidate,"0")!=0)

{

n3++

if(n3==1)

h3=p1

else

p2->next=p1

p2=p1

p1=(struct out *)malloc(sizeof(struct out))

scanf("%s%s%s%s%f%d%f",p1->candidate,p1->goodsname,p1->date,p1->unit,&p1->price,&p1->count,&p1->money)

}

p2->next=NULL

return h3

}

int change1(xiangcun *head1,char *num) //对乡村信息的修改

{

struct xiangcun *p

p=head1->next

printf("\n\n\n\n\n\n")

while(1)

{

if(p==NULL)

{

return 1

}

if(strstr(p->num,num))

{

printf(" 请重新输入要修改乡村的各项:")

scanf("%s%s%d%d%d",p->num,p->name,&p->people,&p->relieve,&p->amount)

return 1

}

p=p->next

}

}

int change2(jiating *head2,char *num) //对家庭信息的修改

{

struct jiating *p

p=head2->next

printf("\n\n\n\n\n\n")

while(1)

{

if(p==NULL)

{

return 1

}

if(strstr(p->fname,num))

{

printf(" 请重新输入要修改家庭的各项:")

scanf("%s%s%s%s%d%f%d",p->num,p->candidate,p->fname,p->sex,&p->fpeople,&p->insert,&p->time)

return 1

}

p=p->next

}

}

int change3(out *head3,char *name) //对物资信息的修改

{

struct out *p

p=head3->next

printf("\n\n\n\n\n\n")

while(1)

{

if(p==NULL)

{

return 1

}

if(strstr(p->goodsname,name))

{

printf(" 请重新输入要修改物资的各项:")

scanf("%s%s%s%s%f%d%f",p->candidate,p->goodsname,p->date,p->unit,&p->price,&p->count,&p->money)

return 1

}

p=p->next

}

}

void Csearch(xiangcun* head1) /* 查询全部乡村中每个村的救济总户数*/

{

struct xiangcun *p

p=head1->next

printf("\n\n\n\n\n\n")

if(p==NULL)

{

printf(" 全乡没有被救济的人!\n")

return

}

while(p!=NULL)

{

printf(" %s救济人数为:%d\n",p->name,p->relieve)

p=p->next

}

return

}

int Esearch(xiangcun * head1,char *name) /*查询全部乡村中某个村的村救济总金额*/

{

struct xiangcun *p

p=head1->next

while(1)

{

if(p==NULL)

{

return 0

}

if(strstr(p->name,name))

{

printf("\n\n\n\n\n\n %s的受救济总金额是:%g\n",p->name,p->amount)

return 1

}

p=p->next

}

}

int Fsearch(jiating* head2,char * name) /*查询某救济户 (如:张三)基本信息*/

{

struct jiating *p

p=head2->next

while(1)

{

if(p==NULL)

{

return 0

}

if(strstr(p->fname,name))

{

printf("\n\n\n\n\n\n 户主的乡村编号:%s\n 户主的身份z号码:%s\n",p->num,p->candidate)

printf(" 户主名字是:%s\n 户主性别是:%s\n",p->fname,p->sex)

printf(" 家庭人数:%d\n 年收入:%g\n /接受救助次数:d\n",p->fpeople,p->insert,p->time)

return 1

}

p=p->next

}

}int frelieve(jiating *head2,out *head3,char * name)/*查询某救济户 (如:张三)救济户物资发放的全部信息*/

{

struct jiating * p

p=head2->next

while(1)

{

if(p==NULL)

{

return 0

}

if(strstr(p->fname,name))

{

struct out *p1

p1=head3->next

printf("\n\n\n\n\n\n %s的物资信息:\n",p->fname)

while(1)

{

if(p1==NULL)

{

return 1

}

if(strstr(p->candidate,p1->candidate))

{

printf("物资名字:%s\n发放日期:%s\n物资的量的单位:%s\n",p1->goodsname,p1->date,p1->unit)

printf("物资单价:%g\n 发放数量:%d\n发放金额:%g\n",p1->price,p1->count,p1->money)

}

p1=p1->next

}

}

p=p->next

}

}

int Relieve(jiating * head2,out *head3,char * name,char *name2)/*查询某救济户 (如:张三)是否发放了某种救济物资 (如:矿泉水)的信息*/

{

struct jiating * p

p=head2->next

while(1)

{

if(p==NULL)

{

return 0

}

if(strstr(p->fname,name))

{

out *p1

p1=head3->next

while (1)

{

if(strstr(p->candidate,p1->candidate)&&strstr(p1->goodsname,name2))

{

return 1

}

p1=p1->next

if(p1==NULL)

{

return 0

}

}

}

p=p->next

}

}

void tprint(xiangcun * head1)/*统计并输出全乡的人口总数、救济总户数、救济总金额*/

{

int peo_sum=0,re_sum=0

float re_cost=0

xiangcun *p=h1

while(p!=NULL)

{

peo_sum+=p->people

re_sum+=p->relieve

re_cost+=p->amount

p=p->next

}

printf("\n\n\n\n\n\n 人口总数:%d\n 救济总户数:%d\n救济总金额:%g\n",peo_sum,re_sum,re_cost)

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/7807775.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存