#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
There are several syntax errors in the code:
-
The function signature for
paixuis not complete, it should bevoid paixu(l *p). -
The function implementation for
paixuis missing the opening brace{. -
The variable
tinpaixushould be of typel, notint. -
The initialization of the array
his incorrect. Instead of usingh[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;
原文地址: https://www.cveoy.top/t/topic/e1cY 著作权归作者所有。请勿转载和采集!