Linux Writing C program __linux

Source: Internet
Author: User
Tags readable

1 Writing and compiling execution

First casually write a C language program, such as: A.C

#####################

#include <stdio.h>

int main ()
{
printf ("Hello word\n");
return 0;
}
#####################

Then GCC A.C//represents compiling the file and compiling it into a binary file.

A a.out file will then appear, representing the executable file, or you can specify the output filename xout,a.out only the system default name (gcc a.c-o main.out # #这样就把输出的可执行文件名改为了main. Out)

#########################

A.C a.out

-rw-rw-r--1 yjz YJZ 76 October 09:42 A.C
-rwxrwxr-x 1 yjz yjz 7340 October 19:43 a.out*
#########################

This can be compared through the above, A.out is-rwx, which means readable writable executable. The expression is the execution file, A.C is only-rw, readable and writable.

(The gcc-c hello.c-o main.o-c parameter representation is compiled into a binary suffix. o file, and-O represents a custom output name.) )

Then in the current directory,./a.out represents the execution of the file

##########################

yjz@yjz-lenovo-s40-70:~/clanguage/ctest/les1$./a.out
Hello Word

##########################

Execution ended with the output Hello Word.


2 multi-source file divide and conquer

In vim compilation, in command mode:

###########################

: Set Nu


1 #include <stdio.h>
2 #include "max.c"
3 int Main ()
4 {
5 int n1=33;
6 int n2=22;
7 int Maxnum=max (N1,N2);
8 printf ("The best value is%d\n", maxnum);
9 return 0;
10}
~

###########################

Represents the display line number.

In vim command mode: SP filename.c# #在同个页面中打开另一个页面, if the page already exists, open if it does not exist, recharge it.

: VSP filename Horizontal score
: SP  filename  Vertical

where ctrl+w+ direction key # # means to switch open pages.


##############################################

int max (int n1,int n2)
{
if (N1&GT;=N2)
{
return N1;
}
Else
{
return n2;
}
MAX.C 1,0-1 Top
#include <stdio.h>
#include "max.c"
int main ()
{
int n1=33;
int n2=22;
int Maxnum=max (N1,N2);
printf ("The best value is%d\n", maxnum);
return 0;
}
HELLO.C 1,1 All
"Max.c" 12L, 107C

#################################################


Of course, if a file calls another file, it contains a declaration of another file.



3 delete operation

In browse mode, at the cursor out of a line, (DD) indicates that a row is deleted, and (x) represents the deletion of the text from the cursor.

Enter a row number at the cursor, and then press (DD) to indicate that all of the rows from the cursor out to the input number are clipped. Then to the file that you want to paste, enter (p) in browse mode and paste it.

(W) for jumping a single word, (o) for switching to the next line input, (g) for switching to the article header input, (i) for the current input

Command mode: Wq exits the current page for saving, WQA to save and exits all open pages.



Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.