7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【苦しんで覚える新元号】UTF-8の令和のデータ表現は2種類ある。

Last updated at Posted at 2019-04-01

新元号"令和"の文字出力

1つ目

令和
#include <stdio.h>

int main(void)
{	
	char reiwa[7];
	reiwa[0]=0xEF;
	reiwa[1]=0xA6;
	reiwa[2]=0xA8;
	reiwa[3]=0xE5;
	reiwa[4]=0x92;
	reiwa[5]=0x8C;
	reiwa[6]=0;
	
    printf("%s",reiwa);
	
	return 0;
}
出力
令和

2つ目

令和
#include <stdio.h>

int main(void)
{	
	char reiwa[7];
	reiwa[0]=0xE4;
	reiwa[1]=0xBB;
	reiwa[2]=0xA4;
	reiwa[3]=0xE5;
	reiwa[4]=0x92;
	reiwa[5]=0x8C;
	reiwa[6]=0;
	
    printf("%s",reiwa);
	
	return 0;
}
出力
令和

対応が面倒になるかもしれないですね。

7
5
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?