関数の実装

#include < stdio.h >

short GetShort();

void main()
{
    short num;
    
    while(1){
        /* short standard input, insert to num */
        num=GetShort();
        /* display num binary */
        ShortBinPrint(num);
    }
}

short GetShort()
{
    char buf[80];
    short num;
    
    fgets(buf, sizeof(buf)-1,stdin);
    num=(short)atoi(buf);
    
    return(0);
}

int ShortBinPrint(num)
short num;
{
    char buf[20];
    
    ShortToBinString(num,buf);
    
    printf("%\n",buf);
    
    return(0);
}

int ShortToBingString(num,buf)
short num;
char *ptr;

ptr=buf;
for(i=15;i>=0;i--){
    *ptr=(char)(((num>>i)&0x01)+'0');
    ptr++;
}
*ptr='\0';

return 0;
}