2

what i tried is... I am writing code to print all the c-language character set ASCII codes [0-255] along with characters (256)! As we know in C, function declaration or header file declaration is optional!

void main()
{
  int i = 0;
  char c1, c2;

  printf("ASCII code\tCharacter\n");
  printf("----------\t---------\n");

  //printing
  while (i <= 255)
  {
    printf("%d\t%c\n", i, i);
    i += 1;
  }

  /*
   my code to move the cursor in console screen
   using up & down arrows!
   ASCII codes of up & down arrows are(0 & 72) & (0 & 80)
   when i press any other non-data key it comeout from program!
  */
  c1 = getch();

  while (c1 == 0)
  {
     c2 = getch();

    if (c2 == 72)//up arrow
       gotoxy(wherex(), wherey()-1);

    else if (c2 == 80)
       gotoxy(wherex(), wherey()+1);

    else //any other key
       break;

    c1 = getch();
  }
}

In turbo-C IDE i can able to see only last console screen, and i can able to move the cursor only within that 1 page console screen only! What i need to do is i want to see from 0th ASCII onwards!

What i got in turbo-C IDE is...

In Turbo-C IDE output: only 1 screen

I am also using Borland-C++ 5.02 IDE. In that IDE i can't even move the cursor! But i am sure gotoxy(), wherex(), wherey() functions are working in that Borland-C++ IDE. Because i allredy checked by writing a small piece of code only accepting arrow keys and functions also worked properly. Actually i am a new be for C/C++. Just working out advanced level for my practise only!

Then, I have downloaded the following C/C++ IDE for my windows7 OS.

<Dev-C++ 5.4.0 verion IDE>.

In that IDE when i use these functions...

gotoxy(), wherex(), wherey()

Undefined reference to 'gotoxy', 'wherex', 'wherey' linker errors.

I saw a question in this site. I was instructed to download latest header file from http://conio.sourceforge.net/ and I got the same errors!

Can anyone suggest me? i am just willing to write some funny and tricky console screen programs. seeking help, for how to add external conio library for dev-C++ IDE or code-blocks IDE? please provide me with fully in detail! I must need the solution on other than turbo-C++ IDE, preferable DEV-C++ OR CODE-BLOCK-IDE FOR WINDOWS7 OS! giving links more help full for me! thanks in advance

Omkar
  • 35
  • 1
  • 4
  • "function declaration or header file declaration is optional". Sure. But why do you think they exist? They make life easier, not harder. – MSalters Nov 20 '13 at 09:34

3 Answers3

2

This is what happens when you use non-ANSI functions and you move to another compiler.

You evidently are compiling C code that came from DOS and the Borland compiler. These specific functions don't exist in Unix.

The Compiler that Dev-C++ uses is a MinGW. So you will need to add "conio.c" to your project and include it your headers

AnaMaria
  • 3,520
  • 3
  • 19
  • 36
1

You need to link with the conio library. Add -lconio to the linker parameters under Project Options.

The linker parameters

If that doesn't work, make sure you have actually downloaded the conio library and put it in the right directory (you'll need the conio2.h file as well as the libconio.a file, which is the library itself).

Wander Nauta
  • 18,832
  • 1
  • 45
  • 62
  • Please review my question and tell me How to add? can you please clearly mention! I have downloaded the conio2.h here in that it clearly mentioned conio for Dev-C++ IDE. My OS is windows7. How to add external library? – Omkar Aug 04 '13 at 15:32
0

The Windows C file conio.h lacks the definition of those functions, but they can be defined.

You can find the functions you need here -> Windows Console Functions

Here are the requested functions defined

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

void gotoxy(short int x, short int y)
{
    COORD pos = { x, y };    
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

int wherex()
{
    CONSOLE_SCREEN_BUFFER_INFO csbi;    
    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);    
    return csbi.dwCursorPosition.X;
}

int wherey()
{
    CONSOLE_SCREEN_BUFFER_INFO csbi;    
    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);    
    return csbi.dwCursorPosition.Y;
}
Alejandro Caro
  • 998
  • 1
  • 10
  • 22