Using while loop to copy String with pointer - C Statement

C examples for Statement:while

Description

Using while loop to copy String with pointer

Demo Code

#include <stdio.h>

void copyString (char *to, char *from){
    while ( *from )
        *to++ = *from++;/*  w w  w  .j a v  a 2 s  . c o m*/

    *to = '\0';
}

int main (void)
{
    void copyString (char *to, char *from);
    char string1[] = "this is a test.";
    char string2[50];

    copyString (string2, string1);
    printf ("%s\n", string2);

    copyString (string2, "So is this.");
    printf ("%s\n", string2);

    return 0;
}

Result


Related Tutorials