0

Unions and pointers

Hi everyone. So I need to create a menu asking the user to select one of the given options. This must be done with a union array and using switch case. Unfortunately my loop isn't running all the way through. Please can someone help point out where I am going wrong Code: #include <stdio.h> #include <string.h> #include <stdlib.h> typedef union { char *plaqueVhc; char plaque[10]; char *colorVhc; char color[10]; char *brandVhc; char brand[20]; float *priceVhc; float price; int *modelYearVhc; int modelYear; } utypeVehicle; int main() { utypeVehicle vehicle; utypeVehicle *vehicleVhc; char plaque[10]; char color[10]; char brand[20]; float price; int modelYear; int op; int i; char p; for (i=0;i<5;i++) { printf("Please select an option:\n1) Plaque\n2) Colour\n3) Brand\n4) Price\n5) Model year\n"); scanf("%d",&op); switch(op) { case 1: printf("Please enter the Plaque: "); scanf("%c",&plaque[i]); vehicle.plaqueVhc = &plaque[i]; break; case 2: printf("Please enter the Color: "); scanf("%c",&color[i]); vehicle.colorVhc = &color[i]; break; case 3: printf("Please enter the Brand: "); scanf("%c",&brand[i]); vehicle.brandVhc = &brand[i]; break; case 4: printf("Please enter the Price: "); scanf("%f",&price); vehicle.priceVhc = &price; break; case 5: printf("Please enter the Model Year: "); scanf("%d",&modelYear); vehicle.modelYearVhc = &modelYear; break;

23rd May 2021, 9:27 PM
Annangelique
Annangelique - avatar
2 ответов
0
You miss the closed bracket
8th Feb 2023, 2:05 PM
Nouhou Issoufou
Nouhou Issoufou - avatar
0
You miss the closed bracket for the switch and the while statement
8th Feb 2023, 2:06 PM
Nouhou Issoufou
Nouhou Issoufou - avatar