Reputation: 485
Okay so I have this code
char from;
clrscr();
printf("Enter: ");
scanf("%s", &from);
if(from == 'a' || from == 'A') {
// blah blah code
}
Is there any other way or shortcut on the condition instead of using ||?
Thanks. :D
Upvotes: 0
Views: 2344
Reputation: 1760
Check this :
#include<stdio.h>
#include<ctype.h>
char from;
clrscr();
printf("Enter: ");
scanf("%c", &from);
if(toupper(from)=='A') {
// blah blah code
}
Upvotes: 0
Reputation: 186098
Assuming the ASCII character set, you could mask the bit that varies between 'A'
and 'a'
:
if ((from | 0x20) == 'a') …
toupper
is clearer and (strictly speaking) more portable, though.
Upvotes: 1
Reputation: 1126
'||' means 'or' don't know if there's another shortcut but what you're doing is right. There's '&&' which means 'and' and this one could be used when you want to meet two conditions in the same conditional if.
Upvotes: 0
Reputation: 3358
You could use toupper
function:
http://www.ousob.com/ng/turboc/ng61ac1.php
if(toupper(from) == 'A') {
// blah
}
Upvotes: 0