Hi, everyone. I'm trying to write a program that has a string array with variable dimension - it reads the dimension from the keyboard, and, depending on the value, gives certain values to the array offsets. However, when I compile the code, I get the following error on the bold lines below: "error: incompatible types when assigning to type 'char[(unsigned int)(size + 1)]' from type 'char *'". The code is as follows:
How can I change the code so that it be correct? Thanks in advance!Code:#include <stdio.h> #include <string.h> int main (void) { int size, i; char name[size + 1]; printf("Choose a size: "); scanf("%d", size); if (size == 2) { name = "AB"; } else if (size == 3) { name = "ABC"; } //prints the string: for (i = 0 ; i < strlen(name) ; i++) printf("%c", name[i]); return 0; }



LinkBack URL
About LinkBacks


