I am making a small program that reads a text file and stores it in the memory. It then lets the user add another line to the file, replace a line, add another word at a specific line etc…
At the end the user can save the content from the memory back to the file.
I did the same program in Python and used a multidimensional array, so each element in the array was an array of words.
This made it really easy to access a specific word at a specific line to be replaced with something else
Now I am trying to do the same thing with C and getting confused. After a little bit of messing around I am leaning more towards having a structure that has char words[]. This way I can delete a specific line by just dereferencing the NextNode from the previous to next.
I have two questions tho:
1. Is this a good way of accomplishing my goal?
2. How do I make a linked list with a FIXED size (e.g. no use of malloc). For example if I want to have a maximum 10 lines, how do I just make ten nodes and avoid malloc?
First of all, Why you want Fixed size?
It is Easy to make a linked list with a FIXED size (e.g no use of malloc), It is called as an array of Structure 🙂
If you can create a structure, say “node” :
You can write:
But you need to write a bit complex code to remove perticular node. It is not simple as compared to removing node from a linked list(with malloc).