Originally Posted by
Adak
Yes, I know you have a lot of lines of data. Don't worry about the number of lines of data now, however. That's a detail!
Right now, get ONE line of test data, to work correctly, with all types of your data - including negative numbers, and all the rest. While you're developing your program, it's best to put off details - ALL the non-critical details (one of the key parts of top down design, btw).
Eliminate all the user input that you reasonably can, and do it later. We need to get the overall logic and the flow of that logic (which part goes first, second, etc.), worked out.
This is what I would do for a char by char design:
fgets() to get a full line of data
Use your char by char input to put each number into a small dataOne char array, that is big enough to hold one number, maybe 30 char's.
You will start with data[0] and your number will stop when you reach either a comma, or a newline: ('\n'), (you won't see the newline but it will be on the end of every line of text, and in your data[] array.)
Now set up your "walk" through the dataOne[] array, to see if it has a decimal point.
If it has NO decimal point, then you can write out the dataOne number, followed by a comma and a space, into the new file. If it's the last number in the row (you reach the \n char), then do not write out the comma, just the newline char.
else it has a decimal point, then follow the logic I posted just above this, to round off the 6th digit after the decimal point. When it's done rounding off that number, write it out to the file, just like all the other numbers.
For right now, just write it out to the screen, because it's WAY faster to see if it's right or wrong. Speeds up everything, and that's VERY important. Writing code can take WAY LONG, if you don't take every speed up in the process, that you can find.
This is the lines of code that I've been working with, for preliminary testing:
0, -2.3999997, 1.0000004, -1.0000001, 28, 17.1234567, -17.1234567, 555.9999990, 555.9999995, -555.9999990, -555.9999998
-2.3999997, 1.0000004, -1.0000001, 28, 17.1234567, -17.1234567, 555.9999990, 555.9999995, -555.9999990, -555.9999998, 0
1.0000004, -1.0000001, 28, 17.1234567, -17.1234567, 555.9999990, 555.9999995, -555.9999990, -555.9999998,0, -2.3999997
28, 17.1234567, -17.1234567, 555.9999990, 555.9999995, -555.9999990, -555.9999998
17.1234567, -17.1234567, 555.9999990, 555.9999995, -555.9999990, -555.9999998, 0, -2.3999997, 1.0000004, -1.0000001, 28
-17.1234567, 555.9999990, 555.9999995, -555.9999990, -555.9999998, 0, -2.3999997, 1.0000004, -1.0000001, 28, 17.1234567 3
555.9999990, 555.9999995, -555.9999990, -555.9999998, 0, -2.3999997, 1.0000004, -1.0000001, 28, 17.1234567 3, -17.1234567
555.9999995, -555.9999990, -555.9999998, 0, -2.3999997, 1.0000004, -1.0000001, 28, 17.1234567 3, -17.1234567, 555.9999990
-555.9999990, -555.9999998, 0, -2.3999997, 1.0000004, -1.0000001, 28, 17.1234567 3, -17.1234567, 555.9999990, 555.9999995
-555.9999998, 0, -2.3999997, 1.0000004, -1.0000001, 28, 17.1234567 3, -17.1234567, 555.9999990, 555.9999995, -555.9999990
Lots of decimal numbers, both positive and negative, and in different positions. Easy to tell if they do/don't round off.
Dig in here! You should be tossing out very specific questions, and you aren't.