Noted. Thanks. And we are clear about memory leaks being a bug. I was just so focused on sorting the nodes at the time.
Type: Posts; User: riddinon24z
Noted. Thanks. And we are clear about memory leaks being a bug. I was just so focused on sorting the nodes at the time.
Yeah I actually forgot. I was going to ask about that because when I took it out, it still worked. So, instead I have to free line.age and line.number after every time it increments in my getData...
Alright I finally got it to work. I'm embarrassed. It may not be the prettiest code, but I got it done. I actually took CommonTater's advice and wrote on paper before I inserted any code. That helped...
I tried that and it didn't work. Sorry, everyone. I'm just not cut out for this, especially during this time of the hour. Thanks for all your advice. A lot of it was more helpful than I thought it...
When you say,
Do you mean putting the if statements in a different order? And as for the pCur, yeah it makes sense to use it to assign anything. If pList is NULL, are pList and pList-> the same...
The reason for the traverse function is that it assigns the value of pCur to pPre and then assigns pCur->link to pCur if the while statement is true. My teacher recommend using this function.
And...
Am I making this way more complicated than it should be? Would it help if I initialized pPre and pCur to something else and go from there?
Thanks, but that didn't sort me out. I don't even understand the second half of that. Am I still not accounting for the next-to-last position?
pPre = NULL;
pCur = pList;
printf("%d\n",...
I keep coming back to something like this:
pPre = NULL;
pCur = pList;
printf("%d\n", pNew->character.age);
while ((pNew->character.age < pPre->character.age) && (pCur->link !=...
Sorry, I'm having trouble understanding. Do you mean something like this: Let's say that so far my list contains 22 33 44 55 and I am trying now to insert 40. The first part of my if statement will...
I changed it again to this:
pPre = NULL;
pCur = pList;
printf("%d\n", pNew->character.age);
while ((pNew->character.age < pPre->character.age) && (pCur->link != NULL))
{
I changed a portion of the insertNode function. Am I not accounting for every situation?
pPre = NULL;
pCur = pList;
while ((pNew->character.age < pPre->character.age) && (pCur->link !=...
If instead I tried to insert the nodes in numerical order based on the age, which would be new->.character.age, is it illogical or incorrect for me to have my if statement the opposite of my while...
Oh I guess I kinda forgot c programming 101. So that means my getData function will also be affected by your advice. I changed the type of the getData function again but this time to my structure...
Ok. Here's what I came up with. I changed the type of the getData function from bool to void. Don't know whether or not that was a good idea. I took the fgets function from getData and put it into...
I'm just thinking out loud. What I'm trying to do is read one line of data from the text file into a node. Then insert that node into my list and put that entire process into a loop until all lines...
I think I see what you're saying. So I should put something like this in my insertNode function:
The reason I'm using dynamic memory allocation is because my teacher told us to do so.
I'm having trouble dealing with the multiple lines of data in my text file:
Note: There are tabs, not spaces, before and after the numbers.
I actually tried reading the data two ways, but...