本文介绍了在C中将utf-16转换为utf-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有大学任务,我需要一些帮助。不要给我解决方案;提示或一小部分代码将不胜感激。 所以,我的大学项目是关于unicode的。确切地说,我必须编写以utf-16格式输入字符的代码,将其转换为utf-8并将其放在适当的出口(终端控制台或file.txt)中,同时我还要执行以下操作: /> 1)不要使用数组 2)使用putchar 3)使用getchar 注意:我在那里的第二年,但如果我不使用指针和scanf,那将是最好的。 如果我的教授正在观看论坛,我宁愿不发布代码。 这是我的开始:I have a university assignment i need some help with. Don't give me the solution; hints or small portions of code would be appreciated.So, my university project is all about unicode. To be exact, I have to write code that takes character input in utf-16 format, converts it to utf-8 and places it in the appropriate exit (terminal console or file.txt), whilst I also do the following:1)Don't use arrays2)Use putchar3)Use getcharNote: I am in my second year there, but it would be best if I did not use pointers and scanf.I'd rather not post code unless necessary, in case my professor is watching the forums.Here's my start:int main(){int char1 = 0,char2;while (char1 != EOF){char1 = getchar();char2 = getchar();char1 <<= 8;char1 += char2;if (char1 >= 0xD800 && char1 <= 0xDBFF) {char2 = getchar();int tempchar = getchar();char2<<= 8;char2 += tempchar;if (char2 >= 0xDC00 && char2 <= 0xDFFF){char1 -= 0xD800;char2 -= 0xDC00;char1 <<= 10;char1 += char2;char1 += 0x010000;//write code that converts to utf 8} else if((char1 >= 0x0000 && char1 <= 0xD7FF )||(char1 >= 0xE000 && char1 <= 0xFFFF)){//write code that converts to utf 8}} 我的代码到目前为止是否正确?转移是对的吗?如果没有向我解释我是如何使它工作的。Is my code up to this point correct? Is the shifting right? If not explain to me how I could make it work.推荐答案 这篇关于在C中将utf-16转换为utf-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-27 16:58