Introduction to C Programming in linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. First, install the compiler. I use gcc. sudo apt-get install gcc.
Then, you can create a new file, just like creating a new file. Right-click the file and choose Create File, write the c program, and edit it to fileName. c.
Then, compile, gcc *. c-o fileName
Finally, run./fileName
For ease of management, you can split files and create a file for each function. And import it through the header file. However, it is inconvenient to compile a function each time. To keep the written Files updated, you do not need to re-compile the files after modification. You can use the make command. However, you need to install the corresponding files. Sudo apt-get install "build-essential ".
Here is an example of mine:
5-main.c
# Include
# Include "chengji. h"
Int main ()
{
Int n, I;
Float average, sum;
Printf ("Please input mount of the students will be calculate :");
Scanf ("% d", & n );
Int array [n];
For (I = 0; I {
Printf ("Please input NO % dst student's mark:", I + 1 );
Scanf ("% d", & array
); } Sum = fun_sum (array, n ); Printf ("The inputed % d students 'total mark is: % f \ n", n, sum ); Average = fun_avg (array, n ); Printf ("The inputed % d students 'average mark is: % f \ n", n, average ); }
Chengji. h
Float fun_sum (int var [], int num ); Float fun_avg (int var [], int num );
Fun_sum-5.c
Float fun_sum (int var [], int num) { Float avrg = 0.0; Int I; For (I = 0; I { Avrg + = var; } // Avrg = avrg/num; Return (avrg ); }
Fun_avg-5.c
Float fun_avg (int var [], int num) { Float AV = 0.0; Int I; For (I = 0; I { Avg + = var; } Avg = avg/num; Return avg; }
There is nothing special about writing makefile. You can also right-click to create a file and rename it. Makefile5 File
Am-main. o fun_sum-5.o fun_avg-5.o Gcc 5-main.o fun_sum-5.o fun_avg-5.o-o 5 5-main.o: 5-main.c chengji. h Gcc 5-main.c-c Fun_sum-5.o: fun_sum-5.c Gcc fun_sum-5.c-c Fun_avg-5.o: fun_avg-5.c Gcc fun_avg-5.c-c After the file is changed, the program dependency is found. When you use the make command after the group, the dependency function is located layer by layer based on the file. Make-f makefile In this case, a file named 5 is generated. Run./5. If you modify any function, you only need to make-f makefile5 again, which is convenient. Now let's get to it. linux programming is just getting started. It's easy to write. Don't laugh.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service