2

I'm working with Code::Blocks and the thing is I tried many times to fix the problem with the Conio library and probably some other libraries as well. Every time I use something like clrscr(); textcolor(); or anything it says ;

 Undefined reference to textcolor.

For example, this simple program is supposed to show the sum in a specific color but it's not working out though I have seen it work before.

#include <stdio.h>
#include <conio.h>
int fx(int x,int y,int z)
{
   return x+y+z;
}
int main()
{
   int a,b,c;
printf("Enter three values to a, b and c.\n");
scanf("%d%d%d",&a,&b,&c);
int total=fx(a,b,c);
textcolor(14);
printf("Output ="); cprintf(" %d",&total);
getch();
return 0;
}

P.S.: I'm using GNU GCC. And sometimes when I select another compiler or just open Code::Blocks it says, "Some plugins are missing," or something like that. Can anyone help??

elixenide
  • 44,308
  • 16
  • 74
  • 100
OsomePersan
  • 21
  • 1
  • 1
  • 4
  • These are ancient Borland CRT functions, dating back to the DOS days. They've never been part of any standard CRT implementation. – Hans Passant Mar 02 '14 at 09:31
  • Just for info: conio.h is also supported by MS but it does not support textcolor. If you want to play with colours using MS, have a look at the wincon.h routines (from kernel32.lib) – cup Mar 02 '14 at 11:08

5 Answers5

2

conio.h is not supported with gcc.

Pranit Kothari
  • 9,721
  • 10
  • 61
  • 137
1

conio.h is not supported by gcc. Here is an implementation of conio.h for gcc though.

HelloWorld123456789
  • 5,299
  • 3
  • 23
  • 33
0

conio.h is not supported in gcc. You may try the curses library, which supports creation of text-user interface. There are many flavor of curses, you may use ncurses or pdcurses library with code-blocks.

Umar Ahmad
  • 410
  • 4
  • 15
0

Some of the functions in the original Borland conio.h are easy to duplicate -- I've recently been porting from Turbo-C programs (from 1990!) to gcc, and found versions of getch and getche (for Linux) that I could use online (but not the C++ version, which won't compile using the gcc command). I wrote my own version of cgets, but haven't found the need to create my own versions of the other functions from that header file yet.

char getch()
{
  char c; // This function should return the keystroke without allowing it to echo on screen

  system("stty raw");    // Raw input - wait for only a single keystroke
  system("stty -echo");  // Echo off
  c = getchar();
  system("stty cooked"); // Cooked input - reset
  system("stty echo");   // Echo on - Reset
  return c;
}

char getche()
{
  char c; // This function should return the keystroke, with echo to screen

  system ("stty raw");      // Raw input - wait for only a single keystroke
  c = getchar();
  system ("stty cooked");   // Cooked input - reset
  return c;
}

char *cgets(char *buf)

/* gets a string from console and stores it in *buf; buf[0] must be initialized to maximum string size and *buf must
be declared by caller to maximum string size plus 3 bytes, to accommodate string, terminating null, size byte in buf[0]
and length of entered string in buf[1]; sets buf[1] to length of string entered and returns pointer to buf[2] */

{

    /* declare and initialize internal variables */

  unsigned int count = 2;   /* start at 2 because [0] is max size including terminator and [1] returns actual */
                /* entry size, also including terminating null */
  char input = '\0';        /* initialize to null */

/* start actual function */

  while (count < buf[0] + 2)    /* while within permitted string length -- +2 for size control bytes */
  {
    input=getch();      /* get a single character, without echo */
    if (input != (char) 13) /* not cr/enter key -- presumed meaningful input */
    {
      printf("%c",input);
      buf[count++] = input; /* store character and increment counter */
    }
      else
      {
    buf[count] = '\0';  /* change cr/enter key to terminating null */
    buf[1]=(char) count - 2;/* store length of entered string (including terminating null) */
    count = buf[0] + 2; /* terminate entry loop -- +2 for size control again */
      }

    }

    return &buf[2];     /* return pointer to start of string */
}

The key thing to remember is that an included file (such as conio.h) doesn't have to be precompiled; it can be just as functional if it's just more C source code.

Zeiss Ikon
  • 481
  • 4
  • 13
0

Try this library: https://sourceforge.net/projects/coniohcloneturboccpp/.

The CONIO features for Windows and Linux are almost complete. It seems to work well.