469,613 Members | 2,028 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

Colour output to the console

(in C programing)
who knows the name of some function which can be used for printing tables or for printing some colorful outputs?
i want to print some data in red color and also want to print and scan some data in table,what shuold i do?
Jan 13 '07 #1
7 3065
Ganon11
3,652 Expert 2GB
Please do not double-post your questions. It will not help them get answered more quickly, it only clutters up the thread list. The second topic has been deleted.
Jan 13 '07 #2
Banfa
9,064 Expert Mod 8TB
colour printing depends entirely on the platform you are using. We will need to know the platform to be able to help.
Jan 13 '07 #3
well,i actually don't understand what you mean from"platform "...!
if you mean the style of my program...well,i have to write a program which make a file for storring data and then using these data in some function...
(data will be taken in form of structures) .here is a piece of this:

Expand|Select|Wrap|Line Numbers
  1.  #include<stdio.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5.  struct INFORMATION{
  6.         long student_number;
  7.         char first_name[20];
  8.         char last_name[20];
  9.         float grade[100];
  10.         int grade_number;
  11.         int unit[100];}info[50];
  12. int menu(void);
  13. void add_student(void);
  14. void view_student(void);
  15. void main()
  16.   {
  17.      clrscr();
  18.      for(;;)
  19.         switch(menu()){
  20.             case 1 : add_student(); break;
  21.             case 2 : view_student(); break;
  22.             case 6 : exit(1);
  23.               }/*End of switch & for*/
  24.      }/*End of main*/
  25. int menu(void)
  26.   {
  27.      int index;
  28.  do{  clrscr();
  29.      gotoxy(5,5);
  30.      printf("<<menu of choices:>>");
  31.      gotoxy(5,7);
  32.      printf("1) Adding a student.");
  33.      gotoxy(5,9);
  34.      printf("2) viewing a student's information.");
  35.      gotoxy(5,11);
  36.      printf("3) Editting a student's information.");
  37.      gotoxy(5,13);
  38.      printf("4) Deleting a student.");
  39.      gotoxy(5,15);
  40.      printf("5) List of students' information.");
  41.      gotoxy(5,17);
  42.      printf("6) Exit setup.");
  43.      gotoxy(5,19);
  44.      printf("enter you select,then press Enter key:");
  45.      scanf("%d",&index);}
  46.      while(6<=index && index<=1);
  47.      return index;
  48.      }/*End of menu function*/
  49. //**************************
  50. void add_student()
  51.   {
  52.     FILE *ptfile;
  53.     static int m=0;
  54.     int course_no=0, index, index1;
  55.     char strno[20];
  56.     clrscr();
  57.     getch();
  58.     ptfile=fopen("fmain.dat","a");
  59.     if(!ptfile)
  60.       {printf("\n can not open the file.");
  61.         getch();
  62.         exit(1);}
  63.         for(index=0 ; index<50 ;index++)
  64.         { info[index].first_name[0]='\0' ;
  65.           info[index].last_name[0]='\0' ;
  66.           info[index].grade[0]='\0' ;
  67.           info[index].unit[0]='\0' ;
  68.           info[index].student_number=0;
  69.           info[index].grade_number=0;}
  70.     info[m].grade_number=0;
  71.     gotoxy(5,5);
  72.     printf("Please enter the student number:");
  73.     scanf("%s",strno);
  74.     info[m].student_number=atoi(strno);
  75.     gotoxy(19,7);
  76.     printf("first name :"); scanf("%s",info[m].first_name);
  77.     gotoxy(19,9);
  78.     printf("last name :");  scanf("%s",info[m].last_name);
  79.     gotoxy(19,11);
  80.     printf(" number of courses :");
  81.     scanf("%d",&course_no);
  82.     for(index1=0 ; index1<course_no ;index1++)
  83.         {gotoxy(19,13);
  84.          printf("grade of course number %d .",index1+1);
  85.          scanf("%s",strno);
  86.          info[m].grade[index1]=atoi(strno);
  87.          gotoxy(19,15);
  88.          printf("unit of course number %d .",index1+1);
  89.         scanf("%s",strno); info[m].unit[index1]=atoi(strno);
  90.  
  91.  (info[m].grade_number)+=(info[m].grade[index1])*(info[m].unit[index1]);}
  92.     (info[m].grade_number)/=course_no ;
  93.     fwrite( &info[m] , sizeof(INFORMATION), 1 ,ptfile);
  94.     m++;
  95.     fclose(ptfile);
  96.     printf("Press any key to continue...");
  97.     getch();
  98.     }
  99. void view_student()
  100.   {
  101.     clrscr();
  102.     FILE *ptfile;
  103.     long number=0,variable=0;
  104.     char strno[20];
  105.     int index=0 ,index1;
  106.     ptfile=fopen("fmain.dat","r");
  107.     if(!ptfile)
  108.         { printf("can not open the file.");
  109.          getch();
  110.          exit(1);}
  111.     printf("Please enter the student's number:\n");
  112.     scanf("%s",strno);  number=atoi(strno);
  113.     fread( &info[index], sizeof(INFORMATION) ,1,ptfile);
  114.     for( index=0 ;  !feof(ptfile) ;index++)
  115.      { if(number==info[index].student_number)
  116.       {
  117.        gotoxy(5,5);
  118.        printf("number: %ld",info[index].grade_number);
  119.       gotoxy(5,6);
  120.                   printf("first name: %s",info[index].first_name);
  121.       gotoxy(5,7);
  122.       printf("last name: %s",info[index].last_name);
  123.       gotoxy(5,9);
  124.        printf("avrage: %d",info[index].grade_number);
  125.        gotoxy(5,10)  ;
  126.        for(index1=1; info[index].grade;index1++)
  127.  
  128. {printf("%d) %f %d",index1,info[index].grade[index1],info[index].unit[index1]);
  129.     gotoxy(5,10+index);
  130.             }
  131.     variable=number;
  132.          }
  133. fread( &info[index+1], sizeof(INFORMATION) ,1,ptfile);
  134.                      }
  135.       if(!variable)
  136.       printf("can not find the student\n");
  137.       fclose(ptfile);
  138.     printf("press any keyto continue...");
  139.     getch();
  140.  
  141.     }/*End of view_student*/
  142. //****************************************
  143.  
Jan 14 '07 #4
Banfa
9,064 Expert Mod 8TB
colour printing depends entirely on the platform you are using. We will need to know the platform to be able to help.
By platform I mean

What OS
What Compiler
What Computer/CPU Chipset
Jan 14 '07 #5
By platform I mean

What OS
What Compiler
What Computer/CPU Chipset
microsoft
Turbo C++ 4.5
intel(R)
Jan 14 '07 #6
Banfa
9,064 Expert Mod 8TB
I believe the Borland C++ has a function cprint or cprintf that outputs in colour. But you will have to look it up as I do not know anything about it.
Jan 14 '07 #7
Ganon11
3,652 Expert 2GB
You can also use a system() call to generate basic background and text colors. Open up a command prompt and type "color fg" to get the basics on how it works. In your program, you will use a call like

Expand|Select|Wrap|Line Numbers
  1. system("COLOR XY");
where X and Y are color constants that you will see in your command prompt when you test it out.
Jan 14 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Bob | last post: by
2 posts views Thread by Steve | last post: by
4 posts views Thread by gurdz | last post: by
1 post views Thread by skeete1990 | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.