Newbie: About C/Java programming

Hi everyone. Altought the title says i’m newbie that’s not absolutely correct, simce i’m familiar with openSuSE. The Newbie comes here:

I have installed GCC 4.2.2. How can i run and make ejecutables from C source codes using good old printf, scanf and so on? There is any limitation between windows execs and linux ones? Apart from the FS paths etc, that is.

I’ll develop in java too. Can you give me directions on a ready environment to compile and run java source codes? This is for university, so if you can be prompt in answering you will be given sweet thanks.

Thank you in advance!

Hey…I suppose you are good enough with C/C++. Put your code in filename.c and save it at some location. Now go there and do “gcc filename.c”(from terminal ofcourse). This creates an executable named “a.out”. Run this by “./a.out”.
Regarding java, install latest sun’s jdk and then I recommend you to install netbeans(IDE). Just google your query put “linux” at the end :).

Hi, thank you for your response!

I cannot use clrscr. Can you provide me with any solution? I included stdio, but can’t include CONIO because gcc can’t find it.

Where can i find the header files? Also, can you provide me with a little but useful appendix on which functions do they include? (This is C knowledge and not SuSE? perhaps.)

Sorry for all those simple questions, but i have to print and show those codes running on monday…

Hi

Header files are in /usr/include directory. You can look directly at the code to see what they define. The C library function are described in the man pages. man is your friend!

There is no clrscr. You have to send ANSI escape sequences to the terminal (see man console_codes). To clear the screen you would send “ESC 2 J” (4 characters).

Hope this gets you started.

Man of what? GCC?

I’ve also fund the header files. Thanks a lot!

And hhow can i pass the ANSI codes from a C code?

I’ve got this rolling! Thank you very much! :slight_smile:

man for ASCI codes ]

> …] (see man console_codes) …]

That was meant literally :slight_smile: the man page for console codes, to be seen by invoking “man console_codes” :smiley:

header files ]

conio.h is not part of standard C but an old DOS relict… see conio.h - Wikipedia, the free encyclopedia

[ANSI codes]

You pass these by simply writing them to the terminal - which will be “stdout”. I strongly recommend to add an abstraction layer for layouted screen handling (and “clearing the screen” already uses the concept of a screen layout!) as there are many ways to skin that cat and you’ll probably want to switch to more elaborate mechanisms later on (ie ncurses or even graphical UIs).

Regards

Jens

Wow, that of conio.h is new.

I’ve recently migrated to 100% C programing under suse, so i’ve said goodbye to borland C, which i used before this one, that’s why i’m having trouble using pause functions (a simple while to 10,000,000 will do) or these headers.

And yes, i’ll be using “elaborate” UI, but still console based (menu with borders, etc). I needed to use clrscr for that reason.

Thanks again!

Single list of HOWTOs

That’s a good place to start. They have a bunch of “how tos” on the specifics of programming under Linux.

If you install KDevelop using Yast, it will automatically set up most of what you need for development. Only one warning (speaking from experience): if you install it under Opensuse 11.1, it will automatically install and upgrade KDE to 4.1. That’s not necessarily a problem if that’s what you’re already using, but if not, it can be extremely annoying.

Qt Creator looks very promising for C++.

Hell, it looks so good I wish I knew C++… for java you can use eclipse or netbeans.
Word of warning with netbeans… it’s disgustingly slow with openJDK (at least for me) menus taking like 4 seconds to show up.

Replace it with Suns version and it’s a lot more responsive.

Both eclipse and Netbeans can be used for C/C++ as well. The latest Netbeans even has Qt support.

I’d recommend you look into (n)curses if you need to produce an “elaborate” console based UI. If I remember right, conio is a fairly basic library which does low level console operations like moving the cursor around , whilst the ncurses libraries provide quite a few bells and whistles from the get go, like support for “windows” with borders, menus with keyboard shortcuts etc. Also, as mentioned above, conio.h is a DOS thing anyway, whilst ncurses binaries should already be installed on your system (though you might need to get the headers too, I don’t know if those are installed by default on OpenSUSE. Should probably be the ncurses-devel package).

I use Netbeans 6.5.1 to develop in C. In tools->options you just point to the location of your C compiler, Make, and Debugger. Obviously, you need to install your gcc first. What I like about it is that it offers a debugger, source control, etc that you wouldn’t get from a standard C IDE. I’m only scratching the surface of functionalities the Netbeans IDE would provide for C. You could also create Ruby/Rails and PHP projects.

Welcome to NetBeans (do the complete install with glassfish)