Write a function the gets two strings and number, the signiture of the function:
void get_formated_integer(char *format, char *result, int num)the function convert the given numbernumaccording theformatand returns a string in the variableresult, for%bconverts int to binary of the number, for example, for the call:get_formated_integer("%b",&result, 18);then*resultwill get the string10010
My code:
#include <stdio.h>
void convert_binary(int num)//converts decimal number to binary
{
if(num>0)
{
convert_binary(num/2);
printf("%d", num%2);
}
}
void get_formated_integer(char *format, char *result, int num)
{
if(format[1]=='b')
convert_binary(num);
}
int main()
{
char result[100];
get_formated_integer("%b",&result, 18);
}
My output:
10010
I don't understand how to do that
*resultwill get the string10010sorry about my English
convert_binary