C语言求回复5555555

图书信息包括书名、出版社和价格,任意输入5个图书信息,查找书名为 C language ,修改其出版社、价格信息为 SUST,39.6
要求,使用指向结构体数组的指针完成

参考如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LEN_NAME    64
struct books
{
    char    name[MAX_LEN_NAME];
    char    publish[MAX_LEN_NAME];
    float    price;
    struct books *next;
};

int main()
{
    int n;
    printf("计划录入图书的数量:");
    scanf_s("%d", &n);

    struct books *root = NULL;
    struct books *cur = NULL;

    while (n)
    {
        if (root == NULL)
        {
            root = (struct books *)calloc(1, sizeof(struct books));
            root->next = NULL;
            cur = root;
        }
        else
        {
            cur->next = (struct books *)calloc(1, sizeof(struct books));
            cur = cur->next;
            cur->next = NULL;
        }
        printf("请输入图书信息:\n");

        printf("书名:");
        scanf_s("%s", cur->name);

        printf("出版社:");
        scanf_s("%s", cur->publish);

        printf("价格:");
        scanf_s("%f", &cur->price);

        
        n--;
    }

    printf("\n图书信息录入完成\n");
    printf("书名\t\t 出版社\t\t 价格\n");
    cur = root;
    while (cur)
    {
        printf("%s\t\t %s\t\t $%.2f\n", cur->name, cur->publish, cur->price);
        cur = cur->next;
    }

    char name[MAX_LEN_NAME] = { 0 };
    printf("请输入要修改的图书名:");
    scanf_s("%s", name);

    cur = root;
    while (cur)
    {
        if (strcmp(name, cur->name)==0)
        {
            printf("出版社:");
            scanf_s("%s", cur->publish);

            printf("价格:");
            scanf_s("%f", &cur->price);
            break;
        }
        cur = cur->next;
    }
    
    printf("修改完成!\n");

    getchar();
    getchar();
    
    
    while (root)
    {
        cur = root->next;
        free(root);
        root = cur;
    }

    return 0;
}

如果对你有用,望采纳。

https://blog.csdn.net/m0_63071038/article/details/122481395多找几个例子参考参考,自己写一下,这边一般没人会帮你写完的