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); } |
see if you have the C compiler installed on your Linux system. In a shell terminal, type the following
Quote:
|
looks like I do this is what came up :
gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 |
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 |
#1, @pnorris1231 : Welcome to LQ.
Your program works OK : Code:
$ gcc print-length-width.c -o print-length-width $ 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.) - |
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. |