Having to praise this book "C and the hands" is one of the best-selling books of the 2014, the author is very responsible, and, every page you can find the place you need to learn, really good, decided to write a blog to record my reading this book harvest.
One, note
In C, if you use/* * * * * * * * * * * to comment out a piece of code, you may not be able to do so, if there is a comment inside the code exists, this will cause problems.
The best way to logically delete a C code is to use the # if directive
#if 0
Statement
#endif
So the statement can be effectively removed from the program.
Second, pre-processing instructions
#include header file
If you have some declarations that need to be used for several different source files, this technique is also an easy way to----you write these statements in a separate file, and then use the # include directive to include the file in the source file where you want to use the declarations, avoiding duplication.
int read_column_numbers (int column[], int max);
A declaration like this is called a function prototype, where the parameter name is not necessary.
void Rearrange (char *ouput,char const *INPUT,INT columns, int const column[]);
In the parameters of this function, the second and fourth are declared as const, stating that the function will not modify the two arguments passed by the function caller.
Hint: If the source code of this program is composed of several sources, then the source file using the function must state the prototype of the function, place the prototype in the header file and include them with the # include directive to avoid maintenance problems caused by multiple copies of the same declaration
Personal supplement:
Common extern is placed in front of the function as part of the function declaration, so what does the C keyword extern do in the declaration of a function? Answer and Analysis: If the declaration of a function has a keyword extern, it simply implies that the function may be defined in another source file, with no other effect. That is, the following two function declarations do not have a significant difference: extern int f (); and int f (); Of course, the usefulness of this is to replace the include "*.h" in the program to declare the function, and in some complex projects, I am more accustomed to adding extern adornments before all function declarations. Three: Get function to read a line of text from the standard input and store it in an array passed to him as a parameter, a line of input consists of a string of characters, ending with a newline character, the Get function discards the newline character, and stores a nul byte at the end (the NUL byte is the byte pattern of all 0 bytes, Similar to a character constant such as '/', then the GET function returns a non-Nul value that indicates that the row has been successfully read, and if no input row exists, it returns a null value of four: the string C language does not have a string data type, But there is a convention in the whole language: a string is a sequence of characters ending in nul byte five: int read_column_numbers (int columns[], int max) {...} In the array parameter of the function declaration, the length of the array is not specified, which is correct, because regardless of the length of the array arguments passed to it by the program that called the function, this function is not mistaken, this is a great feature that allows the function to manipulate a one-dimensional array of any length, The downside of this feature is that the function cannot know the length of the array, and if it does need to know the length of the array, his value must be passed as a separate argument to the function VI: scanf function scanf ("%d", &columns[num]) The scanf function takes several arguments, a format string for the first argument, which describes the expected input type, and several remaining parameters are variables that store the input data read by the function. The return value of the scanf function is the number that the function successfully converts and stores the value in the parameter scanf the function uses all format codes (except%c), the whitespace before the input value is skipped, and the white space after the value ends, so when you enter a string with the%s format code, the middle cannot contain whitespace as in the above example , after the scanf function converts an integer, it returns a value of 1, which is seven: the array standard does not dictate the validity of the C compiler's array subscript to be checked, so in order to avoid the data in the storage unit after the array data overflow destroys, it is necessary to artificially limitNum < Max to ensure that the input array can have up to max. Eight: The puts function puts function is the output version of the Get function, which writes the specified string to the standard output and adds a newline character at the end of Exit (Exit_falure) is the terminating program run, exit_failure This value is returned to the operating system, Tip Error Nine: Parse the following line of code int i; ... while ((I=getchar ())!=eof && i!= ' \ n '); The GetChar function reads a character from the standard input and returns his value, and if the character no longer exists in the input, then EOF is returned in most other languages, and we will write loops like this one i = GetChar (); while (i!=eof && i = ' \ n ') I=getchar (); He will read a character, and then, if we have not yet reached the end of the file or the character being read is not a newline, he will continue to read the next character. In fact, the above two formulations are equivalent, and the C language operation implies that the assignment is inside the while statement, allowing the programmer to eliminate the redundant statement I The reason for being declared as an integer instead of char is that EOF is an integer value, and his number of digits is more than char. The last point of the statement is that a separate point after the while statement is called an empty statement. Ten: strncpy function The first two parameters of the strncpy function are the target string and the source string address, the third parameter is the number of characters that you want to copy, and the last to add a nul character as the Terminator 11: Warning Summary 1. The & character 2 is not added before the scalar parameter of the scanf function. Mechanically copy the format code of the printf function with the SCANF function 3. Use & 4 where && should be used. misused = instead of = = 12: Summary of Programming Tips 1. Use # include directives to avoid duplicate declarations 2. Use # The Define directive names the constant value 3. Place function prototypes in # include files 4. Check their values before using subscript 5. Contains an assignment operation 6 in a while or if expression. How to write an empty loop body 7. Always check to make sure the array is not out of bounds!
Regain the C language---read C and pointers to the Book of the Harvest (1)