How you can run a c program in Linux?

by on October 16, 2007 · 11 comments· LAST UPDATED October 16, 2007

in , ,

Q. I've a c program and I'd like to run in Linux.

A. C program need to compile and run in Linux using cc or gcc command. When you invoke GCC (GNU C Compiler), it normally does preprocessing, compilation, assembly and linking for you. For example to compile hello.c program , type the following command:
cc -o hello hello.c
OR
gcc -o hello hello.c

It will compile and produced an exectuable file called hello. To run program type:
./hello

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 11 comments… read them below or add one }

1 Felix Mwango Mutale March 27, 2009 at 1:46 pm

Hello All,

I need help. I have a ‘C’ program that was compiled on SCO OpenServer 5.05 and now want to compile on Linux Red Hut. This is failing to compile. Here is part of the program:
#define MENU_WD 5
#define MENU_HT 19
#define MENU_HP 27
#define MENU_VP 5

#include

struct s_menus{
int ops;
int y,x,w,o;
int ptr;
char title[20];
char *options[10];
};
typedef struct s_menus MENU;

MENU m;
main()
{
int i;
char a[20];
InitialiseAll();

menus_ini(&m);
menus_op(&m, “Student Records”);
menus_op(&m, “Chameleon 2000″);
menus_op(&m, “Change Password”);
menus_op(&m, ” Exit”);
menus_title(&m,”UNZA”);

i=menus(&m,5,27,5,19);
clear();
refresh();
endwin();
}

How can I make this compile and run ?

Thanking you in advance.

Felix Mwango Mutale

Reply

2 hehehe April 8, 2010 at 2:26 am

that’s very easy, just shut down your computer =)) lol

Reply

3 jadaces June 25, 2010 at 7:22 am

Try adding a header file to #include eg: #include

main() has to be declared with a return value eg: void, int, char,

put int main(){}

compile now and see what happens.

Reply

4 Felix Mwango Mutale October 1, 2010 at 1:44 pm

Dear Sir,

I have been struggling to get bold letters in informix for CentoS 4.8 and how can I use PCL Command Sequences to solve this problem ?

I have the following declarations and print command in my informix-4gl but things don’t seem to get right.

BoldOn CHAR(6),
BoldOff CHAR(6)

—-LET BoldOn = ASCII 27, ASCII ‘&040′, ASCII ‘&115′, ASCII ‘&052′, ASCII ‘&066′
—-LET BoldOff = ASCII 27, ASCII ‘&040′, ASCII ‘&115′, ASCII ‘&048′, ASCII ‘&066′

LET BoldOn = ASCII 27,”(s4B”
LET BoldOff = ASCII 27,”(s0B”

PRINT COLUMN 1, BoldOn CLIPPED, ” “, “TO WHOM IT MAY CONCERN”, BoldOff,
COLUMN 54, BoldOn CLIPPED, ” “, “Ref: “, BoldOff CLIPPED, r_refno

PRINT COLUMN 1, BoldOn CLIPPED, ” “, “This is to certify that: “, BoldOff, r_surname, ” “, r_firstname

and this what I am getting:

^[(s4B TO WHOM IT MAY CONCERN^[(s0B ^[(s4B Ref: ^[(s0B 9844510
^[(s4B This is to certify that: ^[(s0B NAMONJE CAROL
^[(s4B is a registered student of the National Institute of Public Administration^[(s0B

We have HP LaserJet P3005 and P3015 Printers.

How can I avoid printing these charaters and instead print Bold letters ? Are there any settings I need to do in Environmental variables or CUPS settings ?

Your help will highly be appreciated.

Felix Mwango Mutale

Reply

5 priya October 10, 2011 at 7:00 am

yum install gcc is not working

Reply

6 Rahul July 29, 2013 at 7:38 pm

try this
sudo yum install gcc-c++

Reply

7 yogakumar April 6, 2012 at 9:04 am

haha…..simple

Reply

8 akash mishra August 1, 2012 at 7:05 am

i have a compiled c file,i want to execute it and see its result on html page,like in gnome we type ./file name,then we can see the output but i dnt want to do this,i want to make it through html page,thats by click the ouptu should comew hw to do

Reply

9 Rahul July 29, 2013 at 7:39 pm

sudo yum install gcc-c++

Reply

10 dhanya February 20, 2014 at 11:43 am

I have linux mint os.how to compile two or more programs using make file?

Reply

11 sooraj March 31, 2014 at 8:50 am

when i compile my c program in ubuntu terminal using gcc..its says no such directory found..can u help me

Reply

Leave a Comment

Tagged as: , , , , ,

Previous Faq:

Next Faq: