title: What's wrong with these system calls?
body: <p><strong>I'm at a loss debugging this code. I copied the example from a guide, is this file being improperly indexed?</strong> </p>
  
  <pre><code>#include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;math.h&gt;
  
  char *inicio(void);
  
  main(void)
  {
    char *c;
    int fd, sz, i;    
    c = inicio();
  
    fd = open("input.in", O_RDONLY);
    if (fd &lt; 0) { perror("r1"); exit(1); }
  
    sz = read(fd, c, 10);
    printf("We have opened input.in, and have called read(%d, c, 10).\n", fd);
    printf("read has read %d bytes.\n", sz);
    printf("The bytes are these: %s\n", c);
  
    i = lseek(fd, 0, SEEK_CUR);
    printf("lseek(%d, 0, SEEK_CUR) returns the current location on the file being %d\n\n", fd, i);
  
    printf("We now look for the start of the file and call read(%d, c, 10)\n",fd);
    lseek(fd, 0, SEEK_SET);
    sz = read(fd, c, 10);
  
    printf("The reading returns the following bytes: %s\n", c);
  
    printf("We now execute lseek(%d, -6, SEEK_END). and return %d\n",fd, (int) lseek(fd, -6, SEEK_END));
    printf("Executing read(%d, c, 10), we get the following bytes: ", fd);
  
    sz = read(fd, c, 10);
  
    printf("Finally, we execute lseek(%d, -1, SEEK_SET).  This returns -1.\n", fd);
    printf("perror() indicates the fault:\n");
    fflush(stdout);
  
    i = lseek(fd, -1, SEEK_SET);
    perror("l1");
  }
  
  char *inicio(void)
  {
    char *bytes;
    int j;
    bytes = (char *) calloc(100, sizeof(char));
    for(j=0;j&lt;100;j++){bytes[j]=rand()%32+1;}
    return bytes;
  }
  </code></pre>
  
  <p>the input file is:</p>
  
  <pre><code> Jim Plank
   Claxton 221
  </code></pre>