Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error C2018: unknown character '0xa6'

Status
Not open for further replies.

mikelauwrie

Programmer
May 26, 2004
14
GB
I've got a problem with Visual C++6.
I've just started programming and have been building a dialog which uses the symbol: "¦".

I was fairly certain that this is a standard part of the C++ language but when I use it it comes up with the error message: error C2018: unknown character '0xa6'".

Any idea what I can do about it? Do I need to add it somehow? Or is it something to do with the fact that I use a UK keyboard layout? (Sounds unlikely I know).

Any guidance would be gratefully recieved

Mike
 
it means you can not use this character in variable names, expressions, and maybe comments.
for example

int x[©] = 3;
//using of [©] in the name of variable generates
//compilation error

When entering code source use only american or british english.

Ion Filipski
1c.bmp
 
If you want this character as part of a string say, then you need to use the escaped equivalent.
[tt]char mychar = '\xA6';[/tt]

--
 
hmmm. well the code that I'm using ought to be ok as it's from the "SAMS Learn C++ in 21 days" book. Here's the part which has been causing problems:

void CDialogsDlg::OnYesnocancel()
{
// TODO: Add your control notification handler code here
int iResults; //this variable will capture the button selection

//ask the user
iResults = MessageBox("press the yes, no, cancel button",
"yes, no, cancel dialog",
MB_YESNOCANCEL ¦ MB_ICONINFORMATION);

//determine which button the user clicked
//give the user a message showing which button was clicked
switch (iResults)
{
case IDYES: //the yes button?
m_sResults = "yes, yes, yes";
break;
case IDNO: //the no button?
m_sResults = "no, no, no!";
break;
case IDCANCEL: //the cancel button?
m_sResults = "sorry, cancelled";
break;
}
//update the dialog
UpdateData(FALSE);
}

And here's the errors that it creates:

DialogsDlg.cpp(189) : error C2018: unknown character '0xa6'

DialogsDlg.cpp(189) : error C2143: syntax error : missing ')' before 'constant'

DialogsDlg.cpp(189) : error C2059: syntax error : ')'
Error executing cl.exe.

Dialogs.exe - 3 error(s), 0 warning(s)

If I remove the line with the "¦" in it the "unknown character" error dissapears - so that's definately the character which is the problem.

The book says that "¦" represents a binary "OR" whereas "¦¦" represents a logical "OR".

This is starting to get rather irritating. So perhaps someone could suggest what I should do about it!
 
I wonder what | character you're using as my, valid, one looks a tiny bit different than yours.

/Per
[sub]
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."[/sub]
 
you should use only english keyboard when writing applications. You can applications with different human readable language for people working with your applications, but source code must be written in english (excepting comments and string values sometimes but not always)

Ion Filipski
1c.bmp
 
Well my keyboard is setup as English so that shouldn't be a problem. I wonder have any of you used the character in question in your programs much? And if so have you had any problems?

I wonder if there is something that I need to change in Visual C++'s settings...
 
In my ANSI codepage it is 0x7c.
Copy it from below:
Code:
 a | b
Call GetACP () (in C++) to get your current ANSI codepage.
Mine is 1252

Or include the file <iso646.h>
And type "bitor" instead of "|"
Must be in your include directory.

regards
PHaX
 
>I wonder have any of you used the character in question in your programs much?

Oh yes. As you mention its used in logical and bitwise OR, so...

>And if so have you had any problems?
Nope.

>I wonder if there is something that I need to change in Visual C++'s settings...

I doubt it. You are (for some reason) not entering the proper character.
It should be 0x7c (as mentioned). The same you'd get if you do a
<PressAlt>+<Enter124OnNumKeyPad>+<ReleaseAlt>


/Per
[sub]
&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;[/sub]
 
By the way, take a look into your code with HexEdit. If you have there at least one character or equal to 0x80 (or signed char is < 0) change it. That are extended non ASCII characters. The meaning of that characters deppends on language settings.

Ion Filipski
1c.bmp
 
Dashed vertical bar in the 3rd arg of MessageBox() has exactly 0xA6 code on Windows. Yes, it's not the same char as a common vertical bar (OR op sign in C/C++) from 0..0177 ANSI range.
It's the other question where is it from (in the source)...
 
Right it seems to be working now!
The problem was (as suggested) using "¦" rather than "|".

However I had another look at the book and it certainly uses "¦" so there wouldn't have been any way of finding the problem if it hadn't been for all your help!

Cheers

Mike
 
the both symbols "¦" and "|" coule be the representation of the same character. You can try to change font in settings of VisualC++ and you maybe will see "¦" instead of "|". It doeas not mean yet what it is the wrong symbol. That deppends on font are you using. The problem was what you used this symbol from another charset. The fact what you saw the wrong "¦" instead of the good "|" was just a coincidence. Sometimes is no such easy to detect these symbols. You will be 100% sure only when you will analyze code in some hex editor.

Ion Filipski
1c.bmp
 
Vertical and dashed bars are different chars in Windows. Start Word, open insert character dialog. You can see both chars in the common latin-1 set for Arial or Times New Roman.
However I saw a dashed bar instead of a vertical bar on old printers (many years ago;)...
If 0xA6 is in book sample sources it's publisher's mistake.
If dashed bars were printed in the book - it's type-setter's mistake.
 
Anyway, sometimes you may find error only with hexedit. This is not only the case of |. There could be mistakes like russial Z looks like digit 3. Rusian lowercase t looks like m. Russian u looks like y. Russian i looks like u. Russian s looks like c. Russian g looks like r. Russian d looks like latin g and so on. I will not enumerate there all the russian charset. And let's imagine situation:

class car
//suppose by mistake you put above russian s instead of
//latin c
{
......
};

However you are able to handle visually some of situations, this situation you will be able to handle only with hexedit.

Ion Filipski
1c.bmp
 
Yes, it's a possible situation with national charsets.
Luckily for us, if we can type national char in a name, we can type it in IDE editor Search box too...
Apropos, if I suspect wrong chars in someone else's sources, I prefer to write my own simplest C/C++ converter (after my own simple scanner). Most likely, there are many files with that chars in the package...

 
great, but how about chinese, mongolian or russian comments?

Ion Filipski
1c.bmp
 
No problems with 0x80..0xFF chars in a comment (compilers skip it and no need to translit cyrillic chars into latin if we don't know Russian;). Moreover, it's not so hard work to add rudimentary C++ parser capabilities into the comverter...
Oh, Chines - not too well... However I saw Japaness sources all in Latin...
As far as I know, Mongolians use cyrillic (or may be Latin now;)...
 
Great, but in my opinion better is the programmer to take himself a look with hexedit when getting such errors. A tool could remove/change some character but this tool never know what charset were you using. A correct decision could be made only when knowing the charset, but at binary level you can not detect used charset. Moreover, such changes could be dangerous. For example you changed russian S to latin C. But the charset was not russian.... I'm almost sure you will get a lot of compilation errors. So, you will correct again. For a good programmer it is not a problem. Just correct:
class car
//getting error C2018
//and supposing you usedrussian s
{
...
};
//a big project and a lot of code there
....
//as a programmer you don't know how always
//how to spell correctly class names.
//you know only how to use them. You have read the help and
//written the code
//declarations:
car x, y, z;

//using a tool and correcting error:
class war
//the tool suposed a wrong character, there was
//some character from other national language charset
//but had the same code like russian S
{
...
};
//after using a tool and trusting results
//declarations:
car x, y, z; //you get compilation errors there,


class war
{
...
};
//after using a tool and trusting results
//declarations:
war x, y, z; //correcting error

and returning the application back to some client that also use this library. They are also programmers and will correct the application in some way.... and so on. So, a simple using of a tool could generate too many problems.

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top