title: Unix command "ls" in C
body: <p>After a long time to search a solution, I have to ask your precious help. I work on a program which implement "ls" unix command in C. I'd have only name of the file and his size. I looked that I've to use: "stat" and "dirent". I found a "solution" in Stackoverflow but didn't work perfectly for me.
  So I can show the names of the file into the directory but not their size. 
  When I use gcc, whether it shows: 0 octet (while it isn't empty) or "</p>
  
  <blockquote>
    <p>error: format ‘%s’ expects argument of type ‘char *’, but argument 3
    has type ‘__off_t’ [-Werror=format=]   printf("%s - %s", dp->d_name,
    s->st_size);</p>
  </blockquote>
  
  <p>"</p>
  
  <p>My test code (not clean): </p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;dirent.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;poll.h&gt;
  
  struct stat statbuf;
  struct dirent *dp;
  struct stat *s;
  
  int main ()
  {
  DIR *dirp;
  dirp = opendir("/tmp/gestrep");
  
  while((dp = readdir(dirp)) !=NULL)
  {
  
      stat(dp-&gt;d_name, &amp;statbuf);
      printf("%s - %s", dp-&gt;d_name, s-&gt;st_size);
  }
  
  }
  </code></pre>
  
  <p>In fact, I don't know how to solve the format type problem. I saw I could use ftell/fseek but I don't have the right to use FILE* functions.</p>
  
  <p>Thank you for all solutions :)</p>