title: Why when I press CTRL+C the program reads zero bytes? (C-Posix)
body: <p>My program has to do this:
  The user has to pass N absolute pathname for files by command line. Then the i-th thread, with 0&lt;=i&lt;= N, has to write in the i-th file a string passed by user with scanf (or fgets). If CTRL+C is pressed, the program has to print all strings that user has passed with scanf.</p>
  
  <p>When I run this and I insert a string for 1 of the N files and I press CTRL+C, in the function onPress the function read returns 0 (I think that in this case not indicates that the file pointer is in the end of file) and it prints only the string "Strings:"</p>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;pthread.h&gt;
  #include &lt;string.h&gt;
  #include &lt;signal.h&gt;
  
  pthread_mutex_t mutex;
  int fdGlobal;
  
  void* writer (int* arg) {
     int fd_in = *(arg);
     char buffer[100];  
     pthread_mutex_lock(&amp;mutex);
     printf("Write the string that you want to insert in the file\n");
     scanf("%s", &amp;buffer);
     write(fd_in, &amp;buffer, strlen(buffer));
     write(fdGlobal, &amp;buffer, strlen(buffer));
     printf("Finished\n");
     pthread_mutex_unlock(&amp;mutex); 
  }
  
  void onPress(int sig) {
     char buff[100];
     printf("I'm going to print all strings passed in files...\n");
     int rd = read(fdGlobal, &amp;buff, sizeof(buff));
     if (rd == -1) perror("Error in the read of global file\n");
     printf("I read %d bytes\n", rd);
     printf("Strings: %s\n", buff);
     exit(0);
  }
  
  void main (int argc, char* argv[]) {
     int fds[argc-1];
     pthread_t tid[argc-1];
     int i, mu;
  
     if (argc&lt;=1) {
        printf("Insert a number &gt;=1 of  pathname/s\n");
     }
  
     for ( i = 1 ; i&lt;argc; i++) {
        if (argv[i][0] != '/') {
          printf("Insert a pathname\n");
         }
     }
  
     signal(SIGINT, onPress);
  
     fdGlobal = open("globalFile.txt", O_CREAT|O_RDWR, 0666);
     if (fdGlobal == -1) perror("Error in the open of global file\n"); 
  
     mu = pthread_mutex_init(&amp;mutex, NULL);
     if (mu &lt; 0) perror("Error in the creation of mutex\n");
  
     for (i=0; i&lt;argc-1; i++) {
        fds[i] = open(argv[i+1], O_CREAT|O_WRONLY, 0666);
        if (fds[i] &lt; 0 ) perror("Error in the open of the file\n");
  
        pthread_create ( &amp;tid[i], NULL, (void*) writer, &amp;(fds[i]) );
     }
  
    for (i=0; i&lt;argc-1; i++) {
        pthread_join(tid[i], NULL);
    }
    }
  </code></pre>