I'm having problems in C with returning a string from this function:
char setup(){
puts("Please select a size for the string");
scanf("%d", &size);
getchar();
char sequence[size];
printf("Please write any sequence of %d numbers\n", size);
fgets(sequence, size+1, stdin);
return *sequence;
}
Size is set as a global variable. And the main:
int main(){
int program=0;
char sequence_alt[size];
puts("Please select the number of the program to test:");
scanf("%d", &program);
getchar();
switch(program){
case 1:
sequence_alt[size]=setup();
break;
The switch goes on, but nothing else is added on this case. Instead of getting the full string, like 12345 if i choose size 5, i get only the first character. I've searched for a lot of guides but i still can't understand if the problem is actually in my function, or my main when i print the value of the sequence. Any tip and help would be awesome and i've be forever thankful. Sorry if the code is too rudimentary, but im still taking my first baby steps in learning C.
Thanks!