ccharsubstring

Get a substring of a char*


For example, I have this

char *buff = "this is a test string";

and want to get "test". How can I do that?


Solution

  • char subbuff[5];
    memcpy( subbuff, &buff[10], 4 );
    subbuff[4] = '\0';
    

    Job done :)