0

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?

4
Contributors
5
Replies
11
Views
5 Years
Discussion Span
Last Post by jnawrocki
Featured Replies
  • 1
    WaltP 2,905   5 Years Ago

    [QUOTE=slygoth;1489586]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[/QUOTE] Maybe so, but what I wrote was something you [I]needed[/I]. There's a difference. Read More

1

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.

Comments
thanks arbus
0

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

Edited by WaltP: n/a

0

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

1

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.