Thursday, 6 September 2012

STRING COPY WITH POINTERS


#include
void strcpy(char*,char*);
int main()
{
    char t[10];
    scanf("%s",t);
    char s[10];
    strcpy(s,t);
    printf("%s",s);
}
void strcpy(char* s,char* t)
{
    int i;
    i=0;
    while((s[i]=t[i])!='\0')
    i++;
}



2ND METHOD---

void strcpy(char* s,char* t)
{
      while((*s=*t)!='\0')
      {
      s++;
      t++;
      }
}

3RD METHOD----

void strcpy(char* s,char* t)
{
     while((*s++=*t++)!='\0')
     ;
}

No comments: