#include <stdio.h>
void copystr(char *, char * );
int main(void)
{
char aa[]={"His name was John"}; // declare char array and initialize
char bb[ sizeof(aa) ]; // declare char array of equal size
char * paa,pbb ; // declare char pointer
paa=aa; // initialize char pointer to &aa[], or aa common short hand.
pbb=bb; // initialize char pointer to &bb[], or bb common short hand.
printf("Contents of array aa[]: %s\n", paa ); // print string starting at &aa[0]
printf("Contents of array bb[]: %s\n", pbb ); // print string starting at &bb[0]
printf("Calling function copystr.\n");
copystr( paa, pbb) ; // copy contents of aa[] to bb[]
printf("Contents of array bb[]: %s\n", pbb);
return 0;
}
void copystr(char *str1, char *str2 )
{
int ii;
for( ii=0; *(str1+ii); ii++); // ii initialize to zero
// while thing-at position in array is not NULL
// do block
// increment position in array by 1
{
*(str2+ii)=*(str1+ii);
}
printf("Done copying array\n");
}