Skip to content

Instantly share code, notes, and snippets.

@Bevilacqua
Last active November 29, 2016 01:46
Show Gist options
  • Save Bevilacqua/5109c013d638df3215593ed9711d00bc to your computer and use it in GitHub Desktop.
Save Bevilacqua/5109c013d638df3215593ed9711d00bc to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
void find_variants(char *input, char* working, int size);
void bin_str_func(char *input);
int main(int argc, char *argv[])
{
bin_str_func(argv[1]);
return 0;
}
void bin_str_func(char *input)
{
int length;
length = strlen(input);
char *working = malloc(length * sizeof(char));
find_variants(input, working, length);
}
void find_variants(char *input, char* working, int size)
{
if(*input == '\0') printf("%s\n", &working[-size]);
else
{
if(*input == 'x')
{
char* w_branch = working;
char* i_branch = input;
*working = '0';
find_variants(++input, ++working, size);
working = w_branch;
input = i_branch;
*working = '1';
find_variants(++input, ++working, size);
}
else
{
*working = *input;
find_variants(++input, ++working, size);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment