Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-28-2014, 08:29 PM   #1
LQ Newbie
Registered: Apr 2014
Posts: 7

Rep: Reputation: Disabled
compiling C program using vi , trying to use GNU c compiler


I have a program that I need to enter into a file, and to compile and create a executable from. Below is the program. This needs to be done using the GNU c compiler. I am very new to Linux and do not know where to begin.


#include <stdio.h>
float length, width;

printf("\nProgram to calculate the area of a rectangle");

printf("\nPlease Enter the Length: ");
printf("\nPlease Enter the Width: ");

printf("\nLength= %f Width= %f Area= %f\n",length, width,
Old 04-28-2014, 08:31 PM   #2
Registered: Sep 2011
Location: Texas
Distribution: Open SuSE 12.1, Lucid Puppy
Posts: 90

Rep: Reputation: Disabled
see if you have the C compiler installed on your Linux system. In a shell terminal, type the following
gcc --version
Old 04-28-2014, 08:51 PM   #3
LQ Newbie
Registered: Apr 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
looks like I do this is what came up :

gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
Old 04-28-2014, 10:56 PM   #4
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,575

Rep: Reputation: 181Reputation: 181
Save the program in a file. I assume you're supposed to use a command line? Then the command to compile will be

gcc my_program.c -o my_program

Of course, replace the program name. The 'my_program' executable will be created. To run it, use

Old 04-29-2014, 04:54 AM   #5
LQ 5k Club
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2017 CentOS6.9 CentOS7.3 + 50+ other Linux OS, for test only.
Posts: 16,738

Rep: Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318
#1, @pnorris1231 : Welcome to LQ.

Your program works OK :
$ gcc print-length-width.c -o print-length-width

$ ./print-length-width
Program to calculate the area of a rectangle
Please Enter the Length:
I guess you didn't install the complete gcc compiler :
$ sudo apt-get install g++
.... I.e. the g++ part of gcc will take care that the dependencies
making gcc work fully, also are installed. (libc6-dev etc. etc.)

Old 04-29-2014, 08:21 PM   #6
LQ Newbie
Registered: Apr 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
ok, thanks guys. This has been very helpful so far. Now i have created a new file that contains specified inputs for length and width of the rectangle. This file is called "in file" . I need to run my original .exe program utilizing my new input file and making the output go to another new file.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
GNU C compiler feroz Linux - Embedded & Single-board computer 3 06-13-2012 07:52 AM
Compiling another program with mpicc using a non default compiler Ztif Linux - Newbie 2 07-06-2011 09:07 AM
GNU Make and GNU GCC DEBUG vs RELEASE compiler options aryan1 Programming 1 01-12-2010 01:29 PM
Help with GNU C++ Compiler please... Stiltz Linux - Software 1 03-15-2005 10:17 PM
Gnu C Compiler, and compiling c++ in slackware? Volcom Programming 1 06-13-2003 02:57 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:12 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration