LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

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


Hi,

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.

Thanks!



#include <stdio.h>
main()
{
float length, width;

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

printf("\nPlease Enter the Length: ");
scanf("%f",&length);
printf("\nPlease Enter the Width: ");
scanf("%f",&width);

printf("\nLength= %f Width= %f Area= %f\n",length, width,
length*width);
}
 
Old 04-28-2014, 08:31 PM   #2
aristocratic
Member
 
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
Quote:
gcc --version
 
Old 04-28-2014, 08:51 PM   #3
pnorris1231
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
Mara
Moderator
 
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

./my_program
 
Old 04-29-2014, 04:54 AM   #5
knudfl
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 :
Code:
$ 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
pnorris1231
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.
 
  


Reply


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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