在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/C  網(wǎng)絡安全/ C語言代碼不知道哪錯了

C語言代碼不知道哪錯了

1.想用結構數(shù)組執(zhí)行查找書籍的操作,查找定價最高和最低的書名稱并輸出,但不知道錯誤在哪里
2.代碼

#include <stdio.h>
#include <stdlib.h>
void sort(struct book *p,struct book *pmax,struct book *pmin,int n);
struct book
{
    char name[20];
    float price;
}books[20],max,min;

int main()
{
int n,i;
printf("Input n:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
    printf("please input name of the book\n");
    scanf("%s",books[i].name);
    printf("please input the price\n");
    scanf("%f",&books[i].price);
}
    sort(books,max,min,n);
    printf("max\tname:%s\nprice:%.2f\n",max.name,max.price);
    printf("min\tname:%s\nprice:%.2f\n",min.name,min.price);
    system("pause");
    return 0;
}
void sort(struct book *p,struct book *pmax,struct book *pmin,int n)
{
    int i=0;
    *pmax=*p[0];
    *pmin=*p[0];
    for(;i<n;i++)
      {

        if(*(p+i).price>*pmax.price)
            *pmax=*(p+i);
        if(*(p+i).price<*pmin.price)
            *pmin=*(p+i);
      }
}

3.錯誤

E:\CodeBlocks\新建文件夾\查找書籍a(chǎn)\main.c:22:5: error: incompatible type for argument 2 of 'sort'
     sort(books,max,min,n);
     ^
E:\CodeBlocks\新建文件夾\查找書籍a(chǎn)\main.c:3:6: note: expected 'struct book *' but argument is of type 'struct book'
 void sort(struct book *p,struct book *pmax,struct book *pmin,int n);
      ^
E:\CodeBlocks\新建文件夾\查找書籍a(chǎn)\main.c:22:5: error: incompatible type for argument 3 of 'sort'
     sort(books,max,min,n);
     ^
E:\CodeBlocks\新建文件夾\查找書籍a(chǎn)\main.c:3:6: note: expected 'struct book *' but argument is of type 'struct book'
 void sort(struct book *p,struct book *pmax,struct book *pmin,int n);
      ^
E:\CodeBlocks\新建文件夾\查找書籍a(chǎn)\main.c: At top level:
E:\CodeBlocks\新建文件夾\查找書籍a(chǎn)\main.c:28:6: error: conflicting types for 'sort'
 void sort(struct book *p,struct book *pmax,struct book *pmin,int n)
      ^
E:\CodeBlocks\新建文件夾\查找書籍a(chǎn)\main.c:3:6: note: previous declaration of 'sort' was here
 void sort(struct book *p,struct book *pmax,struct book *pmin,int n);
      ^
E:\CodeBlocks\新建文件夾\查找書籍a(chǎn)\main.c: In function 'sort':
E:\CodeBlocks\新建文件夾\查找書籍a(chǎn)\main.c:31:11: error: invalid type argument of unary '*' (have 'struct book')
     *pmax=*p[0];
           ^
E:\CodeBlocks\新建文件夾\查找書籍a(chǎn)\main.c:32:11: error: invalid type argument of unary '*' (have 'struct book')
     *pmin=*p[0];
           ^
E:\CodeBlocks\新建文件夾\查找書籍a(chǎn)\main.c:36:18: error: request for member 'price' in something not a structure or union
         if(*(p+i).price>*pmax.price)
                  ^
E:\CodeBlocks\新建文件夾\查找書籍a(chǎn)\main.c:36:30: error: request for member 'price' in something not a structure or union
         if(*(p+i).price>*pmax.price)
                              ^
E:\CodeBlocks\新建文件夾\查找書籍a(chǎn)\main.c:38:18: error: request for member 'price' in something not a structure or union
         if(*(p+i).price<*pmin.price)
                  ^
E:\CodeBlocks\新建文件夾\查找書籍a(chǎn)\main.c:38:30: error: request for member 'price' in something not a structure or union
         if(*(p+i).price<*pmin.price)
                              ^
Process terminated with status 1 (0 minute(s), 0 second(s))
9 error(s), 3 warning(s) (0 minute(s), 0 second(s))

4.

圖片描述

圖片描述

哪位大佬可以回答一下,萬分感謝

回答
編輯回答
厭遇

你的max和min是book類型,然而你的sort函數(shù)接受的參數(shù)類型是book的指針。更多的看不下去了

2017年2月2日 20:42