LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   compiling C program using vi , trying to use GNU c compiler (https://www.linuxquestions.org/questions/linux-newbie-8/compiling-c-program-using-vi-trying-to-use-gnu-c-compiler-4175503288/)

pnorris1231 04-28-2014 07:29 PM

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);
}

aristocratic 04-28-2014 07:31 PM

see if you have the C compiler installed on your Linux system. In a shell terminal, type the following
Quote:

gcc --version

pnorris1231 04-28-2014 07:51 PM

looks like I do this is what came up :

gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1

Mara 04-28-2014 09:56 PM

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

knudfl 04-29-2014 03:54 AM

#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.)

-

pnorris1231 04-29-2014 07:21 PM

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.


All times are GMT -5. The time now is 01:20 PM.