Please, someone explain me why when I compile this code in Dev-C++ (Windows OS) the following error message apears: 'clrscr' undeclared (first use this function)

int main()
{ int c;
char d;
clrscr();
printf(" Example program for PSC232 \n");
setup();

printf("*IDN?\n\r");
send("*IDN?\n");
printf("RECEIVE...\n\r");
loop:
receive();

goto loop;
}

ps: ignore the functions setup, send and receive

Dani AI

Generated

the error happens because clrscr was a Borland/Turbo C DOS-era helper in conio.h, not part of the C or C++ standards. Dev-C++ uses GCC/MinGW, whose conio.h does not provide clrscr, so the identifier is unknown at compile time. Your workaround (calling the OS to clear the console) is fine for throwaway tools, but it is non-portable and relatively slow since it spawns a shell. is right that it works on Windows; here is a more portable approach you can drop in without extra libraries.

#include <stdio.h>

#ifdef _WIN32
#include <windows.h>
#endif

void clear_screen(void) {
#ifdef _WIN32
    HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
    DWORD mode;
    if (h != INVALID_HANDLE_VALUE && GetConsoleMode(h, &mode)) {
        SetConsoleMode(h, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
    }
#endif
    fputs("\x1b[2J\x1b[H", stdout);  /* ANSI: clear + home */
    fflush(stdout);
}

Notes:

  • On most Unix-like terminals this works out of the box. On newer Windows consoles it works once VT processing is enabled as above. If you are stuck on an old console that does not support ANSI, keep your existing workaround as a fallback.
  • Avoid goto for the receive loop. A simple infinite loop is clearer and easier to maintain:
for (;;) {
    receive();
}
  • Minor I/O tip: for console output, \n is enough; mixing \n\r is usually unnecessary. For instrument commands like *IDN?, many SCPI devices expect \n (some accept \r\n). Keep the console prints and wire protocol separate to avoid confusion.

I've just found a way to solve the problem. Include the stdlib library (#include <stdlib.h>;) and instead of clrscr(); code replace for system("cls"); and voilá it works.

On windows, you can do

system("cls")

to clear the screen

*Didnt see that you had posted and answered your own question lol

Thankx tokenjoker187

You're Welcome...

Also, with my experience with DevC++, getting 3rd party libraries are a pain. This is just a suggestion, but if you are unhappy with DevC++, try CodeBlocks IDE. It has plugins available for things like source code formatting and a class wizard. The other great thing is autocomplete. If you start programming in GTK or have 3rd party libraries you can hit CTRL+Space to get function names.

I'll take a look on CodeBlocks IDE.

I'm using DevC++ only for this project, normally I use NetBeans IDE. Take a look...

Thankx again...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.