1. Rewrite Function Using Pointers

Hi all, I'm new here and I'd first like to say hi! Anyway, I've been programming in Java for a while, and one of my courses recently required that I pick up C. I've tried searching and reading up on pointers already, but would still require help with the following:

Actual Code:
Code:
```int mystery1(int n) {
int bit;
if (n == 0)
return 0;
else {
if (n & 1)
bit = 1;
else
bit = 0;
return bit + mystery1(n/2)*2;

}

}```
To be rewritten using the following function prototype:
Code:
`void mystery1(int *n, B C)`
Where B and C are just placeholders. I'd just need some help in pointing me in the right direction, such as what B and C are? Thanks!

B and C are nothing, unless teh instructor gave you instructions on what they are and you didnt provide that to us.

That function also is subject to an infinite loop for any even value over 1

3. Why would it be an infinite loop?

And you would need at least a type in the prototype.

4. Originally Posted by tabstop
Why would it be an infinite loop?

And you would need at least a type in the prototype.
oh my bad, i was readign it as returning mystery1((n/2)*2), i see now its not an infinite loop, it just coutns the number of bits that are 1's

5. abachler: I've done my homework and that's why I'm asking here. I'm not even asking for the code, I just want to know what B and C might be.

And no, it will not generate an infinite loop. What actually happens is that for a positive number x, the output will also be x. Doing a printf() of bit will show the number in it's binary form. When the input is a negative number x, the output will be the positive form of x.

Also, what I've written is what I'm given. I too, would like to at least know if B C is "int bit" or something, but that was not given =(.

6. there is no way of knowign what it could be, its undefined, and will generate a ciompile error. There is no logical way of determining what it migth be either, it coudl be anything. Ask teh instructor what he intends it to be.

7. >I too, would like to at least know if B C is "int bit" or something, but that was not given =(.
What is this, an algebra problem? "Fill in the blanks" with C code? Clearly the function should be rewritten like this if your teacher really didn't elaborate at all on what needs to be done:
Code:
```#include <stdio.h>

int mystery1 ( int *n, const char *msg )
{
if ( msg != NULL )
puts ( msg );

return *n;
}

int main ( void )
{
int x = 12345;

printf ( "%d\n", mystery1 ( &x, "Mr. Teacher Guy, you're a doofus." ) );

return 0;
}```

8. Thanks for the replies so far. Anyway, the original function returns an int, while the prototype is a void function. Apparent B is the type and C is the identifier. Since the function has no return type now, I'm guessing that *n is used instead to some sort of give a return value. I still can't figure out what B C should be for now.