i was watching this video about type conversion and what the compiler does while converting from small byte formats to large byte formats(and vice versa) etc etc, and tried to write a code for it... but seems that function calls in my code are getting completely bypassed...
once again, here goes my sloppy code:
#include<stdio.h>
short char2shrt(void);
short int2shrt(void);
int shrt2int(void);
int main()
{
char bool=0,option,op=0;
do{
puts("what do you want to do?: \n (1)character to short \n (2)int to short \n(3)short to int \n press 1,2 or 3:\n");
scanf("%c",&option);
switch(option)
{
case 1:
char2shrt(void);
break;
case 2:
int2shrt(void);
break;
case 3:
shrt2int(void);
break;
}
puts("\ndo you wish to iterate once again?yes(1) or no(0):");
scanf("%d",&bool);
printf("\npresent state of bool:%d",bool);
}while(bool==1);
}
short char2shrt(void)
{
char ip;
short op;
puts("enter input:\n");
scanf("%c",&ip);
op=ip;
printf("the output in type short is: %h",op);
}
short int2shrt(void)
{
int ip;
short op;
puts("enter input:\n");
scanf("%d",&ip);
op=ip;
printf("the output in type short is: %h",&op);
}
int shrt2int(void)
{
short ip;
int op;
puts("enter input:\n");
scanf("%h",&ip);
op=ip;
printf("the output in type int is: %d",&op);
}
the attepmts i made were as such:
1st created the functions akin to
void foo(void)
, that didnt work, then i tried making them likesome_type foo(void)
that didnt work eitheri thought making somthing like
switch(option)
{
case 1:
op=char2short(void);
printf("the output in type short is: %h",op);
break;
.
.
with "op" declared as char in the begining, and get them casted to the type i need at eace case:
statements, and then make the functions here being of nature some_type foo(void)
, and have them return in this manner
short char2shrt(void)
{
char ip;
short op;
puts("enter input:\n");
scanf("%c",&ip);
op=ip;
return(op);
}
that didnt work either...
i then thought maybe void foo(void)
isnt allowed in C!! , and as i expected, turned out thats not the case either :(
man, its really hard work to be a beginer :(
can i get any pointers to where (theres probably more than a few) places im going wrong here ??
thanks a bunch in advance :)