title: Why do I need to type Ctrl-D twice to mark end-of-file?
body: <pre><code>char **query; 
  query = (char**) malloc ( sizeof(char*) );
  
  int f=0;
  int i=0,j=0,c;
  
  
  while((c=getchar())!=EOF)
  {      
      if(!isalpha(c))
          continue;
  
      if(f==1)
          query=(char**) realloc(query,(i+1)*sizeof(char*));
  
      query[i]=(char*) malloc(sizeof(char));
      query[i][j]=c;
      j++;
  
  
      while( (c=getchar())!=EOF&amp;&amp;c!=' '&amp;&amp;c!='\t' )
      {      
  
          query[i]=(char*) realloc(query[i],(j+1)*sizeof(char));
  
          query[i][j]=c;
          ++j;
      }   
  
      query[i][j]='\0';
      printf("%s\n",query[i]);
      if(c==EOF){
  
          break;
      }   
  
     ++i;
     f=1;
     j=0;
  }
  </code></pre>
  
  <p>I want the above code snippet to read a line of strings separated by spaces and tabs until ONE EOF but it requires 2 EOFs to end the loop. Also, strings can consist of only alphabetic characters.</p>
  
  <p>I am struggling on about 2 days.
  Please, give some feedback.</p>
  
  <p>EDIT: Most probably the reason is I hit CTRL+D keys after I write last string not the enter key, but now I hit enter and then CTRL+D, it works as expected.
  But, how can I change it to finish after I hit  CTRL+D once following the last string?</p>