Click here to Skip to main content
15,885,855 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 1-Jun-10 21:52pm
v2

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900