- /* k&r(5.5): Character Pointers and Functions
-
created on Mar 21, 2011
-
*/
-
#include "stdio.h"
-
#define MAX 1000
-
void astrcpy(char *, char *);
-
void pstrcpy(char *, char*);
/* main: copy of two strings */
-
int main()
-
{
-
char ps[] = "Hello Mark";
-
char pt[MAX];
-
-
pstrcpy(pt, ps);
-
printf("%s\n", pt);
-
return 0;
-
}
-
-
/* strcpy: copy t to s; array subscript version */
-
void astrcpy(char *s, char *t)
-
{
-
int i;
-
-
i = 0;
-
while((s[i] = t[i]) != '\0')
-
i++ ;
-
}
-
-
/* strcpy: copy t to s; pointer version */
-
void pstrcpy(char *s, char *t)
-
{
-
while ((*s++ = *t++))
-
;
-
}