문제

I have a char *message; which contains some content. I wish to read this message from a specific index (for example 20) and until end of the char*. Is there any clever way to do this? I have been looking at memcpy() and the possibility to copy a "sub-string" from message into a new char *tmp;, but I can't seem to figure out how to start at that specific index (for example 20) and copy until end of message -- rather than starting at the beginning of message.

Any help appreciated. Cheers!

도움이 되었습니까?

해결책

You may try like this:

char *tmp= message + 20;

다른 팁

this is an example to test your need :

main()
{

   char *buff = "hello_word_test";
   char *tmp;

   printf("%s \n",buff);
   printf("%s \n",buff+5);


}

result :

    hello_word_test 
   _word_test 

5 is an index , you can change it as well as you need

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top