Title: string'h
1????? 10
- ?????? string.h
- ?????? ?? ???????
- ????? ???????
2?????? string.h
- ?????? ????? ???? ?? ?? ???????? ????????
- ?????? ???????? .
- ????? ????? ?????? ???????? ??????? (???
??????( ?????? string.h - 1. int strcmp(const char s1,const char
s2) - ???????? ????? ?? ??? ????????
???????????? ( ?? ???? ??? ??????? - ?????? ?????) . ??????? ???? ???? ? 0
?? s1gts2 (????????????), - ???? ??? ? 0 ?? ,s1 lt s2? 0 ?? s1
s2 . - ??????? 0 strcmp(computer,babylon) gt 0
,strcmp(abc,abcd) lt strcmp(Hi,Hi) 0
3?????? string.h ????
- .2 char strcpy(char s1,const char s2 )
- ????? ?? ??????? s2 ???? ??????? s1 ????
???? \0 ???? ??????? - ?? ?? ????? ? s1 ???? . ??????? ?? ?????? ?????
??? ????? ???? ? s1 - ????? ?? ????? ?? ??????? s2 ???? ???? \0 .
?????? s1 ????? . - ??????? ??????
- char s110 ,s2 Hello
- strcpy(s1,s2)
- / s1 Hello /
printf(s,s1) - strcpy(s1,World)
- / s1 World /
printf(s,s1) -
4?????? string.h ????
- size_t strlen(const char s) .3
- ?????? ?? ????? ?? ??????? . ???? ???????
??? ???? ?????? ??????? ?? ???? ???? \0 . -
- ???????
- strlen(1234) / 4 /
- strlen(Example) / 7 /
- ?????? ????? ?? ???????? ? string.h .
5???? ?? ???????
- ??? ????? ?????? ???? ??? ????? ???? C, ????
?????? ?? ???? ?? ??????? - ?????? ?? ???? ????? ???? 4 ?????? ?????? ??????
???? ???????? (??? ?? ?????? ?? ??) - ????? ?????? ???? ??? ????
- char s1 HELLO
- char s2 How are you?
- char s3 I am the longest line here!!!
- char s4 THE END
??????? ?? ???? ????!
6???? ?? ??????? - ????
- ???? ?? ????? ?? ?????
- ????? ????? 10 ?????, ???? ?????? ? ????? ??????
????? ????? ?????
????? ???? ?? ?????? ????? (????? ??? ?????? ????
???? ????? ?????? ????? ?????!)
7???? ?? ??????? - ????
- ?????? ???? ?? ???????
- ???? ?? 4 ?????? ????? ??
- char message
- HELLO!,
- How are you?,
- I am the longest line here!!,
- THE END
HELLO
How are you?
I am the longest line here!!
THE END
8???? ?? ??????? - ????
- ?????? ??????
- ?????? ?????? ???? ?? ???? (?? ?????? ?????,
??????? ?????) ??????? ?? ?? ???? ?????? . - ????? ?? ????? ????? ?? ????? ?????? ????? ??
????? ??????? ???? ????? names?
9????? ?????? ???????
- ?????? ?????? ????? ?? ???? ????? ????? ???? ??
???? ??????? ????? ???, ??????- ???? ????. - ?? ?? ?????? ???? ?? ??????? ?????? ????? ????,
?? ????? ????? ???? ???? (????? ????? ??????
?????? ???????) ??????? ?????? ??????. - ??????, ?? ???? ????? ??????? ???? ????? ??
??????, ???? ????? ??? ???? ???? ?-20 ??????, ??
?? ????? ?? ?????? (?? ??? ????? 32
??????,??????), ?? ????????- ????? ?????? (??
????? ??? ??? 2 ??????).
10????? ?????? ??????? - ????
- ??? ?? ?????? ???????? ?????? ??????? ?? ??????,
???? ????. - ??? ?????? ????????? ??? ?? ????? ?? ??????
stdlib.h
11????? ?????? ??????? - ????
- ??????? ?????? ??????
- void malloc(unsigned size)
- ???????? malloc( ), ???? ??? ?? size ????
,??????? ????? ?????? ???? ??????, ?? NULL ??
?????? ?? ??????. - ?????? ????????? ?????? ??? ?????? void, ?????
????? ?????? ?? ????, ???? ???? ???? ???? ??
?????? ?????? ?????.
12????? ?????? ??????? - ????
- ???? ????? ???? ?? ????? ?????? ???? ?????
??????? ??????. - ?? ???? ?????? ?????? ???????, ?????? ??? ????
????? ????? ????? ?????? ?????? ????? ??? ???- ??
????? ?????? ?? ???? ?????? ?? ????? ?????, ????
???? ?????? ?? ?? ???? ???? ?????? ?? ?????
???????? "????" ???? ???? - ??? ????? ?? ?????? ?????? ?????? ?? ?????? ????
?-NULL
13????? ?????? ??????? - ????
- ???? ????? ???? ?? ????? ?????? ???? ?????
??????? ??????. - ?? ???? ?????? ?????? ???????, ?????? ??? ????
????? ????? ????? ?????? ?????? ????? ??? ???- ??
????? ?????? ?? ???? ?????? ?? ????? ?????, ????
???? ?????? ?? ?? ???? ???? ?????? ?? ?????
???????? "????" ???? ???? - ??? ????? ?? ?????? ?????? ?????? ?? ?????? ????
?-NULL
14????? ?????? ??????? - ????
- ???? ?????? ?????? ???? ?? 50 ?????? ?????
- int p
- p malloc(50sizeof(int))
(int)
???? ????
???? ?(void)
15????? ?????? ??????? - ????
- ???? ?????? ?????? ???? ?? 50 ?????? ?????
- int p
- if ( p (int)malloc(50sizeof(int)) NULL)
-
- printf(Allocation failed\n)
- return 1 / exit(1) /
-
16????? ?????? ??????? - ????
- ???? ?????? ????? ???? ????? ????
- void free(void ptr)
- ???????? free ????? ????? ?????? ?????? ???????
?? ?????? ?????? ?????? ??. - ???? free(p)
17????? ????? ???? ?? ????? ????????
- include ltstdio.hgt
- include ltstdlib.hgt
- define INPUT 0
- define MEMORY 1
- int get_array_size(void) / get the array size
from the user / - void create_array(int, int) / create the array
/ - void read_array(int , int) / read numbers
into the array / - void print_array(int , int) / print the
array / - void error(int) / print an error message /
18????? ????? ???? ?? ?????
- int main( )
-
- int arr, size
- size get_array_size( )
- create_array(arr,size) / we could have
written another version of create_array that
returns int - we would call it arr create_array(size) /
- read_array(arr,size)
- print_array(arr,size)
- free (arr)
- return 0
19????? ????? ???? ?? ?????
- void create_array(int a, int size)
-
- if((a (int)malloc(sizesizeof(int)))
NULL) - error(MEMORY)
- return
20????? ????? ???? ?? ?????
- void print_array (int a,int size)
-
- int i
- printf(\nThe array is \n)
- for (i0iltsizei)
- printf(d ,,ai)
- printf(\n)
- return
-
- void error (int type)
-
- switch(type)
- case INPUT
- printf("Input error!!!! ")
- break
- case MEMORY
- printf("memory allocation failed")
- break
- int get_array_size( )
-
- int size
- printf("\nHow many numbers do you want to write
? \n") - if (scanf("d",size)!1)
- error(INPUT)
- return size
-
- void read_array(int a, int size)
-
- int i
- for (i0 iltsize i)
- if (scanf("d",ai)lt1)
- error(INPUT)
- return
-
21????? ??????? ?? ???? ?? ?????
- ????? ????? ??-????? ??? ?????? ??????
- ????? ????? ?? ??????
22????? ??????? ?? ???? ?? ?????
- ????? ???? ??-????? ????? ?? ??????
?????? ???????? ?? ??? ????
Matrix
???? ?? ??????? ?? ????? ????? ????? ???????
23????? ??????? ?? ???? ?? ?????
- ??? ?????? ??????? ???? ??-????? (???? ?? ??'
?????) ????? ?? ?????? ???? - ?????? ???? ?? ????? ?? ??????? (????? ??????
?????) - ?????? ???? ??-????? ???? ?? ????, ?? ??? ?? ????
????? ?????? ?????? ?????? ?????? ????? 1. - ??? ???? ????? ???
- ????? ?? ???????? ???? matrix, ???? ???? ????
int (????? ?????? ???' ???) - ????? ?? ??????? row ?-col ?? ??? ?? ?????
??????? ???? ??? ????? ??????. - int row,col,i
- int matrix
-
- matrix (int)malloc(rowsizeof(int))
- if(matrixNULL)
-
- printf(Allocation failed\n)
- return 1
-
- for(i0iltrowi)
-
- matrixi (int)malloc(colsizeof(int))
24????? ??????? ?? ???? ?? ????? ????????
- ?? ???? ????? ?? ?????? ???????? ?????, ?? ????
?????? ?????? ????? ??? ?????? matrix ?? ?????
??????? ?? ??? ?????, ??? ???????? ????. - ???? ??? ???? ????? ?????? ???????? ???? ?????
?????? ???? ????? (????? ??? ?????? ???????? ????
?? ???????) - ????? ????? ????? ????? (?????? ?????? ???
????????) - ?????? ?? ???? ?????? ????? ???? ????? ?????????
- ????? ?????
- ?????? ??? ????? ????? ????? ??? ???????? ???
matrix (???? ???? ????? ????? ??? ?????? ?-malloc
????? ???). ???? ?-matrix ??? ?????? int ??
????? ???? ???? ?????? int - ????????? ????? ??
- void mymalloc( int m, int row, int col)
-
- int i
- (m) (int)malloc(rowsizeof(int))
- for(i0iltrowi)
- (m)i (int)malloc(colsizeof(int))
- return
-
- ?????? ???????? ???? mymalloc(matrix,row,col
)
?????? ?????? ?????? ??????? ??????
25????? ??????? ?? ???? ?? ????? ????????
- ????? ??? ?????
- ???????? ????? ??
- int mymalloc(int row, int col)
-
- intm
- int i
- m (int)malloc(rowsizeof(int))
- for(i0iltrowi)
- mi (int)malloc(colsizeof(int))
- return m
-
- ?????? ???????? ???? matrix
mymalloc(row,col) - ?? ????? ???? ???????? ??????? ?-malloc ???? ??
??? ???????. ???? ????? ????? ???? ???? ???? ????
????.
26????? ??????? ?? ???? ?? ????? ????????
- ???? ????? ????? ?? ?????? ?????? ????? ???-?????
???? ????? ????? ???? ?? ??????? ??????? ?????
?????. ????? - matrixij