Trying to write a program but it is giving me a weird error and I cant seem to figure out what it wrong. For the assignment we use a program called code step by step. I'm not sure if it is a program issue or if the code is wrong. here is my code:
char* acronym(char* word){
char result[50];
strcpy(result, "");
int index = 0;
for(int i = 0; i < strlen(word); i++){
if(isalpha(word[i]) && !isalpha(word[i-1])){
char upper = toupper(word[i]);
char * add = &upper;
strncat(result, add, 1);
}
}
char *p = &result;
printf("%s\n", p);
return p;
} here is an image of what it output.
It returns values that don't make sense like "P????","`?@u?", "0>???". and the wanted output the acroyms is listed as an unexpected output. Sorry if this is a repost but I couldn't find any relevant questions. I do get a few errors about pointers but the code still works on a online compiler.
Edit: Theses are the warning that I get from the compiler however it still runs (on the compiler) main.c:17:12: warning: implicit declaration of function ‘isalpha’ [-Wimplicit-function-declaration] main.c:18:26: warning: implicit declaration of function ‘toupper’ [-Wimplicit-function-declaration] main.c:23:15: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types] main.c:28:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
Edit: For this homework assignment we are only able to write a single function. I don't know what the rest of the program on the back end looks like. The program is called codestepbystep this is what I see. https://i.stack.imgur.com/6Lddh.jpg