sortbyName
再帰的なデータ構造を返す関数がありますsortedList
。sortList
それ自体が別の再帰的データ構造へのポインタを含み、stud_type
それらはすべて以下のように定義されています。
typedef struct stud_type_ {
int matricnum;
char name[20];
struct stud_type_ *next_student;
} stud_type;
typedef struct sort_List {
stud_type *cur;
struct sortList *next;
} sortList;
stud_type listofStudents; // Assume that it is not NULL
sortList * sortbyName() {
sortList *sList;
//sort algorithm here
return sList;
}
...
...
int main() {
//trying to define curTEST = sortbyName() here
while (curTEST!=NULL) {
printf("Name: %s\n", curTEST->cur->name);
curTEST = curTEST->next;
}
}
main()
ここで、関数からの戻り値を保持する変数を関数に割り当ててsortbyName
、while ループで繰り返し処理し、結果を出力できるようにします。次に、この変数をどのように定義しますか? 私は試しsortList curTEST;
てみsortList * curTEST;
ましたが、役に立ちませんでした。sortbyName
または、関数の定義に何か問題がありますか?
編集: 私はそれをコンパイルして、ほとんどの些細なエラー/警告を修正しましたが、この現在のエラーレポートに到達するまで、あまり意味がありません。
u2_4.c:208:15: warning: implicit declaration of function 'sortbyName' is invalid in C99
[-Wimplicit-function-declaration]
curTEST = sortbyName();
^
u2_4.c:208:13: warning: incompatible integer to pointer conversion assigning to 'sortList *'
(aka 'struct sort_List *') from 'int' [-Wint-conversion]
curTEST = sortbyName();
^ ~~~~~~~~~~~~~~~~~~
2 warnings generated.
Undefined symbols for architecture x86_64:
"_sortbyName", referenced from:
_main in u2_4-Szd3la.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [u2_4] Error 1
私のmain
関数では、次curTEST
のように定義しました。sortList * curTEST;