リストから各構造体のすべてのメンバーを印刷しようとしています。私はジェネリックリストから要素をプリントアウトするために以下のプリント機能を提供されました。構造体の配列:各構造体のすべてのメンバーを印刷する
struct list_type {
void *data;
int size;
int capacity;
int elementSize;
int (*comparePtr) (void *d1, void *d2);
};
だからジェネリックリストADTのCファイルには、私はこの印刷機能を持っている:
// client needs to send a pointer to a function capable of printing an element
void printl(ListType listptr, void (*printItem) (void *d)) {
int i;
for(i = 0; i < listptr->size; i++) {
// since we cannot use data[i], we need to calculate the address
// of the element to be sent to the client's print function
// since data is of type void, the formula is:
// the beginning address of the array + (offset x element size)
printItem(listptr->data + i * (listptr->elementSize));
printf(" ");
}
printf("\n");
}
ここ
は、一般的なリストのADTのCファイルである私のリストの構造定義であり、
私はそうのような私PRINTL関数を呼び出す:私のドライバファイルで
printl(clientList, printItem);
、elemenをプリントアウトする機能がありますリストからT:私はプログラムを実行すると、私は変な文字の束を得る
struct client_tag {
char id[5];
char name[30];
char email[30];
char phoneNum[15];
};
:
void printItem (int* p) {
printf("%d", *p);
//`my attempt at printing the members of an individual structure from the list
// printf("%s", ((Client *)&p)[0]);
}
はここに私のClient
構造体の定義です。これをどうやって解決するのですか?
我々はprintl'がどのように 'を参照する必要があります構造体定義とは何か、ListTypeは何かを定義します。 – Schwern
http://stackoverflow.com/help/mcve - 最小限の完全で検証可能な例を作成する方法 – Elyasin
@Schwernよ、私はそれらを提供しました。私は十分に願って、私のコードはかなり長いので、私はどのくらいのことを含める必要があるか分からなかった。 – Jasmine