The following is a recursive function that is supposed to turn an integer into a string
char* int_to_word(int word_int){
static char new[2];
char alphabet[26]={"abcdefghijklmnopqrstuvwxyz"};
new[0]=alphabet[word_int%27-1];
//new[1]='\0';
if(word_int/27==0){
return new;
}
static char *word;
strcpy(word,strcat(int_to_word(word_int/27),new));
return word;
}
I'm getting a segmentation fault with the line strcpy(word,strcat(int_to_word(word_int/27),new));
when word_int
> 26. To my knowledge, there's no reason it shouldn't work. My best guess is that I somehow neeed to allocate word
before copying into it, but changing the initializer to static char *word=(*char)malloc(100)
did not help.