Vupping of C.

xiaoxiao2021-03-04  71

String connection

Here is the problem of passing string pointers, starting to write * p in the method, then seeing P pointer, but because he is from Malloc, it must be fly (), look at the forum: " The principle should try to follow as much as possible, that is, allocation and recycling memory should be done as much as possible in the same scope. It is best to avoid allocating space in the subroutine, reclaiming the parent program. To absolutely avoid allocating space in the parent program , In a sub-program, recycling, unless the unique function of the primary, is the recycled memory. "

There is also char a [] = "jklmn", is an array containing six functions, because it also includes '/ 0'; # include "stdafx.h" #define Len 15 # Define LONGER A> B? A: B Void stradd (Char * p, char SRTFRONT [], char SRTBACK []) {INT A, B, C, I; A = (int) strlen (SRTFRONT); B = (int) strlen; c = a B 1; I = longer; for (int MARS = 0; MARS

INT _TMAIN (int Argc, _tchar * argv []) {

Char a [] = "abcdefghi"; char b [] = "jklmn"; char * p; p = (char *) malloc (sizeof (char) * (15)); stradd (p, a, b); printf ("% s / n", p); free (p); system ("pause"); return 0;}

2. Single-lapse table Add, delete nodes.

Mainly, it is good to understand the way the node is handled in the list.

#include #include #include

Struct Lnode {Int Number; Struct Lnode * Next;} * linkList, * P1, * P2, * New, * PRI

Void CreatList (struct lnode * l, int N) {INT i; for (i = 0; i number); if (i == 0) {(* L) .Number = (* p) .Number; Free (p ); Continue;} p-> next = l-> next; l-> next = p; printf ("/ n the number strunt is created / n");}} void listinsert ()}} void listinsert ()}}} void listinsert () {Int ix, insertsite; printf ("please enter the insertsite:"); scanf ("% d", & insertsite); // struct lnode * p1; p1 = (struct lnode *) malloc (Struct Lnode); p1 = linklist; ix = 1 WHILE (LinkList && ix next; ix ;} // struct lnot * new; new = (struct lnode *) malloc (Struct Lnode); Printf ("please enter THE INT: "); Scanf ("% D ", & new-> number); if (insertsite == 1) {new-> next = linelist; linklist = new; Return;} new-> next = linelist-> next; linklist-> next = new; printf ("the number has inserted / n"); linkList = p1; free (p1);}

Void ListDeled () {Int Site, I; Printf ("please enter the int:"); scanf ("% d", & site); p1 = (struct lnode *) malloc (SIZEOF (Struct Lnode); p1 = linklist ; I = 1; While (i next; i ;} // struct lnode * p2; p2 = (struct lnode *) malloc (Struct Lnode); p2 = linklist -> next; if (site == 1) {linkList = p2; free (p1); return;} else {linklist-> next = p2-> next; linklist = p1; free (p2);}} int controller ) {INT I; Printf ("THE 1 IS CREATE / N"); Printf ("THE 2 IS ISERTE / N"); Printf ("THE 3 IS DELETE / N"); Printf ("THE 4 IS Print / N "); Printf (" THE 0 IS EXIT / N "); Printf (" please enter the oparetor: "); scanf ("% d ", & i); switch (i) {case 1: linklist = (Struct Lnode * ) Malloc (Struct Lnode); LinkList-> Next = NULL; CreatList (Linklist, 3); Return 1; Case 2: ListInsert (); Return 1; Case 3: Listdeleted (); Return 1; Case 4: // struct Lnode * Pri; Pri = (Struct Lnode *) Malloc (Struct Lnode); Pri = LinkList; While (PRI) {Printf ("% D / N", (* Pri) .Number ); Pri = pri-> next;} Return 1; case 0: return 0;}}

INT Main (int Argc, char * argv []) {Int i = controller (); while (i = 1) {controller ();} system ("pause"); return 0;}

3. Test the size of the terminal method

INT i = 1; char * pc = (char *) (& I); pc ; if (* pc == 0) Printf ("Small / N"); Else Printf ("Large End / N"); INT 1 The hexadecimal representation is 0x00000001, stores 01000000 in a small-end method machine, which is not equal to 1 when the PC pointing the next address, that is, 0, indicating that the machine is small, otherwise the big end method

转载请注明原文地址:https://www.9cbs.com/read-31705.html

New Post(0)