Originally Posted by
Tryhard
i have another function that checks if the list is empty or not..i just wanna know,
if i put a string in main and call it in this function
Code:
int main()
{
char * string;
addfront(string,"name");
}
how do i add it to this? cause addmyChar is not type char *, it is type Sorted; a type that was created.
i know that the indent is bad..sorry
You have to follow a function's parameter list to get a compile. Look at the signature of function addfront:
Code:
Thelist addfront(Thelist list, Sorted * AddmyChar)
You are expected to pass TheList, and Sorted * type variable in that order. So the string variable is wrong because it isn't the right type for either argument.
Your code needs to decide which parameter is the list you want to add to and which parameter represents the node that you should add. When you make your decision, leave a comment, because it is not clear which parameter is which and if I am reading this right both type names are functionally the same type which is weird. Then you have to rewrite your function to deal with the following cases:
1. When the list you want to add to has no items.
2. When the item you want to add should be placed in the front of the list.
3. When the item you want to add should be placed in the middle of the list.
4. When the item you want to add should be placed in the back of the list.
It is possible that the 3rd and 4th case can be addressed by the same code, but that depends.
If the node you want to add will always look like:
name: <any name>
next: NULL
Then it should be possible.
Before the function can be considered complete something needs to be done with the pointer addmyChar inside of the type:
Code:
struct MyList{
char * name;
Sorted * AddmyChar;
struct MyList * next;
};
It is not clear to me what that pointer is for. And since both of the types Sorted * and Thelist have this pointer something must be done.
Basically I'm trying to rephrase what other people have told you...