Crank up those compiler warnings and heed them. If you write code the compiler says is bad, and force it to compile it, the resultant executable probably wont work like you want.
Code:
char print32bits(int x)
{
...
char *foo; /* bitstring to be returned*/
...
strcat(foo,"0");
...
return foo;
}
You're returning a char * from a function that wants you to return a char.
You can't strcat into a pointer unless it point to valid memory.
Code:
int get_bits_squeeze(int num, int mask)
{
num = print32bits(num); /*translate into bitstring*/
mask = print32bits(mask); /*translate into bitstring*/
char *bitString;
for(int i = 0;i<=32;i++) /*create filtered bitstring*/
if(mask[i]=="1")
strcat(bitString,num[i]);
Those two calls that assign the value of print32bits to num and mask don't do what you think. Declare two variables, say (e.g. char *num_str, *mask_str)as appropriate to receive the value of print32bits.
Your for loop should be < 32. An array of 32 items only has valid indexes of 0..31.
mask and num are single ints, so you can't index it like it's an array. This should be the num_str and mask_str I referred to.
Once you fix that, you can't compare num_str[i] (a char) to "1" (a string). You need single quotes, '1' (for string comparison, you can't use ==, you need strcmp).
Code:
printf("%s",print32bits(num)); /* produce first line of output */
printf("%s",print32bits(mask)); /* produce second line of output */
result = get_bits_squeeze(num, mask);
printf("%s",print32bits(result)); /* produce third line of output */
exit(0);
%s expects a char *, not a char. Also, it should be return 0, not exit(0).
Whew! Good effort, but maybe you ought to go back in your book a bit, or find some more basic tutorials that cover functions, arrays, strings, etc and work some very basic examples in those first, tackling one concept at a time until you are very competent in it, then come back to this program that incorporates several of them at once.