- Joined
 - Jul 16, 2015
 
- Messages
 - 212
 
- Thread Author
 - #1
 
This is a program which combines all possible letter+number combinations to a set length of characters. I sort of understand what is going on but  the 'bruteSequential' function confuses me...don't quite understand that. Was wondering if someone could explain
	
	
	
		
			
			
		Code:
	
	#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static const char alphabet[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";
static const int alphabetSize = sizeof(alphabet) - 1;
void bruteImpl(char* str, int index, int maxDepth)
{
    for (int i = 0; i < alphabetSize; ++i){
        str[index] = alphabet[i];
        if (index == maxDepth - 1) printf("%s\n", str);
        else bruteImpl(str, index + 1, maxDepth);
    }
}
void bruteSequential(int maxLen)
{
    char* buf = malloc(maxLen + 1);
    for (int i = 1; i <= maxLen; ++i){
        memset(buf, 0, maxLen + 1);
        bruteImpl(buf, 0, i);
    }
    free(buf);
}
int main(void)
{
    int x;
    printf("Length: \n");
    scanf("%x",&x);
    bruteSequential(x);
    return 0;
}
	



