동적으로 할당 된 구조체 유형 label
의 배열을 만들려고 노력 중이며 비참하게 실패했습니다. 내 .H 파일에서, 내가 가진 :C에서 동적으로 할당 된 구조체 배열이 작동하지 않는 이유는 무엇입니까?
label* allLabels = (label*) malloc(sizeof(label) * 10); // line 10
int arrayIndex = 0;
을 마지막으로 나는 같은이 .c 파일의 기능을 가지고 :
typedef struct _label {
char name[256];
char type[256];
int address;
} label;
내 .c 파일에
, 내가 맨 위에이 있습니다 그는 파일에서 다른 방법으로 사용되는 배열이 구조체 객체를 추가하기위한 것입니다 :void addLabel(char line[], char type[], int addr) {
label database;
database.name = line; // line 805
database.type = type; // line 806
database.address = addr;
allLabels[arrayIndex] = database;
arrayIndex++;
}
은 기본적으로 그냥 접근 할 라벨의 컬렉션을 갖고 싶어. 누군가 내가 잘못하고있는 것을 이해하도록 도와 줄 수 있습니까? 당신은 문자열 작업 중 하나가 필요
formatBuilder.c:10:3: error: initializer element is not constant
formatBuilder.c: In function 'addLabel':
formatBuilder.c:805:18: error: incompatible types when assigning to type 'char[256]' from type 'char *'
formatBuilder.c:806.18: error: incompatible types when assigning to type 'char[256]' from type 'char *'
어레이는 포인터가 아닙니다. '= '연산자를 사용하여 배열에 새로운 값을 할당 할 수 없습니다. – Jack
코드에서 '데이터베이스'란 무엇입니까? –
'database'는 내 레이블 객체의 이름입니다 – Laurence