วันเสาร์ที่ 29 มกราคม พ.ศ. 2554

system("cls")

ฟังก์ชัน system("cls")
คำสั่งให้ โปรแกรมล้างจอภาพใหม่ Clear Screen เหมือนกับการ run โปรแกรมใหม่

ตัวอย่าง นิยมใช้กับการทำงาน Loop ที่ไม่รู้จบ while(1) เพื่อความสวยงามของโปรแกรม

Coding:

#include
int main (void){
int num1;
while(1){
printf("1.Red\n");
printf("2.Green\n");
printf("3.Black\n");
printf("4.Pink\n");
printf("5.Blue\n");
printf("0.Exit\n\n");

printf("Select->Color :");
scanf("%d",&num1);
if(num1==1){
printf("You Color is Red\n");
}
if(num1==2){
printf("You Color is Green\n");
}
if(num1==3){
printf("You Color is Black\n");
}
if(num1==4){
printf("You Color is Pink\n");
}
if(num1==5){
printf("You Color is Blue\n");
}
if(num1==0){
break;
}
system("pause");
system("cls");
}

}


Output:

1.Red
2.Green
3.Black
4.Pink
5.Blue
0.Exit

Select->Color :4
You Color is Pink

2 ความคิดเห็น:

Hosekil กล่าวว่า...

คำสั่ง system("cls")
จำเป็นต้อง #include ด้วยมั้ยครับ?

Hosekil กล่าวว่า...

"stdlib.h"

Popular Posts