2
Error in C
SofhinWong1 (3)

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

//variable for A1
int menu;
char Name[100];
char Student_ID[100];
char Room[100];
char Bill[100];
int Meal, Gym, Week;

int main(){
printf("1 Room Booking\n2 Room Availability\n3 Payment Details\nPlease enter your option:");
scanf("%i",&menu);
if(menu==1){
A1:
printf("\nPlease enter your name:");
scanf(" %c",&Name);
printf("\nPlease enter your Student ID:");
scanf("%c",& Student_ID);
printf("\n\nPlease choose your gender.\n1 Male\n2 Female");
goto A1;
}
}

When I run the program, it gives me warning.
warning: format specifies type 'char ' but the argument has type 'char ()[100]' [-Wformat]
May I know how to fix it?

You are viewing a single comment. View All
1
mwilki7 (111)

@SofhinWong1
Make sure not to mix up:
int choice
with
scanf("%s",&choice)

%d is for ints int choice; scanf("%d", &choice);
%s is for char arrays char choice[100]; scanf("%s", choice);

something like:

char choice[100];
scanf("%s", choice);
while (strcmp(choice, "done") != 0)
{
    if (strcmp(choice, "A1") == 0)
    {
        do stuff here
    }
    scanf("%s", choice);
}

What the code above does is it keeps reading in input until you write "done"
Fill in what you want A1 to do, copy paste and change it a bit if you want "A2" and "A3"

This function:
strcmp(string1,string2)
compares string1 and string2
if they are the same, it will return 0
otherwise it will be something not 0