/* * ===================================================================================== * * Filename: auta.c * * Description: auticka * * Version: 1.0 * Created: 11/30/2011 04:04:02 PM * Revision: none * Compiler: gcc * * Author: Milan Kabat (), kabat@ics.muni.cz * Company: FI MUNI * * ===================================================================================== */ #include #include #include #include #define YEAR_SPAN 61 #define NUM_COLORS 6 #define NUM_BRANDS 7 char *brands[] = { "Opel", "Mazda", "Toyota", "Skoda", "Audi", "Buick", "Ford" }; enum colors { red, yellow, blue, green, white, black }; struct car { char brand[20]; enum colors color; int year; }; void printCar(struct car *c) { char color[10]; switch(c->color) { case red: { strcpy(color, "Red"); break;} case yellow: { strcpy(color, "Yellow"); break;} case blue: { strcpy(color, "Blue"); break;} case green: { strcpy(color, "Green"); break;} case white: { strcpy(color, "White"); break;} case black: { strcpy(color, "Black"); break;} } printf("| %-10s | %-10s | %d", color, c->brand, c->year); } /* * === FUNCTION ====================================================================== * Name: main * Description: * ===================================================================================== */ int main ( int argc, char *argv[] ) { srand(time(NULL)); printf("\n\n"); struct car parkingLot[10]; for(int i = 0; i < 10; i++) { parkingLot[i].year = rand()%YEAR_SPAN + 1950; parkingLot[i].color = rand()%NUM_COLORS; sprintf(parkingLot[i].brand, "%s", brands[rand()%NUM_BRANDS]); printCar(&parkingLot[i]); printf("\n"); } printf("\n\n"); return EXIT_SUCCESS; } /* ---------- end of function main ---------- */