Author Topic: c++ Help please anyone! Urgent~  (Read 104 times)

::Mr. Hahn::

  • Muthafuckin' Don!
  • *****
  • Posts: 912
  • Karma: 24
c++ Help please anyone! Urgent~
« on: March 19, 2005, 06:44:15 PM »
Hey guys,

Anyone know much about structs or passing variables to const?

I need to pass a user defined string to a function to process the string..

However, the variable in the function is defined as a const, so i dont know what to do...

Please help me..

const int MAXLINES = 500;            // Maximum number of lines of text
const string PUNCTUATION = ",.;:()"; // Punctuation characters
const string SPACE = " \t\n";        // Space characters

struct Text
{
       string lines[MAXLINES];       // Text lines
       int lastLine;                 // Index of the last line with text.
                                     // If there is no text, lastline < 0
};

void tokenise (const Text &text,
               int &countPunctuation,
               int &countWords,  int &countOther,
               Text &tokens)
{

}     

The string entered by the user in the main function has to go to:

"const Text &text"

However, when i go

cin >> text;

It doesnt work..

Idea's?
Currently Training at:
www.VT1GYM.com

Gang Starr


"But they can't take the respect, that I've earned in my lifetime
And you know they'll never stop the furious force of my rhymes
So like they say, every dog has it's day
And like they say, God works in a mysterious way
So I pray, remembering the days of my youth
As I prepare to meet my moment of truth"
 

Da WCC Hopar!

  • Muthafuckin' Don!
  • *****
  • Posts: 1540
  • Karma: 159
  • I love to see her walk off!
Re: c++ Help please anyone! Urgent~
« Reply #1 on: March 19, 2005, 07:20:26 PM »
i dont have single clue on wat u just said ive worked wit c++ before and neva go to far on it
 

::Mr. Hahn::

  • Muthafuckin' Don!
  • *****
  • Posts: 912
  • Karma: 24
Re: c++ Help please anyone! Urgent~
« Reply #2 on: March 19, 2005, 07:32:24 PM »
its cool, thx for like..replying though!~
Currently Training at:
www.VT1GYM.com

Gang Starr


"But they can't take the respect, that I've earned in my lifetime
And you know they'll never stop the furious force of my rhymes
So like they say, every dog has it's day
And like they say, God works in a mysterious way
So I pray, remembering the days of my youth
As I prepare to meet my moment of truth"
 

Suga Foot

Re: c++ Help please anyone! Urgent~
« Reply #3 on: March 20, 2005, 01:21:32 AM »
:banana_llama:
 

Don Seer

Re: c++ Help please anyone! Urgent~
« Reply #4 on: March 20, 2005, 01:43:39 AM »

uh dude...

const means dont touch....


remove the const from your parameter being passed in..

btw.. i've been coding c++ for over 10 years now.. i've been at my current job doing it since mid '96.. and could prog in it for a few years before that..


also.. what are thsoe & things for?


if you mean to modify the variables inside the function.. i'd do it like this...


typedef struct _tag_Text
{
       string lines[MAXLINES];       // Text lines
       int lastLine;                 // Index of the last line with text.
                                     // If there is no text, lastline < 0
} MY_TEXT_TYPE, *PMY_TEXT_TYPE;



void tokenise (PMY_TEXT_TYPE pText,
               int  *pnCountPunctuation,
               int  *pnCountWords,  int *pnCountOther,
               PMY_TEXT_TYPE pTokens)
{

}     




holla..
 

::Mr. Hahn::

  • Muthafuckin' Don!
  • *****
  • Posts: 912
  • Karma: 24
Re: c++ Help please anyone! Urgent~
« Reply #5 on: March 20, 2005, 02:23:04 AM »
i wish it were that simple.

However, thats defined in the header file and we are not allowed to change that struct/function.

We must use it.

We are also not allowed to use pointers to get around the const...sigh...

I heard its got something to do with inputting it through the text.lines[] because its a string array and u use some sort of loop to enter in the data. Then pass it to tokenise..

How do i do that?
Currently Training at:
www.VT1GYM.com

Gang Starr


"But they can't take the respect, that I've earned in my lifetime
And you know they'll never stop the furious force of my rhymes
So like they say, every dog has it's day
And like they say, God works in a mysterious way
So I pray, remembering the days of my youth
As I prepare to meet my moment of truth"
 

Don Seer

Re: c++ Help please anyone! Urgent~
« Reply #6 on: March 20, 2005, 11:18:40 AM »
silly question what is "it doesnt work?" doesnt build?


should it be

cin >> text.lines;

or

cin >> text->lines;

 

boycriedwolf619

  • Muthafuckin' Don!
  • *****
  • Posts: 1758
  • Karma: 163
Re: c++ Help please anyone! Urgent~
« Reply #7 on: March 20, 2005, 06:16:16 PM »
h

also.. what are thsoe & things for?

that symbol means pass by reference