Thread: Unknown Compiling Error

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    15

    Unknown Compiling Error

    "unterminated character constant"

    it seems to be trying to get rid of all the strings where i use a ' between a " " i.e. "Someone's Something"

    now this didn't happen until just a minute ago, so obviously i changed something, but i've checked and rechecked that all my " are closed and all my { have a }

    i'll load the code up, maybe someone can compile it real quick and see what it is.

    I'm using Dev C++ btw.

    Thanx,
    Darkflame

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Whenever you use ' or " in a string, you need to place a backslash (\) before it. For example, on the line with the error, the string would be: "\'s Hitpoints:" instead of: "'s Hitpoints:".
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    If you do not treat them as escape characters, then they will be interpreted as the end of the string, and as you noticed, cause problems (in your case, the ending quotation mark created a new constant string which was not ended on that line).
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    15
    Ok I tried that, but I still get the same error.

    I changed the line from:
    cout << "You Hitpoints: " << playerlife << '/' << playermaxlife << "\t\t" << enemyname << "'s Hitpoints:" << enemylife << '/' << enemymaxlife << '\n';


    To:
    cout << "You Hitpoints: " << playerlife << '/' << playermaxlife << "\t\t" << enemyname << "\'s Hitpoints:" << enemylife << '/' << enemymaxlife << '\n';

    What gets me is this didn't happen until I added the trainlevel structure, which cotains nothing in it that i see would cause this.

    Darkflame

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    You are missing the big point with cout!

    ITS BUFFERED!

    That basically means that cout has an internal buffer and the data in that buffer is not sent to the screen until one of these occur....

    1) an endl ( not a \n)
    2) a call to cin ( because cout is tied to cin)
    3) a flush (i.e. cout<<"I'm getting better at c++"<<flush;)
    4) the buffer is full.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    15

    Question

    So what's the solution? Do i add an endl to the end instead of \n?

    Hmm this actually helped me solve another problem I had, but this one still exists. I don't get it.

    Thanx,
    Darkflame

  7. #7
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    try using the flush buffer.
    Monday - what a way to spend a seventh of your life

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    15
    Bah, I feel like an ass. Just ignore everything here.

    If you look on line 911 You'll see i ended a " with a ' causing the error throught the program. So stupid, just goes to show hmm...

    Thanx for trying to help,
    Darkflame

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  3. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM