-1

For the second part of my project I'm trying to clear the screen after each operation using system("clear");.

This works fine but my teacher/lecturer works with windows and they get the following message in the console when they reach the cls:

'clear' is not recognized as an internal or external command, operable program or batch file.

In that case I would have to change the system("clear") to system("cls");.

Is there anyway that I can check the OS and get the program to switch between "cls" and '"clear"`?

Here is my 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", & code);
// reading item code
while (code != 'T' && code != 'B' && code != 'C') {
  printf("Enter corresponding item code: \n");
  scanf(" %c", & code);
  getchar();
  system("clear");
}
LogicalBranch
  • 4,248
  • 4
  • 21
  • 54

1 Answers1

0

Try using this instead:

system("clear | cls")

You could also try using two pipes (||) instead of one (|), like this:

system("clear || cls")
LogicalBranch
  • 4,248
  • 4
  • 21
  • 54
Yoran Jansen
  • 367
  • 5
  • 22