Hi,
I am using a function which takes a floating point fraction and converts it to binary upto 24 sig fig.I am passing a pointer pointing to an array (where the binary will be stored)to the function and then increasing the address by 1 (pointer arithmetic allows to point the variable to the next entry of the array).But when I run the code it seems the only one item gets copied into the array.
Here is my code:
/*this program converts a fractional decimal to binary e,g 0.625 should give .1010000000000000 upto 22 sig fig*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char myMantissa[25]; /* where the binary number is stored*/
char *fractiontoBinary(double a,char *b){
for(int i=0;i<22;i++)
{
if(a*2>=1)
{
*b='1';
b=b+1;
a=(a*2)-1;
}
else
{
*b='0';
b=b+1;
a=a*2;}
}

return b;
}

int main (void)
{double input;
scanf("%d",&input);
char *s= fractiontoBinary(input,myMantissa);

myMantissa[23]='\0';
printf("%d",myMantissa[1]);
return 0;
}