Hello,
i'm trying to copy a const char* string (call it stringA) to a char* string (stringB).
now lets say stringA is 20 characters long and i only want to copy 10 of those characters to stringB. Whats the best possible way to go about doing it?
i've tried using a for loop..
Code:
int i;
for (i=0; i < 10; i++)
{
stringB[i] = stringA[i];
}
stringB[i] = '\0';
... but this only results in a segmentation core fault.
then i tried using strncpy...
Code:
strncpy(stringB, stringA, 10);
.. but this isnt giving me the results i want. its copying the whole stringA into stringB.
what am i doing wrong? Any help would be great.
Thanks.