encoding c-language CMD windows [duplicate] - c

This question already has answers here:
How to use unicode characters in Windows command line?
(19 answers)
Closed 9 years ago.
I have a problem with encoding in my c-programs. It seems to work fine in Eclipse but when executing the program in CMD in windows its not able to show the swedish "Å" "Ä" "Ö".
Is this because the encoding for the windows-XP is different from the encoding in my c-program.
I did query the local settings through setlocale() and I got the following:
Swedish_Sweden.1252
is there any quick solution to this?

Use the command change codepage:
chcp 850
which will change the code page to Multilingual (Latin I). Make sure your font can display the characters you need.

Related

How can I display a mouse's walking process on linux terminal using c? [duplicate]

This question already has answers here:
How can I print a string to the console at specific coordinates in C++?
(7 answers)
Closed 5 years ago.
Now, I can get a direction txt file from my code:
down
down
right
right
up
.
.
.
I want to ask how can I display the walking process on linux terminal.
For instance, I want to use a dot representing a mouse which can execute the direction above.
nCurses is the best solution. You can het help with the built-in manual:
man -s 3 ncurses
A simpler way to do so is to use ANSI CSI escape sequences:
printf("\x1B[A"); // Up
printf("\x1B[B"); // Down
printf("\x1B[C"); // Left
printf("\x1B[D"); // Right
To move up and print a dot:
printf("\x1B[A.");

printf not printing the same as fprintf [duplicate]

This question already has an answer here:
(C) Program that prints all CP850 characters on the screen and in a file have different outputs
(1 answer)
Closed 6 years ago.
I'm making a program in C for a project where it as to print to a file everything it prints to the console. The problem is that I have to print some special characters like 'Ç', so I use the ascii codes and it printd fine to the console however what it prints to the file is incorrect. Here is an example:
printf(" %c", 128);
output to console: Ç
fprintf(output, " %c", 128);
output to file: €
I ran the command chcp in cmd and it tells me I'm using code page 850 and I used those asci codes, so I don't know what is the problem. The program writes to a notepad txt file.
Ç is 128 in code page 437 or 850 etc., encodings which are sometimes used by Windows consoles. The same code 128 is € in code page 1252 or 1250, encodings which are quite often used by Windows graphical applications. The only reasonable way to proceed is to have your consoles use the same encoding as the graphical applications; for this, you can use the command chcp 1252 (change code page) in the console at the command prompt.
(Note: for chcp to be effective, the console must use a TrueType font such as Lucida Console or Consolas.)
Your command line (console) and whatever you use to display the file use different encodings.
Both times the byte 128 is written, but in some Extended ASCII variant (see also Wikipedia) it is interpreted as a C with cedilla,
whereas a common Windows encoding interprets it as the Euro symbol.

command line * linux [duplicate]

This question already has answers here:
Stop shell wildcard character expansion?
(4 answers)
Closed 6 years ago.
i'm trying to write code in C,which implements a simple calculator.
the input should come from the command line, so for example i if i run
./calculator 5 * 2
the result should be 10
the problem is that when i write * it shows all the files in the current directory and the program doesnt behave well.
there is anyway to overcome this problem?
i tried to find here or in other sites solutions,without success.
i need that * will Be interpreted as a char and not as a linux command.
thanks.
In linux shell, the * has special meaning. It is meant for globbing unless it is quoted like below
./calculator 5 '*' 2
You may also escape the asterisk to strip the special meaning from it
./calculator 5 \* 2

How to key data containing double quotes using Selenium Webdriver? [duplicate]

This question already has answers here:
Escape double quotes in Java [duplicate]
(4 answers)
Closed 6 years ago.
I'm trying to key a password containing a special character double quotes. I'm getting a compile time error in Java as expected for code mentioned below.
driver.findElement(By.id("cred_password_inputtext"))
.sendKeys("ghsfdjfsg"ksdkhkh");
Use escape character '\' while sending the password. i.e;
driver.findElement(By.id("cred_password_inputtext")).sendKeys("ghsfdjfsg\"ksdkhkh");

output redirection produces empty file [duplicate]

This question already has answers here:
Problem redirecting a C program output in bash
(5 answers)
Closed 9 years ago.
So this is probably a stupid question, but I can't see what I'm doing wrong.
I am running a program that produces output when called like ./ar. The output looks like:
-0.00781 0.02344 0.98828
-0.01172 0.02734 0.98828
-0.01562 0.02344 0.98047
-0.00781 0.02344 1.00000
-0.00391 0.02344 0.98438
A new line of output is written every second.
When I call the code like this ./ar > log and kill the program using ctrl-c after a few seconds, the file log is empty.
I am running this code on an embedded system. The system has a writeable partition which is the partition that I am running in, and I have write access as I am logged in as root.
The reason is the lazy writing concept of UNIX system.
Are you sure you are looking at standard output in you call ./ar? It might be standard error.
So, try ./ar >log 2>err to have 2 files, one for stdout and one for stderr.
Or use ./ar 2>&1 >log to get one file for both streams.

Resources