Why don't the lines people[i].name = "something" work?
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
typedef struct {
char name[100];
char number[100];
}
person;
int main(void)
{
person people[2];
people[0].name = "Brian";
people[0].number = "+1-617-495-1000";
people[1].name = "David";
people[1].number = "+1-949-468-2750";
}
My IDE says I should use strcpy but I'm very confused as to why.
char name[100] = "Brian";in the declaration. But that is a special rule, and despite the use of=, this is not an assignment.=operator is not defined for arrays of any type. You can assign to individual array elements, but not whole arrays at once. Arrays lose their "array-ness" under most circumstances. There are legitimate reasons for this behavior, but they won't fit in the space of a comment.