title: How to clear screen in both windows and linux in C
body: <p>For the second part of my project I'm trying to clear the screen after each operation using <code>system("clear");</code>.</p>
  
  <p>This works fine but my teacher/lecturer works with windows and they get the following message in the console when they reach the <code>cls</code>:</p>
  
  <blockquote>
    <p><code>'clear' is not recognized as an internal or external command,
    operable program or batch file.</code></p>
  </blockquote>
  
  <p>In that case I would have to change the <code>system("clear")</code> to <code>system("cls");</code>. </p>
  
  <p>Is there anyway that I can check the OS and get the program to switch between <code>"cls"</code> and '"clear"`?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>printf("Please provide name: \n");
  scanf("%[^\n]s", contact_name);
  getchar();
  system("clear");
  printf("Please provide contact number: \n");
  scanf("%[^\n]s", tel_num);
  getchar();
  system("clear");
  // items
  printf("\t\t\t\t  Our Apparels: \n");
  printf("\t\t\tApparels\t\tItem code\n");
  printf("\t\t\ta)T-Shirts\t\t'T'\n");
  printf("\t\t\tb)Bags\t\t\t'B'\n");
  printf("\t\t\tc)Caps\t\t\t'C'\n\n");
  printf("Enter corresponding item code: \n");
  scanf(" %c", &amp; code);
  // reading item code
  while (code != 'T' &amp;&amp; code != 'B' &amp;&amp; code != 'C') {
    printf("Enter corresponding item code: \n");
    scanf(" %c", &amp; code);
    getchar();
    system("clear");
  }
  </code></pre>