问题描述
我想将character [2]转换为char.
示例代码,
char DocType = 0;
char pType [2] = {0};
char pType包含值为``p'',``x'',``f'',其中以``\ 0''作为终止字符串.
我只想将拳头字符复制到DocType中.
我使用了strcpy,但由于char和char [2]转换而无法正常工作.
所以我用strncpy作为,
strncpy(DocType,pType,1);
但我仍然面临错误,因为
类型"char * strict"的参数无法使用类型"char"的表达式进行初始化.
请帮帮我.
预先感谢.
Hi,
I want to convert character[2] into char.
sample code,
char DocType = 0;
char pType[2] = {0};
char pType contains values as ''p'',''x'', ''f'' with ''\0'' as terminated string.
I want to copy only fist character into DocType.
I used strcpy, but its not working because char and char[2] conversion.
So i used strncpy as,
strncpy(DocType , pType,1);
but still I am facing error as,
A parameter of type "char * restrict" cannot be initialized with an expression of type "char".
Please help me out.
Thanks in advance.
推荐答案
这篇关于C语言中的字符转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!