如何在C语言中打印符号theta [英] How do I print the symbol theta in C language

查看:501
本文介绍了如何在C语言中打印符号theta的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用C语言打印符号theta



我尝试过:



没什么......不知道..................

How do I print the symbol theta in C language

What I have tried:

Nothing...no idea..................

推荐答案

试试:
#include <stdio.h>

int main()
{
    printf("Theta: Θ\n");

    return 0;
}


Google众神有你想要的答案...



使用的搜索: theta字符十六进制值 [ ^ ]



答案: Unicode字符'GREEK SMALL LETTER THETA'(U + 03B8) [ ^ ]
Google gods have the answer that you are looking for...

Search used: theta character hex value[^]

Answer found: Unicode Character 'GREEK SMALL LETTER THETA' (U+03B8)[^]


我无法打印到控制台但是我附加了一个程序,该程序写入可以在记事本(或记事本++)中打开的文本文件

UTF-8规范在维基百科中详细介绍,代码基于那。还有一个注释掉的代码和链接。



I am not able to print to the console but I am attaching a program which writes to a text file that can be opened in notepad (or notepad++)
The UTF-8 spec is detailed in wikipedia and the code is based on that. There is also a commented out code with the link.

#include <stdio.h>

#define MAX_PRINT 		25

int codepoint2utf8(unsigned char *utf8, unsigned int codepoint);
int getbytecount(unsigned int codepoint);

unsigned int alpha = 0x3b1; // UNICODE value for ALPHA
unsigned char utf8str[10];

unsigned char utf8_flag_bytes[] = {	0xef, 0xbb, 0xbf };  // these leading values at start of file (.txt) denote UTF-8 encoding

char *filename = "greek.txt";
void main()
{
	FILE *fp;
	int codelen;
	int i;
	
	fp = fopen(filename, "wb");
	fwrite(utf8_flag_bytes, 1, 3, fp);  // first write the UTF-8 signature to the start of file
	
	for(i = 0; i < MAX_PRINT; i++)
	{
		codelen = codepoint2utf8(utf8str, alpha + i);
		codelen += codepoint2utf8(utf8str + codelen, ' ');

		fwrite(utf8str, 1, codelen, fp);
	}
	
	fclose(fp);
}

int codepoint2utf8(unsigned char *utf8, unsigned int codepoint)
{
	unsigned char byteval, mask, leadbyte = 0, countbit = 0;
	int numbytes, i;
	
	mask = 0x3f;   // mask for continuation byes ie for extracting least significant 6 bits
	
	numbytes = getbytecount(codepoint);
	if(numbytes > 1)
		countbit = (1 << 7);
	for(i = numbytes - 1; i > 0; i--, countbit >>= 1)
	{
		byteval = (codepoint & mask) | (1 << 7);
		leadbyte |= countbit;  // set next significant bit for each byte added
		codepoint >>= 6;      // next 6 bits
		utf8[i] = byteval;
	}
	leadbyte |= (countbit | codepoint);
	utf8[i] = leadbyte;
	
	return numbytes;
}

int getbytecount(unsigned int codepoint)
{
	unsigned int i, bits, continuations = 0, leadbits = 5;
	
	for(i = 31, bits = 0; i > 0 && bits == 0; i--)
	{
		if((1 << i) & codepoint)
			bits = i + 1;
	}
	
	if(bits <= 7)
		goto exitpoint;
	
	continuations = 1;  // min value
	while(bits > leadbits + continuations * 6)  // 'leadbits' is no of bits avail for coding in lead byte 
	{                                           // every continuation byte is of the form 10xxxxxx where 'xxxxxx' represents part codepoint value
		leadbits--;
		continuations++;
	}
	
exitpoint:
	return (1 + continuations);  // no of bytes reqd is 1(for lead byte) + no of continuation bytes
}

/*
-- link http://stackoverflow.com/questions/4607413/c-library-to-convert-unicode-code-points-to-utf8
if (c<0x80) *b++=c;
else if (c<0x800) *b++=192+c/64, *b++=128+c%64;
else if (c-0xd800u<0x800) goto error;
else if (c<0x10000) *b++=224+c/4096, *b++=128+c/64%64, *b++=128+c%64;
else if (c<0x110000) *b++=240+c/262144, *b++=128+c/4096%64, *b++=128+c/64%64, *b++=128+c%64;
else goto error;
*/


这篇关于如何在C语言中打印符号theta的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆