#include <stdio.h>
int strO (char* myStr[]) {
char str[] = "hello";
myStr[0] = str; // < Part to be modified?
return 0;
}
int main() {
char* string_list[10] = {NULL};
strO(string_list);
printf("%s\n", string_list[0]);
return 0;
}
In the strO function, we want to substitute the string indicated by str in string_list[0] and output it from main. (i.e., I want to print out "hello".)
However, the garbage value continues to be printed in the above code. Is there a way to get the result I want by modifying only the marked part?
c parameter pointer string function
char str[] = "hello";
Please correct the code above as below.
static char str[] = "hello";
© 2024 OneMinuteCode. All rights reserved.