#include<stdio.h>
#include<string.h>
void recurse(char [],const char *);
int main() {
char *charset="abcdefghij";
recurse("",charset);
}
void recurse(char str[],const char *charset) {
int len;
len=strlen(str);
strcat(str,charset[len+1]);
if(len<strlen(charset))
recurse(str,charset);
printf("%s",str);
}
Like the question says, what is wrong here? This is the logic of my program
1. Keep a string called charset which I can fill any amount of numbers, characters
2. The first digit should first be passed to printf (or) any function I make, then the 1st two digits followed by first three, all the way till the the strlen of the passed string is same as that of the charset
I heard that if i use a function like with a global variable charset having A,B,C,D,etc.
void somefunction(char str[]) { //str is initialized here as "String"
for(int i=0;i<5;i++) {
calledfunction(strcat(str,charset[i])); // Here the string goes as "StringA"
}
anotherfnction(str); // Here the string goes as "String"
}
newbie at C.. do help me fix this..