I have a function sortbyName
that returns a recursive data structure sortedList
. sortList
itself contains a pointer to another recursive data structure stud_type
and they are all defined as below.
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;
}
}
Now I would like to assign a variable in the main()
function to hold the return value from my sortbyName
function so I can iterate through it with a while loop and print out the results. How do I then define this variable? I tried sortList curTEST;
and sortList * curTEST;
to no avail. Or is there something wrong with my definition of the sortbyName
function?
EDIT: I've tried compiling it and corrected most of the trivial and not so trivial errors/warnings until it came to this current error report which doesn't make too much sense to me.
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
In my main
function, I defined curTEST
like this: sortList * curTEST;