ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm doing c programming in linux and trying to use fgetws with xfce4-terminal. and the problem is after typing multibyte string into terminal using fgetws function, when I delete with backspace, it only deletes half of the character. after pressing enter, fgetws(line,MAXLINES, stdin) != NULL dies off prematurely.
is there alternate to fgetws or terminal library or alternate to stdin with wide stream or other possible solution to this?
Did you try other terminal-emulators like xterm, rxvt, konsole, gnome-terminal, eterm, etc?
You might find out that the problem isn't related with this xfce4-terminal.
Edit: Did you call setlocale(LC_ALL,"") in your code?
I did include setlocale at the beginning of the main() in source code.
when I use xfce4-terminal, it seems to me in the command line that for multibyte letters, it deletes twice for functioning properly.
for ascii, the terminal deletes one character, for multibytes, it deletes two characters for each backspace stroke.
wonder what function from of what library the terminal uses..
Actually it is bash (actually: readline) that does this editing.
Did you try other terminal-emulators like xterm, rxvt, konsole, gnome-terminal, eterm, etc?
You might find out that the problem isn't related with this xfce4-terminal.
I searched. and the answer was to use readline library
Thank NevemTeve for fast replying
edit: I used xterm with utf8 setting, and fgetws did the same
it deletes only half the character when pressing backspace but internally deletes a wide character
I've just started experimenting, first test: read(2):
Code:
terminal LC_CTYPE stty test result
8-bit .ISO-8859-2 -iutf8 read(2) single-byte, backspace ok
utf8 .UTF-8 iutf8 read(2) utf8-sequences, backspace ok
utf8 .UTF-8 -iutf8 read(2) utf8-sequences, backspace NOT ok
fread(3), fgets(3): same as read(2) -- well, they do call read(2)
Edit: also tried on AIX: very similar, except it doesn't have 'stty iutf8' option, so backscpace (and Ctrl+W) always does the wrong thing.
Edit: Testing fgetws
Code:
terminal LC_CTYPE stty test result
8-bit .ISO-8859-2 -iutf8 fgetws(3) wide characters, backspace ok
utf8 .UTF8 iutf8 fgetws(3) wide characters, backspace ok
utf8 .UTF8 -iutf8 fgetws(3) errno=84: Invalid or incomplete multibyte or wide character
Note: 'fgetws' doesn't work after 'fgets'; so I created a copy via dup+fdopen
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.