I ran your code as is and entered 3 students worth of data in step 1, and then went to step 3 and the data displayed as I had entered them. What does your output look like (you can paste it right in with code tags).
I don't think this is the root of it, but you might want to consider converting your scanf statements for the strings into fgets statements, that way your user can't input something that will overrun the char array.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
Well, if you haven't added any records in, then don't try to display them. You've discovered that when you declare a variable in C, there could be any junk at all in it. You could add something to your code to make sure that there are records before you display them.
Also, why is the menu in that screenshot different than the one in your code?
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
Okay. My sentiment is still the same, though, you can't display what you haven't put in yet... What do you expect will happen when you do that? (maybe I'm missing something here)
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
malloc sets aside a block of memory, it does nothing to initialize it whatsoever. You get whatever happens to be sitting there. You could possibly use memset to blank the char arrays out (I do not know enough about how it behaves or if there are any side effects/gotchas associated with that). I'd say just put a guard in place to prevent the user from displaying the data before there are data to be displayed if you are concerned about it.
jonsca
Quantitative Phrenologist
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581