I'm a beginner C programmer, yesterday I learned the use of C structs and the possible application of these ones about the resolution of specific problems. However when I was experimenting with my C IDE (Codeblocks 16.01) in order to learn this aspect of C programming, I've encountered a strange issue. The code is the following:
#include <stdio.h>
#define N 30
typedef struct{
char name[N];
char surname[N];
int age;
} data;
int main() {
data s1;
s1.name="Paolo";
s1.surname = "Rossi";
s1.age = 19;
getchar();
return 0;
}
During the compilation, the compiler (GCC 4.9.3-1 under Windows) reported me an error that says
"error: assignment to expression with array type error"
on instruction
s1.name="Paolo"
s1.surname="Rossi"
while if I do
data s1 = {"Paolo", "Rossi", 19};
it works. What am I doing wrong?
s1 = (const data){"Paolo", "Rossi", 19};
– Rattray