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 ;
我正在处理代码::Blocks,关键是我尝试了很多次来解决Conio库以及其他一些库的问题。每次我使用clrscr()之类的东西;输入textcolor();或者它说的任何话;
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??
注:我正在使用GNU GCC。有时当我选择另一个编译器或打开代码::block时,它会说“有些插件丢失了”,或者类似的东西。谁能帮忙吗? ?
4 个解决方案
#1
1
conio.h
is not supported with gcc.
conio。gcc不支持h。
#2
0
conio.h
is not supported by gcc
. Here is an implementation of conio.h
for gcc
though.
conio。gcc不支持h。下面是conio的实现。尽管h为gcc。
#3
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.
conio。在gcc中不支持h。您可以尝试curses库,它支持创建文本用户界面。诅咒有很多味道,你可以使用带有代码块的ncurses或pdcurses库。
#4
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.
一些功能在最初的Borland conio。h很容易复制——我最近从Turbo-C程序(从1990年开始)移植到gcc,发现了getch和getche(用于Linux)的版本,我可以在网上使用(但不能使用gcc命令编译c++版本)。我编写了自己的cget版本,但是还没有发现需要从那个头文件中创建我自己的其他函数版本。
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.
需要记住的关键是,包含的文件(如conio.h)不必预先编译;如果它只是更多的C源代码,它也可以具有同样的功能。
#1
1
conio.h
is not supported with gcc.
conio。gcc不支持h。
#2
0
conio.h
is not supported by gcc
. Here is an implementation of conio.h
for gcc
though.
conio。gcc不支持h。下面是conio的实现。尽管h为gcc。
#3
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.
conio。在gcc中不支持h。您可以尝试curses库,它支持创建文本用户界面。诅咒有很多味道,你可以使用带有代码块的ncurses或pdcurses库。
#4
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.
一些功能在最初的Borland conio。h很容易复制——我最近从Turbo-C程序(从1990年开始)移植到gcc,发现了getch和getche(用于Linux)的版本,我可以在网上使用(但不能使用gcc命令编译c++版本)。我编写了自己的cget版本,但是还没有发现需要从那个头文件中创建我自己的其他函数版本。
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.
需要记住的关键是,包含的文件(如conio.h)不必预先编译;如果它只是更多的C源代码,它也可以具有同样的功能。