Zhou Ligong teaches you how to learn C language programming: construct an double pointer with an array

The first chapter is the basis of programming. This article is the second point in the 1.8.3 pointer array: the pointer to the string and the pointer , the third point: the string and the two-dimensional array .

> > > >   1.   String and pointer pointer

In addition to the operands of sizeof or &, the array name of the pointer array is equivalent to a double pointer constant in the expression, and its right value is the first address of the array variable. such as:

Int main(int argc, char *argv[])

It is completely equivalent to

Int main(int argc, char **argv)

Obviously, if you want to access an array of pointers, it is most convenient to use a pointer to the pointer, but you will write the wrong program occasionally if you don't pay attention. See Listing 1.45 for details.

Program list   1.45   a wrong sample program

1 #include

2 int main(void)

3 {

4 char **pKeyWord;

5 static char * keyWord[5] = {"eagle", "cat", "and", "dog", "ball"};

6

7 pKeyWord = keyWord;

8 while(**pKeyWord != NULL)

9 printf("%s", *(pKeyWord++));

10 return 0;

11 }

Since the null character at the end of the string or '\0' is exactly equal to the value of null pointer or NULL, the compilation and execution of the above code is correct, but it is a wrong example. Because most compilers do type conversions in compile list 1.45(9), convert **pKeyWord from char type to void *, or convert NULL from void * to char type, but generally at compile time Give a warning message because the null character is an integer type and the null pointer is a pointer type.

The reason for writing such a code shows that the programmer does not understand the difference between """ and NULL. If the compiler completely disables the conversion between char and pointer, the above code may fail to compile. It can be seen that each warning message given by the compiler needs to be taken seriously, and the reason for the warning message needs to be analyzed, instead of just compiling and the program execution result is correct.

Listing 1.46 is a solution for Listing 1.45. It first determines if *keyWord is a null pointer. If it is a null pointer, it exits the loop; if not, it outputs the string, and then pKeyWord is incremented by 1 to the next string.

Listing 1.46 deals with multiple strings with pointer array variables and double pointer variables

1 #include

2 int main(void)

3 {

4 char **pKeyWord;

5 static char * keyWord[6] = {"eagle", "cat", "and", "dog", "ball", "NULL"};

6

7 pKeyWord = keyWord;

8 while(*pKeyWord != NULL)

9 printf("%s", *(pKeyWord++));

10 return 0;

11 }

Since arrays of pointer types are also one-dimensional arrays, the arithmetic operations of double pointers are very similar to the arithmetic operations of ordinary pointers. When pKeyWord points to keyWord, keyWord[i], pKeyWord[i], *(keyWord+i), and *(pKeyWord+i) are the equivalent representations of the access pointer array variable elements. keyWord[i] points to the first address of the i-th string, which is the address of the first character of the i-th string. If the target variable pointed to by the pointer keyWord[0] is accessed, the value of *keyWord[0] is the first character M of the string "Monday". Of course, *keyWord[0] can also be written as *pKeyWord[0], **keyWord, **pKeyWord and other expressions.

Listing 1.47 is another solution for Listing 1.45. It first determines whether the *pKeyWord points to an empty string (that is, a string containing only '\0', that is, a string whose 0th element is '\0'). If it is an empty string, then Exit the loop; if not, the output shows the string, then pKeyWord is incremented by 1 to the next string.

Program list   1.47   Handling multiple strings with pointer array variables and double pointer variables (2)

1 #include

2 int main(void)

3 {

4 char **pKeyWord;

5 static char * keyWord[6] = {"eagle", "cat", "and", "dog", "ball", "NULL"};

6

7 pKeyWord = keyWord;

8 while(**pKeyWord != ""[0]) // ""[0] is equivalent to '\0'

9 printf("%s", *(pKeyWord++));

10 return 0;

11 }

In practical applications, """[0]" in Listing 1.47(9) is a very rare use. If you replace it with '\0', the function is the same, and the execution efficiency is slightly higher. Since the string constant is a read-only character array, the string constant """" is a string constant with only the end character of the string '\0', that is, the value of the 0th element of the array variable is '\0'. Since """ is an array variable, you can use the subscript operator to evaluate """" to get the specified array element, resulting in the value '\0' of """[0]". In general, '\0' does not use ""[0] directly in most programs, and the use of """[0]" in Listing 1.47(8) has two meanings:

● Corresponds to the program list 1.47 (5) to make the meaning of the program clearer. When * pKeyWord points to the last character string of the 0th element, the end of the cycle; Note: The 0-th element of the string and any other element of a string of 0's are not the same.

●   Better portability. If the character of the future C language to modify the definition of the end of the character, the program is not compulsory to change. For example, in order to support Chinese, if a Chinese character is used as a character, the character type must be corrected because it is no longer 8 bits, so its ending character may also be modified.

If you want to store static tabular data, you should of course use arrays. The search program must know how many elements are in the array. The way to deal with this problem is to pass an array length parameter. Another method used here is to choose the pointer array method. which is:

Const char * keyWord[6] = {"eagle", "cat", "and", "dog", "ball", NULL};

That is, a NULL pointer is added at the end of the table. This NULL pointer enables the function to detect the end of the table when searching the table without knowing the length of the table in advance. The corresponding search sample program is shown in Listing 1.48.

Program list   1.48   Search sample program

1 int lookup(char *word, char *keyword[])

2 {

3

4 for(int i = 0; keyiWord[i] != NULL; i++)

5 if(strcmp(word, keyWord[i] == 0))

6 return i;

7 return -1;

8 }

In C, the string array parameters can be char *keyiWord[] or char **keyWord. Although they are all equivalent, the former form can express the usage of the parameters more clearly.

The search algorithm used here is called sequential search, which checks each data one by one. If the number of data is small, the sequential search is also very fast. The standard library provides functions that can handle certain types of sequential search problems. For example, strchr and strstr can search for characters or substrings in a given string, if there is such a function for a data type. It should be used directly.

Although the search looks very simple, its workload is proportional to the number of data being searched. If the data you are looking for does not exist, and the amount of data doubles, the search workload will be doubled. This is a linear relationship whose run time is a linear function of the data size, so this search is also known as linear search.

> > > >   2 .   String and two-dimensional array

There are two styles describing C-style arrays of strings, namely two-dimensional arrays and arrays of pointers, such as:

Char keyWord[][6] = {"eagle", "cat", "and", "dog", "ball"};

Char * keyWord[5] = {"eagle", "cat", "and", "dog", "ball"};

Among them, the first statement creates a two-dimensional array, as shown in Figure 1.16(a). The second declaration creates an array of pointers, each of which is initialized to point to a different string constant, added in Figure 1.16(b).

Figure 1.16 Rectangular array and irregular array


If you use a two-dimensional array instead of a pointer array to modify the program listing 1.44, the two methods use the same initialization list, the for loop code that displays the string is also the same, so just modify the declaration of the formal parameters and local variables. Since the value of an array variable name is a pointer, the function can run regardless of whether it is a pointer or an array name passed to the function. Although their declarations are different, in some ways they are very similar, both representing five strings. When a subscript is used, it represents a string, but the types of the two are not the same. When using two subscripts, each represents a character. For example, keyWord[1][2] represents the third letter 't' of the string pointed to by the second pointer in the keyWord array. At first glance, the efficiency of a two-dimensional array seems to be lower because each line is fixed to the length of the longest keyword, but it does not require any pointers. On the other hand, pointer arrays also take up memory, but the memory space occupied by each string constant is only its own length.

If they are about the same length, the two-dimensional array form is more compact. If the length of each string is very different, most of the strings are very short, only a few are very long, then the use of pointer array form will be more compact, depending on whether the space occupied by the pointer is less than each string The space wasted by storing a fixed length line. In fact, apart from very large tables, the difference between them is very small, so it doesn't matter at all. A two-dimensional array is a better choice unless you want to change any of these strings.

1.27mm Female Pin Header

1.27mm (0.050") Pitch Female Headers
Like the 1.27mm pitch male header, the 1.27mm pitch female header is used in densely-packed devices, requiring space-saving connections. The low profile, 1.27mm pitch female header addresses the need for connecting a variety of board-to-board configurations, with vacuum pick and place that makes it suitable for high volume automated manufacturing. It can be available in varying elevated stack heights, pass-through, rugged, high-density, and in numerous low-cost designs.
Antenk offers 1.27mm pitch female headers in either SMT or THM orientation at high quality and affordable China-quoted price that snuggly fits with the pins of a male header and acts as a receptacle.
Assembly and service is simple with either vertical (straight), elevated or at a right angle orientation, which can dissipate current of about 1.0 A or less in a tape and reel packaging. The filleted corners can also remove shadowing allowing optimization of LED output.
The 1.27mm pitch female headers are commonly found in PC`s and are also made to work in Arduino boards, Arduino Pro and Arduino Mega with either single or double-row female headers, facilitating connections for programming and incorporation into other circuits. They have the perfect height for clearing the USB-B connector and great for stacking multiple shields.
Female header always called as [Header connector", Antenk provide widely range of header connector, from 2.54mm (.100″ inch) pitch to 1.0mm (.039″ inch) pitch. The number of pins (contacts) is from 2 to 40 pins per orw. There are three type: Straight (Dip Vertical), Right angle, SMT (surface mount).
If you can not find the items you interest from above items, welcome to contact us, and you will always get fully responsive from us.


Applications of 1.27mm Pitch Female Headers
Its small size is most suitable for PCB connections of small equipment and devices such as:
Arduino Boards
Architectural and sign lighting
Retail and display lighting
Fluorescent LED retrofit lighting
Cabinet or furniture lighting
Commercial / residential cove lighting
WiFi equipment
Gaming consoles,
Measurement instruments
Medical Diagnostic and Monitoring equipment
Communications: Telecoms and Datacoms

Industrial and Automotive Control and Test


Mount Type: Through-hole vs Surface Mount
At one side of this female header is a series of pins which can either be mounted and soldered directly onto the surface of the PCB (SMT) or placed into drilled holes on the PCB (THM).

Through-Hole (Poke-In)
Best used for high-reliability products that require stronger connections between layers.
Aerospace and military products are most likely to require this type of mounting as these products experience extreme accelerations, collisions, or high temperatures.
Useful in test and prototyping applications that sometimes require manual adjustments and replacements.
1.27mm vertical single row female header, 1.27mm vertical dual row female header, 1.27mm Elevated single row female header, 1.27mm Elevated dual row female Header, 1.27mm right-angle single row female header and 1.27mm right-angle dual row female header are some examples of Antenk products with through-hole mount type.

Surface-Mount
The most common electronic hardware requirements are SMT.
Essential in PCB design and manufacturing, having improved the quality and performance of PCBs overall.
Cost of processing and handling is reduced.
SMT components can be mounted on both side of the board.
Ability to fit a high number of small components on a PCB has allowed for much denser, higher performing, and smaller PCBs.

1.27mm Right-angle Dual Row female header, 1.27mm SMT Single row female header, 1.27mm SMT Dual row female header and 1.27mm Elevated Dual Row female Header are Antenk`s SMT female headers.


Soldering Temperature for 1.27mm Pitch Female Headers
Soldering SMT female connectors can be done at a maximum peak temperature of 260°C for maximum 60 seconds.

Pin-Type: Vertical (Straight) and Right-Angle
1.27mm pitch female headers may be further classified into pin orientation as well, such as vertical or straight female header or right-angle male header.

Vertical or Straight Female Header Orientation
One side of the series of pins is connected to PCB board in which the pins can be at a right-angle to the PCB surface (usually called "straight" or [vertical") or.

Right-Angle Pin Female Header Orientation
Parallel to the board's surface (referred to as "right-angle" pins).
Each of these pin-types have different applications that fit with their specific configuration.


PCB Connector Stacking
Profile Above PCB
This type of configuration is the most common way of connecting board-to-board by a connector. First, the stacking height is calculated from one board to another and measured from the printed circuit board face to its highest insulator point above the PCB.

Elevated Sockets/Female Headers
Elevated Sockets aka Stacked sockets/receptacles or Mezzanine are simply stacked female headers providing an exact distance requirement between PCBs that optimizes electrical reliability and performance between PCB boards.

Choosing this type of stacking configuration promotes the following benefits:
Connector Isolation - the contacts are shrouded preventing cable connection mishaps and good guidance for the mating header connectors.
For off-the-shelf wireless PCB module, stacking height is optimized with elevated sockets.
Offers superior strength and rigidity.
Polarisation prevents users from inverted insertion.

Single, Dual or Multiple Number of Rows
For a 1.27mm straight or vertical female header, the standard number of rows that Antenk offers ranges from 1 to 2 rows. However, customization can be available if 3 ,4 or n number of rows is needed by the customer. Also, the number of contacts for the single row is about 2-40 pins while for dual row, the number contacts may vary from 2-80 pins.

Pin Material
The pins of the connector attached to the board have been designed with copper alloy. With customer`s demand the pins can be made gold plated.

Custom 1.27mm Pitch Female Headers
Customizable 1.27 mm pitch female headers are also available, making your manufacturing process way faster as the pins are already inserted in the headers, insulator height is made at the right size and the accurate pin length you require is followed.
Parts are made using semi-automated manufacturing processes that ensure both precision and delicacy in handling the headers before packaging on tape and reel.

Tape and Reel Packaging for SMT Components
Antenk's SMT headers are offered with customizable mating pin lengths, in which each series has multiple number of of circuits, summing up to a thousand individual part number combinations per connector series.

The tape and reel carrier strip ensures that the headers are packaged within accurately sized cavities for its height, width and depth, securing the headers from the environment and maintaining consistent position during transportation.

Antenk also offer a range of custom Tape and reel carrier strip packaging cavities.

Pcb Connector,1.27Mm Female Pin Header,1.27 Header connecto,1.27Mm Pcb Header,1.27Mm Pcb Connector,0.050" Female Headers,1.27mm Female Pin Header SMT, 1.27mm Female Pin Header THT

ShenZhen Antenk Electronics Co,Ltd , https://www.antenkconn.com

Posted on