我有一個C語法的小問題。我想建立一個結構數組。但之前返回C結構聲明
預期的聲明說明符或「...」「城市」
這裏是我的代碼
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
struct City {
int plateNumber;
char name[32];
double area;
int population;
int populationDensity;
int cityCenterPopulation;
char region[32];
double latitude;
double longitude;
};
struct City cities[81];
#define Struct_Size sizeof(struct City)
void printCityData(cities[], int i);
void readFile();
void readFile(){
int fd = open("data.dat", O_RDONLY);
if(fd<0) {
printf("Error while opening file!");
return;
}
int i;
for (i = 0; i < 81; i++) {
while(read(fd,&cities[i], Struct_Size)>0) {
printCityData(cities[i],i);
}
}
}
void printCityData(cities[], int i) {
printf("CITIES\n");
printf("plateNumber: %d\n", cities[i].plateNumber);
printf("name: %s\n", cities[i].name);
printf("area: %lf\n", cities[i].area);
printf("population: %d\n", cities[i].population);
printf("populationDensity: %d\n", cities[i].populationDensity);
printf("cityCenterPopulation: %d\n", cities[i].cityCenterPopulation);
printf("region: %s\n", cities[i].region);
printf("latitude: %lf\n", cities[i].latitude);
printf("longitude: %lf\n", cities[i].longitude);
}
int main(int argc, char const *argv[]) {
readFile();
return 0;
}
我怎樣才能解決這個問題?
'無效printCityData(市[],int i)以{' - >'無效printCityData(int i)以{'' – BLUEPIXY
的#define STRUCT_SIZE的sizeof(結構市)'至少是一個命名錯誤的宏,因爲它甚至不會引用哪個'struct'的意思。說,更好地完全刪除這個宏。不要太喜歡宏,特別是作爲初學者。 (也可以用'inline'函數代替) – Olaf