You say that you have this:
char array[20]; char string[100]; array[0]='1'; array[1]='7'; array[2]='8'; array[3]='.'; array[4]='9';
And you would like to have this:
string[0]= "178.9"; // where it was stored 178.9 ....in position [0]
You cannot do this. A char has 1 character. It. A βstringβ in C is an array of characters followed by a sentinel character (NULL terminator).
Now, if you want to copy the first x characters from array to string , you can do this with memcpy() :
memcpy(string, array, x); string[x] = '\0';
Mike
source share