I cant figure out why either of the following code fails to operate as expected. There both compiled into execution files.
Outputs:
a.out , prints 1, expected "no value"
a.out 1, prints 2, expected 1
a.out 2, prints 2, expected 2
Using a case:
void main(int in)
{
int a = in ;
printf("In function if\n");
if ( in == 1 )
printf("1\n");
else
if ( in == 2)
printf("2\n");
else
printf("wrong value\n");
}
Using a switch:
void main(int in)
{
switch( in )
{
case 1: printf("1\n"); break;
case 2: printf("2\n"); break;
default: printf("wrong value\n"); break;
}
};
I'm trying to get the following LISP functionality in C code:
(cond ((= in 1) 1)
((= in 2) 2)
(t nil))
Thank you for your assistance.