Remove first 4 chars from char array

Hi, I need to remove 4 chars at begin of char array. For example, I want to remove "ABCD". I try:

char source[] = "ABCDEFGHIJ";
char destination[10];

// char * strncpy ( char * destination, const char * source, size_t num );
/* partial copy (only 5 chars): */
strncpy ( destination, source, 3 );

But I do not know how to do it. I found strncpy, but num param means 0..num.

Depends what you mean by "remove". You could just index four elements into the existing array.

char source = “ABCDEFGHIJ”;
copy “EFGHIJ” to “char destination[10];”

Is there any comfortable solution then for loop?

Is there any comfortable solution then for loop?

strcpy() can be used, where the second argument is &source[4]. This says that the string to be copied starts at the 4th position in the array, skipping the 0th, 1st, 2nd, and 3rd.

But, what's wrong with an easy to understand for loop?

On for loop is nothing bad.

Are these 2 two solutions good?

for (byte i=0; i <= sizeof(source)/sizeof(source[0]); i++) {   
  destination[i] = source[i+4];    

strncpy (destination, &source[4], sizeof(sizeof(source)/sizeof(source[0])) );
i <= sizeof(source)/sizeof(source[0])

Maybe strlen, but not sizeof, and probably “<”


for (byte i=0; i < strlen(source); i++) {   

destination[i] = source[i+4];   

strncpy(destination, &source[4], strlen(source)-4 );

I try it and strncpy takes 8 bytes of flash less than for loop.

strncpy probably uses pointers, such as:

char *str = "ABCDEFGHIJ";

for(char *dst = str, *src = str + 4; *dst = *src; src++, dst++);