get char on screen - c++

I've looked through the NCurses function list, and I can't seem to find a function that returns the characters already printed on the screen. Is there an accessible value for the char stored in each character cell? If not, is there a similar function in the Windows terminal?
I want to use this to replace all the characters on the screen of a certain value (ex: all the a's) with a different character, or with new attributes.

The function inch() gets the character and returns it as a chtype. Use winch() to get a character from a window other than stdscr.

Related

how to replace char with other in hexdecimal

I'm a new user who using mainframe, I have a file and I need to change all dots '.' in file with space, I was trying to write this statement on command
change X'05' X'40' all
after I converted the file to hexdecimal, but It doesn't work.
How can I change all the dots with space in file, in simple way please?
The dots are non-displayable characters. You can match them using picture strings in the ISPF editor (which is what I assume you're trying to use to edit the file?)
Try the command
change p'.' ' ' all
The "p'.'" part will match any non-displayable character and change it to a blank.
Hans answer above will certainly change any non-displayable character to a space. However you need to make sure you really want to change all non displayable characters to a space. Turn HEX ON to look at the actual data. You can then do a F p'.' to find the non-displayable character(s) prior to changing it. Browse shows non-displayable characters as a dot. However Edit would replace the value with an attribute for display purposes and this keeps you from typing over the data. You have to turn on HEX mode to manually modify the non-displayable value or use the Change command as you were trying. Typically any hex value from x'00' - x'3F' would be non-displayable. So a
C P'.' X'40' ALL
would modify every one of those values to a space. This may or may not be desirable depending on the file.

How does the escape sequence '\b' work in C++? Alternate display method?

So I've outputted a string of various ASCII characters. This program involves parts of this string being modified, and then re-displayed.
Instead of clearing the entire screen and re-displaying everything, which produces an unwanted flicker effect, I've decided on moving the cursor and then rewriting only the characters that have changed.
I'm moving the cursor with SetConsoleCursorPosition, part of windows.h.
However, once I try and cout something, it pushes all of the text in front of it ahead by a space; another unwanted effect.
In an attempt to fix this, I tried various forms of 'cout<<"\b";' to remove the old, unmodified character. But there was either no effect, or it actually added a space, which is obviously not a desired effect here.
I read somewhere that in order to remove the unwanted character that you actually have to use the escape sequence twice, Example: '\b\b', because the first one moves the cursor back a space, and the second one overwrites the character in front of it with a space (' ') or something like that.
'\b\b' didn't work either, unsurprisingly. Or maybe that is surprising, I don't actually know.
My question is: How do I remove the unwanted character? Or better yet, How do I overwrite text that has already been outputted with new text?
EDIT: I apologize, I'm running Windows 7
I think maybe clearing the ENABLE_INSERT_MODE with the SetConsoleMode function might help. It should prevent the console from inserting characters and pushing the old characters forward.

C++ - Displaying and Storing Japanese Characters

So, I'm attempting to use C++ and Windows Forms to create an application that will help me study Japanese (for now, Hiragana and possibly Katakana only). The aim is to be able to create a program that has the user select the character sets they want to use (A through O, KA through KO, etc.), and either view the cards freely or have the program test them over the characters. For debugging purposes, I currently have the View button set to output 5 values to 5 different text boxes - the Roman pronunciation, the corresponding character, its position in an array in which all of the characters are stored, and a Boolean value.
My problem lies in the fact that the characters all show up as "?", and I get multiple warnings when I compile. An example of this warning:
1>c:\users\cameron\documents\visual studio 2010\projects\japanesecards\japanesecards\Form1.h(218): warning C4566: character represented by universal-character-name '\u3093' cannot be represented in the current code page (1252)
This shows up 46 times, 1 for each Japanese character in the array. The array's declaration line is,
std::string hiraList[5][11][2];
An example of inserting a Romanji-Hiragana pair is,
hiraCheck[0][0][0] = "A";
hiraCheck[0][0][1] = "あ";
Finally, the Hiragana is being inserted into a text box using the following code:
System::String^ displayText = gcnew String(hiraList[x][y][1].c_str());
textBox5 -> Text = displayText;
Basically, given all of this, my question is - How can I get my form to display Japanese characters properly in a text box?
Okay! I've done a bit of tweaking and experimenting with wchar_t, and I've found out a solution.
First, I reduced the hiraList array to a two-dimensional array, and moved the Hiragana characters into their own, array, defined like so:
wchar_t hiraChar[5][11];
And added values like so:
hiraChar[0][0] = L'あ';
Then, I went down to the code for the 'View' button and made a few changes:
Deleted the method for declaring and filling the displayText variable
Updated the line of code which assigns textBox5 its text value to read from hiraChar[x][y]
A line of the new code has been pasted below:
textBox5 -> Text = hiraChar[x][y].ToString();
In essence, the program now creates three variables for Hiragana - One to monitor check boxes, one to store the romanji values, and one to store Hiragana characters. When at least one check box is selected, and the View button pressed, five things are outputted to text boxes - the character, its position in the array (x and y are separate boxes), its romanji equivalent, and a 'True' value which was used earlier in development for debugging purposes.

Changing Char of a textbox to it's next char

In Qt, I want to make something which will show the next char of the char input.
For example, I entered 'a' into a QTextEdit, it automatically turns to 'b' in another QTextEdit, and when I again enter 'b', it turns to 'c'. Which algorithm is perfect for this?
As mentioned in a comment, you want to do the following things (which are not code):
Detect a change in the first input box
Decide how to modify the second text box given the value of the first text box
Update the second text box
Step 2 might be (from your example) to ensure the text has more than one character and, assuming its a std::string, get text[text.length() -1] and Step 3 might be to get the text of the second text box, append that character and assign it.
This would work for a modifiable or non-modifiable second text box since it does not re-modify each character in the string -- just the added one.
But, you need to clearly define what you want to happen.
If you can modify the characters directly, you can set each character like tChar = iChar + 1. It'd get a little wonky if you put in something that isn't a letter (spaces or enter key). In that case you'd wrap it with if (iChar >= 'a' && iChar <= 'Z') { which uses the 'n' syntax to alias the actual number codes. Another method would be to subclass the Qtextedit control and overload the void Qtextedit::keyReleaseEvent(QKeyEvent* event) virtual function to intercept the key strokes and check that way. The comparison is similar, but you'd use Qt::Key_A instead of 'a' to check that it's a letter key, then modify the resulting char appropriately.
See also: http://doc.qt.nokia.com/4.7-snapshot/qtextedit.html

C++ new line not translating

First off, I'm a complete beginner at C++.
I'm coding something using an API, and would like to pass text containing new lines to it, and have it print out the new lines at the other end.
If I hardcode whatever I want it to print out, like so
printInApp("Hello\nWorld");
it does come out as separate lines in the other end, but if I retrieve the text from the app using a method that returns a const char then pass it straight to printInApp (which takes const char as argument), it comes out as a single line.
Why's this and how would I go about to fix it?
It is the compiler that process escape codes in string literals, not the runtime methods. This is why you can for example have "char c = '\n';" since the compiler just compiles it as "char c = 10".
If you want to process escape codes in strings such as '\' and 'n' as separate characters (eg read as such from a file), you will need to write (or use an existing one) a string function which finds the escape codes and converts them to other values, eg converting a '\' followed by a 'n' into a newline (ascii value 10).