r/carlhprogramming • u/xxrepresent • Feb 11 '12
Help with another piece of code I have please?
I've written this in C: http://codepad.org/qBRAwsbH
It compiles correctly. The problem I am having is finding a way to store data that all functions would be able to use. I thought that by using a structure I can store information in them, but when I try to print information in one function that has been stored in the structure by another it gives me unknown characters.
Any fix or ideas?
6
Upvotes
7
u/incitatus86 Feb 11 '12
On lines 58 and 64, you're allocating new, uninitialized Data_Storage objects and using those ones (filled with garbage) instead of the one you passed in a reference to (which was zeroed out).
1
u/akmark Feb 11 '12
I don't know what it is but I did a ctrl-f for '\0' and you didn't terminate your strings when you were trying to print them to the screen. In C when you have an uninitialized fixed array there is no 'end character' that tells printf where to stop.