i gelöst mich, vermisst einen Zeiger *
typedef struct tabp *tabP;
struct tabp {
prodItem *vettP;
int nP;
};
Produkt item.h:
#ifndef prodItem_h
#define prodItem_h
#include <stdio.h>
#include <stdlib.h>
typedef struct proditem *prodItem;
typedef char* prodKey ;
prodItem prodItemScan(FILE*);
void prodItemShow(FILE*, prodItem);
int prodItemCheckVoid(prodItem);
void prodItemFree(prodItem);
int prodItemGreater(prodItem,prodItem);
prodKey prodKeyGet(prodItem);
int prodKeyComp(prodKey, prodKey);
#endif /* prodItem_h */
Symbol table.h
#ifndef tabP_h
#define tabP_h
#include <stdio.h>
#include "proditem.h"
typedef struct tabp *tabP;
tabP tabPScan(FILE*);
void tabPShow(FILE*,tabP);
void tabPFree(tabP);
int tabPCount(tabP);
int tabPSearch(tabP, prodKey);
#endif /* tabP_h */
Symbol table.c
#include "tabP.h"
struct tabp {
prodItem *vettP;
int nP;
};
tabP tabPScan(FILE *f) {
int max;
fscanf(f,"%d", &max);
tabP tab = malloc((sizeof(*tab)));
tab->nP = max;
tab->vettP = malloc(max * sizeof(prodItem));
for(int i=0; i<max; i++) {
tab->vettP[i] = prodItemScan(f);
}
return tab;
}
void tabPShow(FILE *f, tabP tab){
for(int i=0; i<tab->nP; i++) {
prodItemShow(f, tab->vettP[i]);
}
}
int tabPCount(tabP tab) {
return tab->nP;
}
int tabPSearch(tabP tab, prodKey key) {
for (int i=0; i<tab->nP; i++) {
if (prodKeyComp(prodKeyGet(tab->vettP[i]), key)==1){
return i;
}
}
return -1;
}
Und was ist 'struct prodItem'? Du tippst eine 'struct' als' pointer' ein. – user3078414
Sind alle diese Codes in der gleichen Datei? Einschließlich 'struct prodItem' - für mich klingt es so, als ob' struct prodItem' nicht bekannt ist, wenn Sie den Code 'tab-> vettP [i]' – 4386427
Typedef Zeiger ist eine schlechte Idee: meine persönliche Meinung. BTW Tab-> vettP = malloc (max * sizeof (* prodItem)); 'sollte' tab-> vettP = malloc (max * sizeof (struct proditem)); ' – LPs