Below is one of my C functiosn:
void test(char * ptr)
{
ptr[0] = 'T';
ptr[1] = 'O';
ptr[2] = 'P';
ptr[3] = '\0';
}
Is there a way to shorten this? I’ve tried
void test(char * ptr)
{
ptr[0] = "TOP";
}
but that doesn’t work. [Note: I do not have the library function strcpy() or similar.]
No, you need to write your own strcpy(). You can only do
char ptr[] = "TOP"for initializers.But you can do this which can easily be changed to strcpy():