unknown errors (to me at least)

This is a discussion on unknown errors (to me at least) within the C++ Programming forums, part of the General Programming Boards category; I am a relative newcomer to C++. I have some history in BASIC ( I like goto loops!), but the ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    6

    unknown errors (to me at least)

    I am a relative newcomer to C++. I have some history in BASIC ( I like goto loops!), but the C++ syntax is new to me.

    The program I am trying to create is a simple game modifier that changes a value in the game's user.ini file so that a new action will be bound to a certain key.
    What I want it to do is open and run through the user.ini file, copying every line exactly until it finds the line that begins with "X=" (with X being the letter the user picked.) where I want to make it "X=playvehiclehorn 1" then continue on copying the rest of the lines of the program and stop when it reaches the end. I don't want the program to overwrite the file it reads from, just to make a copy in the same directory as the program is run, so the user can manually add it.

    I am using Bloodshed Dev C++. The compiler is throwing some errors at me I have never seen before. It is giving me errors on lines that don't have any code and past the end of the program. I have used all these commands before, maybe not in the same program, so I should be able to make it work. But no one can honestly say the error messages in Bloodshed help a novice very much . Thanks in advance!

    here is my code:

    Code:
    #include <iostream>
    #include <cstdlib>
    #include <string>
    #include <fstream>
    using namespace std;
    
    int main()
    {
    	char peeker = 'z', def = 'y', newkey = 'H', custkey = 'z', gettest = 'z', peeker2 = 'z', done = 'n';
    	string filename, linein;
    	ifstream infile;
    	ofstream outfile;
    
    	while (def != 'y' || def != 'n')
    	{
    		cout << "Is your program installed in the default directory?" << endl << "c:\UT2004  (y/n): ";
    		cin >> def;
    	}
    
    	if (def == 'n')
    	{
    		cout << "Enter the location of your user.ini file" << endl << "Example: c:\ut2004\system\user.ini" << endl << ": ";
    		cin.ignore(400, '\n');
    		getline(cin, filename);
    		infile.open(filename.c_str() );
    	}
    
    *29*	else 
    		infile.open("c:\ut2004\system\user.ini");
    
    	if (!infile)
    	{
    		system("pause");
    		return 1;
    	}
    
    	outfile.open("user.ini");
    
    	cout << "Do you want to use the 'H' key? (y/n): ";
    
    	while (custkey != 'y' || custkey != 'n')
    		cin >> custkey;
    
    	if (custkey == 'n')
    	{
    		cout << "Enter your new key to bind to the horn. It must be a CAPITAL letter." << endl << "Ex: H  : ";
    		cin >> newkey;
    
    	while (newkey < 'A' || newkey > 'Z')
    	{
    		cout << " Invalid key, enter another: ";
    		cin >> newkey;
    	}
    
    	while (!infile.eof())
    	{
    		peeker = infile.peek();
    		
    		if (peeker == newkey && done == 'n')
    		{
    			infile.get(gettest);
    			peeker2 = infile.peek();
    
    			if (peeker2 == '=')
    			{
    				outfile << newkey << "=" << "playvehiclehorn 1" << endl;
    				done = 'y';
    				infile.ignore(100, '\n');
    			}
    			else
    			{
    				infile.putback(gettest);
    				getline(infile, linein);
    				outfile << linein << endl;
    			}
    		}
    
    		else
    *79*		{
    			getline(infile, linein);
    			outfile << linein << endl;
    		}
    	}
    
    	infile.close();
    	outfile.close();
    
    	system("pause");
    	return 0;
    *90*  }
    lines with errors are marked with: *linenumber*

    here are my error messages
    Line | Error
    --------------
    102: non-hex digit 'T' in universal-character-name
    *note, the program has only 90 lines
    79: non-hex digit 't' in universal-character-name
    79: [Warning] unknown escape sequence '\s'
    79: non-hex digit 's' in universal-character-name
    29: non-hex digit 't' in universal-character-name
    29: [Warning] unknown escape sequence '\s'
    29: non-hex digit 's' in universal-character-name
    In function `int main()':
    *no line number
    91: syntax error at end of input

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Remember backslash in a string is the escape character.

    > cout << "Is your program installed in the default directory?" << endl << "c:\UT2004 (y/n): ";
    cout << "Is your program installed in the default directory?" << endl << "c:\\UT2004 (y/n): ";

    > cout << "Enter the location of your user.ini file" << endl << "Example: c:\ut2004\system\user.ini" << endl << ": ";
    cout << "Enter the location of your user.ini file" << endl << "Example: c:\\ut2004\\system\\user.ini" << endl << ": ";

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    6
    thanks so much! I remember that now, but for the life of me I didn't think of that before! I would have never figured that out. Between that and a stupid missing bracket, the program is at least compiling now. Thanks again!

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Glad you got it compiled! Just to correct myself, I probably should have said:
    Backslash in a string is the start of an escape sequence. So two backslashes will give you one.
    Last edited by swoopy; 11-18-2004 at 07:15 PM.

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    6
    ya, I think I remember now, kinda like you use a backslash to put a quotation mark or a newline character. It is so easy once you remember once . Thanks again, I got it working right!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21