I'm writing a program that replaces every character where `position % step = 0`
As command line arguments I'm giving `1. file` `2. character` and `3. step`. I can only use system calls. Here is my main function:

```
int main(int argc, char **argv){

   assert(argc ==  4);

   int fdInput = open(argv[1], O_WRONLY);
   if(fdInput == -1)
      fatalError("Error opening input file.\n");

   char c[1];
   c[0] = argv[2][0];
   unsigned step = atoi(argv[3]);

   int fileSize;
   if((fileSize = lseek(fdInput,0,SEEK_END)) < 0)
      fatalError("Lseek error: Determining file size\n");

   if(lseek(fdInput,0,SEEK_SET) == -1)
      fatalError("Lseek error: Returning to the beginning\n");

   int i;
   for(i = 0; i*step < fileSize; i++)

      if(step - 1 > 0){
         if(lseek(fdInput, i*step - 1, SEEK_SET) == -1)
            fatalError("Lseek error: Within loop\n");

         if(write(fdInput, c, 1) != 1)
            fatalError("Writing error\n");

      }
      else {

         if(write(fdInput, c, 1) != 1)
            fatalError("Writing error.\n");
      }
      close(fdInput);
      return 0;
   }

```

**Example:** 

> 
> input.txt: 123456789
> 
> 
> 

`./output input.txt x 3` would return `12x45x78x`

**Problem:** For some reason, when I compile and execute for the first time, *everything works fine*! BUT: when I execute it for the second time, it won't work. When I try to `cat/less` `input.txt` it tells me that file is binary.

* `echo "123456789" > input.txt` -> creates `.txt` file
* `./output input.txt x 3` -> `12x45x78x`
* `./output input.txt x 3` -> won't work (program is finished), but:
* `less input.txt` -> `input.txt" may be a binary file. See it anyway?`

How can file be binary? It should be plain text file. What am I doing wrong here? Am I doing something wrong with `open`?