- 1、本文档共15页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C语言答案第8章
第8章
[习题-1]/*c8_1.c*/
#include stdio.h
struct book
{
char title[20];
char aditor[10];
int year;
int month;
char flag;
}liber[10];
void main( )
{
int i;
for(i=0;i10;i++)
{
rintf(Input book title:\n);
scanf(%s,liber[i].title);
printf(Input book aditor:\n);
scanf(%s,liber[i].aditor);
printf(Input print date,year and month :\n);
scanf(%d%d,liber[i].year,liber[i].month);
printf(Input book information:\n);
scanf(%c,liber[i].flag);
}
for(i=0;i10;i++) printf(%s,%s,%d-%d,%c\n,liber[i].title,liber[i].aditor,liber[i].year,liber[i].month,liber[i].flag);
}
[习题-2]/*c8_2.c*/
#include stdio.h
#include stdlib.h
#include string.h
struct list
{
char words[20];
int num;
struct list *next;
};
typedef struct list node;
typedef node *link;
void count(char *str) /*统计正文中单词个数*/
{
link ptr,head,ptrn,headnew;
int i=0,j=0,prei=0;
char temp[20];
ptr=(link)malloc(sizeof(node));
head=ptr;
ptr-next=NULL;
do
{
if(*(str+i)== ||*(str+i)==\0)
{ /*出现一个单词*/
temp[j]=\0;
ptr=head;
while(ptr-next!=NULL)
{
if(strcmp(ptr-next-words, temp)==0) /*该单词已经出现*/
{
ptr-next-num++;
break; /*结束内层while循环*/
}
else
ptr=ptr-next;
}
if(ptr-next==NULL) /*该单词是新单词*/
{
ptr-next=(link)malloc(sizeof(node));
strcpy(ptr-next-words,temp);
ptr-next-num=1;
ptr-next-next=NULL;
}
if(*(str+i)==\0) break; /*全部正文已经结束,跳出循环*/
j=0;
i++;
continue;
}
temp[j++]=str[i++];
}while(1);
ptrn=(link)malloc(sizeof(node)); /*新建一个按照顺序排列的链表*/
headnew=ptrn;
ptrn-next=NULL;
ptr=head-next;
ptrn=headnew;
while(head-next!=NULL)
/*把head链表中的结点依次取出按照顺序链接到新的链表headnew中*/
{
while(ptrn-next!=NULLptrn-next-num=ptr-num)
ptrn=ptrn-next;
head-next=ptr-next;
ptr-next=ptrn-next;
ptrn-next=ptr;
ptr=head-next;
ptrn=headnew;
}
ptr=headnew-next;
while(ptr!=NULL){ /*将排好序的结点输出*/
puts(ptr-words);
printf(%d\n, ptr-num);
ptr=ptr-next;
}
}
void mai
文档评论(0)