I need some help with the toupper code.

int main()
{
char pick;
printf("A. Local needs\n");
printf("B. Local Service\n");
scanf("%d",& pick);
switch (pick)
{
case 'a':
printf("Hello World");
case 'b':
printf("Hello Nation");
}
getch()
return 0;
}

How would i implement the toupper code so i could change pick to upper case if the user entered a common letter. And do i have to # include anything at the top to use toupper?

Hello slygoth,
You should include ctype.h for using toupper.
To convert lowercase letter to uppercase you should give

pick=toupper(pick);

If the user enters 'a' you can convert it to 'A' using the above.

commented: thanks arbus +1

I need some help with the toupper code.

int main()
{
char pick;
printf("A. Local needs\n");
printf("B. Local Service\n");
scanf("%d",& pick);
switch (pick)
{
case 'a':
printf("Hello World");
case 'b':
printf("Hello Nation");
}
getch()
return 0;
}

How would i implement the toupper code so i could change pick to upper case if the user entered a common letter. And do i have to # include anything at the top to use toupper?

Q1) Do you know what %d does in your scanf() call?
Q2) What does the documentation say about using toupper() ?
Q3) Has anyone taught you how to format your code? If not, see this

THanks Waltp i was just writing peace of the code not all of it. But Arbus answer was really helpful and thats the exact thing i wanted

THanks Waltp i was just writing peace of the code not all of it. But Arbus answer was really helpful and thats the exact thing i wanted

Maybe so, but what I wrote was something you needed. There's a difference.

I would just bitwise "or" with 0x20 (ie. a |= 0x20;) . If 'A' it becomes 'a'. If 'a' it stays 'a'.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.