title: Reading in a variable length string user input in C
body: <p>I am trying to read in a variable length user input and perform some operation (like searching for a sub string within a string).</p>
  
  <p>The issue is that I am not aware how large my strings (it is quite possible that the text can be 3000-4000 characters) can be. </p>
  
  <p>I am attaching the sample code which I have tried and the output:</p>
  
  <pre><code>char t[],p[];
  int main(int argc, char** argv) {
      fflush(stdin);
      printf(" enter a string\n");
      scanf("%s",t);
  
      printf(" enter a pattern\n");
      scanf("%s",p);
  
      int m=strlen(t);
      int n =strlen(p);
      printf(" text is %s %d  pattrn is %s %d \n",t,m,p,n);
      return (EXIT_SUCCESS);
  }
  </code></pre>
  
  <p>and the output is :</p>
  
  <pre><code>enter a string
  bhavya
  enter a pattern
  av
  text is bav 3  pattrn is av 2
  </code></pre>