Hi all,
I have written a c program that prompts the user for integers 1 and 2 and then prints out that number in different way. Here it is
My problem is that from that program I must write a function pack (a,b) to pack two 8-bi "char" variables a and b into a 16 bit "int" variable. I am supposed to modify the program that i wrote above to call the pack function as instructd by the user. The values a and b are entered in hex and teh packed variables are printed as decimal numbers.Code:#include "stdafx.h" #include <stdio.h> void main () { char c; int i, n1, n2, number; long k; float f; while () { printf ("enter first number: "); scanf("d%", &n1); printf ("d%", &n1); printf ("enter last number: "); scanf("d%", &n2); printf ("d%", &n2); for (number=n1; number <=n2; number++) { c = number; i = number; k = number; f = number; printf("char: (dec) = \t%12d (uns dec) = %12u (hex) = %12x\n",c,c,c); printf("int: (dec) = \t%12d (uns dec) = %12u (hex) = %12x\n",i,i,i); printf("char: (dec) = \t%12ld (uns dec) = %12lu (hex) = %12lx\n",k,k,k); printf("f: (float) = \t %12.3f\n\n\n", f); } } }
pack (0, 80) = 128
pack (0,ff) = 255
I am not sure how i can do this nor do i know how to use the pack function. Can someone help me please? Help me please!


