Click here to Skip to main content
14,271,130 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100