Thread: How to change color in menu selection in C

  1. #1
    Registered User
    Join Date
    Feb 2019
    Posts
    2

    How to change color in menu selection in C

    I started learning C at college and have some problem here, I created a simple menu using switch case, when i select the function of the menu I want the funtion selected change color then it go to the function, please help me, thank you How to change color in menu selection in C-untitled-jpg

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    36,906
    Which compiler are you using.

    Show us the 10 or so lines of code you use to just print the menu.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    2
    Quote Originally Posted by Salem View Post
    Which compiler are you using.

    Show us the 10 or so lines of code you use to just print the menu.
    Sorry, my internet connection lost these days
    Here is the code
    Code:
    #include<stdio.h>#include<conio.h>
    #include<stdlib.h>
    #include<windows.h>
    typedef struct {
    	unsigned int Ngay , Thang , Nam;
    } Date;
    
    
    typedef struct {
    	char FirstName[20];
    	char LastName[10];
    } Name;
    
    
    typedef struct {
    	Name ten;
    	char maLop[10];
    	char masinhvien[10];
    	Date dob;
    	float diemtrungbinhtichluy;
    } SinhVien;
    void M1(){
    	
    }
    void Writefile(char *file){
    	FILE *f;
    	int n,i;
    	
    }
    void M2(){
    	system("cls");
    			printf("+--------------------------------+DANH SACH SINH VIEN+---------------------------+\n\n");
    			printf("+------------------+--------------+-------------------+-----------------+--------+\n");
    			printf("|     Ho Va Ten    |    Ma Lop    |    Ma Sinh vien   |    Ngay Sinh    |   DTB  |\n");
    			printf("+------------------+--------------+-------------------+-----------------+--------+\n");
    			printf("+------------------+--------------+-------------------+-----------------+--------+\n");
    			getch();
    }
    void sapxep_key(){
    	system("cls");
    	printf("Cac khoa sap xep:\n");
    	printf("1.Ten\n");
    	printf("2.Ngay sinh\n");
    	printf("3.Diem TB\n");
    	printf("Enter your choice: ");
    	int temp;
    	scanf("%d",&temp);
    	getch();
    }
    void M3(){
    	system("cls");
    	printf("1.Sap xep chon\n");
    	printf("2.Sap xep noi bot\n");
    	printf("3.Sap xep nhanh\n");
    	printf("Enter your choice: ");
    	int temp;
    	scanf("%d",&temp);
    	switch(temp){
    		case 1:{
    			sapxep_key();
    			break;
    		}
    		case 2:{
    			sapxep_key();
    			break;
    		}
    		case 3:{
    			sapxep_key();
    			break;
    		}
    		getch();
    	}	
    }
    void timkiem_key(){
    	system("cls");
    	printf("Cac khoa tim kiem:\n");
    	printf("1.Ten\n");
    	printf("2.Ngay sinh\n");
    	printf("3.Diem TB\n");
    	printf("Enter your choice: ");
    	int temp;
    	scanf("%d",&temp);
    	getch();
    	}
    void M4(){
    	system("cls");
    	printf("1.Tim kiem tuan tu\n");
    	printf("2.Tim kiem nhi phan\n");
    	printf("Enter your choice: ");
    	int temp;
    	scanf("%d",&temp);
    	switch(temp){
    		case 1:{
    			timkiem_key();
    			break;
    		}
    		case 2:{
    			timkiem_key();
    			break;
    		}
    		getch();
    	}	
    }
    void M5(){
    	system("cls");
    	printf("1.Thong ke so luong SV theo lop\n");
    	printf("2.Thong ke phan loai ket qua hoc tap\n");
    	printf("Enter your choice: ");
    	int temp;
    	scanf("%d",&temp);
    	switch(temp){
    		case 1:{
    			break;
    		}
    		case 2:{
    			break;
    		}
    	}
    	getch();
    }
    int main(){
    	Sinhvien sv;
    	int temp;
    	do{
    	printf("====MENU QLSV====\n");
    	printf("1.Them moi ho so\n");
    	printf("2.In danh sach\n");
    	printf("3.Sap xep\n");
    	printf("4.Tim kiem\n");
    	printf("5.Thong ke\n");
    	printf("0.Thoat\n");
    	printf("Enter your choice: ");
    	scanf("%d",&temp);
    	switch(temp){
    		case 1:{
    			M1();
    			break;
    		}
    		case 2:{
    			M2();
    			system("cls");
    			break;
    		}
    		case 3:{
    			system("color 3");
    			M3();
    			system("cls");
    			break;
    		}
    		case 4:{
    			M4();
    			system("cls");
    			break;
    		}
    		case 5:{
    			M5();
    			system("cls");
    			break;
    		}
    		case 0:
    		  	break;
    	}
    	}while(temp!=0);
    	getch();
    	return 0;
    }
    I tried to use windows.h library, but don't know what to do? pls help me

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    36,906
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. i need help on my pseucode for do a selection color effect
    By joaquim in forum Game Programming
    Replies: 1
    Last Post: 03-28-2016, 10:18 AM
  2. How do i change backround color and text color?
    By Nathan the noob in forum C++ Programming
    Replies: 1
    Last Post: 02-17-2009, 04:39 AM
  3. Listview selection change
    By twomers in forum Windows Programming
    Replies: 1
    Last Post: 02-07-2009, 10:16 AM
  4. menu selection trouble
    By Spectrum48k in forum C Programming
    Replies: 13
    Last Post: 11-20-2002, 11:06 PM
  5. Menu Selection
    By Ruski in forum C++ Programming
    Replies: 13
    Last Post: 10-12-2002, 09:11 PM

Tags for this Thread