[Ilugc] First Encounter with GCC

  • From: girishvenkatachalam@xxxxxxxxx (Girish Venkatachalam)
  • Date: Thu, 28 Jul 2011 13:22:01 +0530

On Thu, Jul 28, 2011 at 12:01 PM, Avinash Sonawane
<avinash.sonawane1990 at gmail.com> wrote:

Sir,
Since this is my first encounter with GCC, I am totally a newbie.

This is g++

When I tried to run the following program using GCC it gave me some errors.

Program :

# include <stdio.h>
# include <conio.h>

?void main()
{
clrscr();
printf("First program using GCC");
getch();
}


This is not a C program at all. Just remove "include <conio.h>" and
 it will compile.

$ make f

if the program is f.c

or

$ gcc f.c -o f

of even just

$ gcc f.c

output in a.out.

Run it with

$ ./a.out

If you want to compile only and not link

then

$ gcc -c f.c

If you want to only preprocess then

$ gcc -E f.c

and so on.

You can also use the

$ gcc -O2

switch along with others like -fomit-frame-pointer and
 100 other switches.

Errors:

first.c:2:20: fatal error: conio.h: No such file or directory
compilation terminated.


You don't need this. It is a C program. Not C++.

When I removed conio.h header file it gave me errors regarding clrscr() and
getch() since these two functions are defined in conio.h

These are nCurses calls. Include

#include <curses.h>

or just

$ man getch

Here is an except:


urs_getch(3)                                                    curs_getch(3)

NAME
       getch, wgetch, mvgetch, mvwgetch, ungetch, has_key - get (or push back)
       characters from curses terminal keyboard

SYNOPSIS
       #include <curses.h>

       int getch(void);
       int wgetch(WINDOW *win);
       int mvgetch(int y, int x);
       int mvwgetch(WINDOW *win, int y, int x);
       int ungetch(int ch);
       int has_key(int ch);

So my questions are:
1) How to clear the output screen (replacement of clrscr() ) in GCC ?

It is not a compiler thing. This is a nCurses library feature.

C is meant to be a very thin language with most features provided by
standard libraries.

As opposed to perl or python where the language itself has  several
OS, networking and
 file I/O bindings.

2) Is there any similar ?kind of replacement for getch() too ?

Yeah. Without using nCurses you can do getchar(). This is available as
part of standard
 C library.

3) Why conio.h doesn't work in GCC ?

Because it is C++.

Don't learn it. C is a great language. Stick to it.


Avinash Sonawane
PICT Pune
Facebook <http://www.facebook.com/avinash.sonawane1990>

Not needed.

Twitter <http://www.twitter.com/SonawaneAvinash>

Either have a serious signature like me or have none at all. ;)

-Girish

-- 
G3 Tech
Networking appliance company
web: http://g3tech.in ?mail: girish at g3tech.in

Other related posts: