There are several syntax errors in the code:

  1. The function signature for paixu is not complete, it should be void paixu(l *p).

  2. The function implementation for paixu is missing the opening brace {.

  3. The variable t in paixu should be of type l, not int.

  4. The initialization of the array h is incorrect. Instead of using h[5]={...}, it should be initialized using curly braces {...}.

Here's the corrected code:

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

typedef struct lol { char name[20]; char weizhi[20]; int xueliang; int price; } l;

l h[5] = { {"wuqidashi", "shangdan", 500, 3150}, {"jifengjianhao", "zhongdan", 450, 6300}, {"anyelieshou", "sheshou", 400, 4800}, {"kuangzhanshi", "daye", 510, 5300}, {"rinv", "fuzhu", 600, 450} };

void paixu(l *p) { l t; for (int i = 0; i < 5 - 1; i++) { for (int j = 0; j < 5 - i - 1; j++) { if (h[j].price > h[j+1].price) { t = h[j]; h[j]= h[j+1]; h[j+1] = t; } } } for (int z = 0; z < 5; z++) { printf("%s %s %d %d\n", h[z].name, h[z].weizhi, h[z].xueliang, h[z].price); } }

int main(int argc, char const *argv[]) { paixu(h); return 0;

#include stdioh#include stringh#include stdlibhtypedef struct lol char name20; char weizhi20; int xueliang; int price;l; l h5;void paixul pl h5; int t; for int i = 0; i 5 - 1; i

原文地址: https://www.cveoy.top/t/topic/e1cY 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录