I am having a hard time understanding why in the following C program, I am not able to properly return an array of characters. The issue seems to be in the line:
results[indx][indx2]='X';
#include <stdio.h>
#include <string.h>
const char *PrintPlaceholder(char *words[], char *results[], int wordsNumber);
int main(){
char *word[]={"Hello","Fun"};
char *results[2];
PrintPlaceholder(word, results,2);
for (size_t indx=0; indx<2; indx++){
printf("Output is %s\n",results[indx]);
}
return 0;
}
const char *PrintPlaceholder(char *words[],char *results[], int wordsNumber){
size_t wordLength;
for (size_t indx=0; indx<wordsNumber; indx++){
wordLength=strlen(words[indx]);
printf("Word length is %d\n",wordLength);
for (size_t indx2=0; indx2<wordLength; indx2++){
printf("2nd for loop");
results[indx][indx2]='X';
printf("Char is %c ",results[indx][indx2]);
}
printf("\n");
}
}
Many thanks