title: Copying string without strcpy using pointers
body: <p>I'm trying to copy a string str into str using pointers. i think this can be achieved using a single pointer itself. whenever i run my code im getting str1 to display but with excessive unwanted garbage characters. please help. provide some insights </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  void main()
  {
    char str[10];
    char str1[10];
    printf("Enter a string");
    scanf("%s",str);
    char *p;
    char *q;
    int len=0,i=0;
    p=&amp;str;
    q=&amp;str;
  
    while (*p!='\0')
    {
      len=len+1;
      p=p+1;
    }
  
    printf("%d",len);
    printf("\n");
  
    while (len&gt;0)
    {
      str1[i]=*q;
      len=len-1;
    }
  
    printf("%s",str1);
  }
  </code></pre>