title: unable to read from stdin inside a loop
body: <p>This code works when these lines are commented out as shown.But if those 4 lines are uncommented,there is a SIGSEV fault-string 's' does not get initialised . How is it that a function call works at its own but not in a loop ? when the loop has nothing to do with the function's data. </p>
  
  <pre><code>  #define yes 1
      #define no 0
      #include&lt;stdio.h&gt;
      #include&lt;stdlib.h&gt;
      #include&lt;string.h&gt;
      char *readline(FILE *f){
          char *buff=NULL,*newbuff=NULL,c;
          int buf_sz=1,len=0;
          int keep_going=yes;
          while(keep_going){
              c=fgetc(f);
              if(c==EOF || c=='\n'){
                  keep_going=no;
                  break;
              }
              if(len==buf_sz-1 &amp;&amp; keep_going!=no){
                  if(!buff){
                      buf_sz=512;
                      newbuff=malloc(buf_sz);
                  }
                  else{
                      buf_sz*=2;
                      newbuff=realloc(buff,buf_sz);
                  }
                  buff=newbuff;
              }
              buff[len++]=c;
          }
          return buff;
      }
      int main(){
          char *s;
          int l,left_mid,right_mid,lp,rp,change=no;
      //  int n;
      //  scanf("%d",&amp;n);
      //  while(n--){
          s=readline(stdin);
          l=strlen(s);
              printf("%d",l);
          //}
  
              return 0;
  
            }
  </code></pre>