I am trying to get 3 characters combinations using recursion but after some calls i get Segmentation fault

#include <cs50.h>
#include <stdio.h>

void three_Characters(char c, char c2, char c3);

int main(void){
    three_Characters('A', 'A', 'A');
    return 0;

void three_Characters(char c, char c2, char c3){

//print 3-characters 
    printf("%c%c%c - ", c, c2, c3);

    /*Recursion termination*/
    if(c == 'z' && c2 == 'z' && c3 == 'z'){

    /*Avoid symbol characters */
    if(c3 == 'Z'){
        c3 += 6;
        if(c2 == 'Z'){
            c2 += 7;
            if(c == 'Z'){
            c += 7;

    if(c3 == 'z'){
        if(c2 == 'z'){
            c += 1;   c2 = 65;   c3 = 64;
            c2 += 1;  c3 = 64;
    three_Characters(c, c2, c3 + 1); 

If I had to bet on something it would be for a stack overflow, although I recognize that I am not a great expert in terms of the stack, it is bad programming practice to use large amounts of memory in the stack, one solution could be to use the dynamic allocation of memory, although I do not see very clear how to use it with recursion


Answer from stack overflow illustrating the reason of segmentation fault and the recursion solution may take more time than loops


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .