This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

strcpy and strncpy and strrncpy

"Keil C51 is very good"

strncpy can Get sub str from Left.

I want to get "very good".

Is there a function "strrncpy" to uses ?

Parents
  • If you want the n rightmost bytes of a string, it's easy to code yourself on top of the existing ANSI C string functions.

    char* strrncpy (char* dst, const char* src, int n)
       {
       return strncpy (dst, src + strlen(src) - n, n);
       } // strrncpy
    

    You might want to add an error check for n > strlen(src).

Reply
  • If you want the n rightmost bytes of a string, it's easy to code yourself on top of the existing ANSI C string functions.

    char* strrncpy (char* dst, const char* src, int n)
       {
       return strncpy (dst, src + strlen(src) - n, n);
       } // strrncpy
    

    You might want to add an error check for n > strlen(src).

Children
No data