Apolyton Archive  |  Preserved copy of the Apolyton Civilization Site and its forums as they stood in September 2005. Read-only; nothing here can be posted to or replied to.  |  Forum index |  About this archive |  The 1998–2001 UBB forums
Today on Apolyton WARDELL INTERVIEW PROMO A.C.S. HISTORY CHAPTER 4 GET CIV4 /w FREE PLUS! A.C.S. PHOTO GALLERY GET A.O.M. V1.1
Apolyton Civilization Forums
main| civ2| civ3| civ4| smac| ctp2| ron| moo3| galciv| galciv2| alt| about|
ApolytonPLUS | register | search | faq | new posts | pm (-/-) | upload | members
hall of fame new! | civgroups | civgroups news | interviews | the column | radio | chat | directory | news | store | PLUS
Apolyton Civilization Forums : Powered by vBulletin version 2.0.3 Apolyton Civilization Forums > Miscellaneous > Archive > Off-Topic-Archive > help with a C program (very basic).
Show a Printable Version | Email This Page to Someone! | Receive updates to this thread | Report this to Apolyton news!

bottom of page
  
Author
Thread    < Last Thread     Next Thread > Post New Thread     Post A Reply
Kaak is offline Kaak
King
Lost
May 1999
time: 23:25
  Old Post 28-01-2003 15:57 Visit Kaak's homepage!
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
help with a C program (very basic). Browse Apolyton AD-FREE

If any of you are on that can help, please respond. time is of the essance!!!

Sir Ralph is offline Sir Ralph
Emperor
Long live teh Schwampel!
Dec 2001
time: 06:25
  Old Post 28-01-2003 15:58
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Tired of ads?

What do you need to know?

Kaak is offline Kaak
King
Lost
May 1999
time: 23:25
  Old Post 28-01-2003 16:13 Visit Kaak's homepage!
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Get a bigger avatar today!

quote:

#include
#define NUM_COLUMNS 80


main()
{
int maxChars = 9999;
char newLine[maxChars];
char data [maxChars];

int c=0, i=0, y=0, x=0, z=0, numChars=0, done=0, numSpaces=0 ;
int beginOfLine, temp;

while ((c = getchar()) != EOF)
{
if (c == '\t')
c = ' ';
data [x] = c;
++numChars;
++x;
}
if (numChars > NUM_COLUMNS)
for (i=NUM_COLUMNS-1; i <= numChars; i += NUM_COLUMNS)
{
numSpaces=0;
y = i;
while(data[y] != ' ')
y--;
data [y] = '\n';

// **************************************************
*******everything works above here
/* numSpaces = NUM_COLUMNS - y;
beginOfLine = i-NUM_COLUMNS+1;

for (z = beginOfLine; z < beginOfLine + NUM_COLUMNS+1; z++)
{
c=0;
newLine[c]=data[z];

while(numSpaces >=0)
{
/* c=0;
newLine[c]=data[z]; */
if (newLine[c]==' ')
{
temp=data[z+1];
newLine[c+1]=' ';
newLine[c+2]=temp;
c+=3;
z++;
numSpaces--;
}
else
{
c++;
z++;
}
}

printf("\n%s\n", newLine); */
}
}



printf("\n%s\n", data);

}


what i am trying to do is take input, from a file, or command line, break it off at 80 columns (if that is in the middle of a word, then i go back to the first space, and switch it for a new line char.

Then (and this is the part that doesn't work) i'm tring to justify each line to 80 chars by doubling the white spaces.

And that is where i have my problem...

Sir Ralph is offline Sir Ralph
Emperor
Long live teh Schwampel!
Dec 2001
time: 06:25
  Old Post 28-01-2003 16:19
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Support Apolyton, buy Civilization: The Boardgame

I look into it, hold on

Kaak is offline Kaak
King
Lost
May 1999
time: 23:25
  Old Post 28-01-2003 16:30 Visit Kaak's homepage!
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Lose 30 kilos (of popups)

one error in that code...the last close comment should be one bracker lower. Also, if you need a sample file, and a working version of the program, i can send it to you.

Kaak is offline Kaak
King
Lost
May 1999
time: 23:25
  Old Post 28-01-2003 16:32 Visit Kaak's homepage!
Edit/Delete Message Reply w/Quote
#6 Report this post to a moderator
Support Apolyton buy from Amazon

another mistake i made. I need to add the spaces before i'm adding the /n chars...

Sir Ralph is offline Sir Ralph
Emperor
Long live teh Schwampel!
Dec 2001
time: 06:25
  Old Post 28-01-2003 16:35
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Remove this text

I had a hard time to get it even compiling, due to the mistake in the comments and the commented out {}'s. Yes, send me a sample file to "sirralph at gmx dot com". I'm away for 30 minutes now and will look into it after I return. I hope that's ok with you, I'm at work.

Kaak is offline Kaak
King
Lost
May 1999
time: 23:25
  Old Post 28-01-2003 16:35 Visit Kaak's homepage!
Edit/Delete Message Reply w/Quote
#8 Report this post to a moderator
Suffering from ads?

nevermind, it should work the way it is...

Sir Ralph is offline Sir Ralph
Emperor
Long live teh Schwampel!
Dec 2001
time: 06:25
  Old Post 28-01-2003 16:40
Edit/Delete Message Reply w/Quote
#9 Report this post to a moderator
Increase Your PM Length

As you wish. Btw: This can't work:

int maxChars = 9999;
char newLine[maxChars];
char data [maxChars];

You can't declare arrays in C with variable sizes. If you want to do this, you have to allocate it dynamically:

In plain C:

int maxChars = 9999;

char* newLine = (char*)malloc(maxChars);
char* data = (char*)malloc(maxChars);

...

free(data);
free(newLine);


or in C++:

int maxChars = 9999;

char* newLine = new char[maxChars];
char* data = new char[maxChars];

...

delete data;
delete newLine;

Kaak is offline Kaak
King
Lost
May 1999
time: 23:25
  Old Post 28-01-2003 17:08 Visit Kaak's homepage!
Edit/Delete Message Reply w/Quote
#10 Report this post to a moderator
Support Apolyton

oh no, i know it doesn't work, i was just talking about the logic of it. i'll send you the samples...

Kaak is offline Kaak
King
Lost
May 1999
time: 23:25
  Old Post 28-01-2003 17:08 Visit Kaak's homepage!
Edit/Delete Message Reply w/Quote
#11 Report this post to a moderator
Put an end to popups!

i appreciate your help!!!

Sir Ralph is offline Sir Ralph
Emperor
Long live teh Schwampel!
Dec 2001
time: 06:25
  Old Post 28-01-2003 17:16
Edit/Delete Message Reply w/Quote
#12 Report this post to a moderator
Put an end to popups!

Kaak: I'm back. You sent me gcc compiled binary. What about the source?

Kaak is offline Kaak
King
Lost
May 1999
time: 23:25
  Old Post 28-01-2003 17:28 Visit Kaak's homepage!
Edit/Delete Message Reply w/Quote
#13 Report this post to a moderator
Support Apolyton, buy Civilization III: Complete

that is program she let us use to see how it was supposed to work. I don't have the source for it...I'll send you what i have

Sir Ralph is offline Sir Ralph
Emperor
Long live teh Schwampel!
Dec 2001
time: 06:25
  Old Post 28-01-2003 17:59
Edit/Delete Message Reply w/Quote
#14 Report this post to a moderator
Help yourself to an AD-FREE life

Well, I found 2 bugs so far, both the same thing:

You have in the second half of the program two loops with a position variable c. First mistake, in both loops c is set to 0 in every run of the loop. That is most likely incorrect. Place the two "c = 0;" lines before the for and while lines.

Second, in the first of these loops, c is never counted up, thus always replacing the 0th character of newLine. I think, the corrected statement in the first loop should be "newLine[c++] = data[z];".

It still doesn't work entirely, but at least better. May be this helps you to hunt the rest of the errors down. I must work a bit for my money and will look into this thread again later.

Kaak is offline Kaak
King
Lost
May 1999
time: 23:25
  Old Post 28-01-2003 18:00 Visit Kaak's homepage!
Edit/Delete Message Reply w/Quote
#15 Report this post to a moderator
Support Apolyton buy from Amazon

lol...thanks again

XarXo is offline XarXo
Prince
of the "I agree"
Jul 2000
time: 05:25
  Old Post 28-01-2003 20:03
Edit/Delete Message Reply w/Quote
#16 Report this post to a moderator
Get a bigger avatar today!

Ahem, you have the nested comments compatibility turn on?

Kaak is offline Kaak
King
Lost
May 1999
time: 23:25
  Old Post 28-01-2003 22:26 Visit Kaak's homepage!
Edit/Delete Message Reply w/Quote
#17 Report this post to a moderator
Lose 30 kilos (of popups)

that is where the problem is

raghar is offline raghar
Chieftain
I wish somewhere else.
Oct 2002
time: 05:25
  Old Post 29-01-2003 05:21
Edit/Delete Message Reply w/Quote
#18 Report this post to a moderator
Support Apolyton or Terrorists Win

#include
#define NUM_COLUMNS 80

what is incude? (i'm JAVA programmer you know )

I think your problem is that you do in C problems that could be more easily solved in JAVA.
I newer used (char*)malloc(maxChars);

Last edited by raghar on 29-01-2003 at 05:55

Kaak is offline Kaak
King
Lost
May 1999
time: 23:25
  Old Post 29-01-2003 12:19 Visit Kaak's homepage!
Edit/Delete Message Reply w/Quote
#19 Report this post to a moderator
Support Apolyton buy from Amazon

i have to do java programs too

orange is offline orange
Emperor
It doesn't matter what your name is!
Feb 2000
time: 00:25
  Old Post 29-01-2003 12:39 Visit orange's homepage!
Edit/Delete Message Reply w/Quote
#20 Report this post to a moderator
Support Apolyton buy from Amazon

C or Basic? Which is it?

Skanky Burns is offline Skanky Burns
Deity
Skanky Bastard Quartermaster
Aug 2001
time: 14:25
  Old Post 29-01-2003 12:39
Edit/Delete Message Reply w/Quote
#21 Report this post to a moderator
Support Apolyton buy from Amazon

Java is much nicer than C.

Asher is offline Asher
King
Calgary, Alberta
Nov 1999
time: 22:25
  Old Post 29-01-2003 12:40 Visit Asher's homepage!
Edit/Delete Message Reply w/Quote
#22 Report this post to a moderator
Browse Apolyton AD-FREE

This thread sucks.

XarXo is offline XarXo
Prince
of the "I agree"
Jul 2000
time: 05:25
  Old Post 29-01-2003 20:28
Edit/Delete Message Reply w/Quote
#23 Report this post to a moderator
Inflate your Upload Space

Basic is the Micro$oft bullshit program code. Is great if you like type 45 chars for a stupid command in place of 3 in C.

  < Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:25.
Apolyton Time is 00:25.
    top of page
Rate This Thread:
archivepost
Forum Jump:
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
 




Contact Us - Apolyton Civilization Site - Support Us!

Building a better Apolyton through better information. Click here and take our poll!
Non-US visitors, click here!

Powered by: vBulletin Version 2.0.3
Copyright ©2000, 2001, Jelsoft Enterprises Limited.

Page generated in 0.0465 seconds (90.33% PHP - 9.67% MySQL) with 31 queries
Page Loading Time:

Support Apolyton: Amazon USA | Amazon UK | Amazon DE | Amazon FR |
Support Apolyton and get FREE PLUS, Buy from Chips&Bits: Galactic Civilizations | Galactic Civilizations: Deluxe Edition | Call to Power 2 | Civilization: The Boardgame | GURPS/ Alpha Centauri | Alpha Centauri | Civilization IV | Civilization III: Complete |


Front Page | Civilization IV | Civilization III | Civilization II | Call to Power II | Alpha Centauri | Master of Orion III
Rise of Nations | Galactic Civilizations | Galactic Civilizations II | Misc
Alt.Civs | Civ I | C:CtP I | About | News | Directory | Apolyton Store | Forums | Chat | Columns | Interviews | Newsletter
Scenario League | CSC | Clash of Civs | Spanish Site | CtP Maps | Cradle of Civ | WesW's Ctp1/2 Site | Civ3 Haven

apolyton.net | apolyton.com | civilization2.net | civilization3.net | civilization4.net | civilizationiv.info | calltopower.net | galciv.net | galciv2.net | moo3.net