title: format ’%s’ expects argument of type ’char *’
body: <p>For exercising my programming skills in C I'm trying to write the strncpy function by myself. Doing that I kept hitting errors, solving most of them eventually I'm stuck with no further inspiration to go on.</p>
  
  <p>The error I receive is:</p>
  
  <pre><code>ex2-1.c:29:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
     printf("The copied string is: %s.\n", stringb);
  </code></pre>
  
  <p>The thing is that it's a very common error and that it's also already described on SO, only I can't seem to apply the tips other people have already pointed out. I get that I'm using a wrong type when printing the variable, and when I use the %d format it will return an integer which is probably the ASCII value of the first character, as it doesn't change when increasing the max number of bytes to copy.</p>
  
  <p>Using GDB I've found out that the b variable when done iterating through the while loop holds the correct string, still I can't seem to print it. </p>
  
  <p>I'm probably lacking a very fundamental part of knowledge about the C language and I apologise for asking this novice question (once again). Also I would appreciate it if you could give feedback or point out other flaws in my code.</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  void strmycpy(char **a, char *b, int maxbytes) {
    int i = 0;
    char x = 0;
  
    while(i!=maxbytes) {
    x = a[0][i];
    b[i] = x;
    i++;
    }
  
    b[i] = 0;
  
  }
  
  
  int main (int argc, char **argv) {
    int maxbytes = atoi(argv[2]);
    //char stringa;
    char stringb;
    if (argc!=3 || maxbytes&lt;1) {
          printf("Usage: strmycpy &lt;input string&gt; &lt;numberofbytes&gt;. Maxbytes has to be more than or equal to 1 and keep in mind for the NULL byte (/0).\n");
          exit(0);
       } else {
  
    strmycpy(&amp;argv[1], &amp;stringb, maxbytes);
    printf("The copied string is: %s.\n", stringb);
  
    }
  
    return 0;
  }
  </code></pre>