Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am writing a program to change the first few lines of text files so the dat can be read by a new software. I have been doing it manually until I am able to finish the program. The file download link is here:
http://www.mediafire.com/?m1txbnxjvmj
I have commented as best I can to show what it does and what the problems are. Mostly I can't get the loop that changes the file name being read to work, it just goes through the first file, and when I try to send the name to my writing function the numbers get messed up. It seems to me that everything is fine and I have no idea why it won't work. If somone could take a look at it and suggest how I could fix it I would greatly appreciate it. Thanks a lot in advance.

You know, there's probably a problem with having two batch file guys, 1 PERL/AWK guy, and 1 other guy; especially when said other guy isn't always around.
char filename1[13]; //file name variable 1filename1 is overflowing; it should be at least 20 characters.
. . . . .
sprintf(filename1, "data/D042%d.PRN", number);if(inputfile != NULL)If the file open failed, the program quits. This is also why your loop doesn't loop.
. . . . .
else
return(1); //don't know what this is for . . .Also, if you're using C, you should use /* . . . */ instead of // to denote comments.
while (number < 7002)You can use a for loop, and you probably should.
. . . . .
number++;
}int loc3; //second part of locationIf you're not doing math on these numbers, you should leave them as char arrays.
float dist; //distance part of location
int time1; //count start time
Et cetera

Thanks for going through that, though I have one more question. How do I prevent the program from terminating instead of moving on if it can't open the file?

I made a lot of changes and now I have everything working except the loop...here is the updated file:
http://www.mediafire.com/?jm0wypzwzw1
Thanks a lot for the help.

I have everything working except the loop
The loop won't work as long as it's commented out.Then get rid of the else and its return 1;.

The loop won't work as long as it's commented out.
Haha yeah I know. I was just using it that way to get it to work for one file. However I think this program is doomed to not work. It seems I'm getting segmentation faults due to inconsistency in the data, so my method would need to be completely reworked. By the time I got something else figured out I'll probably have them all done by doing them manually...thanks for the help though I really appreciate it.

Sorry to hear that. If you give me an example of the old file, and its desired output, I could quickly show you how to do it in C++. (Really, almost everything I know about C, I learned from C++.)

Did it in perl. What I got half done with 265 lines in C took only 85 to do flawlessly in perl. I may never use C again.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |