Thread: Compile Error: Unterminated character constant??

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    44

    Compile Error: Unterminated character constant??

    So whats this all about then?

    It's in the following line of code:
    cout << "Too many... can't be more than ";<<max_r<<" !";
    I'm using Bloodsheds Dev-C++ Compiler.

    JamMan..

    Curious if I can live forever? CLICK HERE

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    Change:

    cout << "Too many... can't be more than ";<<max_r<<" !";

    to

    cout << "Too many... can't be more than "<<max_r<<" !";

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    44
    Cheers ArseMan , but...

    Changed that but still same error code apppearing??

    189: unterminated character constant

    Is there anywhere that describes the compile error codes in detail, I'm using Bloodsheds: 'Dev-C++'.
    I'm using Bloodsheds Dev-C++ Compiler.

    JamMan..

    Curious if I can live forever? CLICK HERE

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    Show more of your code because that statement compiles fine for me and im using Dev-c++.

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    44
    Cheers for the help ArseMan its greatly appreciated.

    Here is the whole program, and have you got a simular programs to this as I'm new to C++ and would like some source code to look through and hopefully learn. As I've got loads of books but find looking at source code I can understand it better.

    #include <iostream.h>
    #include <string.h>
    #include <stdlib.h>
    #include <fstream.h>
    #include <io.h>

    //--- Some global variables
    typedef unsigned int manname;
    const manname max_r=100; //maximum records
    const manname max_n=30; //maximum length of a name


    char *book[max_r];
    void Initialize()
    {
    //create the array
    for(manname a=0;a<max_r;a++)
    book[a]=new char[max_n];
    }
    //---------------------------

    //--- Functions definitions
    void fMenu();
    void fAfterInput(manname count);
    //-------------------------


    int compare(const void *i, const void *j)
    {
    return( strcmp(*(char **)i, *(char **)j) );
    }


    void fInputFile()
    {
    char string[40];
    char file[30];

    cout << "Enter filename to input: ";
    cin >> file;

    ifstream ReadFile(file);

    if(ReadFile)
    {
    while(!ReadFile.eof())
    {
    ReadFile >> string;
    cout << string<<endl;
    }

    fMenu();
    }
    else
    {
    cout << "Error reading file!\n";
    cout << "Make sure it exists...\n\n";
    fInputFile();
    }

    }
    void fSaveFile(manname count)
    {
    char filename[30];
    char inputstring[200];

    cout << "Enter filename: ";
    cin >> filename;

    ifstream GetOld(filename);
    ofstream SFile("temporary.txt");

    while(!GetOld.eof())
    {
    GetOld >> inputstring;
    SFile << inputstring << endl;
    }
    GetOld.close();

    for(ui f=0;f<count;f++)
    SFile << book[f]<<endl;

    SFile.close();

    _unlink(filename);
    rename("temporary.txt",filename);
    cout << "Saved!\n";
    fAfterInput(count);



    //GetOld.close();

    }


    void fSeeTheRecords(manname count)
    {
    for(manname b=0;b<count;b++)
    cout<<book[b]<<endl;

    fAfterInput(count);
    }
    void fSortTheRecords(manname count)
    {
    qsort(book,max_r, sizeof(char *),compare);
    cout << endl;

    char ask_u[5];

    cout << "Do you want to see the sorted records?";
    cin >> ask_u;

    if(ask_u[0]=='y')
    {
    fSeeTheRecords(count);
    }
    else
    fAfterInput(count);
    }
    void fAfterInput(manname count)
    {
    manname wanted;
    cout << "/----------------------------------\" << endl;
    cout << "| 1) Sort The Records |" << endl;
    cout << "| 2) See The Entered Records |" << endl;
    cout << "| 3) Save The Records To A File |" << endl;
    cout << "| 4) Go Back To The Menu |" << endl;
    cout << "| 5) Exit |" << endl;
    cout << "\----------------------------------/" << endl;
    cout << endl;
    cin >> wanted;

    if(wanted > 5)
    {
    cout << "Wrong Input\n";
    fAfterInput(count);
    }
    else
    {
    switch(wanted)
    {
    case 1:
    fSortTheRecords(count);
    break;
    case 2:
    fSeeTheRecords(count);
    break;
    case 3:
    fSaveFile(count);
    break;
    case 4:
    fMenu();
    break;
    case 5:
    exit(0);
    break;
    }
    }
    }

    //--- Getting the input from the user
    void fGetInput(manname max_entered)
    {
    cin.getline(book[0],max_n);
    for(manname c=0;c<max_entered;c++)
    {
    cout<<"Enter entry #"<<c+1<<" : ";
    cin.getline(book[c],max_n);
    }

    fAfterInput(max_entered);
    }
    //----------------------------




    void fUserInput()
    {
    manname num_rec;
    char answer[5];

    cout << "How many records you want to enter? : ";
    cin >> num_rec;

    if(num_rec > max_r)
    {
    cout << "Too many... can't be more than "<<max_r<<" !";
    cout << "Do you want to try again?";
    cin >> answer;

    if(answer[0]=='y')
    fUserInput();
    else
    {

    cout << "Do you want to go back to the menu?";
    cin >> answer;
    if(answer=="y")
    fMenu();
    else
    exit(0);
    }
    }
    else
    fGetInput(num_rec);



    } //---End of fUserInput()

    //--- Menu
    void fMenu()
    {
    manname wanted;
    cout << "---------------------------------" << endl;
    cout << "| 1) Input Specified File |" << endl;
    cout << "| 2) Enter Records |" << endl;
    cout << "| 3) Exit Program |" << endl;
    cout << "---------------------------------" << endl;
    cout << endl;
    cin >> wanted;

    if(wanted > 3)
    {
    cout << "Wrong input!\n";
    fMenu();
    }
    else
    {
    switch(wanted)
    {
    case 1:
    fInputFile();
    break;
    case 2:
    fUserInput();
    break;
    case 3:
    exit(0);
    break;
    }
    }

    }


    void main()
    {
    Initialize();
    fMenu();
    }
    I'm using Bloodsheds Dev-C++ Compiler.

    JamMan..

    Curious if I can live forever? CLICK HERE

  6. #6
    Unregistered
    Guest
    The actuall error that you had was at this section of code
    Code:
    void fAfterInput(manname count) 
    { 
        manname wanted;
        cout << "/----------------------------------" << endl; // took out the \" because \" tells the compiler
                                                               // to print out the character " and not termanate the string
        cout << "| 1) Sort The Records |" << endl;
        cout << "| 2) See The Entered Records |" << endl;
        cout << "| 3) Save The Records To A File |" << endl;
        cout << "| 4) Go Back To The Menu |" << endl;
        cout << "| 5) Exit |" << endl;
        cout << "----------------------------------/" << endl; // took out the \- because the \ tells the
                                                               // compiler that whatever comes next is a special character
                                                               // such as \n wich means newline or \t wich means tab
        cout << endl;
        cin >> wanted;
    there also an error at this section of code
    Code:
    void fSaveFile(manname count) 
    { 
        char filename[30];
        char inputstring[200];
    
        cout << "Enter filename: ";
        cin >> filename;
    
        ifstream GetOld(filename);
        ofstream SFile("temporary.txt");
    
        while(!GetOld.eof())
        {
            GetOld >> inputstring;
            SFile << inputstring << endl;
        }
        GetOld.close();
    
        for(ui f=0;f<count;f++)  // the compiler dosn't know what ui is
            SFile << book[f]<<endl;

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    61

    oops!

    oops I forgot to sign in that was me who posted that!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get wide character and multibyte character value
    By George2 in forum C++ Programming
    Replies: 27
    Last Post: 01-27-2008, 05:10 AM
  2. mega compile errors for small program
    By s_UNI_ in forum C++ Programming
    Replies: 4
    Last Post: 04-28-2005, 12:00 PM
  3. empty character constant error
    By Sway in forum C++ Programming
    Replies: 1
    Last Post: 10-08-2002, 08:27 PM
  4. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM