Hello,
The next exercide I have is to convert a decimal to a binary.
So I made this :
It won't compile because uitkomst2 = "0/1" + uitkomst2 is wrong.Code:int main ( int argc, char *argv[] ) { int nummer, uitkomst, remainder ; char uitkomst2 ; nummer = 4 ; uitkomst = 4 ; while (uitkomst <0) { uitkomst = nummer/2; remainder = nummer%2; if (remainder == 1) { uitkomst2 = "1" + uitkomst2 ; } else { uitkomst2 = "0" + uitkomst2; } nummer = uitkomst; } printf ("uitkomst is %s", uitkomst2); return EXIT_SUCCESS; } /* ---------- end of function main ---------- */
I get this error :
test2.c|34 col 15| warning: assignment makes integer from pointer without a cast
What I'm trying to achieve is this:
Let says the number is 4
Then 4/2 = 2 with no remainder so it will be a 0
Then 2/2 = 1 with no remainder so it will be a 0
Then 1/2 = 0.5 a remainder so it will be a 1
So uitkomst will be 001
Oke, almost right.
But what Am i thinking wrong here.? I know I have to read the outcome from end to beginning.
Roelof



1Likes
LinkBack URL
About LinkBacks



