Makefile summary and inverse sequence character array, the whole right-shift array, Yang Hui triangle!

Source: Internet
Author: User

2015.1.23
I'm on duty today.
Continue with yesterday Makefile's goal begins to record:
The first kind: there is. Phnoy declaration, but no dependent file after colon
. Phnoy:clean
clean://No dependent files
RM *.0 Temp

The second type: the file before and after the colon does not have a direct dependency or can not depend on the file
. Phnoy:all
1 all:main.o f1.o f2.o f3.o
2 Gcc-o all MAIN.O f1.o f2.o f3.o
3 MAIN.O:MAIN.C
4 gcc-c Main.c-o MAIN.O
5 f1.o:f1.c
6 Gcc-c F1.c-o F1.O
7 f2.o:f2.c
8 Gcc-c F2.c-o F2.O
9 f3.o:f3.c
Ten gcc-c F3.c-o f3.o
Clean:
RM main.o F1.O F2.O F3.O
13

The Third kind: all has. Phnoy declaration, there are dependent files, but no command line
. Phnoy:all
1 all:main.o f1.o f2.o f3.o

3 MAIN.O:MAIN.C
4 gcc-c Main.c-o MAIN.O
5 f1.o:f1.c
6 Gcc-c F1.c-o F1.O
7 f2.o:f2.c
8 Gcc-c F2.c-o F2.O

The fourth kind: No. Phnoy statement

Clean
clean://No dependent files
RM *.0 Temp

Pseudo-target function: To write multiple target files to pseudo-target, can be generated at the same time, examples are as follows:
1 all:main.o f1.o f2.o f3.o
2 Gcc-o all MAIN.O f1.o f2.o f3.o
3 MAIN.O:MAIN.C
4 gcc-c Main.c-o MAIN.O
5 f1.o:f1.c
6 Gcc-c F1.c-o F1.O
7 f2.o:f2.c
8 Gcc-c F2.c-o F2.O
9 f3.o:f3.c
Ten gcc-c F3.c-o f3.o
Clean:
RM main.o F1.O F2.O F3.O
Rebuild:all clean//Two pseudo-targets,

When executing, enter: Make rebuild

Note: Pseudo-targets can be nested in layers:
All:*****about
About:****hello
hello:********

Use of special symbols in make:
1 all:main.o f1.o f2.o f3.o
2 Gcc-o all MAIN.O f1.o f2.o f3.o
3 MAIN.O:MAIN.C
4-gcc-c main.c-o MAIN.O//Front Plus-if error is ignored, continue execution
5 f1.o:f1.c
6 @gcc-C f1.c-o f1.o//Front plus @, if something goes wrong, terminate immediately
7 f2.o:f2.c


Make-s indicates that the command line does not output when executing
Make-f name tells make to look for name, not makefile
Make does not follow the target, the system will default to generate the first line of the target file, the following target needs to be specified, such as the above example: make clean

Makefile Summary:
1. Make tool default Makefile
Gnumakefile > Makefile > Makefile

2.make-s CC=GCC All
command line macro definition > Makefile definition > Shell definition > Pre-defined

3. Variable reference: $ (), ${}, single character can be referenced directly; for example: C=GCC, reference: $C

Basic syntax format for 4.Makefile:
Target files: Dependent files
Command line
There is no command line, but the dependent file must have
5.Makefile Format conversion function
Patsubst
Wildcard

SRCS = $ (wildcard *.c)//assigns all point C files in the current directory to SRCs
SRCs = $ (patsubst%.c,%.o,< directory or File >)//Replace All. c files in > < directories or files with. o files and assign to SRCs

%.O:%.c
Gcc-c $<-o [email protected]
The above two sentences mean converting any. c file to an. o file!

6.Makefile pre-defined variables:

[email protected] The full name of the target
$+ all dependent files and separated by spaces,
$< the name of the first dependent file
$* does not include a target name for the extension
$? All dependent files and separated by spaces, mostly all changed files
$^ all dependent files, separated by spaces, not containing duplicate dependent files


Use of special symbols in 7.make:
1. Previous plus-number, if error is ignored, continue execution
2. The front plus @, if something goes wrong, immediately terminates
1 all:main.o f1.o f2.o f3.o
2 Gcc-o all MAIN.O f1.o f2.o f3.o
3 MAIN.O:MAIN.C
4-gcc-c main.c-o MAIN.O//Front Plus-if error is ignored, continue execution
5 f1.o:f1.c
6 @gcc-C f1.c-o f1.o//Front plus @, if something goes wrong, terminate immediately


Suddenly want to implement a two-dimensional array inside a number of characters nginx one after the reverse of the output: here with a macro definition, easy to change the size of the array!

#include <stdio.h>
#include <string.h>

#define M 3
#define N 6

void Inverse (char str_array[][n]);

int main (char argc,const char * * argv)
{
Char i,j;
Char str_array[m][n]={"Hello", "every", "one"};

for (i = 0; i < M; i++)
for (j = 0; J < N; J + +)
{
printf ("%c", Str_array[i][j]);
if (j = = N-1)
{
Putchar (' \ t ');
}

}
Putchar (' \ n ');

Inverse (Str_array);
for (i = 0; i < M; i++)
for (j = 0; J < N; J + +)
{
printf ("%c", Str_array[i][j]);
if (j = = N-1)
{
Putchar (' \ t ');
}

}
Putchar (' \ n ');
return 0;

}
void Inverse (char str_array[][n])
{
char (*P) [n], (*Q) [n];
Char I, j, K;

for (i = 0; i < M; i++)
{
p = q = Str_array;
j = 0;
while (* (P[I]+J))
{
j + +;
}
j--;
k = 0;
if ((P[I]+J) > Q[i])
{
* (P[I]+J) ^= * (Q[I]+K);
* (q[i]+k) ^= * (P[I]+J);
* (P[I]+J) ^= * (Q[I]+K);
j--;
k++;

}



}
}

Program Run Result:
[Email protected]:/mnt/hgfs/source test/test# gcc text7.c
[Email protected]:/mnt/hgfs/source test/test#./a.out
Helloeveryone
Oellhyvereeno
[Email Protected]:/mnt/hgfs/source test/test#

Move the two-dimensional array to the right by one column, and place the last column where the original first column is:

#include <stdio.h>

#define M 2
#define N 3

int main (char argc,const char * * argv)
{
int Array[m][n] = {1,4,6,8,10,12};
int I, j, temp;

for (i = 0; i < M; i++)
{
for (j = 0; J < N; J + +)
{
printf ("%d\t", Array[i][j]);
}
Putchar (' \ n ');
}

for (i = 0; i < M; i++)
{
temp = array[i][n-1];

for (j = N-1; j > 0; j--)
{
ARRAY[I][J] = array[i][j-1];
}
ARRAY[I][0] = temp;
}

for (i = 0; i < M; i++)
{
for (j = 0; J < N; J + +)
{
printf ("%d\t", Array[i][j]);
}
Putchar (' \ n ');
}
}


Program execution Effect:
[Email protected]:/mnt/hgfs/source test/test# gcc text5.c
[Email protected]:/mnt/hgfs/source test/test#./a.out
146
81012
614
12810
[Email Protected]:/mnt/hgfs/source test/test# ^c


Yang Hui triangle:

#include <stdio.h>

#define M 10//control Yang Hui triangle length

int main (char argc,const char * * argv)
{
int I, J;
int a[m][m];

printf ("\ n");

for (i = 0; i < M; i++)
{
A[i][0] = 1;
A[i][i] = 1;
}

for (i = 2; i < M; i++)
{
for (j = 1; j < I; J + +)
{
A[I][J] = A[i-1][j-1] + a[i-1][j];
}
}

for (i = 0; i < M; i++)
{
for (j = 0; J <= I; j + +)
{
printf ("%5d", A[i][j]);
}
Putchar (' \ n ');
}
return 0;

}

[Email protected]:/mnt/hgfs/source test/test# gcc text4.c
[Email protected]:/mnt/hgfs/source test/test#./a.out

1
1 1
1 2 1
1 3 3 1
1 4 6) 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
[Email Protected]:/mnt/hgfs/source test/test#

Today, the basic knowledge of Linux system is finished, compared to the first two days, the new content of contact today is less, analysis of some of the array of programs, or very rewarding, the above several programs are also very fun
These two days also began for the graduation thesis, based on the DSP AC servo system design, carefully read a section of the motor's three closed-loop control and vector control technology, the difficulty level than I thought the larger,
Now training embedded, self-study PCB design, plus to do graduation thesis, feel time is tight, change a point of view, this graduation thesis if I can be very good to make, to me in strong electricity convenient knowledge expansion
is still very good, hold live, hold LIVE!!!

*************************************************************************************************************** *******************************************
*************************************************************************************************************** *******************************************
*************************************************************************************************************** *******************************************

Makefile summary and inverse sequence character array, the whole right-shift array, Yang Hui triangle!

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.