C语言中的字符转换 [英] Character conversion in C

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

问题描述



我想将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.

推荐答案

我认为最简单的方法可能是处理char到char方法.即

DocType = pType [0];

我相信这种方法将使您从要复制到char的字符串中获取第一个char.

同时,如果您有其他更好的方法,请发邮件至
saxena.amit2007@hotmail.com或amcomp2008@gmail.com
I think the simplest approach could be that you deal with char to char approach. i.e.

DocType=pType[0];

I am sure that this approach will let you get the first char from the string to be copied to the char.

At the same time if you gets another better method pls mail me at
saxena.amit2007@hotmail.com or amcomp2008@gmail.com


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

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