Hi, I am writing a program that allows a user to enter a string of 0s, 1s, and x's. The program will then print out all of the possible combinations that a binary number can have with the string.
Example:
If the input is 1xx0
The output would be
1000
1010
1100
1111
The part that I am having trouble on is that I need to write this program using recursion. I'll let you guys know that I am terrible at recursion =(. Any hints or tips about how I should approach this program would be appreciated. Thanks
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 50
// I may need this
/*int find_x(char number[]){
int i, loc_of_x;
for(i= strlen(number) - 1; i >= 0; i--){
if (number[i] == 'x'){
loc_of_x = i;
return loc_of_x;}
}
return 0;
} */
int count_x(char number[]){
int i, number_of_x;
for(i=0, number_of_x = 0; (i < strlen(number)); i++){
if (number[i] == 'x')
++number_of_x;
}
return number_of_x;
}
void display(char number[]){
if (count_x(number) == 0)
printf("%s\n", number);
}
int main(){
char number[MAX_SIZE];
int number_of_x, i;
printf("Binary number: ");
scanf("%s", number);
display(number);
return 0;
}