I have found piece of C code which would be very useful for what I want do to under this link: All possible combinations of characters and numbers
#include <stdio.h>
//global variables and magic numbers are the basis of good programming
const char* charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
char buffer[50];
void permute(int level) {
const char* charset_ptr = charset;
if(level == -1){
puts(buffer);
}else {
while(buffer[level]=*charset_ptr++) {
permute(level - 1);
}
}
}
int main(int argc, char **argv)
{
int length;
sscanf(argv[1], "%d", &length);
//Must provide length (integer < sizeof(buffer)==50) as first arg;
//It will crash and burn otherwise
buffer[length]='\0';
permute(length - 1);
return 0;
}
However, when I try to compile it as it is suggested, I get following errors. Can anyone please help me to correct it?
$ make CFLAGS=-O3 permute && time ./permute 5 >/dev/null
make: Nothing to be done for 'permute'.
./permute: line 3: //global: No such file or directory
./permute: line 4: const: command not found
./permute: line 5: char: command not found
./permute: line 7: syntax error near unexpected token `('
./permute: line 7: `void permute(int level) {'
Also when I try to use gcc I get Segmentation fault error:
$ mv permute permute.c
$ gcc permute.c -o permute.bin
$ chmod 755 permute.bin
$ ./permute.bin
Segmentation fault (core dumped)
./permute.bin