# Create a program that completes binary numbers. - 76595

Request Posted by

## machine392

Rating : No Rating
Earned: \$0
Request Detail
Price: \$10
• From: Computer Science, C Programming
• Due on: Fri 13 Mar, 2015 (11:00pm)
• Asked on: Fri 13 Mar, 2015
• Due date has passed, but you can still Post Solution.
Description

A binary number is made up of 0's and 1's but the input strings you will receive can
also contain 'x''s. An x represents a digit that can be either a 0 or a 1. Your
program should display all the possible binary digits that can be formed. For
example the string x1x0 could represent either 0100, 0110, 1100, or 1110.
2. Your program should accept the binary string as a command line argument
3. You MUST solve this program RECURISIVELY
4. Examples
1../bin_str.out 0110
0110
2../bin_str.out 01x0
0100
0110
3../bin_str.out xx
00
01
10
11
4../bin_str.out 101x100x11x
10101000110
10101000111
10101001110
10101001111
10111000110
10111000111
10111001110
10111001111

If it helps i have this so far but im stuck.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char* convertString(char *c,int len);
int main(int argc,char *argv[])
{
int i,length;
char *cs;

length=strlen(argv[1]);

cs=convertString(argv[1],length);

for(i=0;i<length;i++)
printf("%c", cs[i]);
//getch()
return 0;
}

char* convertString(char *c,int len)
{
char* newchar,newchar1;
int i,count = 0;

printf("\n");

for(i=0;i<count;i++)
{
if(c[i]=='0'||c[i]=='1')
{
newchar[i]=c[i];
}
if(c[i]=='x')
{
if(count==0)
{
newchar[i]='0';
}
if(count==1)
{
newchar[i]='1';
}
}
}
printf("\n");
for(i=0;i<count;i++)
{
printf("%c",newchar[i]);
}
count++;

if(count==1)
{
return(convertString(c,len));
}
return newchar;
}

Here's another attempt of the problem.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void convertString(char *str[], int len, int i)
{
if (i>=len)
return;
if (str[i] == '0' || str[i] == '1')
printf("%c", str[i]);
else
printf("%d", str[i] % 1);
convertString(str[i], len, i+1);
}

int main(int argc, char *argv[])
{

char *str = argv[1];
int len = strlen(str);
printf("Original: %s\n", str);
printf("New result: ");
convertString(str, len, 0);
printf("\n\n");

return 0;
}

Should only take like 10 minutes to complete..