有戏

 找回密码
 立即注册
简历下载
搜索
热搜: 活动 交友 discuz
查看: 666|回复: 0

C

[复制链接]

1000

主题

1002

帖子

25万

积分

论坛元老

Rank: 8Rank: 8

积分
251951
发表于 2015-1-17 13:42:08 | 显示全部楼层 |阅读模式
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
typedef struct
{
    char name[40];
    char author[40];
    char place[40];
}Book;

Book * book=NULL;
int current=0;
int total=100;

void insert()
{
    if(current>total)
    {
        printf("当前存储空间不足,请输入图书量以分配图书空间\n");
        printf("PS:当前图书空间为%d",total);
        scanf("%d",&total);
        printf("修改成功,当前空间为%d",total);
    }
    printf("请输入图书名字");
    scanf("%s",&book[current].name);
    printf("请输入图书作者");
    scanf("%s",&book[current].author);
    printf("请输入图书出版社");
    scanf("%s",&book[current].place);
    current++;
}
void query()
{
    char *word;
    printf("请输入搜索关键字");
    int hasfound = 0;
    scanf("%s",word);
    int i;
    char *s;
    for(i=0;i<current;i++)
    {
        s=strstr(book[i].name,word);
        if(s == NULL)
        {
        s=strstr(book[i].author,word);
        if(s == NULL)
            {
            s=strstr(book[i].place,word);
            if(s != NULL)
            printf("%s,%s,%s",book[i].name,book[i].author,book[i].place);
            hasfound=1;
            }
        printf("%s,%s,%s",book[i].name,book[i].author,book[i].place);
        hasfound=1;
        }
    printf("%s,%s,%s",book[i].name,book[i].author,book[i].place);
    hasfound=1;
    }
    if(hasfound=0)
        printf("不存在");
}


void del()
{

    int hasfound = 0;
    int i;
    printf("请输入要删除的书名:");
     char name[40];
    scanf("%s", name);


    for (i=0; i<current; i++)
    {
        if (strcmp(book[i].name, name) == 0)
        {
            hasfound = 1;
            memmove(&book[i], &book[i+1], (current-1-i)*sizeof(Book));
            printf("删除成功\n");
            current--;
            //return ; //0;
        }
    }
    if(hasfound == 0)
        printf("该书不存在\n");
}
大家好
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|有戏 粤ICP备2020111303号

GMT+8, 2025-12-6 13:26 , Processed in 0.075178 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表