-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_string.c
More file actions
38 lines (31 loc) · 838 Bytes
/
binary_string.c
File metadata and controls
38 lines (31 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
This program finds the various permutations of a binary string and prints them respectively.
'X' denotes 1
'O' denotes 0
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
void string_printing(char *curr_char, char* str);
void bin_string(char *str);
void string_printing(char *curr_char, char *str) {
if (*curr_char == '\0') {
printf("%s\n", str);
} else if ((*curr_char) == 'x' || (*curr_char) == 'X') {
*curr_char = '0';
string_printing(curr_char + 1, str);
*curr_char = '1';
string_printing(curr_char + 1, str);
*curr_char = 'x';
} else {
string_printing(curr_char + 1, str);
}
}
void bin_string(char *str) {
string_printing(str, str);
}
int main(int argc, char *argv[]) {
bin_string(argv[1]);
return 0;
}