title: Timeout Function
body: <p>I want to make a code in which Name of User will be asked to input, but in a time limit of 15 seconds. If user cross the limit &amp; failed to input a name(or any string), then code will be terminated &amp; "Time Out" Massage will be display otherwise Name should be saved &amp; "Thanks" massage will be display. I had try like this but it's wrong &amp; not working. Please give me a solution for this.. Thanks.   </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;time.h&gt;
  
  int timeout ( int seconds )
  {
      clock_t endwait;
      endwait = clock () + seconds * CLOCKS_PER_SEC ;
      while (clock() &lt; endwait) {}
  
      return  1;
  }
  
  int main ()
  {
      char name[20];
      printf("Enter Username: (in 15 seconds)\n");
      printf("Time start now!!!\n");
  
      scanf("%s",name);
      if( timeout(5) == 1 ){
          printf("Time Out\n");
          return 0;
      }
  
      printf("Thnaks\n");
      return 0;
  }
  </code></pre>