.com.unity Forums
  The Official e-Store of Shrapnel Games

This Month's Specials

Raging Tiger- Save $9.00
winSPMBT: Main Battle Tank- Save $6.00

   







Go Back   .com.unity Forums > Shrapnel Community > Space Empires: IV & V

Reply
 
Thread Tools Display Modes
  #1  
Old April 5th, 2004, 06:52 AM
Fyron's Avatar

Fyron Fyron is offline
Shrapnel Fanatic
 
Join Date: Jul 2001
Location: Southern CA, USA
Posts: 18,394
Thanks: 0
Thanked 12 Times in 10 Posts
Fyron is an unknown quantity at this point
Default Coding Inquiry

So I am writing this program to generate HTML files from a Components.txt file (have to do something during a quarter with no computer science classes ), and I have run into a problem. I can not seem to find any way to get ofstreams to accept strings as their filename, only arrays of characters. This sucks, as I can't make an array of characters with a dynamic size. I want to have separate HTML files for each General Group. Everything is working great except for the naming issue. Any group with a space generates gobbley-gook character arrays, even when I have a special case for spaces being turned into underscores. Also, it inserts a bunch of what I can only assume are null characters at the _beginning_ of the char array, rather than the end... :-\ Since I plan on releasing this open-sourced anyways, please take a look at the current freeze of the source code. The offending code starts with this line (can't get the line number, as on a crappy Dell comp atm...):

code:
 while (generalGroupVector.size() > 0) 

__________________
It's not whether you win or lose that counts: it's how much pain you inflict along the way.
--- SpaceEmpires.net --- RSS --- SEnet ModWorks --- SEIV Modding 101 Tutorial
--- Join us in the #SpaceEmpires IRC channel on the Freenode IRC network.
--- Due to restrictively low sig limits, you must visit this link to view the rest of my signature.
Reply With Quote
  #2  
Old April 5th, 2004, 07:56 AM
Ruatha's Avatar

Ruatha Ruatha is offline
Major General
 
Join Date: May 2002
Location: Linghem, �sterg�tland, Sweden
Posts: 2,255
Thanks: 0
Thanked 0 Times in 0 Posts
Ruatha is on a distinguished road
Default Re: Coding Inquiry

Sorry, don't have any C program, only does Delphi.
Reply With Quote
  #3  
Old April 5th, 2004, 10:39 AM
Jack Simth's Avatar

Jack Simth Jack Simth is offline
Major General
 
Join Date: Oct 2002
Posts: 2,174
Thanks: 0
Thanked 0 Times in 0 Posts
Jack Simth is on a distinguished road
Default Re: Coding Inquiry

Just at a glance, I suspect your problem is the various incarnations of
code:
for(int i = 0; i < BUFFER_SIZE; i++)
{
buffer[i] ='\n';
]

for clearing out your strings; if this is it, then the problem would be that "standard" strings are terminated with a 0 in c, not with the newline character (this may vary by OS, if the one you are used to working in uses a 0 for the newline character). Your internal representation of strings appears to use the newline character for terminating, but then you turn around and use standard routines for output - the standard routines output the newline, don't see a 0, and so keep going through memory, spouting whatever happens to be there, until they do hit a 0. The suggested fix, bearing in mind that the possibility exists that this isn't actually the problem; I don't have great experiece with c, would be to change the various incarnations of the above to
code:
for(int i = 0; i < BUFFER_SIZE; i++)
{
buffer[i] = 0; /* yes, c does allow you to give a character a numeric value */
]

and then have the newline character tacked on in your output routines.

Edit:
Also, c strings *are* character arrays already; further, you may want to go through and set it up to destroy some of those dynamic variables you keep allocationg

[ April 05, 2004, 09:41: Message edited by: Jack Simth ]
__________________
Of course, by the time I finish this post, it will already be obsolete. C'est la vie.
Reply With Quote
  #4  
Old April 5th, 2004, 12:56 PM
Atrocities's Avatar

Atrocities Atrocities is offline
Shrapnel Fanatic
 
Join Date: Dec 2000
Location: USA
Posts: 15,630
Thanks: 0
Thanked 30 Times in 18 Posts
Atrocities is on a distinguished road
Default Re: Coding Inquiry

If you want to write a program, write one that automatically breaks the files down into easy to follow and PRINTABLE tech trees for use with mods.
__________________
Creator of the Star Trek Mod - AST Mod - 78 Ship Sets - Conquest Mod - Atrocities Star Wars Mod - Galaxy Reborn Mod - and Subterfuge Mod.
Reply With Quote
  #5  
Old April 5th, 2004, 08:26 PM
Fyron's Avatar

Fyron Fyron is offline
Shrapnel Fanatic
 
Join Date: Jul 2001
Location: Southern CA, USA
Posts: 18,394
Thanks: 0
Thanked 12 Times in 10 Posts
Fyron is an unknown quantity at this point
Default Re: Coding Inquiry

Setting the characters to be newline characters is not used on any of the strings where this problem occurs. Earlier when reading in the components, I use the newline character because I want lines read in that are just newlines (blank lines) to be skipped. If getting a line results in the string being just a newline, it gets skipped. I don't think this has anything to do with having lots of stuff appended to the beginning of the char arrays in this section, as I do not reference this function, nor the buffer string.

I am well aware that strings are just arrays of characters, but the ofstream class is unfortunately not aware of this. :-\
__________________
It's not whether you win or lose that counts: it's how much pain you inflict along the way.
--- SpaceEmpires.net --- RSS --- SEnet ModWorks --- SEIV Modding 101 Tutorial
--- Join us in the #SpaceEmpires IRC channel on the Freenode IRC network.
--- Due to restrictively low sig limits, you must visit this link to view the rest of my signature.
Reply With Quote
  #6  
Old April 5th, 2004, 08:26 PM
Fyron's Avatar

Fyron Fyron is offline
Shrapnel Fanatic
 
Join Date: Jul 2001
Location: Southern CA, USA
Posts: 18,394
Thanks: 0
Thanked 12 Times in 10 Posts
Fyron is an unknown quantity at this point
Default Re: Coding Inquiry

Quote:
Originally posted by Atrocities:
If you want to write a program, write one that automatically breaks the files down into easy to follow and PRINTABLE tech trees for use with mods.
That would be rather hard to do... if each tech only had one level, it would be easy. But with lots of levels, it becomes messey... :-\
__________________
It's not whether you win or lose that counts: it's how much pain you inflict along the way.
--- SpaceEmpires.net --- RSS --- SEnet ModWorks --- SEIV Modding 101 Tutorial
--- Join us in the #SpaceEmpires IRC channel on the Freenode IRC network.
--- Due to restrictively low sig limits, you must visit this link to view the rest of my signature.
Reply With Quote
Reply

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 08:33 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2024, Shrapnel Games, Inc. - All Rights Reserved.