hi

With the help of below program i try to print out different combinations of characters but when i compiled it i got some problem with it can anyone please help me with the errors in logic with the program

#include <stdio.h>
#include <stdlib.h>
 
char CharList[] =
{
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
    'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
    'u', 'v', 'w', 'x', 'y', 'z','0','1','2','3','4','5','6','7','8','9'
};
 
 
char* ChangeCharacters(int pos,char* sb,int lngth)
{
    int i;
    for (i = 0; i <= sizeof(CharList) - 1; i++)
    {
        sb[pos] = CharList[i];// Replace the character in the character array (string).
 
        if (pos == lngth - 1)
        {
            // Write the generated word.
            printf(sb);
            printf("\n");
        }
        else
        {
            ChangeCharacters(pos + 1, sb, lngth);
        }
    }
 
    return sb;
}
 
void StartCharPrint(int lngth)
{
    char sb[lngth];
    int i;
    char currentChar = CharList[0];
 
    for (i = 1; i <= lngth; i++)
    {
        sb[i] = currentChar;
    }
 
    ChangeCharacters(0, sb, lngth);
}
 
int main()
{
    StartCharPrint(4);
    return 0;
}

My expected output is

aaaa
aaab
aaac
.
.
.

but the output i got is

aaaaa���@$�@�@���(�@ �@]@�U@
aaaba���@$�@�@���(�@ �@]@�U@
aaaca���@$�@�@���(�@ �@]@�U@
aaada���@$�@�@���(�@ �@]@�U@
aaaea���@$�@�@���(�@ �@]@�U@
.
.
.


can any one please help me with it

cheers

Unexpected garbage at the end of the string typically means you forgot to append '\0'.

p.s. Start using code tags, please. I won't answer any but the most trivial questions that don't use code tags.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.