LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-23-2018, 03:32 PM   #1
illy
LQ Newbie
 
Registered: Jun 2018
Posts: 8

Rep: Reputation: Disabled
C printing extended ascii characters?


I'm trying to print out characters like ö,ä and å with printf() in C to console. Instead I get squares with question marks inside them.
I'm using Ubuntu and I have searched a bit and tried few solutions but they didn't work.
For example this worked for me on windows but not Linux.
Code:
#include <stdio.h>
#include <locale.h>

int main()
{
	setlocale(LC_ALL, "");
	
	printf("%c\n", 'ä');
}
I've also tried using unicode but couldn't get it to work and I have discovered that if I don't include <stdio.h> printf() displays those characters just fine. But I need <stdio.h> for other functions.
Anyone knows a way to print these characters ä,ö, and å in C to the console?
 
Old 09-23-2018, 10:51 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,860
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
First, you should settle down for one encoding (such as ISO-8859-1 or UTF-8), and use it in every context:
. settings of the terminalemulator (eg xterm, putty etc)
. settings of the text editor (eg mcedit)
. LC_CTYPE environment variable
. settings of the compiler (-finput-charset and -fexec-charset in gcc; clang is simpler: it doesn't support anything other than UTF-8)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert Unicode (or extended ASCII) characters in text files? tommyttt Linux - General 4 12-28-2012 05:28 PM
Extended ASCII characters on Framebuffer Console BoraxMan Linux - Desktop 3 12-12-2011 11:10 AM
using extended ascii characters sasser Linux - Newbie 2 04-06-2010 08:50 AM
bash printing extended ASCII characters nutthick Programming 6 02-04-2005 02:15 PM
Extended ASCII characters in UNIX MatSzor Programming 5 05-15-2004 09:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration