Copies one array of characters into another. - C String

C examples for String:char array

Description

Copies one array of characters into another.

Demo Code

#include <stdio.h>

#define SIZE 10/*from   w w  w  .  jav  a 2 s  .  c o m*/

void copyarrays( int orig[], int newone[])
{
    int ctr = 0;

    for (ctr = 0; ctr < SIZE; ctr ++ )
    {
        newone[ctr] = orig[ctr];
    }
}

int main( void )
{
    int a[SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int b[SIZE];

    printf("values before copy");
    for (int ctr = 0; ctr < SIZE; ctr ++ ){
       printf( "a[%d] = %d, b[%d] = %d\n", ctr, a[ctr], ctr, b[ctr]);
    }

    copyarrays(a, b);

    printf("values after copy");
    for (int ctr = 0; ctr < SIZE; ctr ++ ){
       printf( "a[%d] = %d, b[%d] = %d\n", ctr, a[ctr], ctr, b[ctr]);
    }

    return 0;
}

Result


Related Tutorials