PDA

View Full Version : wierd I need some symbols



ThaDoctor99
November 24th, 2009, 09:13 PM
This is really strange and I know this is incorrect.
So I would like to know how I could install the needed.


#include<iostream>
using namespace std;
int main()
{
int b, h, loop, nu;
b=0;
h=0;
loop=0;
string hex = "\xFF";
beforeloop:
while(b<20)
{
while(h<40)
{
cout << hex;
h++;
}
h=0;
cout << endl;
b++;
}

return 0;
}


but my output is.
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
����������������������������������������
which I find strange.

Can+~
November 24th, 2009, 09:21 PM
string hex = "\xFF";
...
cout << hex;

What's so wrong about it? You're just outputting character 255 (http://www.asciitable.com/) (0xFF = 255) 800 times.

ThaDoctor99
November 24th, 2009, 09:30 PM
Well yeah but most of AA AB FF AC and such gives the same result... the one in the previous output.

MindSz
November 24th, 2009, 09:41 PM
Have you looked at the ASCII table to see which characters you're trying to print? 0xAA, 0xAB, 0xFF, and 0xAC are not really characters and the terminal might not know how to interpret them.

Try to output stuff between 0x21 and 0x7A since those are stuff you use daily.

johnl
November 24th, 2009, 09:51 PM
Because 0xFF is an unprintable character.

If you include the <cctype> header, you can use the function 'isprint' which will tell you whether the character you passed in is a printable character or not.

This is just a C++ wrapper around the C header 'ctype.h', so there might be some C++-way of determining this (locale, maybe?), but I am not familiar with it.



#include <iostream>
#include <iomanip>
#include <cctype>

using namespace std;

int main(int argc, char* argv[])
{
for(int i = 0; i < 0x100; ++i) {
cout << "0x" << hex << setw(2) << setfill('0') << i << ": ";

if (isprint(i)) {
cout << '"' << static_cast<char>(i) << '"' << endl;
} else {
cout << "<not printable>" << endl;
}

}

return 0;
}

ThaDoctor99
November 25th, 2009, 10:18 AM
Okay there are some differences from DOS to linux.
Well there are sort of different symbols between 0x21 and 0x7A.
However there are more in DOS
there I can use from 0x00 to 0xFF I think, there are some colours in however.
But I will try this when I get home.
Thanks for the help so far.

lisati
November 25th, 2009, 10:26 AM
Thadoctor: were you expecting the characters output to somehow depend on variables b & h? If so, you will need to find a way of incorporating b & h into what gets passed to cout. (Oops, I neearly finished the sentence with ";"!!!!)

wmcbrine
November 25th, 2009, 04:24 PM
Okay there are some differences from DOS to linux.
Well there are sort of different symbols between 0x21 and 0x7A.
However there are more in DOSI guarantee you there are more in Linux. :) However, in Linux (or at least in Ubuntu, and probably in most current distros), the character set you have to work with is UTF-8, not a DOS code page. UTF-8 sequences can be several bytes per character, but not all bytes start a valid sequence.


there I can use from 0x00 to 0xFF I think, there are some colours in however.Neither DOS nor Linux will let you change colors with single-character codes. (To find a system that does, you'd have to look back to the days of 8-bit computers.) Both will support escape sequences, though the details differ slightly (but ANSI-style sequences will work in most terminals).

ThaDoctor99
November 25th, 2009, 07:05 PM
Well I am exploring a bit here, and trying to find where there are valid signs which are neither letters nor numbers or fractions....
Besides from that I really like this idea however basic it is.

MindSz
November 25th, 2009, 08:23 PM
This might help?

wmcbrine
November 25th, 2009, 10:33 PM
It might, if Ubuntu used that character set. But it doesn't. (Only the 32-127 portion is fully applicable.)

Unicode is almost endless, and since not all byte sequences are valid UTF-8, you won't get very far by "exploring". Instead, you should consult charts like this one:

http://www.fileformat.info/info/unicode/block/index.htm

to find the symbols you're interested in.

gil_johnson
November 26th, 2009, 08:58 PM
[...]
Neither DOS nor Linux will let you change colors with single-character codes. (To find a system that does, you'd have to look back to the days of 8-bit computers.) Both will support escape sequences, though the details differ slightly (but ANSI-style sequences will work in most terminals).

Curses (#<include curses.h>, ncurses in Linux) will let you change colors of each character, foreground and background both. Curses does, indeed, go back to ancient days - I think it goes back to the time they used notches on sticks.

Curses is idiosyncratic, and the mechanism for changing colors is cumbersome, but if you are desperate, it can be done. It also doesn't help with characters greater than 0x7E either, it displays the same symbol as above. I resorted to a lookup table for hex numbers, displaying them as strings," 7F", " 80", " 81"... There are probably better ways of doing this, but I was working on a hex viewer and I wanted three byte strings, not 0xNN.

Gil

lisati
November 26th, 2009, 09:10 PM
e.

Neither DOS nor Linux will let you change colors with single-character codes. (To find a system that does, you'd have to look back to the days of 8-bit computers.) Both will support escape sequences, though the details differ slightly (but ANSI-style sequences will work in most terminals).

+1
On ALL of the x86-based computers I've used, even if you were to write directly to the graphics hardware in 80x25 text mode, you'd still need at least two bytes to set the character displayed and its attibutes.

Edit: Accessing the hardware directly isn't recommended unless you have good reason to do so and you know what you're doing

wmcbrine
November 26th, 2009, 11:50 PM
Curses (#<include curses.h>, ncurses in Linux) will let you change colors of each characterCurses uses those escape sequences I mentioned to do its work. "Single-character codes" means codes that are a single character, not codes that apply to a single character. Examples can be found in character sets (if that's still the right term) like PETSCII (http://en.wikipedia.org/wiki/PETSCII). I assumed this was the sort of thing the OP was talking about (incorrectly) when he said "there I can use from 0x00 to 0xFF I think, there are some colours in however", although his meaning is not entirely clear.

miklcct
November 27th, 2009, 01:19 PM
You tried to output lots of '\xff'. Does your terminal's encoding supports '\xff'?

gil_johnson
November 28th, 2009, 10:40 PM
Curses uses those escape sequences I mentioned to do its work.

Ahh! Thanks for the explanation - I was frustrated by the inability of ncuses programs to display N characters to a line when trying to use high-bit characters.

I've done some reading since posting, but I didn't find that bit.
Gil