How Can You Correctly Read and Format File Data in C?

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 4K views
NDiggity
Messages
53
Reaction score
0

Homework Statement


Ok, here is the other question that's giving me a headache. There is a file which holds 5 data items per line and a minimum of 1 line. The data is always in the order float float integer float string and each element is separated by a space. So we need to ask the user for a file name and then we need to output the data to the user in a user friendly way. It let's me compile but after it prints out everything i get a stack smashing detected error which I have no clue as to its meaning. We just learned pointers and how to open and read files and stuff and I am very confused. We were never taught fgets in class so I tried to teach myself on the net so I am a little confused. It let's me put the whole contents of the file I'm reading into a 20 character array i made called weatherFile?

I also somehow need to print off each individual data item with several spaces in between instead of single spaces like how the original file is to make it more user friendly and I'm not sure how to do that with the way I have it written now. So if someone can take a look at the program I have so far and help me, it would be very greatly appreciated. Thanks for your time! :)

Program: http://rafb.net/p/FaBfWS88.html
 
Last edited by a moderator:
Physics news on Phys.org
Your paste on rafb.net has expired. Please repost.