![]() |
[Q] Is there any one good at linked lists - C - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: C, C++, & Obj-C (https://sinister.ly/Forum-C-C-Obj-C) +--- Thread: [Q] Is there any one good at linked lists - C (/Thread-Q-Is-there-any-one-good-at-linked-lists-C) |
[Q] Is there any one good at linked lists - C - Altair - 10-20-2017 This is a beginning of my homework but I don't know what is the problem in my code. I need to store every word separately in a linked list. Splitting process is just working fine, but problem in the add() function I think. In the main func. I send every word to add() function to add in linked list's end. I assign new word into current->data and It seems working fine when I output it inside the add() function, but the problem is also head node which is my root node is also changing, it shouldn't be changed. Help me please here is the sample Input1.txt sample text Wrote:Term Frequency is a feature representation technique. Term frequency is often used in As seen on output below, all my current->data and head->data are same in every loop. But head->data have to stay as first word('Term' in this case) ![]() My codes: http://codepad.org/aGtLDUja Code: #include <stdio.h> ![]() RE: [Q] Is there any one good at linked lists - C - ProstatePete - 10-21-2017 Looks fine like this: https://ideone.com/a7QjtT Perhaps check your file reading. RE: [Q] Is there any one good at linked lists - C - phyrrus9 - 10-21-2017 (10-20-2017, 06:33 PM)Altair Wrote: Help me please I took a whirl at it, here's my code. I just modified what you had, and I didn't test it out, but anywhore, give this a shot. I made comments to help guide you. I actually wrote a tutorial on making linked lists in C a while ago. You can find that tutorial at: https://sinister.ly/Thread-Tutorial-C-Linked-list Alternatively, I have a list of all my tutorials that you can browse through at https://sl.ipseitysoftware.com/ (it's also in my signature). Feel free to ask my any questions. I also added a pastebin link here with syntax highlighting on Code: #include <stdlib.h> RE: [Q] Is there any one good at linked lists - C - Altair - 10-21-2017 @phyrrus9 Thank you so much very well explained. I see my all mistakes, I wasn't actually using typedef but I saw in every tutorial on the net they're using it so I thought I should also use. Freeing up memory also didn't come to my mind, good to learn, and strdup() also. " c = malloc(20); " this one is really useful, what a shame I didn't know it before I learned much from your corrections, very much appreciated master ![]() RE: [Q] Is there any one good at linked lists - C - phyrrus9 - 10-21-2017 (10-21-2017, 09:36 PM)Altair Wrote: @phyrrus9 Thank you so much very well explained. Any time man. Feel free to ask me if you need any help, I lurk the forums 15ish hours a day and am always idling in the discord. As for the typedefs, I was just giving you shit, it doesn't really make any difference programatically if you use them or not. I choose not to use them because in C, the following isn't legal Code: struct something Code: struct something While it makes no difference between doing it this way and with a typedef, I feel like having to add the word struct adds valuable information to the programmer. Knowing it's a structure and not a builtin or POD type is useful information in my eyes. Malloc is very useful. What you had: Code: char c[20]; Code: char *str1 = "Hello "; Code: char *str1 = "Hello "; Malloc is an extremely useful tool, but don't forget that you need to use free for anything you've malloc'd. You don't need to free things you define with brackets. I'm curious, did my answer solve your problems? RE: [Q] Is there any one good at linked lists - C - Altair - 10-21-2017 (10-21-2017, 09:48 PM)phyrrus9 Wrote: I'm curious, did my answer solve your problems? Actually, my HW's deadline was an hour ago( That wasn't the whole problem, I sent it. Not perfect but at least it's working ![]() RE: [Q] Is there any one good at linked lists - C - phyrrus9 - 10-21-2017 (10-21-2017, 10:49 PM)Altair Wrote:(10-21-2017, 09:48 PM)phyrrus9 Wrote: I'm curious, did my answer solve your problems? Well that's sad. Hope you get a decent grade anyways. Is this just a high school level class or uni? Give me some more details on the class, I'm interested. It's becoming increasingly rare that any Uni teaches any non-Java language, let alone C. It's practically nonexistent here in the US for a high school to teach programming, and the ones that do try to pass off basic HTML as programming. You don't know how lucky you are to be getting a real world education. RE: [Q] Is there any one good at linked lists - C - Nil - 10-21-2017 (10-21-2017, 10:56 PM)phyrrus9 Wrote:(10-21-2017, 10:49 PM)Altair Wrote:(10-21-2017, 09:48 PM)phyrrus9 Wrote: I'm curious, did my answer solve your problems? Unis usually teach 2 + other languages other than the intro one as electives. For example, C and python were options at my school at the time. If it's HS though, very impressive. Especially with learning linked lists. Puts you well above the curve going into uni if that is the case. RE: [Q] Is there any one good at linked lists - C - Altair - 10-21-2017 (10-21-2017, 10:56 PM)phyrrus9 Wrote: Well that's sad. Hope you get a decent grade anyways. Is this just a high school level class or uni? Give me some more details on the class, I'm interested. It's becoming increasingly rare that any Uni teaches any non-Java language, let alone C. It's practically nonexistent here in the US for a high school to teach programming, and the ones that do try to pass off basic HTML as programming. You don't know how lucky you are to be getting a real world education.I hope, thanks ![]() I'm studying CSE at University 2nd grade. Class name is called "Data Structures", java was in the previous year but not now, we are studying this class with C only as far as for now. There are much more topics actually, linked lists is the beginning, we learned trees etc. etc. I don't remember what we learned actually, I couldn't join clases recently ./ I'm from Turkey btw. RE: [Q] Is there any one good at linked lists - C - phyrrus9 - 10-21-2017 (10-21-2017, 11:14 PM)Altair Wrote:(10-21-2017, 10:56 PM)phyrrus9 Wrote: Well that's sad. Hope you get a decent grade anyways. Is this just a high school level class or uni? Give me some more details on the class, I'm interested. It's becoming increasingly rare that any Uni teaches any non-Java language, let alone C. It's practically nonexistent here in the US for a high school to teach programming, and the ones that do try to pass off basic HTML as programming. You don't know how lucky you are to be getting a real world education.I hope, thanks Well kudos to Turkey for having a useful University program. I wish the US wasn't falling so far behind. Data structures and algorithms are always fun to play around with. I think it's key that you learn how to do these in C, it teaches you how everything works under the hood, so when you move to C++, Java, and C# you understand how they work and know how to treat them with respect. |