title: Why am I getting a segmentation fault when I run this code?
body: <p>I'm learning the use of the switch statement and using the rand() and srand() functions  but then I'm getting a segmentation fault when I try to run this code I got from this book I'm learning C from. What's could be causing this to happen?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
  
  int iRandomNum = 0;
  srand(time());
  
  iRandomNum = (rand() % 4) + 1;
  
  printf("\nFortune Cookie - Chapter 3\n");
  
    switch (iRandomNum) {
  
     case 1:
        printf("\nYou will meet a new friend today.\n");
        break;
     case 2:
        printf("\nYou will enjoy a long and happy life.\n");
        break;
     case 3:
        printf("\nOpportunity knocks softly. Can you hear it?\n");
        break;
     case 4:
       printf("\nYou'll be financially rewarded for your good deeds.\n");
        break;
  
    } //end switch
  
  printf("\nLucky lotto numbers: ");
  printf("%d ", (rand() % 49) + 1);
  printf("%d ", (rand() % 49) + 1);
  printf("%d ", (rand() % 49) + 1);
  printf("%d ", (rand() % 49) + 1);
  printf("%d ", (rand() % 49) + 1);
  printf("%d\n", (rand() % 49) + 1);
  
  } //end main function
  </code></pre>