0
Good night.
I was writing a program to read strings from a text file, and put these on a list simply chained in case its length was equal to 5.
The problem is that the program started to not work the way I did waited, and after a few tests, I discovered that a pointer I was on using would point from nowhere to another memory address, after a few iterations and a fscanf command'.
I put in Pastebin the test code I wrote: https://pastebin.com/4VRrxqgJ
The "Keys.txt" file contains the following strings:
m4mSx
fr4
mWKgC
7bbak
7
Np3rw
I wrote another code that solves without problems what I wanted to do, but i would like to know why is happening this mistake with this test code, since from what I know it doesn’t make sense that this is occurring.
Do not forget that strings in C are terminated by ' 0' so to save "m4mSx" you will need at least 6 boxes.
– JJoao
I tested your program and there was no change of address... The program you passed was edited, right? Could you provide the original? I don’t see any problems other than what @Jjoao mentioned and the fact that you did type-cast us
malloc
s.– Nexus