(Reposted) (Favorites) C Language Replenishment Notes

xiaoxiao2021-03-06  19

This note is suitable for information as a C language summary:

The first day is the first day of the first day, and finally there is a chance to hear the class of Mr. Lin. I think he is better than the old man, although I have not heard the old man's class, but I believe in the greatness Some people in schools are the "C program design" in the old pool. The benefits of this book are much, the most important point is to illustrate some concepts with vivid examples, but it is a bit of a bad place, which is that this book is all about the foundation, and there is no some students to go deep into depth. The topic of research. I know a "C language design tutorial" translated by the mechanical industry, this book has a large number of instance exercises, and it is around life. Learning and fun, I am having a few particularly attracting my topics when I am watching this book! The book is introduced here, or it is still going back to the course today. Today, because of the first day, the teacher is still not very clear about our bottom. It is because we have been fully studying before, so I have to touch it. At first, he directly introduced the first question of the afternoon of the upper programmer exam, which is a programming filling question. As follows: code] int strcmp (char * s, char * t) {while (* S && * t && _______) {s ; t ;} return ________;} [/ code] This is imitation C language character log library The character comparison function, I thought of a way in the first time, the first empty because everyone didn't have a problem, * s and * t should be logical, indicating that this storage unit uses characters, Everyone knows that there is no string in the C language. Only the character number, '/ 0' this symbol is used to indicate that this character number is ended. There is another new concept to talk about it, it is C. The non-zero in the language logic is true, then '/ 0' this symbol is zero. So fill in this air, there should be no more difficult, follow, there is a condition to exit the loop, because it is more small, as long as you keep, continue, so the conditions can also be written out * s == * t . As for the second question, my thinking was set in the conditional operator, because the return value is three kinds, greater than returning positive, equal to returning zero, less than returning negative numbers. I know that these three may be filled with the conditional operator. I at the time is like this * s == * t? 0: * s> * t? 1: -1, this is not very long, actually My answer I don't know if it is right, but the real answer is * s - * t. Why is this? I was threatened by the answer, because I thought that it was compared to use them. It can be obtained (using the ACSII code), * s - * t If the unit pointed to by the S pointer is greater than or the positive number, follow other principles, this is no longer detailed. In addition to quoting this question, I have said a lot of basic knowledge, and I will introduce us a pointer in more detail, hehe! Why did the teacher say that it is always clear that if you can teach a lot, you can take a lot of detours. Forget it, say these words are useless, only now you can learn well. Everyone is the foundation of the pointer. It is important to mention the teacher today, which is a concept that the pointer is pointing to the address. I am here today. The next day, because the teacher touched the relationship between our teachers, I would like to make up the base part of the previous one. He first lists a table of data types, as follows: | Integer | Character | Basic Type <| | single-precision | | real type (floating point) <| | | Double-precision | | Enumeration Type | | Data Type <| Array Type | Construction Type <| Structural Type (Structure) | | Common Body Type (United) | Pointer Type | Space Type Above this table, basic type is usually used, including integrity , Characters, real-purpose (floating point), come from the most common data type here. To talk about the data content of the C language, it is necessary to talk about what is stored in the computer. You should know that the computer can only handle the number of binary, because it is hardware relationship (bibly devices), these can only There are two states of representation, so it is particularly useful in the computer.

From now on, we have to know all the data from the computer, then how do he calculate it? Teacher first conversion to some of the number of decimal numbers to the number of binary counts, these pediatrics are of course no problem, It's very simple. The teacher, of course, we know that we will do, but in fact, we think that we can find a simpler conversion method when doing these topics. Example: 1011101 = (93) 10 It is very simple to calculate, my method is the traditional calculation method. They all have their own rights, the first one is 20, the second is 21, followed by some types of push, will take the number of 1 to the number of points to add together, equal to 93. Here is that in fact, the second-party secondary is particularly good, just like our memory, 1-2-4-8-16-32-64-128-256-512-1024 ... Do you know this law? If you know if it is calculated, don't do it! However, the teacher puts forward a better way here, at least than a one plus it. It is the number of the number to be converted to 1111111. Do you know how much this number? In fact, there is a skill in it, look at 10,000,000 minus 1! So, is it soon you know how much is 10000000, it's ok, it's 128, and then 1 is 127. On the basis of the two numbers of the original binary bit of zero, the first one Zero in the second, so 2, the second zero in the sixth place, so 32, add it to 127 to lose 93, is it very simple and convenient? (Learn something fast tuition fee Ah, haha ​​~). Do you know how many operations in the computer? I will tell you here, in fact, there is such a kind of way is the addition operation (you don't tell me that you will even make a binary addition, it is actually one Why do you say this? In fact, the binary also has subtraction operations and multiplication, but there is a method of complementing the complement in the computer, which can change the subtraction operation into an additional operation. As for how to implement teachers, there is no more deeply told (in some additions) The multiplication is also use shift to achieve the transfer to addition. Now transferring into the integer data of the C language, the integer data of the C language is 2 bytes, which is 16 bits, up to 65536, and his range is -32768 to 32767. The C language is divided into symbol type and unsigned type. If there is no symbol, the range of integers is 0 to 65535. Regarding character data, if it is strict, there is no character in the C language, because he is stored is its ASCII code. Directly can be used and other data type operations, such as: [code: 1: 02699cb095] main () {char s = 'a'; int i = 2; s = S I; Printf ("% d", s ); / * Here you can directly output its ASCII code * / printf ("% c", s); / * The result of this here is the character S of the character S, the output is 'c' * /} [/ Code: 1: 02699cb095] Then do not say a string, the string is only used in the C language, and the other high-level languages ​​are different, and there is a string type, but also characters and strings combined. In the same type. Now, the real data is now used, and the real type is usually used in some data in a small number.

Just like this: s = 1/1 1 / 3-1 / 5 1/7 ... 1 / 2N-1 This program is I wrote: [Code: 1: 02699cb095] main () {Int n , I, S; INT R = 1; Printf ("PLEASE INPUT:"); Scanf ("% D", & n); for (i = 1; i <= n; i ) {s = s r / ( 2 * i-1); r = -1 * r;} Printf ("% d", s);} [/ code: 1: 02699cb095] This is in the exam: [Code: 1: 02699cb095] Void fun FLOAT * SN, INT N) {FLOAT S = 0.0, W, F = -1.0; INT I = 0; for (i = 0; I

However, I have to write down today, and there is no special reason. I want to have a memories. Today is all about arrays, we define different arguments and other advanced language definitions in C language, which shows C language and other languages. C language foxbase int a [10] [10]; DIM A (10, 10) is also different, we used to be used as small parentheses, but now, it is really uncomfortable. What about it. But who told us to learn C language, don't get used to it. I still remember that I didn't have to pay attention to it. I only knew it, even if I used it, I used wrong. But the C language is not, after you define an array, you have to take a good control, because the number of borders will never notify you. The definition and calling method of arrays is also a lot, really flexible, there is no longer repeating the things. Now define an array to see: Int a [10]; as shown in this table, there is a relative address after the array definition, and the array name A is the first address of these addresses. Now we define a integer pointer variable, int * p; let it point to array a, p = a; we try to make pointer operations to increase a P ; we see the result is P pointing to the new address 2003, original The address is 2001. Why is you incrementing one to 2003, not 2002? Isn't it 2002? Is it correct? In fact, it explains why we define the pointer variables is intended, because all the pointer operations do what kind of pointer itself is what type of pointer is made. It is now intellectual type, and the integer data store is required for 2 bytes, so the needle finger operation is also made in this way, and the results are obviously moving down. In fact, here is so much, the book is basically a detailed description of the book, so I first said that as long as I have read the book, it should be very easy to understand (but it may be blurred by me). Ok, let's make some questions, this is the question of today's teacher gives us, in fact, the topic that appears in the 2001 program afternoon exam. So please do it yourself, think more, see who is better. In the N line N column matrix, each line has the maximum number, this program seeks the minimum of these maximum numbers. [Code: 1: 02699cb095] #include #define n 100 int a [n] [n]; void main () {int Row, col, max, min, n; / * input legal N and N * N integers code, note, a part of a part to the back exercise yourself * / for (row = 0; ROW

[Code: 1: 02699cb095] Printf ("Enter the dimension N:"); Scanf ("% D", & n); for (row = 0; ROW 32767);} [/ code: 1: 02699cb095] The next is the second question, the topic is as follows: seeking N * N diagonal and This question is written by writing itself, so there are all kinds of writing. Let's write my most basic simple way below. [Code: 1: 02699cb095] #include #define n 5 main () {int a [n] [n]; int in, col; int sum = 0; / * input * / for (row = COL = 0; ROW

[CODE: 1: 02699cb095] #define n 8 main () {Int a [n]; int I, j, t, s; for (i = 1; i <= 7; i ) a [i-1] = i * 10; for (i = 0; i <7; I - IF (a [i] = 0; J -) {IF (n 0; I -) for (j = 0; j a [j 1] {exchange}; [/ code: 1: 02699cb095] The above is the bubbling method [CODE: 1: 02699cb095] int N = 6, i, j; for (i = 0; i i; j -) IF (a [j]

We are basically practicing this sort today. It's time to get out of school, but the teacher still grasped the time, it is really not wasteful, and also dragged half a hour. Hey ~, sometimes I think others is good, it is really bad. But what said, he is our teacher. Then he dragged us half a minute is to finish the conditional statement in the C language, but it really has learned something. There are several forms of Conditional statements in the C language, with conditional operators?:, The basic IF statement, and the Switch statement, as for the most flexible, the Answer operator?: The operator is operator. Why is this flexible, because his parameters are expressions, the c language is the most flexible, then can it be flexible! A source program is given here: [CODE: 1: 02699CB095] INT A = 5, B = 10, C = 8; if (A> B) IF (A> C) Printf ("a"); ELSE IF > c) Printf ("b"); Else Printf ("c"); [/ code: 1: 02699cb095] Do you make you feel uncomfortable? This is another feature of C language, you Do you know the answer to this program? But it is not difficult, the program is also very short, let me say the answer is good, the answer is not to output B, the reason is very simple to see, who? Who? Who When you are messy here, will the answer be output B, stupid! So you write your hard work, you can't buy it. Let's make the program [Code: 1: 02699cb095] int A = 5, b = 10, c = 8; if (a> b) IF (A> c) Printf ("a "); Else IF (b> c) Printf (" b "); Else Printf (" c "); [/ code: 1: 02699cb095] Is this clear? The answer is nothing, because the first is the first If the IF statement is not established, there is an answer! It also shows a situation here, so we have to accompany the format of the code, if there is a good program, there is a good program. And I understand today, I want to see the following IF statement: if IF else else if Else IF else else if Else I originally thought that these two are different, the impression in QB is two Not an IF statement. But today I will understand it, everyone should know, maybe I am stupid. In the C language, SWTICH is also different from other high-level languages. Do you have discovered? Now, look at the fourth day. The two bars know this statement clearly, and the condition is constant, So the teacher said to us to listen to himself, don't like to use this SWTICH statement. If you understand this conditional operator?: It is really convenient, this is also unlimited, not so much here, let yourself feel slowly. Day 5 Today is the last day of the discrete school, my grades, of course, I will not get it there, it is also very likely the first (countdown). I blame myself, but I can't quit. Because the school's original computer curriculum is also a lot, all are in teaching graphics, what PS, CW must go to the class, it is a bit uncomfortable. Ok, don't say too much of your own school's shame. Then let's learn today's knowledge, many friends are I am typing all day, but I don't think that these are not a lot of time, and more than the benefits (I have listened to the morning, I was reviewed at night.). The reason is that there is a cloud "Wen knows new", I think this sentence is especially reasonable, because I can never see the teacher in the classroom in the classroom. I still talk about today's learning. . Yesterday, we gave us a question. I have been busy yesterday, but today I suddenly remembered the rushing to do it, this is a question: give a positive intent of 5 digits, require: 1, this There are several bits 2, print each bit, 3 reverse order print, such as 321 output 123. It's not difficult to say this, I have finished it for a while.

[Code: 1: 02699cb095] main () {int N; int Num; INT i = 0, A [5]; Printf ("Please type no more than 5 digits"); scanf ("% d", & num ); Do {DO [/ i] = Num% 10; Num / = 10; i ;} while (NUM! = 0); n = i; printf ("len% d", n); for (i = n -1; I> = 0; I -) Printf ("% d", a [i]); for (i = 0; i 10) Break; Printf ("% d", i); [/ Code: 1: 02699cb095] This is how much here I? This is related to this operator incremental operator, there can be two ways, one is i is like the above, as for the other is i, here The answer is that the former is equal to 12, and the latter is equal to 11. It is all because the increments are incremented by the two ways, then we have to master this, you try to do it yourself.

Another program is good to see this incremental operator: [Code: 1: 02699cb095] INT i = 0; if (i ) Printf ("a"; / * If you really output a * / else printf "b"; / * Otherwise, it is output B * / [/ code: 1: 02699cb095] I try it yourself, is it clear that this incremental principle is, here, I , this is the first i After the comparison is , it is natural that it is 0. Of course, it is output B, then the i will first compare i plus 1, then you really output A, ok, then increment and - - Decreasing is the same nature. However, it is important to note that these two incremental decrement operators are variables, they can't operate with constant. Ok, I have finished the looping statement. Of course, I want to use it in programming. I have already! So the teacher immediately gave us an idea, but I believe that some people have studied, it is "Magic Cube", but the teacher said that although this Rubik's square is directly algorithm can operate. But let us think that this question is to do this, use the computer's ability to complete, but seeing so many numbers to arrange so many, the loop is not to say much, so I can't think of it. (Start dizzy Finally, there is no one can make it. I have to listen to the teacher, but the teacher is not fully finished, just gave us a structure, such as the fifth day, the second graphics let us have interest to complete it, I Mathematics This thing is the most Feel. Ok, then continue the second question, it is also a problem of alignment, you should have the second edition of the "C-program language" in his hand, then please turn over the book. To page 121, 6.15, this question is to arrange the topic of the combination. This is actually a rule that can be found, but it is not what we find but the teacher says it. Today, this class really has too many problems. At least for me. I have no mouth in the next, I have to show the teacher's method, such as the fifth day, the three programs are also under the fifth day. [Code: 1: 02699cb095] char XYZ [] = [' X ',' Y ', "Z'; INT I, J, K; For (i = 0; i <3; i ) for (j = 0; j <3; j ) IF (j == i0 Continue For (k = 0; k <3; k ) IF (k == i || K == J) Continue; Printf ("A-% C / N", XYZ ['I]); PriHTF ("B -% C / N ", XYZ [J]); PRIHTF (" C-% C / N ", XYZ [K]); [K]); [/ Code: 1: 0 2699cb095] Let everyone understand it yourself? Today, my head is also particularly halo, and the shoulder also special acid. But I still have to work hard! On the September 18, 2002, the entire course of today is only such a question, but it has been a lot of things. This topic is given below: the character number is converted to an integer value (characters can be arbitrary: such as "342a") encountered other no numbers.

The procedures I have written are as follows, I think it is good: [CODE: 1: 02699cb095] #define n 10; int Catio (const char * str) / * Const role is constant, so the address here will not return to the real Gin * / {Int Num [N]; INT i = 0; j = 1, n = 0; for (; * Str ; i ) {IF (* STR <48 || * STR> 57) BREAK; / * Judgment whether the numeric value * / NUM ['I] = * STR-48;} for (i- = 1; I> = 0; I -) {n = NUM ​​[' i] * J; j * = 10; } return n;} [/ code: 1: 02699cb095] Do you say that it is more simple? Now you can't see another program that you finish reading the following first. As follows: [CODE: 1: 02699CB095] Long catio (char C []); {INT N, D; Char * q, * p; long E = 1, s = 0; for (q = p = c, n = 0; * p! = '/ 0' && * p> = '0' && * p <= '9'; p , n , e * = 10); while (n> 0) {d = * q ; switch (d) {CASE 48: D = 0; Break; / * too long, slightly * /:: case 57: D = 9; Break;} S = D * (E / = 10); n--;} Return (s);} [/ code: 1: 02699cb095] Now look at it, but although this procedure is complicated than me, there is also his ideas and ideas. Like that for loop, a command has been very convenient. In fact, we can continue to transform this procedure, we follow the teacher's ideas step by step, now look at the following: [Code: 1: 02699cb095] long catio (char C []); {Int n, d; char * q * p; long E = 1, s = 0; for (q = p = c, n = 0; * p && * p> = '0' && * p <= '9'; p , n , e * = 10); While (n> 0) {d = * q - '0'; s = D * (E / = 10); N-;} return (s); [/ code: 1: 02699cb095] Is it more simplified? Can you still simplify? We can make it out, when the teacher said it is more simple, we have to listen to the mood of the expectation. He stepped by step, the first is to change in the S D * (E / 10) here, S = S * 10 D, if you can remove a extra variables in this way, the variable e is not. The next thing is not opinion, I don't know how to say, look at the program first.

[CODE: 1: 02699cb095] long catio (char * c); {long s = 0; for (; * p && * c> = '0' && * c <= '9'; s = s * 10 * C - '0'); return (s);} [/ code: 1: 02699cb095] Do you see it? It turns out that such a long program can be further simplified to this point, this is the flexibility of C language (I seem to have said It's been a few times, I really don't have a way, I have to admire it). Today is such a question, you can really surprise! Ok, now I don't write, there is also a trip exercise problem waiting for me to do it, everyone must work hard! On the 7th day, on August 18, 2002, today, I finally told the C language comparison, "function" said that everything in the C language is really right (possibly, I don't know)?. Many books have said that the function is the C language, that is, the function is constituted C language? Look at the following procedures: [Code: 1: 02699cb095] main () {printf ("Hello World";} [/ code: 1 : 02699cb095] Main () is the most special function in the C language is the key to constitute the entire program. The first thing to find out in the C compiler is to find out the compilation, ok, say some books Things. Now let's take a look at the functions in the C language. If we don't mean from the foundation, then we will say from the other characteristics of the function, "recursive function" believes many people I know this, I have seen the tutorial of the old pool should all know the first recursive procedure of his classic: [Code: 1: 02699cb095] int ABC (int N) {Int S; if (n> 1) s = n * ABC (N-1); Else S = 1; return (s);} [/ code: 1: 02699cb095] It is easy to see a function with his name, so we look at it later In a function, call yourself is a recursive function. And let's take a recursive function to see if it is a return condition, just like a black and deep cave, we have to explore, if you go, you must look back. Even if it is deeper, it is necessary to return! So we judge whether a recursive function is also established, it is often seen in the return condition. As for the source program above, I don't want to say more, I should understand it. Let's see it. Another topic that uses the recursive function, it is the Noko Tower (there is also the book in the old man).

[Code: 1: 02699cb095] #include void move (char x, char y) {printf ("% c ->% C / N", x, y);} void hanoi (int N, Char One, Char Two, Char Three {IF (N == 1) Move (One, Three); Else {Hanoi (N-1, One, Three, Two); Move (One, Three); Hanoi (N- 1, Two, One, Three;}} main () {Int m; Printf ("INPUT The Numr of Diskees:" Scanf ("% D", & M); Printf ("The Step to Moving% 3D Diskees: / N ", M); Hanoi (M, 'A', 'B', 'C');} / * Operation is as follows: Input the Number of Diskees: 3 Enter The Step to Moving 3 Diskes: A - > C a -> b c -> b A -> C B -> a b -> c a -> C book saying Hanoi (N-1, One, Three, TWO); N-1 on "One" is moved to "TWO", then move (one, three); then Hanoi (N-1, Two, One, Three), TWO, N-1 on "Two" "Three" moved; | h (2, 1, 3, 2) | h (1, 1, 2, 3) => Move (1, 3) <----- 1 ------ | | Move (1, 2) <----- 2 ------ | H (1, 3, 1, 2) => Move (3, 2) <----- 3 --- --- | Move (1, 3) <----- 4 ------ | H (3, 1, 2, 3) | | h (1, 2, 3, 1) => Move 2, 1) <----- 5 ------ | h (2, 2, 1, 3) | Move (2, 3) <----- 6 ------- | | h (1, 1, 2, 3) => Move (1, 3) <----- 7 ------ | * / [/ Code: 1: 02699cb095] Note that the above is a netizen written Not what I wrote. Nordan The most different tower is that it has repeatedly called themselves, so it looks more complicated. At that time, I was watching this program and I didn't understand the old half-day. It is best to see a friend on the Internet saying that he really took some dishes. I tried it. Later, I also I tried to see, the effect is really good (I certainly don't have a stupid drink, write big, middle, small) with my disc, you don't know how to visit. In addition, I saw this picture, I am also very clear, I want to thank the netizen, do you say that? This program must slowly understand it, I wish you all an early understanding. Recurrent function I can't say anything because I don't know much, now come to see another content of the function, is the parameter call of the function. I will give a program first: [code: 1: 02699cb095] int ABC (int A, int b) {a = a = b; return (A b);} main () {int xy [] = {3,5}; int S; s = ABC (XY [0], XY [1]);} [/ code: 1: 02699cb095] Here, XY [0] and XY [1] is introduced into shape In this point here is that the other advanced languages ​​are different, the C language function call is one-way passed. Limited to participate in the ginseng, it will not return to the collections, so we must remember this.

As another question: [CODE: 1: 02699cb095] int A []) {INT I, J; / * Sort * /} main () {INT X [5] = {3, 5, 1, 2, 4} ABC (X); / * Output * /} [/ code: 1: 02699cb095] Why can this source change the value of the argument? The old man's book is very clear, saying because This is the address delivery, but our teacher does not agree with this. He said that this should also be a value transfer, but this value is a relatively special value, it is the address, so it can be called by calling this address by calling this address. Element. If this procedure is called by the old pool, the following procedures call the address delivery? [Code: 1: 02699cb095] int ABC (int * p) {* p = 10;} main () {Int a = 20, * W; W = & abc (w); / * ABC (& a) * / printf ("% d", a);} [/ code: 1: 02699cb095] pointer P is just a value, this value is address. If this is the address delivery, shouldn't it be to pass the address to the form? The left is everyone thinks about it. (You can't say anyone who is wrong) next to the storage category of the variable, in fact, this knowledge point is also very easy to understand, but it may be confused with the relationship between the C language too much. The type of variables in the C language, the storage category of variables, the globality of variables or local, is it static or dynamic. Everything is something of C language variables, and we will have a good end of this. (We all read books) is very sorry, because today my eyes are a bit problem (it may be too long to see the computer). So don't continue to talk to you further storing categories, here there is a source program to see it, I can't do it, I have to take a good rest. [Code: 1: 02699cb095] INT ABC (INT A) {INT I, J; Scanf ("% D% D", & I, & J); if (i> j) {INT K = 1, i = 2, J = 3; Pirntf ("% d / n", i * 3); Printf ("% d / n", j * 10);} printf ("% d", k);} [/ code: 1: 02699cb095 The eighth day of 2002, 2002, I didn't talk about the class today. Because the teacher is busy with some other things, I heard that it seems to be a multimedia game, I have to pay today. Then we have to return to the books in the classroom, but we haven't seen any books during this time, just everyone talked. I also inserted a few words, but I was so sincerely, hehe! I have to sleep for a while. When I took a break, I found that the teacher had already come back, and said to let us go online today. Today is the first time in the machine room, but if I am not, I don't want to go to the machine room, because I think the teacher is okay. We went to the computer room, and the teacher gave a procedure us, hey! This is not the Noko Tower you want to do before two days! Moreover, it is combined with graphical representation. We are all excited and began to study this procedure.

I started to implement this Nota. The parameters he given is not a lot. It is just ten plates. Do you know how long I have been pressed? I have been watching it. I have read it. This is. The problem is complicated. Looking at these drawing demonstrations let me know more clearly, I don't dare to selfish here. I will pay my home. The source program is also going home. The following is: [Code: 1: 02699cb095] #include #include char DD [10] [20], Space [20]; Int a [11], b [11], c [11]; init () {INT i , J; for (i = 0; i <20-1; i ) Space ['i] =' '; Space [' I] = '/ 0'; for (i = 0; I <10; i ) { For (j = 0; j <20-1; j ) DD ['i] [j] ='; DD ['I] [J] =' / 0 '; for (j = 9-i; j < = 9 i; j ) DD ['i] [j] =' a ' i;} for (i = 0; i <10; i ) a [' i] = i, b ['i] = - 1, C ['I] = - 1; A [10] = 2, B [10] = 25, C [10] = 50; for (i = 0; I <10; i ) {gotoxy (a [10 ], 10 i); CPRINTF ("% s", DD ['I]);}}}}}}} Move (INT * S, INT * D) {INT I, J; for (i = 0; s [' I] == - 1 && i <10; i ); gotoxy (s [10], 10 i); CPRINTF ("% s", space); for (j = 0; D [j] == - 1 && j <10; J ); J -; gotoxy (d [10], 10 j); CPrintf ("% s", DD [S ['I]]); D [J] = S [' I]; S ['i ] = - 1; getChe (); void hanoi (int N, int * s, int * w, int * d) {INT i; if (n == 1) Move (s, d); else {hanoi N-1, S, D, W); MOVE (S, D); Hanoi (N-1, W, S, D);}} main () {clrs CR (); init (); getChe (); ha NOI (10, a, b, c); getche ();} [/ code: 1: 02699cb095] Finally, in addition to watching this procedure, the teacher also tried to use the TC debugging process. Do you know what my previous debugger is? I just directly Alt F9 to see if there is any error, if there is a modification, it is not successful. But I really realize the true method of the TC debugger, in fact, TC There is a big debugging tool. This is my previous, I only know one is one step by step, I have not known anything else. In fact, the value of some variables can be displayed in TC, which is an important means of debugging procedures. I used to write this feature to write on paper with a pen. It can now be very convenient to see. The following picture below is what I have cut out. Let's see if you know it (you may know, it is my dish.). Today's curriculum is also learning something, I should go back to use this feature to debug the program.

The ninth day finally arrived in the core part of the C language today. The pointer has always been a big focus of learning C language, if we don't learn C language pointers, then we can say that there is no school. C language. But then, when I just started to get in touch C, the basic syntax is very fast, but I learned that the pointer is stupid in the array, because I can't see it, I can have so many array calls. Way (binding pointer). In fact, I'm very difficult to understand the guy. Please ask you to debug a lot of debugging. After adding the experience, look back and look at the chapter of the pointer, I believe it can also touch it. Because I also came over, I also read a lot of source program using pointers. Now we start with a relatively simple one-dimensional array relative to the two-dimensional array, first look at how to define a pointer to the one-dimensional array. INT A [5] = {1, 2, 3, 4, 5}; int * p; p = a; / * Here A is because it is a group of variable names, its value is the first address of this array * / follow us You can change the value of the array of value P ; * p = 6; / * The second element of the array is equal to 6 * / The meaning here is to move the pointer down, and point to the second part of the array. Element. Let's take a look at its address, through this pointer, the address of the current pointing element. Then how the address is running? P this command is to move down, if you follow the type of array A, the array A is an integer, the space is two bytes, while P is only Plus 1, the top of the top half is the first half of the first element, where can you refer to the second element? In fact, it is related to the type of definition pointer, and we define the integer type here, "Yes." The definition is correct here, because it is to point to plastic data, then of course, it is necessary to define this type. "In fact, this is not a real answer, and it is not necessary to define the same as the pointing. Type, we can define the type of pointer to be other. For example, it is defined as float, but here is executing P directly skip a array element, then let's take a look at what is going on. In fact, our defined pointer type is used to combine a pointer to make a certain rules. Here, it can be seen that if it is the definition int type, you can go to the second element, indicating that P is not a simple address plus one, but first combines this type to make an operation, add once, equal to the address. 2. The Float moved 4 digits, so the combination obtained was moved to the third element. Take a look at: a = a 1; here we perform address shift assignment, but this command is wrong, the C language is a set of address constants, so it does not change its value. Next, it is said that the two-dimensional array is, because our task today is to first figure out a one-dimensional number of groups first. Now let's define a two-dimensional array Int a [2] [4]; here I don't repeat things in the book, I tell the idea of ​​the teacher gives us. Let's take a look at a two-dimensional array, which is a one-dimensional array of elements, so nested. Of course, the other multi-dimensional numbers are nestled in this way. Let's take a look at this picture. The ninth day of the figure is easy to explain why A [0] and & a [0] are the same representative address, in fact, just the first address, it is difficult here from text. Speaking, but it can be understood in a sense. We act as a one-dimensional array of two-dimensional arrays, not think of it as two-dimensional, so that it is as follows: a [1] [1]; act as a one-dimensional M is named M [1]; / * call The second element * / We tried to treat all this as such a one-dimensional array INT A0 [4], A1 [4], A2 [4]; this, we know A0, A1, A2 is the first address. Ok, it may also be more blurred. If you don't understand, you will consider an array according to your original thoughts, because everyone has their own ideas and understanding. Top Ten Days, August 18, 2002, today, the two-dimensional array of days, let's see how the pointer to the two-dimensional array is. I want to repeat again before telling, if you understand the two-dimensional array, press you to understand. But more ways to think about it is also a good thing, then let's talk about it. Now let's take a look at the two-dimensional number of pictures yesterday, the ninth day.

We define a pointer INT A [3] [4]; int * p; p = a; in fact, this also points to the pointer of the one-dimensional array, the two-dimensional array is priority, one line It's the column order, we can use the pointer to guide the column, as follows: p ; we point here to the first column of the 0th line, then how can we go to the next line, actually define the memory The array assigns a series of consecutive spaces, we can move the pointer directly, when moving to the last column of 0 rows, it will be the first line. In fact, there is a more way to point to the method in the C language, see the following: int (* p) [4] / * Here is the first number pointer, and this pointer is pointer to the four elements of the group * / Let's see This definition method, * p Why must be parentheted, because [] This operator is higher than * priority, if it is not incorporated, it will become a definition of another pointer value, as for what pointer is in the best Tell, let's take a look at this pointer. P = a; p ; what will this be the result of this? It is directly moved, which is the same as the reason that the previous day, is the combination of defined types to operate. We know how can you move, then how to be changed? This problem is more complicated, trying to move the pointer to Chain 2 of Chain 1. Let's take a look at this expression, A 1 is the first address of the first line, the same P 1 is the first address of the first line. As for the column? Think about how the one-dimensional array moves to the column, it is the first address plus the order! Then we can express the first-dimensional array of first-dimensional array first, * (p 1) 2, see, does this point to the second column of the first line. We can not understand (P 1) is a line, from another meaning, it can be seen as the first address of the column (it is too difficult to understand, there is still a little clear, but I still want to use it back. Always understand the pointer, don't integrate, so it's too wrong. I have said that I have another pointer, what is the other pointer, and the character pointer is relatively simple, but there are some special things. Let's take a look at some of the following programs: char * p; p = "abc"; / * Here, since it is a string, there must be ended, this is a different * / such assignment of the character array. Here is the first address of the string ABC to the pointer P, then look at another program: char a [4]; a = "abc"; Is there a mistake here? For C language is wrong. Because the character array A is a constant, it cannot be assigned. Other advanced languages ​​can be paid directly to it, then we want to assign ABC to the character array, there are several ways, one is a character assignment, one is to use the pointer, but here Or use the copy string function in the C language function library to complete strcpy (); everyone should have a function of this function, well, now give five minutes to do exercises, prepare a function of strcpy () . ............ Time is really fast, I will write it out. Mycpy (; * s1 = * s2 ;} is ok, so in such a short second line, the copy function is completed, this only C language can do it. Now take a look at the following Two programs Char * p, * q; char * p, * q, * r; p = "abc"; r = "abc"; q = "abc"; p = r; * q = 'd'; Q = R; Printf ("% s",% s ", p, q); * q = 'd'; printf ("% s,% s ", p, q); what is the answer here? Think now. Ok, you should have finished thinking, now give the correct answer, the first program is output ABC, DBC, and the second procedure is to output DBC, DBC. Why is it? Is it because The first program is pointing to the same address, that is of course the same value.

Now there is a function pointer, in fact, we are often not very many people, but the teacher still gives us a special place, and today we discovered today, the procedure is as follows: [Code: 1: 02699cb095 ] int b = 0; int A [2] = {10, 20}; int * ab (int * p) {p ; return (p);} main () {b = * ab (a); / * Here We tried to return the address that will be returned to the address, see if you can't point to that value, as for the result, we haven't tried it, I didn't have the machine when I wrote this diary, everyone If you are interested, you will try it. How is this problem? In fact, we first defined a pointer to the function, such as (* CD) (), we propose if there is no parentheses, Because the original (* CD) () is a function that points to a returning pointer value, then we try * / printf ("% d", b);} [/ code: 1 for the function of returning the pointer value. : 02699cb095] Ok, today, I will finish the pointer, but there are still many in the use of the pointer, I know that there is a structural and common numerals to use the pointer, follow the other comprehensive use of the latch , Stack, queue, etc. I think I just didn't have a little experience in this regard. I have seen the data structure and there is not much interest in it. Because I saw a lot of pointers have dizzy. However, in recent days, I will take a look at what I'm thinking, and I feel that I am not dizzy. On August 18, 11th, on August 18, 2002, I told the structure today. I will tell the practice questions that have been arranged before the day before. Those topics are the chapters of the pointer in the old Tan book. Everyone will do it slowly, it is very important to master the pointer, learning programming is to practice more. Today, I saw a very good article, I post: Sender: YCS830 (old goat), the letter area: c Title: Re: If you quickly learn the C language Society C language is easy, it is not a few statements There are not a few functions. But it is another thing. Just like Huashan swordsmanship, Li Master learned a number of years, but no one won't win. Only three tricks were only losing, and the fox brother was a few hours, but he first saw the sent swordsmanship, and the integration needs to go back and forth with the master. Studying C is a process, I am now looking at C and ten years ago. Speaking of the bottom, c is just a tool, the question is what you want, how to do it. C is good, just like a priest, you can look down on other swords. But Yue does not learn to have the effect of the fox rush. Learning mathematics to logical thinking skills is a workout. Most of my math knowledge also gave teachers, but logical thinking ability is very useful for programming. Score, high generation, air solution as the basic course of mathematics, is really useful to me. The C language is dead, the algorithm is alive, just like the khikijoul. How do you think? Do you think slowly. Ok, now I will talk about today's topics, structures. Let's take a look at what is called struct. In fact, the structure is like records in the database, and the structure is equivalent to each attribute in a record. We are usually a whole, which is usually a whole. It's better than a student, and the students have his related properties, such as name, age, gender, class, and so on. Although multiple variables can be defined in the program, we represent these properties, so that one of them will not focus on a whole, so the C language takes into account this structure. Let's take a look at how to define a structure, as follows: struct student {char name [10]; char sex; intact;::}; / * Note 喔, this semicolon is must be 喔 * / define one Structural student, but this is definitely not defined a variable that can be called, which is just a structure, we have to define a variable of a structure, just like definition actually type: int A, b; and Struct Student A, b; all the same truth, just define a variable, the type is to look at the front. The same type can be defined, such as Struct Student * P; this is also correct (some of the structural arrays). This type of pointer is very important in the list you want to talk, then let's take a look at this structural pointer first.

We can also point to the first address of this structure with a pointer: A.SEX = 'm'; this is the element operator in the most call structure. Struct Student * P; (* p). SEX = 'm' This is also the same here, but the structure has another well-expressed manner, and it is used to use another operation symbol->. P-> sex = 'm'; let's understand this expression, P is address, -> This is in this structure, p-> sex is pointing to the element in this structure. Time is very fast, I haven't mentioned how much I am going to school? I don't have much to say it. Today is this. Day 12, on August 18, 2002, the teacher and us talked about the list. As everyone in the old Tan book, everyone can listen to it. So here, I will no longer be repeated. Everyone will slowly look at the chain of the old Tantan book, and it will never feel difficult, but also some vivid examples come to illustrate. Below I found some articles about the pointer from the Internet, this person is definitely a master, everyone should study it. I believe that there is a probably a pointer after reading the first pass, the second time I have impressed in my mind, and the third time I can tell it. Serve for beginners. This is my post. I am also an initiator (emphasizing countless times), I put it out with my understanding of the initiator. Due to the language of the primary school, the language is not necessarily to achieve this goal. Try to do our best. The pointers are difficulties and focuses in C and C . I only master the BASIC under DOS. Other various features of the C language, there are similar things in Basic. Only pointers are not available in Baisc. The pointer is the soul of C. I don't want to repeat most books, I just said that I didn't know if I have seen the book I have seen, and I think I understand something that I understand is a bit. My purpose is: 1. Written by writing these things, clearing the blurred knowledge about C in my head. 2. Give beginners a little prompt. 3. Earn a few experience values. (Because it is suspected of sticking these things) first chapter. The concept pointer of the pointer is a special variable, which is interpreted as an address in the memory. To figure out a pointer, you need to figure out the four aspects of the pointer: the type of pointer, the type pointed to by the pointer, the value of the pointer or the memory area pointed to by the pointer, and the memory area occupied by the pointer itself. Let us explain separately. First declare several pointers to put the example: Example 1: (1) INT * PTR; (2) Char * PTR; (3) int ** PTR; (4) int (* ptr) [3]; (5) INT * (* PTR) [4]; If you don't understand a few examples, please refer to the article I posted for some time. "How to understand the complex type declaration of C and C >>. 1. Type of pointer. From a grammatical point of view, you only need to remove the pointer name in the statement statement, and the remaining part is the type of this pointer. This is the type of pointer itself. Let's take a look at the type of each pointer in Example: (1) INT * PTR; / / The type of pointer is int * (2) char * PTR; / / pointer type is char * (3) int ** PTR; / / The type of pointer is int ** (4) int (* ptr) [3]; / / The type of pointer is int (*) [3] (5) INT * (* PTR) [4]; // pointer The type is int * (*) [4]? Is it very simple to find out the type of a pointer? 2. The type pointed to the pointer. When you pass the pointer to access the memory area points to the pointer, the type pointed to by the pointer determines what the compiler will treat the content in the memory area. From the grammar, you only need to remove the pointer name and the pointer declare * on the left side of the name of the pointer statement. The remaining is the type pointed to by the pointer. For example: (1) INT * PTR; / / The type pointed to by the pointer is int (2) char * PTR; / / The type pointed to by the pointer is the CHAR (3) int ** PTR; / / pointer points to Type is int * (4) int (* ptr) [3]; / / The type pointed to by the pointer is int () [3] (5) INT * (* PTR) [4]; / ​​/ pointer points to The type is int * () [4] In the arithmetic operation of the pointer, the type pointed to by the pointer has a large role. The type of pointer (ie, the type of pointer itself) and the type pointed to by the pointer are two concepts.

When you are more familiar with C, you will find that the "type" "type" of the pointer stir together is divided into "the type of pointer" and "the type pointed to the pointer", which is the key point of the proficiency pointer. one. I have read a lot of books, I found some books that were poor, and the two concepts of the pointer were stirred together, so I looked at the conflict before and after, the more I saw it. 3. The value of the pointer or the memory area or address pointed to by the pointer. The value of the pointer is the value stored in the pointer itself, which will be used as an address by the compiler, not a general value. In a 32-bit program, all types of pointers are a 32-bit integer because the memory address is all 32-bit in the 32-bit program. The memory area pointed to by the pointer begins with the memory address represented by the value of the pointer, and the length is a memory area of ​​the SIZEOF (the type pointed to by the pointer). In the future, we said that the value of a pointer is XX, which is equivalent to the memory area that is the address of XX as XX; we say that a pointer points to a block memory area, which is equivalent to this pointer is this The first address of the memory area. The type of memory pointed to the pointer and pointer is two completely different concepts. In the example one, the type pointed to by the pointer is already, but since the pointer has not been initialized, the memory area indicted to it does not exist, or meaningless. In the future, every time a pointer should ask: What is the type of this pointer? What is the type pointing to the pointer? Where is the pointer pointing? 4. The memory area occupied by the pointer itself. How much memory itself does the pointer itself? You will know if you use a function Sizeof (type of pointer). In the 32-bit platform, the pointer itself occupies 4 bytes of length. The concept of the memory itself is useful when it is determined whether a pointer expression is a left value. Chapter two. The arithmetic operation pointer of the pointer can be added or minus an integer. The meaning of this operation of the pointer and the meaning of the usual value of the usual value are different. For example: Example 2: 1. CHAR A [20]; 2. INT * PTR = a; ... 3. PTR ; In the above example, the type of pointer PTR is int *, which point points to INT, which is initialized to point to the shaping variable A. In the next article 3, the pointer PTR is added 1, the compiler is processed: it adds the value of the pointer PTR with SIZEOF (int), in the 32-bit program, is added 4. Since the address is in units, the address pointed to by the PTR increases by 4 bytes from the address of the original variable A. Since the length of the CHAR type is one byte, the original PTR is four bytes that point to No. 0 unit of array A. At this point, at this point, at this point, at this point, at this point, the four bytes starting from the 11th unit in the array A. We can use a pointer and a loop to traverse an array, see example: INT Array [20]; int * ptr = array; ... // This will be omitted to the code of the integer assignment. ... for (i = 0; i <20; i ) {(* PTR) ; PTR ;} This example adds the value of each unit in the integer array 1. Since each loop is plugged in 1, the next unit of the array can be accessed each time a loop. Look at the example: Example 4: 1. CHAR A [20]; 2. INT * PTR = a; ... 3. PTR = 5; In this example, PTR is added 5, the compiler is processed: adding the value of the pointer PTR plus 5 by sizeof (int), in the 32-bit program plus 5 multiplication 4 = 20. Since the unit of the address is byte, the address pointed to by the current PTR moves 20 bytes to the high address direction than the address pointed to the PTR after adding 5. In this example, it is not added to the four bytes starting from the PTR before 5, and the PTR has pointed to the legal range of the array A. Although this situation will have problems in the application, but it is possible in grammar. This also reflects the flexibility of the pointer. If in the previous example, PTR is subtracted 5, then the processing process is similar, but the value of the PTR is subtracted to be subjected to 5 multiply SizeOf (int), the new PTR pointing is lower than the address pointed to by the original PTR. The address direction moves 20 bytes. Summary, after a pointer Ptrold couples an integer N, the result is a new pointer PTRNEW, PTRNEW type, and the type of Ptrold, the type pointed to by PtrNew and the type pointed to by Ptrold.

The value of the PTRNEW will add N-multiply SIZEOF (Type of Ptrold) by the value of Ptrold. That is to say, the memory area pointed to by PtrNew moves N-multiply SIZEOF (Type of Ptrold) by the memory area pointed to by PTROLD. After a pointer Ptrold minus an integer N, the result is a new pointer PTRNEW, the type of PTRNEW, and the type of Ptrold, the type pointed to by PtrNew and the type pointed to by Ptrold. The value of PTRNEW will reduce N-multiply size and the value of the N multiply sizeof (Type of Ptrold) by the value of Ptrold, that is, the memory area pointed to by PtrNew will move n-by-multiply SIZEOF in the memory area pointed to by PTROLD. (Type pointed to Ptrolt) byte. third chapter. Operators & and * Here & It is to take the address operator, * is ... The book is called "indirect operator". The calculation result of & a is a pointer, the type of pointer is the type of A plus a *, the type pointed to by the pointer is the type of A, the address pointed to by the pointer, that is, the address of A. * P The calculation result is a five-flowers. In short, the result is something pointed to P, this feature: It is the type of P pointing, and its address is the address pointed to by P. Example 5: INT A = 12; int b; int * p; int ** PTR; P = & // & a result is a pointer, the type is int *, the pointing type is int, the pointing address is the address of A . * P = 24; // * P results, here it is int, the address it occupies is the address pointed to by P, apparent, * p is the variable A. The result of PTR = & / / / & P is a pointer, the type of the pointer is the type of P, adding a *, here is Int **. The type pointed to this pointer is the type of P, which is int *. The address points to the pointer is the address of the pointer P. * PTR = & // * Ptr is a pointer, and the result of & B is also a pointer, and the type of two pointers and the type pointed to the type, so use & b to give * PTR assignment is no problem. ** PTR = 34; // * PTR's result is something pointed to by PTR, here is a pointer, and then doing the pointer again * calculation, the result is a Int type variable. Chapter Four. Pointer expression. The last result of an expression If it is a pointer, then this expression is called a pointer expression. Here are some examples of pointer expressions: Example 6: Int A, B; int Array [10]; int * Pa; PA = & // & a is a pointer expression. INT ** PTR = & // & pa is also a pointer expression. * PTR = & // * PTR and & B are both a pointer expression. PA = Array; PA ; // This is also a pointer expression. Example 7: char * arr [20]; char ** PARR = arr; // If arr is regarded as a pointer, Arr is also a pointer expression char * STR; str = * parr; // * Parr is a pointer expression STR = * (PARR 1); // * (PARR 1) is a pointer expression Str = * (PARR 2); // * (PARR 2) is a pointer expression due to pointer expressions The pointer expression also has four elements of the pointer: the type of pointer, the type pointed to by the pointer, the memory area pointed to by the pointer, the memory itself occupies. Ok, when a pointer expression results pointer have explicitly have the memory itself, this pointer expression is a left value, otherwise it is not a left value. In Example 7, & A is not a left value because it has not yet occupied a clear memory. * PTR is a left value, because * PTR This pointer has occupied memory, in fact, * PTR is a pointer PA, since PA has already had its own position in memory, then * PTR has its own position. chapter Five. The relationship between arrays and pointers If you don't understand the statement of the declaration array, please refer to the article I have been posted for some time. "How to understand the complex type declaration of C and C >>.

The number of groups of arrays can act as a pointer? Cong Lu? Example 8: int Array [10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, value; ... ... value = array [0]; // can also be written: value = * array; value = array [3]; // can also be written: value = * (array 3); value = array [4]; // can also be written: value = * (Array 4); in the upper example, generally, the number of group names array represents the array itself, the type is int [10], but if Array is as a pointer, it points to the array 0 units, types are int *, the type pointed to which is the type of array unit, inT. So * Array is not surprising. Similarly, Array 3 is a pointer to the third unit of array, so * (array 3) is equal to 3. Others are so pushing. Example 9: CHAR * STR [3] = {"Hello, this is a name!", "Hi, Good Morning.", "Hello World"}; char s [80]; STRCPY (S, Str [0]) ; // can also be written as STRCPY (S, * STR); STRCPY (S, STR [1]); // can also be written into STRCPY (S, * (STR 1)); STRCPY (S, STR [2]) ; // can also be written as STRCPY (S, * (STR 2)); in the above example, STR is an array of three units, and each unit of the array is a pointer, which points to a string. That a pointer is used as a pointer, it points to the number 0 unit of the array, its type is char **, which is a type of char *. * STR is also a pointer, its type is char *, the type it is pointing is char, which pointing the address is the first character of the string "Hello, this is a sample!", 'h' address. Str 1 is also a pointer, pointing to No. 1 unit of array, its type is char **, which is a type of char *. * (STR 1) is also a pointer, its type is char *, which is the type of char, which points to "Hi, Good Morning." first characters 'h', and so on. The following is summarized below the number of group names of the array. Declare an array type array [n], then array name Array has two meanings: First, it represents the entire array, its type is type [n]; second, it is a pointer, the type of the pointer Is Type *, the type of pointer is Type, which is the type of array unit. The memory area points to which the pointer points is an array No. 0 unit, which accounts for a separate memory area, pay attention to it and the array No. 0 unit The memory area is different. The value of the pointer cannot be modified, ie the expression like Array is wrong. ARRAY can play different roles in different expressions in different expressions. In the expression sizeof (array), the array name array represents an array itself, so the sizeOf function measured the size of the entire array at this time. In the expression * array, Array plays a pointer, so the result of this expression is the value of the array No. 0 unit. SizeOf (* array) is measured by the size of the array unit. Expression Array N (where n = 0, 1, 2, .....), Array plays a pointer, so the result of Array N is a pointer, its type is type *, it points to the type It is TYPE, which points to the array N number unit. Therefore, SizeOf (Array N) is measured by the size of the pointer type. Example 10: Int Array [10]; int (* ptr) [10]; PTR = & in the previous example PTR is a pointer, its type is int (*) [10], the type he point to INT [10] We initialize it with the first address of the entire array. In the statement PTR = & Array, Array represents an array itself.

In this section, the function sizeof () is mentioned, then I will ask questions, the SIZEOF (pointer name) is measured by the size of the pointer itself or the size of the type pointed to by the pointer? The answer is the former. For example: int (* ptr) [10]; in the 32-bit program, there is: sizeof (int (*) [10]) == 4 sizeof (int [10]) == 40 sizeof (PTR) == 4 In fact, SizeOf (object) is measured by the size of the object itself, rather than any other type of size. Chapter Six. The relationship between pointers and structural types can declare a pointer to the structural type object. Example 11: struct mystruct {int A; int b; int C;} mystruct ss = {20, 30, 40}; // Declare structure object SS, and initialize SS three members to 20, 30 and 40 . MyStruct * ptr = & // Declare a pointer to the structural object SS. Its type is mystruct *, which points to which is mystruct. INT * PSTR = (int *) & // declares a pointer to the structural object SS. But its type and the type and PTR it point to it are different. How to access the three member variables of SS through the pointer PTR? Answer: ptr-> a; ptr-> b; ptr-> c; how to access the three member variables of SS by pointer PSTR? Answer: * PSTR // Access the member a of SS. * (PSTR 1); // Access the member B of SS. * (PSTR 2) // Access the member C of SS. Oh, although I have repel the above code in my MSVC 6.0, I have to know that I use PSTR to access structural membership is inquirable. In order to explain why I don't regular, let's see how to access arrays through the pointer. Each unit: Example 12: int Array [3] = {35, 56, 37}; int * pa = array; three units of the three units of array from the pointer PA are: * pa; // Access 0 Number * (PA 1); // Access the No. 1 unit * (PA 2); // Access the No. 2 unit from the format is the same as the format of the unflavible method of accessing the structure by the pointer . When all the C / C compilers are arranged in the array, the individual array units always store each array unit in a continuous storage area, and there is no gap between the unit and the unit. However, when the various members of the structural object, in a certain compilation environment, the word alignment or double word alignment or other alignment is required, it is necessary to add a number of "padding bytes" between adjacent two members. This leads to a number of bytes of voids between each member. So, in Example 12, even if the * PSTR accesses the first member variable A of the structural object SS, it is not guaranteed * (PSTR 1) will be able to access the structural member B. Because there may be some filling bytes between member a and members b, maybe * (PSTR 1) just visited these padding bytes. This also proves the flexibility of the pointer. If your purpose is to see if there is any fill byte between the members of each structure, hey, this is a good method. The correct way to access structural members through the pointer should be a method of using a pointer PTR in an example 12. Chapter VII. The relationship between the pointers and functions can declare a pointer into a pointer to a function. INT FUN1 (CHAR *, INT); int (* pfun1) (char *, int); pfun1 = fun1; .... .... Int a = (* PFUN1) ("Abcdefg", 7); ///// By function pointer 饔      指 指 指 作为 形.. In a function call statement, you can use a pointer expression as an argument. Example 13: INT Fun (Char *); int A; char str [] = "abcdefghijklmn"; a = fun (str); ... int fun (char * s) {Int num = 0; for (INT i = 0; i {NUM = * S; S ;} return;) This example is the sum of the ASCII code value of each character in a string.

As mentioned earlier, the name of the array is also a pointer. In the function call, after the STR is transmitted to the formation S, the value of the STR is passed to the address pointed to the STR, which is consistent with the address pointed to by the STR, but the STR and S are occupied. Storage space. The self-inclination of S in the function is not intended to be a self-adding 1 calculation on the STR. chapter eight. Pointer Type Conversion When we initialize a pointer or assign a pointer, the left side of the assignment number is a pointer, the right side of the assignment number is a pointer expression. In the example we mentioned earlier, in most cases, the type of pointer and the type of pointer expression is the same, the type pointed to the pointer and the type pointed to by the pointer expression. Example fourteen: 1. Float f = 12.3; 2. Float * fptr = & 3. INT * P; in the above example, if we want the pointer P to point to the real number f, how should it be? Is it using the following statement? P = & wrong. Because the type of pointer P is int *, the type it points to is int. The result of expression & f is a pointer, the type of pointer is float *, which point points to float. The two are inconsistent, and the method directly assigned is not. At least on my MSVC 6.0, the assignment statement of the pointer requires the same type of assignment number, the type pointed to the same, the same type, I have not tried it on other compilers, everyone can try it. In order to achieve our goal, it is necessary to "Mandatory Type Conversion": P = (INT *) & If there is a pointer P, we need to change its type and the type pointed to Tyep * and Type, then the syntax format is: (TYPE *) P; This is the result of the forced type conversion is a new pointer. The type of new pointer is type *. It points to Type, which is the address whose point points to the original pointer pointing. And all attributes of the original pointer P have not been modified. A function If the pointer is used as a ginseng, the pointer type conversion will occur during the combination of the actual parametric and metall parameters of the function call statement. Event 15: Void fun (char *); int A = 125, b; fun ((char *) & a); ... ... void fun (char * s) {char C; c = * (s 3); * (S 3) = * (S 0); * (S 0) = C; c = * (S 2); * (S 2) = * (S 1); * (S 1) = C;}} Note that this is a 32-bit program, so the int type accounts for four bytes, and the char type accounts for one byte. The function of function FUN is to reverse the order of the four bytes of an integer. Notice? In the function call statement, the result of the real arguments & a is a pointer, its type is int *, which is the type whose point is Int. The type of parameter this pointer is char *, which is the type of CHAR. Thus, during the binding process of the arctic and meticulum, we must conduct a conversion from int * type to char * type. Combined with this example, we can imagine the process of transformation of the compiler: The compiler first constructs a temporary pointer char * TEMP, then execute Temp = (char *) & A, and finally passing the value of TEMP to S. So the final result is: the type of S is char *, which is the type of char, which is the first address of A. We already know that the value of the pointer is the address pointed to by the pointer. In the 32-bit program, the value of the pointer is actually a 32-bit integer. Can you assign an integer directly to the pointer directly as the value of the pointer? Just like the following statement: unsigned int a; type * ptr; // type is int, char or structural type. ... a = 20345686; PTR = 20345686; // Our purpose is to make the pointer PTR point to address 20345686 (decimal) PTR = a; // Our purpose is to point the pointer PTR to address 20345686 (decimal) Compile it. It was found that the following two statements were all wrong. So, is our purpose? No, there is also a way: unsigned int a; type * ptr; // type is int, char or structural types. ... a = a number, this number must represent a legal address; PTR = (Type *) a; // Oh, this is OK.

Strictly speaking (Type *) and pointer type conversion (Type *) is still different. Here (Type *) means that the value of the unsigned integer A is treated as an address. The above emphasizes that the value of A must represent an legitimate address. Otherwise, if you use PTR, illegal operational errors will occur. Think of that you can't turn it, the value of the pointer to the pointer is taken out as an integer. absolutely okay. The following example demonstrates the value of a pointer as an integer, then uses this integer as an address to a pointer: Example 16: INT A = 123, B; int * Ptr = & char * STR ; b = (int) PTR; // Put the value of the pointer PTR as an integer. Str = (char *) b; // Put the value of this integer as an address to the pointer STR. Ok, now we already know, you can take the value of the pointer as an integer, or you can use an integer value as an address to a pointer. Chapter nine. Safety problem of pointer looks down below: CHAR S = 'a'; int * ptr; ptr = (int *) & * ptr = 1298; pointer PTR is an int * type pointer, it points to type Be int. The address it points to is the first address of S. In the 32-bit program, s is one byte, and the int type is four bytes. The last statement not only changed one byte of S, but also changes the three bytes of the high address direction from S. What is the three bytes do? Only the compiler knows that the writer is unlikely. Perhaps these three bytes have a very important data, perhaps the three bytes are just a code of the program, and because of your horses and tiger applications, these three bytes have changed, this will Resulting in crash errors. Let's take another example: Eighteen: 1. CHAR A; 2. INT * PTR = & ... 3. PTR ; 4. * PTR = 115; this example can be compiled and can be executed. But seeing no? The third sentence is used for the pointer PTR, and the PTR points to a storage area in the high address direction adjacent to the plastic variable A. What is this storage area? We don't know. It is possible that it is a very important data, and may even be a code. The fourth sentence actually writes a data in this memory area, which is a serious mistake. So when using a pointer, the programmer must be very clear: Where is my pointer pointing? When accessing arrays with a pointer, be careful not to exceed the low-end and high-end boundaries of the array, otherwise a similar error can also cause a similar error. In the mandatory type of the pointer TR1 = (Type *) PTR2, if SIZEOF (Type of PTR2) is greater than SizeOf (Type of PTR1), it is secure when using the pointer PTR1 to access the PTR2. If SIZEOF (Type of PTR2) is less than SizeOf (PTR1), it is not safe when using the pointer PTR1 to access the storage area pointed to by PTR2. As for why, the reader will think about it in conjunction with the seventeen, it will be understood. On the 13th, 2002, I was particularly excited today. I got up very early. I took the computer before I left, and of course, I didn't know if I could do this after school, because some factors in the family. However, as long as I can serve everyone, I am very happy, and there is also a sense of strong happiness. This kind of happiness is not a general family happiness. I have done it, I often ask some netizens about this matter. They all say that only you can do it, they all support me to do it, say far away, I said today. . Today's curriculum also made me aesthetically surprised, it is a tree in the data structure. Why didn't you talk about the tree directly? Will you get too fast, and we have just finished the fake, some people have not concentrated the spirit to class. However, I will believe that the teacher's choice should have his reasons. Then tell some basic concepts of the tree, everyone knows that the tree is one of the nonlinear structures in the data structure. It is completely different from the list of the previously, and the list is only the front drive and the subsequent node, but the tree is not. He can have a lot of nodes, called branch nodes, and his branch node can have branch nodes. Because the concept of the tree is too much, I have to look at the book. The tree is used very widely, and the file management in our operating system is, multi-level directory. The secondary directory is like the tree tree of the tree, and there may be a lot of sub-trees in the sub-tree, the more the next level.

Let's try to define a tree structure. The general tree is very casual. All us will also draw a tree here. Look at the picture (13th day Figure 1) We see that the circle represents a node, And the top of the top is the root point, and the down is the sub-node. The previous one of the sub-nodes is the parent node, and the same level is from the brothers. We define one according to this structure, as follows: struct tree {int Data; Struct Tree * next; / * Right brother node * / struct tree * pre; / * left brothers Node * / Struct Tree * Up; / * Father Node * / struct tree * down; / * sub-node * /}; let's see how to build a tree. [CODE: 1: 02699cb095] struct Tree * p, * r; r = (struct tree *) malloc (Struct Tree); / * Establish root node space * / r-> DATA = 3; / * root Node assignment * / r-> next = r-> pre = r-> Up = null; p = (struct tree *) malloc (Struct Tree)); / * Establish a second node * / r- > down = p; / * Sub nodes of root nodes are connected to new sub-nodes * / p-> data = 5; / * Subpoint assignment * / p-> pre = null; p-> next = (Struct Tree *) Malloc (Struct Tree)); P-> Next-> Data = 2; P-> Next-> pre = p;::: [/ code: 1: 02699cb095] Because of the more No regularity, all such establishment methods cannot be used, now just take it out to study how a tree is established. Now talk about another tree "binary tree". Because the binary tree is compared with the general tree structure, the binary tree is more standardized and more determined, so applications are more wide than the tree. The binary tree is different from the tree, and the first binary tree can be empty, the empty binary tree has no nodes; in addition, in the binary tree, the bifurcation of the node is ordered, and the left and right sub-bifurcies. How is the binary tree be established? It is very simple here because the binary tree has its regularity. Please see [Code: 1: 02699cb095] Typedef struct bnot {int data; struct bNode * Left, * right;} btree; void Creat BTree * b) {int x; btree * S; b = null; do {scanf ("% d", & x); s = (btree *) malloc (sizeof (btree)); S-> Data = x; s -> LEFT = S-> Right = NULL; INSERT (B, S);}} void insert (btree * b, btree * s) {if (b == null) b = s; ELSE IF (S-Data = = B-> DATA) RETURN (); Else IF (S-Data data) insert (b-> left, s); Else IF (S-Data> B-> Data) INSERT (B-> Right , S);} [/ code: 1: 02699cb095] This procedure only established only one tree, and it is also placed (left on a small right). Enter the corresponding value to see the result, as shown on the thirteenth day. Today is these, and you have to be able to see more recursive procedures, because the establishment and operation of the tree is inseparable.

It is also the following questions, it is known to have a disorderly binary tree, allowing us to use the middle traversal to arrange a large to a small program. Day 14, on August 18, 2002, continued to talk about binary trees today, and an important operation of the tree is traversed. The so-called traversal is to output all the nodes, and the binary tree is different from the tree, because the binary tree is characterized by the left and right sub-trees, all of which have another traversal method, is the order. These traverses are also very simple, the most important thing is to look at the front of the root traversal. Here, see the 14th day, these color circles are representatives as a tree, all we know that their rules can be written, the procedures are also very simple, as follows: [Code: 1: AFF89524CB] OUT1 (btree * T) / * Pre-sequence * / {Printf ("% D", T-> DATA); OUT1 (T-> LEFT); OUT1 (T-> Right);} OUT2 (BTREE * T) / * Order Traverse * / {OUT2 (T-> Left); Printf ("% D", T-> DATA); OUT2 (T-> Right);} OUT3 (BTREE * T) / * Sequence Traverse * / {OUT3 T-> Left); OUT3 (T-> Right); Printf ("% D", T-> Data);} [/ code: 1: AFF89524CB] The above three traversal is not very simple (this is in mind I will understand it), and they are like just changing the position, and we can see that if the output of the predecessor is the first, follow the left tree to the right tree. After reading the traversal Look at the binary look tree, the binary look tree is such a tree, and his left knot is smaller than the root, and the right node is greater than the left knot. There is such a nature, so his insertion is particularly good, and the method of designing this sequential traversal is particularly good, because this tree is originally sorted. Let's take a look at how the program is implemented [CODE: 1: AFF89524CB] INSERT (BTREE * H, BTREE * P) {if (h = = null) h = p; P-> Left = P-> Right = NULL ; / * The last node must be no left and right bonus * / else {if (p-> Data data) insert (h-> left); if (P-> Data> H-> Data) Insert (H-> Right);}} [/ code: 1: AFF89524CB] It looks very simple, but because of the recursive to understand some ideas, see how it produces inserted to the right position, and the former one Like the establishment of the two-fork trees, it is also comparing his value large and small position. Everyone should understand well. It is because several students in our class are more strange to the tree, can't keep up, so the teacher decided to first put the tree, in fact, there are still many knowledge of the tree, but I have to wait a row of thinking. It can continue, in fact, if I haven't seen myself before, I may really can't understand when I said it, I can't understand it. Time really used a lot of things on these trees, and there is no big effect. Teachers are also working immediately, skip this section to find this chapter. It is actually that we will always have accessible. In particular, when I learned FoxBase, I basically fell inseparable, but the lookup at that time was such a command. Now I have to make myself, I really are very fun. I used to completely encapsulated FoxBase commands. Today, I have to build it in the C language of this system to study it. The previous list and structure are used to do a database (if I have no estimation.). Said more, and immediately talk about the situation in learning. The order looks to believe that everyone knows the principle, because one of a order judgment is equal to this is the most common. I am not talking here, I will continue to talk about one, and I've been folded. Before talking about this, the teacher and we did a game, that is, he wrote a value on the paper, and we guess it in 1 to 1000. If we say the number of teachers, the teacher is too big, too small.

In fact, this folding half of the primary is always seen in QB, and there is nothing difficult. Soon we will guess the number of guess it in accordance with that method. Teacher see us understand it. Tell us to write a program. At the time, I saw that this question of repeated regular regularity has been doing this, but I am wrong, but this is going to learn another trick. Let's take a look at my programs first, as follows: If a [] is already a value, but it is still in order. [CODE: 1: AFF89524CB] SerCH (int R, INT K, INT N) {INT MID; if (r> k) Return (-1); Else {MID = (R K) / 2; IF (A [ MID]> N) SERCH (R, MID-1, N); IF (a [MID] k) Return (-1); MID = (R K) / 2; IF (a [MID] = = N) Return (MID); ELSE {a [MID]

[CODE: 1: AFF89524CB] INT A [10] = {8, 7, 10, 30, 5, 1, 7, 10, 0, 25}; INT I, J, K; For (i = 1; i < n; i ) {for (t = e ['I], j = I-1; j> = 0 && t a ['I]) {t = a [j]; a [j] = a [' i]; a ['i] = t;}} [/ code : 1: AFF89524CB] No [code: 1: AFF89524CB] for (i = 1; i = 0; J -) IF (k> a [j]) Break; ELSE A [J 1] = a [j]; a [j 1] = k;} [/ code: 1: AFF89524CB] before three programs Everyone is analyzed, be sure to have a brain to think. Ok, the problem is finally coming out, that is, the algorithm of this sorting becomes a chain form. Do you think of it? We all rush to try it? But in the end, it is not possible, and if it is normal to get in front of it, all we have not made. Let's take a look at the program written by the teacher: Sketch of the top definition [Code: 1: AFF89524CB] P = H-> next; h-> next = null; while (p) {ix (p-> data < H-> data) {q = p-> next; p-> next = h; h = p; p =} else {q = h; r = q-> next; while (R && P-> DATA > r-> data) {q = r; r = r-> Next;} Q-> next = p; p = p-> next; q-> next-> next = r;}} [/ code: 1 : AFF89524CB] Today I am a little lost, it may be because of the questions, anyway, I don't know anything, but I still stick to it, I will continue to work hard, I hope everyone can work hard with me. 16 Tian today continues to be sorted by the chain form, the day before yesterday, everyone can understand. Don't understand it, it is going to come slowly, and you can't come.

[CODE: 1: AFF89524CB] P = h-> next; h-> next = null; while (p) {if (p-> data data) {= p-> next; p-> next = H; h = p; p =} else {q = h; r = q-> next; while (r && p-> data> r-> data) {q = r; r = r-> Next } Q-> next = P; p = p-> next; q-> next-> next = r;}} [/ code: 1: AFF89524CB] According to the idea of ​​this program, let us think about the entire process This procedure is divided into two parts. Part of the node value to be sorted is plugged into the first one, because if the one of the comparative head is already less than it, Don't compare it. If the node value to be inserted is not less than the current header node, then you should find the right position to insert the node, let's see what Q and R pointer are used to do, it points to the head Pointers h and r point to Q pointers, because we know that the shortcomings of the one-way linked list cannot know what it is in front of it, so it may be guided to the linked list. Our purpose is to use Q to save its previous node. There are two possibilities in the While cycle, one is R is empty, where R is empty, explaining that this linked list is already the last one, so the junction that is inserted directly is inserted. As for P-> Data> r-> DATA is to wait for P-> Data than r-> Data hours, you can continue to insert down the steps of the insertion. The While is that if these two conditions are true, the explanation has not found yet, then the two double-chain pointers will be moved afterwards, and then they can be inserted. If you still have more vague, you don't want it, then look at this procedure below: [CODE: 1: AFF89524CB] struct node * li_sort (struct node * h) {struct node * t, * s, * u, * v; s = H-> next; h-> next = null; while (s! = null) {for (t = s, v = h; v! = null && v-> data data; u = v, v = V-> Next; if (v == h) h = T; Else U-> Next = T; t-> next = v;}} [/ code: 1: AFF89524CB] We can see that this program is very similar to it, but it is more simplified, and the entire judgment is in a for statement. Let's take a look at this program, I believe that if you think about it, everyone should understand. S = H-> Next and H-> Next = NULL These two sentences are the same, and they separate them into partned part and to be sorted. Following the main thing to see the for statement, because all judging conditions are here. Here T is the temporary variable generation S, the role of S is the node, V and U pointers that are currently inserted, and Q and R of the above programs are the disadvantages of the unidirectional linked list. The conditions here are the same, and the above programs are the possibility of integrating two situations. It is the following procedure to make a condition to be inserted into the head or in the middle?? Still a sentence to be your own The brain is thinking, this sixteenth day is a whole process. Of course, the one-way linked list is to talk about the two-way linked list, because the two-way linked list can go forward, so the program is better, but it is the insertion and deletion of it, and it is another practice Link list operation. Opportunity.

Everyone thinks yourself, try to write the procedure, with the basis of the above one-way linked list should be easy to follow the idea. Everyone sends a good program to http://zhgpa.vicp.net/bbs programmer exam, see where everyone's way is discussed. Don't look at me below: Some definitions [CODE: 1: AFF89524CB] while (p) {for (q = p-> pre, r = p; Q && P-> Data Data; Q = Q-> pre); p = p-> next; r-> pre-> next = p; if (p) p-> pre = r-> pre; if (q) {p-> next = Q- > next; if (q-> next) q-> next-> pre = p; p-> pre = q; q-> next = p;} else {r-> Next = h; r-> pre = null H-> pre = r;}} [/ code: 1: AFF89524CB] Ok, what is your program? I hope everyone will discuss it. Although the contents of learning in these days, it is absorbed by a lot of experience, and now the operation of the list is more step forward. I know some ways to analyze the program. Programming this road is really long. I don't understand anything in this road, but I will stick to it. On the 17th day, I lost five days from the last time, but I was just a few blink of an eye in my eyes. Because I didn't have anything in my mind in the past few days, I have a repetition and simple life every day. How simple method? That's of course, sitting in front of the computer, you can talk about it all day. Ok! Ok, don't say this, this is not the focus I want to say. I would like to ask if you have to learn about the document? Here is the truth, I didn't pay too much attention to it when I came to the C language before, I casually turned him over (um! It's so simple, I I understand, after it. I really had a bitter, I found a bitter, I found out that I didn't understand the text flow and the concept of binary stream at all. God! It is very simple from the text surface. It is not that the content is the ascii code is the text, and the binary flow is of course the content is binary. Haha is not simple. I think so too, the concept of text flow is to understand, but the credit will be confused. I always think that the file I opened is "101100101" in binary form, but I don't see this, but some symbols I don't know at all. All this is all of this day, but all this has passed. I truly realize that these concepts, in fact, the binary flow is not true that the content stored is 101001, which is the same as in the form of memory, so each blame is composed of these consecutive bits per 8 bits.

Hey ~, I have been working so many days. The first thing to go back to the school today is of course the homework that is arranged during the holiday. Hey, don't tell others that my program is done last night, and there is still Bug is here! Now I haven't changed the original procedure when I didn't change the time: [Code: 1: AFF89524CB] #include #define size 5 typedef struct student {int Num; char name [10]; int score; float averge; Struct student * next;} student; void main () {file * fp; student * h, * p; int i; if ((fp = fopen ("stud.txt", "wb") == null) {printf ("Can't open the file"; exit (1);} h = p = (student *) malloc (SIZEOF (STUDENT)); for (i = 0; i num, p-> name, & p-> score); / * Here you often have inexplicably strange problems * / P-> AVERGE = P-> score / 3; P-> Next = (student *) malloc (SIZEOF (STUDENT)); P = P-> Next;} P-> Next = null; for (p = h, i = 0; I next) {Printf ("% s", p-> name); fwrite (p, sizeof (student), 1, fp); / * Here, it is not possible to use a pointer * /} Fclose (fp);} [/ code: 1: AFF89524CB] Here, I have encountered two problems. I have encountered it before, but I didn't pay attention to it. But now I have a hard time. But now the network is convenient, and 9CBS Master is like a cloud, there is a problem, of course, is 9CBS (not selling advertising? Haha). 9cbs learned that the original scanf () This function has a buffer problem, so the number of inputs is not ended, there is a method herein. Give Scanf ("% D% S% D", & P-> Num, P-> Name, & P-> score; above with a function of processing buffer FFLUSH (stdin); as for usa The book is fine. The second question is not a problem after learning the reason, in fact, it is right.

Why do I have this misunderstanding, the reason I am trying to read the data, add some additional supplementation procedures as follows: [Code: 1: AFF89524CB] #include #define Size 5 Typedef strunt student {int Num; char name [10]; int score; float avert; struct student * next;} student; void main () {file * fp; student * h, * p; student test [size]; / * Plus this definition is for the following test * / int i; if ((fp = fopen ("STUD.TXT", "WB") == NULL) {Printf ("can't open the file"; exit) 1);} h = p = (student *) Malloc (SIZEOF (STUDENT)); for (i = 0; i num, p-> name, & p-> score); p-> avert = p-> score / 3; P-> Next = (student *) malloc (SIZEOF (STUDENT)); p-> next = null; for (p = h, i = 0; i Next) {Printf ("% s", p-> name); FWRITE (P, Sizeof (student), 1, fp); / * Here, I don't do * /} / *** Here, add file *** / for (i = 0; i

Here the parameters are 0, which means that the file pointer points to the top, ok, look at the results we want. Let's continue to study the chapter of the file. Have you ever thought about displaying the program C program you wrote itself on the screen, of course, not using some other commands such as DOS command type, just use C language programs Read itself. In fact, this problem is too simple. Have you seen the chapter of the old pool? Remember the small instance of the file COPY? Haha ~~, look at the program: [Code: 1: AFF89524CB] #include main () {file * fp; char C; IF ((fp = fopen ("Currently Write File Name", "R") == NULL) {Printf ("Can't Open THE FILE"; EXIT (1 );} C = fgetc (fp); WHLE (! Feof (fp)) {c = fgetch (fp); PUTCHAR (C);}} [/ code: 1: AFF89524CB] Remember? Yes, this is this Simple, follow the more challenging below. We will output your own reversal, 嘻嘻, in fact, don't be afraid. If you have the two file functions of fseek () and ftell (), everyone will try to write, My procedure is as follows: [Code: 1: AFF89524CB] #include main () {file * fp; char C; long se; if ((fp = fopen ("currently written file name", "R ") == null) {printf (" can't open the file "; exit (1);} fseek (fp, 0, 2); / * Here is the last byte * / se = ftell (FP ); / * Combined with the top number of total characters * / for (; se> = 0; SE -) {FSeek (FP, SE, 0); FREAD (& C, 1, 1, FP); P / CARAR ( c);}} [/ code: 1: AFF89524CB] Look, is it very cool and very enjoyable, your own source procedure is over. Ok, the article also comes to a paragraph. Because this afternoon must go to school reasons Nature's things are more, then ... Hey, my word should be more, this is to got everyone. But because I have done a lot of initial topics today, I don't have much. Write up, write a more useful, as follows: [Code: 1: AFF89524CB] / * This program's role is to change the letters in a character array to lowercase * / void main () {INT i = 0 CHAR S [120]; Printf ("e NTER a string / n "; scanf ("% s ", s) while (_____) {if (_____) s [· i] = s [· i] - 'a' 'a'; i ;} Printf "% s / n", s);} [/ code: 1: AFF89524CB] If it is more familiar with the string, I believe that this question is already in the case. The scary sentence here is S = s-'a ' ' a '; it is actually nothing, everyone thinks about sending your answer to http://zhgpa.vicp.net/bbs (no way My site is very popular, huh, oh, okay, I haven't ended this. I don't have to say it today. I don't have to say anything in the 18th day, I will enter the topic (So I will say that I have more saliva, haha) . So what do you have learned today? The knowledge is of course absorbed every day, but it cares much. Sometimes a small problem that looks, it can trigger other problems, all of which look at yourself, see how you treat these problems.

We are now doing an initial topic. You don't want to see less initial questions. In fact, this question I have seen it in the middle of the test questions, but different places just change it to pointers. So I also want to talk about it, in fact, most of the questions in the middle are flexible around the pointer (I don't think it as "hard", just too "flexible", it is difficult to master some, So the people in the same way we have taken the way must be well mastered. The problem is as follows: Read the following programs and C code, will be filled in the words of __ (n) __, write in the corresponding column of the answer sheet. [Program Description] A bead having different colors numbered No. 0 to N-1 (alphabetic, the color of the N-grain beads is represented by the input character string for the color of the N-grain beads. The ring is divided in the ring, and the beads on the ring form a sequence, then take the beads from the sequence as follows: First take all the continuous pairing beads from the left end of the sequence; then from the right end of the sequence in the remaining beads All continuous cohable beads were taken away, and the two of the two can be taken away from the number of beads. Cutting at different positions, the number of beads that can be taken is endless. The procedure is obtained which position is cut on the ring, and the number of beads that can be taken away according to the above rules. The array is stored in the program. For example, 10 granular beads correspond to "AaabbBADCC", cut from the top 0 beads, the sequence is aaabbbadcc, take 3 capsules from the left end, take the 2 grain C color beads from the right end, take a total of 5 Particle beads. If the BBBADCCAAA can take 6 beads in front of the 3rd beads. [Code: 1: AFF89524CB] [Program] #include int count (char * s, int start, int end) {INT i, c = 0, color = s [start], step = (start> End)? -1; 1; for (i = start; s [· i] = color; i = step) {if (step> 0 && I> end || __ (1) __) Break; __ (2 ) __} Return C;} void main () {Char T, S [120]; INT I, J, C, LEN, MAXC, CUT = 0; Printf ("Please enter the ring on behalf of different color bead strings:" ); Scanf ("% s", s); len = strlen (s); for (i = maxC = 0; i maxc) {CUT = I; MAXC = C;} / * array S element cycle to left Move a location * / t = s [0]; for (j = 1; j

The first is the program in the main function, for (i = maxc = 0; i End)? -1: 1; Wonderful cooperation with the problem IF (Step> 0 && I> end || __ (1) __) Break; __ (2) __ It is not difficult to see here, because there are two possibilities, here is the first empty only judged that the direction has not judged in the opposite direction, what are you waiting for? Isn't you fill in the answer right? Setp <0 && i

[Program Description] The function of the function first_insert () in this program is to insert a specified value-based gate before the first table of the known chain table; the function REVERSE_COPY () function is to copy a new list in the known chain table, but The sequence of the new list of the new list is reversed in the order of the table meta links of the known chain table; the function print_link () is used to output the value of each table element in the linked list; the function free_link () is used to release the full table element space of the linked list. [Program 2] [CODE: 1: AFF89524CB] #include #include typedf struct node {int val; struct node * next;} node; void first_insert (node ​​** p, int V ) {Node * q = (node ​​*) malloc (sizeof (node)); q -> va1 = v; __ (1) __; * p = __ (2) __;} node * reverse_copy (node ​​* p) { Node * u; for (u = null; p; ​​p = p -> next) first_insert (__ (3) __); return u;} void print_link (node ​​* p) {for (; __ (4) __) Printf ("% D / T", P -> VAL); Printf ("/ n";} void free_link (node ​​* p) {node * u; while (p! = null) {u = p-> next; free (p); __ (5) __;}} void main () {node * link1, * link2; int i; linkl = null; for (i = 1; i <= 10; i ) first Insert (& link1, i ); Link2 = revere_ copy (link1); print_link (link1); freejink (linkl); free_link (link2);} [/ code: 1: AFF89524CB] This is the problem of the list, in fact, we know Daily Daily Basically, there will be an topic of the list, so everyone should be ready to take these 15 points. I have said before the list. I will not go any more. Let's do these fill in the blank, we have to analyze Discussion. [CODE: 1: AFF89524CB] void first_insert (node ​​** p, int V) {node * q = (node ​​*) malloc (sizeof (node)); Q -> va1 = v; __ (1) __; * p = __ (2) __;} [/ code: 1: AFF89524CB] This function is equal to establishing a linked list, but the most particularly here is the pointer to the pointer. In fact, there is no big deal, because the pointer is also a variable, of course, there is address! So we just define another pointer to this pointer. Using the pointer is because this function does not return a value, we want to return to the address to call there, you have to use the address to pass. Take a look at the first empty, the function of the entire function is to insert a new knot in the chain head So, then fill in this empty, is of course good, it is Q-> Next = * P, why is P are the address and *? It is not a pointer to the pointer, this is of course, it is to get a list. Head pointer, put the new node on the header of the list. The second empty is also too simple, because we have to refer to the chain header, so turn the new joined node into the head node, that is, the Q is the line.

[CODE: 1: AFF89524CB] Node * Reverse_copy (Node * P) {node * u; for (u = null; p; ​​p = p -> next) first_insert (__ (3) __); return u;} [/ Code: 1: AFF89524CB] This empty is the same, copy a new reserved chain table. Because the first_insert () parameter is a point to the pointer, so we have to use & to take the address to assign u 's address to the function. There is also another parameter to data, data is the data of the P pointer just in the loop. Now you can fill this empty, P-> Val, this is done. [CODE: 1: AFF89524CB] void print_link (node ​​* p) {for (; __ (4) __) Printf ("% d / t", p -> val); printf ("/ n";} if it is calculated Links, even this output, I won't say it. The answer is p; p = p-> next. Void free_link (node ​​* p) {node * u; while (p! = Null) {u = p-> Next Free (p); __ (5) __;}} [/ code: 1: AFF89524CB] This is also relatively simple, it is easy to see, because the list cannot be disconnected, so delete is also a one in order If you come, you can delete your way. You must have a temporary variable to save the integrity of the linked list to completely delete the list, the answer is very simple p = u, although it is difficult However, friends who don't engage in the list will have to take some opportunities. If there is any problem, you can send E-mail, e-mail is zhgpa@sohu.com, but here is that I am also a beginner. I would like to make progress with everyone. Today, I gave a question today, and this question is the problem that the same color beads I have said in two-way linked lists, so I can see the question of our programmer exam again. Most of them are inseparable from the list and pointers. The pointer is of course the most important because the linked list is made up. Be sure to be familiar with the pointer. Please read the following procedures: Read the following procedures and C code, will fill in The word sentence in __ (n) __ is written in the corresponding column of the answer sheet. [Program Description] Set a ring with different colors of different colors with 0 ~ n-1 (alphabet for each bead color Indicates that the n-granulosion color is represented by the input string). A breakpoint between a two-piece beads on the ring, and take the continuous colored beads from the breakpoint one side, and then press counterclockwise from the other party from the breakpoint. The direction of the remaining beads will be taken away from the continuous colored beads, and the two can take the number of beads. Move breakpoints, the number of beads that can be taken is endless. This program can be taken to take the most The number of beads and breakpoints. Store strings in two-way linked lists in the program. For example, the string of 10-granulated colors colors numbered 0-9 is "aaabbbadcc", and the corresponding linked list is: Figure 20 At the No. 2 and No. 3 beads, it can take 6 beads, and the number of beads taken is most.

[Program] [CODE: 1: AFF89524CB] #include #include #include type {char d; struct node * fpt; / * Backrope pointer * / struct Node * BPT; / * Front pointer * /} node; node * building (char * s) / * generated two-way circular loop table * / {node * p = null, * q; while (* s) {q = (Node *) Malloc (SIDE)); Q -> CH = * S ; if (p = null) P = q -> fpt = q -> bt = q; Else {P -> BPT -> fpt = q; q -> fpt = p; q -> bpt = __ (1) __; __ (2) __;}} return (q)} int count (node ​​* start, int mapn, int steel) / * Beaded particles * / {Int Color, C; Node * p; color = -1; c = 0; for (p = start; c o? P -> fpt; p -> bpt) {IF (color == -1) color = p -> ch; else if (__ (3) __) Break; C } return (c);} int find (char * s, int * cutpos) / * look Take the maximum number of breakpoints and particles of the number of beads * / {INT I, C, CUT, MAXC = 0, 1EN = Strlen (s); Node * p; if ((p = building (s)) = null) {* Cu1tpos = -1; return -1;} i = 0; do {c = count (p, 1EN, 1); C = C __ (4) __; if (c> maxc) {MAXC = C; CUT = I;} __ (5) __; i ;} while (i

[Code: 1: AFF89524CB] Node * building (char * s) / * Build two-way circular list * / {node * p = null, * q; while (* s) {= (node ​​*) malloc (sizeof (Node) )); Q -> ch = * s ; if (p = null) p = q -> fpt = q -> bt = q; else {p -> bpt -> fpt = q; q -> fpt = P; Q -> BPT = __ (1) __; __ (2) __;}} return (})} [/ code: 1: AFF89524CB] This also illustrates that the BPT refers to a node, and the fpt is a node pointing. . Ok, continue to see the program if (p = null) p = q -> fpt = q -> bt = q; this is easy to determine that the first is the first tie point when it is specifically used to handle the new list, initialize the knot Point q, make two front and rear pointers point to yourself. P -> BPT -> fpt = q; q -> fpt = p; q -> bpt = p-> bpt; p-> bpt = q; here is given first, because this question is really difficult, so directly Talk about how he established a two-way loop linked list, as for I can understand it really hard to guarantee. Here I am here to emphasize that I am a beginner, but I will do my best to learn with you. One sentence is finished, P-> btp-> fpt = Q; and Q-BPT = P-> BPT; these two sentences are the skills of establishing a two-way loop linked list, so we have to understand these two sentences. P-> btp-> fpt = q; Demolition this sentence to each other, p-> BTP is the node pointed to by the front pointer representing the two-way linked list, pay attention to the bidirectional linked list The front pointer is always the end of the final node, so on this basis, add-> ftp, p-> btp-> fpt, ​​you can get the node points to the last node. , Then link the newly established node Q, P-> btp-> fpt = q; it is a link to a new node. Q-> ftp = p; there is nothing special here, just directly, the pointer points to the head knot, so that the head node and the tail joint phase chain. Continue to see the third line Q -> BPT = P-> BPT; here there is also a new knot point pointer to the tail joint point of the old bidirectional linked list. (This is also the same characteristic, the node pointed to by the head knot "is the fourth sentence is to point the first pointer to the newly inserted new node (ie the new two-way linked point" to point to the newly inserted nodes (ie the new two-way linked point "to point to the newly inserted nodes (ie the new two-way linked point" to point to the newly inserted nodes (ie the new two-way linked point "to point to the newly inserted nodes (ie the new two-way linked point) to point the header node pointer (ie the new two-way linked point" ), Then constitute the two-way linked list again. I hope everyone can understand what I wrote. If it is really not Taiming, please contact me with E-mail, I will try my best, because we all work hard for the test. I believe our efforts will not be quaint, work hard ~ Struggle ~~~ The 21st day (finish) soon today is the day of the completion class, now the mood is really difficult. So I also said less, because I can't use the text to express my present mood. Before school, the teacher also agreed to us, if we got a programmer, please ask us to eat. I must work hard to get the meal, everyone works hard, I am grateful when I see it. Ok, let's talk about the last day. Today, I still focus on exercises, and the topic of the chain table (I emphasized again, the chain list is the focus of the exam).

See the program: [Code: 1: AFF89524CB] typef struct elem {int val; struct elem * next;} intNode; / * When you see the structure, you know that it is a list * / / * merge ascending chain table * / intNode * MERGE (intNode * a, intNode * b) {intNode * h = a, * p, * q; while (b) {for (p = H; P && P-> Val val; q = p, P = p-> next); / * Note that here is used herein * / if (p = = h) _________; ELSE_____2____; q = b; b = b-> Next; ____ 3_____;} return h;} [/ Code: 1: AFF89524CB] Look at the topic knows that this is two linked lists to synthesize a new list, and the parameters are of course there are two linked lists. This procedure is also relatively simple, just testing our familiarity, I have talked a lot of knowledge about the list of linked lists in the posting note in the previous few days, so I will not go. Let's take a look at how to fill these empty IF (p = h) _________; Else_____2____; here is the reason if it is inserted in front of the head knot, which is of course the characteristic of the one-way linked list. From the conditions in the context P-> Val VAL know that when B-> Val is less than P-> Val, we have to plug, of course, the point to point B. The first empty can write h = b immediately, and now it is not to insert the head knot. This problem is relatively simple, here uses two pointers, ie Q and P, q must be a node before P, why do you want to use double pointer? This is also the shortcomings of one-way linked list. The second air filling Q-> Next = B, the following Q = B is the node before P, b = b-> Next continues to prepare the next node to be inserted, the third space can be pressed The form of the list can be fill what to fill it. In fact, didn't point B-> next to its next node, but we have moved B = B-> next to the next node, so I can't use B. -> Next = P, but the good Q is to assign B's address to it before, the third empty is of course Q-> next = P. Below we tried to change this program, in the above program, the two linked lists are already the characteristics of the sequence, so the efficiency is not high. See the program: [Code: 1: AFF89524CB] intNode * MERGE (intNode * a, intNode * b) {intNode * h = a, * p, * q; p = h; / * is here in advance, what else Didn't move over * / while (b) {for (; p && p-> val val; q = p, p = p-> next); / * Note that here is used in double pointers * / if P = = h) h = b; ELSE Q-> Next = B; Q = B; b = b-> Next; Q-> Next = P;} return h;} [/ code: 1: AFF89524CB] We are So shifted, the efficiency of the entire program is improved, here is because A is already an orderly, the program does not have to start searching a A chain table from the beginning, and then continue in the current location.


New Post(0)