structs, verschiedene Datein, Zugriff
Verfasst: Fr Jan 18, 2013 6:48 pm
Hallo allerseits,
folgender Fehler tritt beim Compilieren meines Codes auf:
"Anfrage nach Element "xPos" in etwas, was keine Struktur oder Variante ist"
Der Fehler entsteht in der zweiten Zeile. Diese steht in meiner main.c, die Funktion getObjects sowie die Deklaration des structs "struct object" stehen in einer object.c bzw. object.h die per include in main eingebunden sind.
object.c:
object.h:
Deklaration von movingObjects in main.c:
Es scheint mir, als wenn das Dateienübergreifende das Problem ist. Die Funktionen createObject und getObjects habe ich bereits seperat in object.c getestet. Sie funktionieren einwandfrei, man kann auf die einzelnen structs im Array zugreifen.
Ich bitte um Hilfe, vielen Dank im Vorraus, mit freundlichen Grüßen,
petterapamm
folgender Fehler tritt beim Compilieren meines Codes auf:
"Anfrage nach Element "xPos" in etwas, was keine Struktur oder Variante ist"
Code: Alles auswählen
if((movingObjects=getObjects())!=NULL) value++;
printf("bla: %d",movingObjects[0].xPos);
object.c:
Code: Alles auswählen
...
#include "objects.h"
struct object* createObject(char id, int xPos, int yPos, int healthPoints, int attack, char type){
struct object* newObject = malloc(sizeof(struct object));
newObject->id = id;
newObject->xPos = xPos;
newObject->yPos = yPos;
newObject->healthPoints = healthPoints;
newObject->type = type;
newObject->attack = attack;
return newObject;
}
struct object** getObjects(){
struct object** objects = (struct object**) malloc(50*sizeof(struct object*));
objects[0] = createObject(1,50,50,100,10,0);
return objects;
}
Code: Alles auswählen
struct object{
char id;
int xPos;
int yPos;
int healthPoints;
int attack;
char type;
};
struct object** getObjects();
Code: Alles auswählen
struct object** movingObjects;
Ich bitte um Hilfe, vielen Dank im Vorraus, mit freundlichen Grüßen,
petterapamm