title: How to read numbers from stdin until end
body: <p>Where there is <code>for(;;)</code> I need something to read from stdin and save to <code>N</code>.
  Something with <code>read(stdin,N,sizeof(float))</code> and <code>while(s!=EOF)</code> <code>s=getc(stdin)</code> maybe?  <em>I'm assuming a list of numbers is saved on stdin separated end of lines</em></p>
  
  <p>The question was something like:</p>
  
  <blockquote>
    <p>Your program must print its pid to standard output. Then it should start to read values of N from standard input until the end of the file. After receiving a signal (SIGUSR1) your program should subtract (then multiply, then divide, then subtract) the value of N from sum (first value of sum=0) as a cycle. After receiving SIGUSR2 your program should print the current sum.</p>
  </blockquote>
  
  <p>How I interpreted the question and attempt:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;signal.h&gt;
  
  float N,sum=0;
  int count=0;
  
  void handler(int s){
      count++;
      if (s==SIGUSR1){
          if (count==1){
              sum-=N;
          }   
          if (count==2){
              sum*=N;
          }
          if (count==3){
              sum/=N;
          }
          if (count==4){
              sum+=N;
              count==0;
          }
  
      }
  
      else if (s==SIGUSR2){
          printf("sum=%d",sum);
      }
  }
  
  
  int main(){
      pid_t pid=getpid();
      signal(SIGUSR1,handler);
      signal(SIGUSR2,handler);
      printf("%d",pid);
      fflush(stdout); 
  
      for(;;)
      scanf("%d",&amp;N);
  
  
      return(0);
  }
  </code></pre>