Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Algorithms and flowcharts (Yet another C++ assignment).
#14
SaptaZapta Wrote:Sorry for taking so long to get to this.

As for the c_str() thing - you can't use it there because it is "const char *", meaning it's read-only. You can't use it if you're trying to update the value of the string.

I just rechecked the reference and http://www.cplusplus.com/reference/strin...tor%3E%3E/ says "cin >> inFileName" should work. I don't know why your compiler is giving you a hard time with it. Personally I'd just use the same workaround as before, changing the variables to char[256], because that really isn't the important part of this assignment and we shouldn't waste time on it.

Fair enough. My main issue with that is that the programs are submitted through UNIX, and it checks to see if we have completed specific conditions for the completed program. Last time, it checked if I'd used .c_str() and since I didn't, I'd lost points for it. It's not a huge loss right now, though; as long as the program works the way it's intended to work and I can submit this on time (it's due in five and a half hours OH LORD GOTTA HURRY).

Now, a question... though maybe I should worry about making this work first and asking questions later, but what's the purpose of this exactly? I'm not quite getting it.

Code:
if (ch == '+')
{
    if (linepos > 0) ExitWithError("two line positions provided for one word");
    else linepos = num;
}
else
{
    if (wordpos > 0) ExitWithError("two word positions provided for one word");
    else wordpos = num;
}

The way I'm seeing it, based on the error, is that it's checking to see if there have been two positions entered using the same indicator? But I'm not seeing how if it's checking for the number used for word/linepos. Unless I'm misunderstanding it.

EDIT: After some tweaking, I get a warning saying ch is uninitialized. I didn't know a char had to be initialized, though this is probably because the function is checking whether ch equals something.

EDIT2: Nooooo... I'm trying to get it to count the words read, but it's not working. Is it too soon to do that, should I worry about the other stuff first? Sad I tried doing so within the function before realizing that that would need another loop inside it and I don't want to complicate things even further.

Code:
while (inF >> contents)
{
    GetWord(inF, linepos, wordpos, word);
    numWords = numWords + 1; //This has been initialized in the main.
}

cout << "PARAGRAPH CONTAINS " << numWords << " WORDS" << endl;

It's telling me that linepos, wordpos and word are undeclared... but they were declared inside the function?? (I mean, word technically was not, but...)
Reply


Messages In This Thread
Algorithms and flowcharts (Yet another C++ assignment). - by MariettaRC - 2013-09-25, 05:35 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)