Accessing substrings by offset and length

Hi,

I have a simple question... In C do we have a standard library function which will return the pointer to a substring at certain offset and having certain length...

Ofcourse we should take care not to access beyond allocated length in the parent string and don't overwrite beyond allocated length in the destination string...

it may look like this

int foo (char *s, char *t, int offset, int length);

if *s = "vishnu"; offset = 3; length = 2; it should give back
*t = "sh"

I'm not saying I want a function with the exact interface as above, but anything which allows me to access substrings by offset and length would be great...

This is not a homework question!!! I work in an office and write small C programs and sh scripts to automate task in a UNIX environment..

Thank you!
Vishnu.

strncpy() can copy n bytes. If you want to start at position 3 then you need to skip the first two bytes. So use strncpy(dest, s+2, 2). The first 2 is number of bytes to skip, the second 2 is the number of bytes to copy.

That was great Perderabo... and I learnt a lesson too! I certainly need to put more thought before taking for granted utility of certain standard C functions.. I have seen the strncpy(), but thought I'm restricted to access only from the beginning always...