Monday 26 May 2014

How to copy string using pointer in C Programming

#include"stdio.h"
#include"conio.h"
void main(int argc,char *argv[])
{
void stringcopy(char *,char *);
char target[10];
clrscr();
fflush(stdout);
if(argc<2)
{
printf("\nWrong number of argument parameter");
exit(0);
}
stringcopy(target,argv[1]); // target, &target[0]
printf("\nSource string %s, Target String %s",argv[1],target);
getch();
}
void stringcopy(char *trg,char *source)
{
while(*trg++=*source++);
//Alternative way pretty adhoc process
/*while(*source)
{
*trg = *source;
trg++;
source++;
}
*trg=*source;*/
}

No comments:

Post a Comment