last day (15 days later) » 

3:55 PM
0
Q: Debugger says I have uninitialized variables

Bane BojanićAfter hours and hours of searching, I became desperate because I just fail to find uninitialized reads that I apparantly have, according to Valgrind and Dr. Memory, so I'll ask here for help. I used the Code Blocks' debugger and its variable watch, but all I saw there was everything going smoothl...

 
debugger is usually right
Code pasted on an external resource (e.g. pastebin) doesn't count. You need to create a mcve and post it in the question
If the debugger says "uninitialized variable" and gives you the exact line of the error,what more do you need?
 
This is the first time in my life getting in contact with a memory debugger such as Valgrind. With "fgets(temp_line, 121, adressbookf) != NULL && strlen(temp_line) > 0" in the outer while and with c < strlen(line) I basically abort reading when I reach the end of line or the file. I thought someone with more experience could read it somewhat easilly, because I just can't see where could I possibly touch something uninitialized in those lines.
 
I think I have found your problem, see my answer. But bolov is right, please post the example included in your question!
 
debugger is usually right... debugger also sometimes gives false positives
 
How do you mean example? The debugger crashes it as soon as the function is called (and its called in the beginning of the main, like I posted).
 
3:55 PM
read my comment about paste bin and mcve. Also you need to post the exact error message.
 
It's not on pastebin anymore. Do you want me to post the whole code (200+ lines)? I'll add the error message to the original post.
 
struct Adress{.. and then int read(struct Adresa array[]) Is Adresa a typo?
 
While I see various problems with your code - the main question is: Why are you not simply using fscanf or at least strtok(_r)?
 
You should use sizeof(temp_line) instead of 121
 
@bolov: no, English is not my native tongue, so it just remained from the original code from before translating it.
Andreas; I thought this is simpler because of the trailing '\n' and the commas in the file.
 
3:55 PM
without a file it runs ok. Paste the file on pastebin and I will run the program. Post the link as a comment.
 
bolov: here's the complete program with the file at the end: pastebin.com/NdUtPfNQ
 
mr5
As this is tagged along with C++, why not use C++ features and completely refactor your code in a much more readable way?
 
it runs fine (the short version from the question) with the file.
 
can you compile the complete program? I don't see why would one work and the second would not.
 
Probably not related to your problem, but in the nested conditions, you should probably use temp_line[c] != '\0', rather than c < strlen(temp_line). It's both more idiomatic, and a lot more efficient. (Most idiomatic, of course, would be to use pointers, rather than indices.) And your code is pure C; you should remove the C++ tag
 
3:55 PM
the full program runs and then asks for some kind of input. On an unrelated note I just noticed that you copy to the fields of Adress without checking you don't step outside of the buffers. (e.g. you copy to the email filed and don't check you don't copy more than 48 characters. Also don't copy char by char. Use strcpy (but again make sure you don't overflow.
 
Err, did you run it through Valgrind? Because my homework's error is reported by it. The program does work well when it's normally ran.
 
no _comment_padding
 
Perhaps this might be rewritten with fscanf or something? I tried parsing it with fscanf(adresarf, "%s[^,]", adresbook.name) but it wasn't a success.
Bolov: well, if you have Valgrind or Dr Memory or something like that installed, you can easily recreate the error.
 
I couldn't reproduce your error. As I said the program runs on my system. Beyond that I think it is not my job to check your homework.
 
Please make sure that your code compiles without warnings before posting it (unless the question is about failing to understand why the code doesn't compile).
 
4:02 PM
@AugustKarlstrom the point is in Valgrind. The code compiles well.
 
4:55 PM
@Bane So when did semicolons become optional as statement terminators?
 

last day (15 days later) »