Computing.Net > Forums > Programming > C program help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

C program help

Reply to Message Icon

Name: Poco87
Date: July 23, 2008 at 07:15:42 Pacific
OS: Windows
CPU/Ram: n/a
Product: n/a
Comment:

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.




Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: July 27, 2008 at 17:53:25 Pacific
Reply:

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 1
. . . . .
sprintf(filename1, "data/D042%d.PRN", number);
filename1 is overflowing; it should be at least 20 characters.

    if(inputfile != NULL)
. . . . .
else
return(1); //don't know what this is for
. . .
If the file open failed, the program quits. This is also why your loop doesn't loop.

Also, if you're using C, you should use /* . . . */ instead of // to denote comments.

while (number < 7002) 
. . . . .
number++;
}
You can use a for loop, and you probably should.

  int loc3;         //second part of location
float dist; //distance part of location
int time1; //count start time
Et cetera
If you're not doing math on these numbers, you should leave them as char arrays.

0

Response Number 2
Name: Poco87
Date: July 29, 2008 at 09:22:43 Pacific
Reply:

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?


0

Response Number 3
Name: Poco87
Date: July 29, 2008 at 11:08:52 Pacific
Reply:

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.


0

Response Number 4
Name: Razor2.3
Date: July 29, 2008 at 18:01:37 Pacific
Reply:

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;.


0

Response Number 5
Name: Poco87
Date: July 30, 2008 at 05:20:15 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: Razor2.3
Date: July 30, 2008 at 09:27:36 Pacific
Reply:

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++.)


0

Response Number 7
Name: Poco87
Date: August 7, 2008 at 07:41:48 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: C program help

C programming help www.computing.net/answers/programming/c-programming-help-/6364.html

C Programing HELP www.computing.net/answers/programming/c-programing-help/13625.html

c program help www.computing.net/answers/programming/c-program-help/8129.html