Thread Tools
Old January 28, 2003, 06:57   #1
Kaak
Civilization II Multiplayer
King
 
Kaak's Avatar
 
Local Time: 09:15
Local Date: November 1, 2010
Join Date: May 1999
Location: Lost
Posts: 1,020
help with a C program (very basic).
If any of you are on that can help, please respond. time is of the essance!!!
__________________
"Mal nommer les choses, c'est accroître le malheur du monde" - Camus (thanks Davout)

"I thought you must be dead ..." he said simply. "So did I for a while," said Ford, "and then I decided I was a lemon for a couple of weeks. A kept myself amused all that time jumping in and out of a gin and tonic."
Kaak is offline  
Old January 28, 2003, 06:58   #2
Harovan
staff
PtWDG Gathering StormPtWDG2 Monty PythonC4DG Gathering Storm
Civ4: Colonization Content Editor
 
Local Time: 16:15
Local Date: November 1, 2010
Join Date: Dec 2001
Posts: 11,117
What do you need to know?
Harovan is offline  
Old January 28, 2003, 07:13   #3
Kaak
Civilization II Multiplayer
King
 
Kaak's Avatar
 
Local Time: 09:15
Local Date: November 1, 2010
Join Date: May 1999
Location: Lost
Posts: 1,020
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...
__________________
"Mal nommer les choses, c'est accroître le malheur du monde" - Camus (thanks Davout)

"I thought you must be dead ..." he said simply. "So did I for a while," said Ford, "and then I decided I was a lemon for a couple of weeks. A kept myself amused all that time jumping in and out of a gin and tonic."
Kaak is offline  
Old January 28, 2003, 07:19   #4
Harovan
staff
PtWDG Gathering StormPtWDG2 Monty PythonC4DG Gathering Storm
Civ4: Colonization Content Editor
 
Local Time: 16:15
Local Date: November 1, 2010
Join Date: Dec 2001
Posts: 11,117
I look into it, hold on
Harovan is offline  
Old January 28, 2003, 07:30   #5
Kaak
Civilization II Multiplayer
King
 
Kaak's Avatar
 
Local Time: 09:15
Local Date: November 1, 2010
Join Date: May 1999
Location: Lost
Posts: 1,020
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.
__________________
"Mal nommer les choses, c'est accroître le malheur du monde" - Camus (thanks Davout)

"I thought you must be dead ..." he said simply. "So did I for a while," said Ford, "and then I decided I was a lemon for a couple of weeks. A kept myself amused all that time jumping in and out of a gin and tonic."
Kaak is offline  
Old January 28, 2003, 07:32   #6
Kaak
Civilization II Multiplayer
King
 
Kaak's Avatar
 
Local Time: 09:15
Local Date: November 1, 2010
Join Date: May 1999
Location: Lost
Posts: 1,020
another mistake i made. I need to add the spaces before i'm adding the /n chars...
__________________
"Mal nommer les choses, c'est accroître le malheur du monde" - Camus (thanks Davout)

"I thought you must be dead ..." he said simply. "So did I for a while," said Ford, "and then I decided I was a lemon for a couple of weeks. A kept myself amused all that time jumping in and out of a gin and tonic."
Kaak is offline  
Old January 28, 2003, 07:35   #7
Harovan
staff
PtWDG Gathering StormPtWDG2 Monty PythonC4DG Gathering Storm
Civ4: Colonization Content Editor
 
Local Time: 16:15
Local Date: November 1, 2010
Join Date: Dec 2001
Posts: 11,117
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.
Harovan is offline  
Old January 28, 2003, 07:35   #8
Kaak
Civilization II Multiplayer
King
 
Kaak's Avatar
 
Local Time: 09:15
Local Date: November 1, 2010
Join Date: May 1999
Location: Lost
Posts: 1,020
nevermind, it should work the way it is...
__________________
"Mal nommer les choses, c'est accroître le malheur du monde" - Camus (thanks Davout)

"I thought you must be dead ..." he said simply. "So did I for a while," said Ford, "and then I decided I was a lemon for a couple of weeks. A kept myself amused all that time jumping in and out of a gin and tonic."
Kaak is offline  
Old January 28, 2003, 07:40   #9
Harovan
staff
PtWDG Gathering StormPtWDG2 Monty PythonC4DG Gathering Storm
Civ4: Colonization Content Editor
 
Local Time: 16:15
Local Date: November 1, 2010
Join Date: Dec 2001
Posts: 11,117
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;
Harovan is offline  
Old January 28, 2003, 08:08   #10
Kaak
Civilization II Multiplayer
King
 
Kaak's Avatar
 
Local Time: 09:15
Local Date: November 1, 2010
Join Date: May 1999
Location: Lost
Posts: 1,020
oh no, i know it doesn't work, i was just talking about the logic of it. i'll send you the samples...
__________________
"Mal nommer les choses, c'est accroître le malheur du monde" - Camus (thanks Davout)

"I thought you must be dead ..." he said simply. "So did I for a while," said Ford, "and then I decided I was a lemon for a couple of weeks. A kept myself amused all that time jumping in and out of a gin and tonic."
Kaak is offline  
Old January 28, 2003, 08:08   #11
Kaak
Civilization II Multiplayer
King
 
Kaak's Avatar
 
Local Time: 09:15
Local Date: November 1, 2010
Join Date: May 1999
Location: Lost
Posts: 1,020
i appreciate your help!!!
__________________
"Mal nommer les choses, c'est accroître le malheur du monde" - Camus (thanks Davout)

"I thought you must be dead ..." he said simply. "So did I for a while," said Ford, "and then I decided I was a lemon for a couple of weeks. A kept myself amused all that time jumping in and out of a gin and tonic."
Kaak is offline  
Old January 28, 2003, 08:16   #12
Harovan
staff
PtWDG Gathering StormPtWDG2 Monty PythonC4DG Gathering Storm
Civ4: Colonization Content Editor
 
Local Time: 16:15
Local Date: November 1, 2010
Join Date: Dec 2001
Posts: 11,117
Kaak: I'm back. You sent me gcc compiled binary. What about the source?
Harovan is offline  
Old January 28, 2003, 08:28   #13
Kaak
Civilization II Multiplayer
King
 
Kaak's Avatar
 
Local Time: 09:15
Local Date: November 1, 2010
Join Date: May 1999
Location: Lost
Posts: 1,020
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
__________________
"Mal nommer les choses, c'est accroître le malheur du monde" - Camus (thanks Davout)

"I thought you must be dead ..." he said simply. "So did I for a while," said Ford, "and then I decided I was a lemon for a couple of weeks. A kept myself amused all that time jumping in and out of a gin and tonic."
Kaak is offline  
Old January 28, 2003, 08:59   #14
Harovan
staff
PtWDG Gathering StormPtWDG2 Monty PythonC4DG Gathering Storm
Civ4: Colonization Content Editor
 
Local Time: 16:15
Local Date: November 1, 2010
Join Date: Dec 2001
Posts: 11,117
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.
Harovan is offline  
Old January 28, 2003, 09:00   #15
Kaak
Civilization II Multiplayer
King
 
Kaak's Avatar
 
Local Time: 09:15
Local Date: November 1, 2010
Join Date: May 1999
Location: Lost
Posts: 1,020
lol...thanks again
__________________
"Mal nommer les choses, c'est accroître le malheur du monde" - Camus (thanks Davout)

"I thought you must be dead ..." he said simply. "So did I for a while," said Ford, "and then I decided I was a lemon for a couple of weeks. A kept myself amused all that time jumping in and out of a gin and tonic."
Kaak is offline  
Old January 28, 2003, 11:03   #16
XarXo
Prince
 
XarXo's Avatar
 
Local Time: 15:15
Local Date: November 1, 2010
Join Date: Jul 2000
Location: of the "I agree"
Posts: 459
Ahem, you have the nested comments compatibility turn on?
__________________
Signature: Optional signature you may use to appear at bottom of your posts
XarXo is offline  
Old January 28, 2003, 13:26   #17
Kaak
Civilization II Multiplayer
King
 
Kaak's Avatar
 
Local Time: 09:15
Local Date: November 1, 2010
Join Date: May 1999
Location: Lost
Posts: 1,020
that is where the problem is
__________________
"Mal nommer les choses, c'est accroître le malheur du monde" - Camus (thanks Davout)

"I thought you must be dead ..." he said simply. "So did I for a while," said Ford, "and then I decided I was a lemon for a couple of weeks. A kept myself amused all that time jumping in and out of a gin and tonic."
Kaak is offline  
Old January 28, 2003, 20:21   #18
raghar
Chieftain
 
Local Time: 15:15
Local Date: November 1, 2010
Join Date: Oct 2002
Location: I wish somewhere else.
Posts: 34
#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; January 28, 2003 at 20:55.
raghar is offline  
Old January 29, 2003, 03:19   #19
Kaak
Civilization II Multiplayer
King
 
Kaak's Avatar
 
Local Time: 09:15
Local Date: November 1, 2010
Join Date: May 1999
Location: Lost
Posts: 1,020
i have to do java programs too
__________________
"Mal nommer les choses, c'est accroître le malheur du monde" - Camus (thanks Davout)

"I thought you must be dead ..." he said simply. "So did I for a while," said Ford, "and then I decided I was a lemon for a couple of weeks. A kept myself amused all that time jumping in and out of a gin and tonic."
Kaak is offline  
Old January 29, 2003, 03:39   #20
orange
Civilization III Democracy GameNationStatesDiplomacyApolytoners Hall of Fame
Emperor
 
orange's Avatar
 
Local Time: 10:15
Local Date: November 1, 2010
Join Date: Feb 2000
Location: It doesn't matter what your name is!
Posts: 3,601
C or Basic? Which is it?
__________________
"Chegitz, still angry about the fall of the Soviet Union in 1991?
You provide no source. You PROVIDE NOTHING! And yet you want to destroy capitalism.. you criminal..." - Fez

"I was hoping for a Communist utopia that would last forever." - Imran Siddiqui
orange is offline  
Old January 29, 2003, 03:39   #21
Skanky Burns
Alpha Centauri Democracy GameACDG The Cybernetic ConsciousnessC4DG Team Alpha CentauriansApolytoners Hall of FameACDG3 Spartans
 
Skanky Burns's Avatar
 
Local Time: 02:15
Local Date: November 2, 2010
Join Date: Aug 2001
Location: Skanky Father
Posts: 16,530
Java is much nicer than C.
__________________
I'm building a wagon! On some other part of the internets, obviously (but not that other site).
Skanky Burns is offline  
Old January 29, 2003, 03:40   #22
Asher
Apolytoners Hall of Fame
President of the OT
 
Asher's Avatar
 
Local Time: 09:15
Local Date: November 1, 2010
Join Date: Nov 1999
Location: Calgary, Alberta
Posts: 40,843
This thread sucks.
__________________
"I'll never doubt you again when it comes to hockey, [Prince] Asher." - Guynemer
Asher is offline  
Old January 29, 2003, 11:28   #23
XarXo
Prince
 
XarXo's Avatar
 
Local Time: 15:15
Local Date: November 1, 2010
Join Date: Jul 2000
Location: of the "I agree"
Posts: 459
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.
__________________
Signature: Optional signature you may use to appear at bottom of your posts
XarXo is offline  
 

Bookmarks

Thread Tools

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 11:15.


Design by Vjacheslav Trushkin, color scheme by ColorizeIt!.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Apolyton Civilization Site | Copyright © The Apolyton Team