I’m using Dev C++ for this programming assignment.
I’ll try and give a basic rundown of the problem…
I’m trying to write a program that will read a time stamp and temperature reading from a file, then put the time stamp in a specific format and convert temperature to Celsius if needed. The input file has a sentinel number at the top of the file to tell how many lines of data need to be read. After this single int, each line then contains a number (ie. 200103121915 F51.13), there is a single space between the date and temp. The format is for YYYYMMDDHHMM. Without using pointers or any object oriented programming, we are supposed to convert each entry into a MM/DD/YYYY HHMM format and if the temperature is given in Fahrenheit, it needs to be converted to Celsius.
I’m running into problems with every approach I’ve tried. First, I was just going to read the entire 12 digit number as an int and then use some modulus commands to separate out each part. However, I found that int won’t hold a number that large. Next, I thought to read each digit into an array and then piece together the individual arrays into the correct format. I don’t know how to read in one digit at a time. I was thinking the array would need to be and int type, but then how would I deal with the F or C label? Basically I’m just looking for some basic ideas on how to accomplish this task, not asking for someone to write the code.
If you’re just getting started with I/O in C++, you might bookmark a reference site, because the library provides a lot of options and features.
As a further pointer, the
std::setwmanipulator might help to extract a given number of characters — although it won’t stop numeric extraction from being too greedy.