Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to truncate a part of an array by C programming?
How to truncate a part of an array by C programming?
Truncating a part of an array is equivalent to getting a subset of the array.

If it is a character array, you can use the strncpy function to intercept the required part as needed.

Strncpy is one of the library functions of C language. It comes from the standard library of C language and is defined in string.h, char * strncpy (char * dest, char * src, int n). It copies the first n bytes of the string pointed by src into the array pointed by dest, and returns a pointer to dest.

If it is an ordinary array, you can use the loop statement to assign the required parts one by one.

For example:

# include & ltstdio.h & gt

int? a[ 10]={0, 1,2,3,4,5,6,7,8,9 }; //source array a

int? b[ 10],I; //subset array b

int? main(){

for(I = 5; I< 10; i++)? b[I-5]= a[I]; ? //Get the numbers from 6th to 10 in array A and store them in B.

Return? 0;

}