Title: ' "
1???? ????? ????? ?' ???"?
????? ????? ??????? ???????
www.cs.tau.ac.il/armon/cprog08b.html
2??????? ??????
- ?????? ??? ??? ????? ??? ?????? (???? ???? ??
????). - ??? ????? ?????? ??????? ????? ?? ?????, ??????
???? ??????? ???? ?? ??-????? \0. - ???? ????? ?????? ?????? char message Hello
world! - ???? ???? ???/??? ?? ??????? ??-?? ??????, ??
???-??? - scanf(s, str), scanf(40s, str),
gets(str), printf(s,str) - ?????? string.h ?? ?????? ???????? ?? ???????
(??? ?? ????, ??-???? ????? ab ??? ??????
??????? ?? ab ??? ??????). - ?????? ctype.h ?? ?????? ???????? ?? ?????
(islower,toupper,...).
3string.h ??????? ????????
- ????? ???? ??????? (??? ????? ?? ??-????? '0\')
- len strlen(my_string)
- ?????? ??????? (?? ?? ???? ????? 0)
- equal strcmp(str1, str2)
- ????? ?????? ??????? ???? (source ??????
?-target) - strcpy(target, source)
- ?????? ??????? (????? ?? str2 ???? str1)
- strcat(str1, str2)
- (????????? ????? ?????? ?? ????? ?? ????? ???????
?????).
4????? ?????? ?????? ????? ???????
- includeltstdio.hgt
- includeltstring.hgt
- int main()
-
- int o_votes 0 , m_votes0
- char vote7
- while(1)
-
- scanf(6s, vote)
- if (strcmp(vote, Obama)0) o_votes
- else if (strcmp(vote, McCain)0)
m_votes - else if (strcmp(vote, Stop)0)
break - else printf(Wrong vote!\n)
-
- printf(Obama received d votes and McCain
received d - votes\n, o_votes, m_votes)
????? ?????? ??????? ???????, ?? ??????? ?? ?????
?????? ?????? ??????
break?????? ????? ?? ???? ?"?
????? ?????? ????? 6 ??? ?????
?????? ???? ?????? ?????
5??????? ????? ??????-??
- ????????? ??????? ??? ?"? ????? ?? ?????? ????,
?? ??-????? '0\' ????? ???????? ???? ???? ???????
(??? ??????? ???? ??????). ???? - char str Hello
- scanf(s, str) scanf(40s, str) gets(str)
- ?? ?????? ?????? ??-?? (?? ?"? ?????-??? ??
?????? ????), ?? ???? ?????? ????? ?? ??-?????
\0 ??? ????? ????-??? ?????? ?? ??????? ???????
(?????? ?? ??????? ?????? ??? ???????? ?- \0).
6??????? ??? ????? ??????-??
- ????? ??- Enter ?????? ????? ???? ????
???????-???? ?? ?????. ????? ?? ????? ?? ????
?????? ?????? ?? ??? ???? ?? \n (??? ?????
????? ?? ????) - scanf(s, str)
abcd - scanf(c, tav)
- ??? ?????? ????, ???? ?????? ?? ?? ?"? ?? ?????
??????-???? ???? ???? ?? \n - scanf(s, str)
abcd - scanf(\nc, tav) e
7 ?????? ???????? ?? ?????
- ??????ctype.h ??????? ???????? ?? ?????
(????????? ??? ?????? ?? ???? ??? ??????). ???
?????????? ????????? ?????? ???? - int isalpha(char c)
-
- int islower(char c)
- int isupper(char c)
- int isdigit(char c)
- char tolower(char c)
- char toupper(char c)
- (?? tolower ?? ????? ??? ????? ?? ??? ?? ????
????, ??? ?? ?? toupper ?? ????? ??? ????). - - ?? ?????? ?????? ???????? ?? ???????.
????? ??? ??? ??? ??? (????? 0 ?? ?? ?? ?? ?????
??? ???? ?- 0).
??? ??? ??? ??? ????
??? ??? ??? ??? ?????
??? ??? ??? ?????
???? ??? ????? ???? ????? ???????
???? ??? ???? ???? ?????? ???????
8????? ???????
9????? ?????? ???? ?????? ????????
- ??? ?????? ???????
- ?????? ?? ??????
- ??? ??????? ??? ???? ????? ????
- ??????? ???????
10?????? ???????
- ????? ???? ???????? ?? ????? ????? ????? (????)
????. ??????? ???????? ????? ????????? ??????
?????????. - ??? ?? ??????? ?? ????? (???? ??).
- ?? ????? ???? ??????? ??? ?????? ??????? (???
???? ????? ???? ??? ???, ????? ?????? ??????). - ????, ????????? ????? ??-???
int i - ????? ???? ???? ?????? i ???? ??????? ??????
???? ????. ??? ???? ???? ?? ?????? ???????.
11?????? ??????? - ?????
???????
???????
???? ???????
?????
?????
?
i 7500
7500
????? ????? ?????? ???
????? ????? ?????? ???
12?????? ??????? - ?????
???????
???????
???? ???????
?????
?????
10
i 7500
7500
??? ?????? ?????? ???????
13?????? ??????? - ?????
???????
???????
???? ???????
?????
?????
10
i 7500
7500
???? ??? ?? ???? ???? ???????
14?????? ??????? - ?????
???????
???????
???? ???????
- int main()
-
- int i10
- char cA
10
?????
?????
7500
i 7500 c 9200
A
9200
?? ?? ???? ?????? ?????? ?????
15?????? ??????? - ?????
???????
???????
???? ???????
- int main()
-
- int i10
- char cA
10
?????
?????
7500
i 7500 c 9200
65
9200
?????, ????? ???? ??? ????? ?? ???
16?????? ??????? ???? ??????
- ????? ??????? ???? ???? ????, ???? ???? ?????
(????) ??????? ????? ?????? ???. - ????, char ????? ??-??? ??? ???, int ??-???
?????, ????? double ????? (???? ???????????). - ??????? ???????? ??????? ??? ?? ?????, ????? ????
????? ???? ?????? ??? ???? ??????? ???? ???? ???
????, ??? ??? ???? ????? ??? ?? ???? ???.
17?????? ??????? - ?????
???????
???????
???? ???????
- int main()
-
- int i10
- char cA
?????
?????
????
0
0
0
10
i 7500 4 c 92001
7500
65
9200
????? ???? 4 ???? (????). int???? ?? ????? ???
?? ?????? ???????? ???? ???????.
18?????? ???????
- ?? ????? ???? ?????? ??????? ???????
- ?? ???? ?? ?????? ??????? ???????
- ??????
19?????? ??? ???????? ?????
- ??? C ?????? ??? ???? ??? ?????? ??????? ??? ????
????? ??????. - ?????? ????? ?? ?????? ?? ??????.
- ???? i ??? ?????? ??????? ?? ?????? i.
- ?????? ?????? i ???? 7500.
20?????? ??????? - ?????
???????
???????
???? ???????
?????
?????
????
10
i 7500 4
7500
i ?? 7500
21?????? ??? ?????? ?????
- ????? ??????? ????? ?? ?????? ?? ?????.
- ???? i ??? ?????? ??????? ?? ?????? i.
- ?????? ?????? i ??? ???? 7500.
- ?????? ????? ???? ????? ?????? ???????.
- ???? (4000) ?? ???? ????? ?????? 0040.
- (c) ?? ???? ?? ?????? c (?? ?? ???? ?????
?????? ??(c .
22?????? ??????? - ?????
???????
???????
???? ???????
?????
?????
65
c 9200
9200
(9200) ?? 65
23?????? ?? ???? ????? ????
- ?? ???? ????? ????? ?? ?????.
- ????? ?? ???? ????? ???? i5000.
- ???? ????? ?? ???? ????? ?????? ???????.
- ???? (c)A.
- ?? ??? ????? cA.
- ????? ????? ?? ???? ????? ?????? ????? ??????
????? ?? ?????. ???? (4000)123. - ????? ?????? ????? ???? ??????? ????? ??????
??????, ?????? ??????? ????. - ??? ???? ?? ????? ?? ?????? ???????.
24????? ?? ?? ?? ????
- ??? ??? ????? ??? ?? ????? ???? ???? ???? ?? ???.
???? i10. ?? ????? ?? ????? ???? ?? ?????? ???? - ??? ?????? ???? ??? ?????? ??????? ??? ??????
???? ??? ???????
25????? ?? ????? ???????
- ????? ??? ????? ???? ?? ???? ???????? ???? ?????
??. - ????? ??????? ??? ????? ??? ?? ????? ???? ???????
????, ???? ?? ????? ??. - ????, ?? ????? ???????? ???? ??? ?????? (??? ??
????? ??? ???), ?? ???? ?????? ???? ?? ???????
????. ?? ????? ?? ????? ????? ???? ?? ??????
???????.
26????? ??????
- ??????? ?????? ????? ???????? scanf, ?????? ??
????? ?????? ????? ????? ????. ???? - int grade
- scanf(d, grade)
- ?????? grade ?? ????? ???????? scanf ???? ?? ??
?????? ????? ???. - ???????? scanf ????? ?? ?????? ?? ?????? ???????,
??? ????? ?? ????? ????? ?? ???? (????? ??????
?????? ????). - ????? ???? (???? d) ???? ?- scanf ?? ?? ????
?????? ??? ???????, ????? ???? ???? ???? ????
??????.
27?????? ??????? - ??????
- ????? ?????? i
- ???? ?????? ??? ?????? ?? ??????
- ?? ????? ??? ????? ???? ?????? ??? ????????
- ??????
28????? ?? ?????? - ???????
- ?? ?-C ??????-?????? ?????? ?????? ???????.
- ?? ?????? "???????" ?? "?????????".
- ???? ?????? ????
- char my_pointer_to_char
- int the_pointer_to_int
- ????? ????, ??? ?????? ????? ???? ?????, ??????
?? ??? ?????? ????? ???????, ??????? ???? ??
??????. - ??? ??????? double my_pointer float ptr
char ????? ?????? ????? ?? int ????? ??????
????? ??
29????? ?? ?????? - ???????
- ?? ?-C ??????-?????? ?????? ?????? ???????.
- ?? ?????? "???????" ?? "?????????".
- ???? ?????? ????
- char my_pointer_to_char
- int the_pointer_to_int
- ????? ????, ??? ?????? ????? ???? ?????, ??????
?? ??? ?????? ????? ???????, ??????? ???? ??
??????. - ???? ?? ??? ????? ??? ??????? (?????? ?????
?????? ?????), ???? ?????? ?????? ???? (?????
???? ??????).
char ????? ?????? ????? ?? int ????? ??????
????? ??
30??????? ??????
- ????? ???? ????? ????? ("??") ?????? ???. ??????
- int i10
- int my_pointer_to_int
- my_pointer_to_int i
int ????? ????? ?????? ????? ??
i?????? ???? ?????? ??????? ??
31???? ?????? ??-??? ?????
- ?????, ??? ??????? ???? ????? ?????? ???????,
??????? ????? . ????? ??? ?????? ?????? ?? ?? - int i10
- int my_pointer_to_int
- my_pointer_to_int i
- my_pointer_to_int100
- printf(The value of i is now d, i)
int????? ????? ??
i???? ?????? ?? ????? ??????
???? 100 ????? ????????? ????? ????
????? ????? 100
32??? ?? ????? ???? ??? ??????
- ??? ?????? ???? ?? ???? ?????? ???????? ????,
???? ????? ??????? ????? ?????? ???? (???? ??? ??
????). - ?? ?????????? ???? ????? ???????, ????? ???? ????
???? ??? ????? ????, ?????/????? ?? ???? ?????. - ????? ????? ??? ?? ????? ?? ?????
"??????-??????". - ?? ????? ???? ?- int ????? ??????? ???? ???? i,
?? ???? ?????? 1 ?????? ?? i, ?????? ??? ????
???? ?????? ????? ????? ?? int
33??????? ??????? ?????? ??????-??
- ???? ?? ???????? ???????? ??? ?????. ????, ??
????? - 5
- (i2)
- ?? ??????? ?? ?????.
- ????? ??? ???? ????? ????? ?? ????? (????? ????
????), ?? ???? ???? ???? ???? ab.
34"????? ?? ????"
- ?? ????? ???? ?????? ?? ????? ???? ????? (????
???? ??????? ?????? ??), ?? ????? ??????? ?? ??
???? NULL. - ????
- int my_pointer_to_intNULL
- NULL ??? ???? ????? 0 ?????? ?"? define ??????
stdlib.h.
35??????? ????? ??????
- ??? ?????? ??????? ?????? ????? ?? ????? ???.
- ??? ?????? ???? ?????? ?"? ??? ?????? ????????
???? ?- . ???? int my_ptr - ???? ???? ?????? ????????? ????? ???? ????? .
???? my_ptr5 - ??????
36??????? ?????
- ???? ??????? ?????? ?????? ?? ??? ?????? ????
int, ??????? ??? ?????? ????. - (?? ????? ?? ?????? ????? ??????? ?????? ????? ??
??? ?????? ???? int, ?? ????? ?????? ???? int
???????? ?? ????? ?? ???? ??????, ???????? ?????
?????? ?? ??? ???). - void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- ?????? ???? ??-??? swap(i, j)
first ??? ?????? ??????? ?????? ?? ????? ?? ???
?????? ??????? ?????? ?? second
37????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
38????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
39????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
10
i
20
j
40????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
first
second
10
i
20
j
41????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
first
second
temp
10
i
20
j
42????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
first
second
temp
10
10
i
20
j
43????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
first
second
temp
10
20
i
20
j
44????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
first
second
temp
10
20
i
10
j
45????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
20
i
10
j
46????? ??????? ?????? ??? ???? ??????
- void swap(int first, int second)
-
- int temp
- tempfirst
- firstsecond
- secondtemp
-
- int main()
-
- int i10, j20
- swap(i,j)
??? ??????? ?? ?????? ????? ???? ?????? ???
??-??? ???????
20
i
10
j
47??? ?? ???????? ????????
- ????? ????? ?????? ???????? ???? ????? ?????.
??????, ??????? ????? ???? ??????? ???? ??????
??????? ?? ?????? ????? ??????? - int address_of _the_higher_number(int a, intb)
- ??? ????? ????? ????? ?????? ???? ???????? ?????
??????. ?? ??????? ???????? ???? ???????? ??????
?? ?????. ???? ???????? ???? ????? ?????? - int give_pointer_to_zero()
-
- int i0
- return i
48????? ???????
49??????? ???????
- ????????
- char array10
- ?????? ??????? 10 ???? ?????? ???? 10 ?????,
??????? array ???? ?? ????? ??? ?????? ???????.
500
array
????? 500 (????)
50??????? ???????
- ??-???? ????? ????? ?? ???? (??? ????? ?????
?????). - ??? ?? ???? ????? arrayarray1, ?? array0.
- ???? ???? ????? ?? ???? ???? ?????. ???? ?????
- char array_ptr
- array_ptrarray
- (????? ??????? ????? ?????array_ptr array0
) - ?????, ????? ???? ??? ??? ?? ????? (??? ??
?????). - ???? ??? ????? ????? ????? ????? ?????? ??? ????
????? ????.
(???? ?????? ?? ????? ??? ?????? ?????)
51???? ????-???? ??? ??????
- ?? ?????? ????
- int array10
- int array_ptr
- array_ptrarray
- ?? ???? ???? ????-????? ?? ??? ?????? ????,
??? ?????? ?????. 3 ??????? ????? ????? ???? ???
(???? 100 ??? ??' 5 ?????) - array5100
- (array5)100
- (array_ptr5)100
- - ????? ???? ??? ???? ?????? ??????? ??????
?????? ?-5 ???? ?????, ?? ?????? ?????? ??????
??? int ???? ???? ??? ???? ?? int ???? (?????,
???? ????? ?????? ??????? ????).
(????? ?? ??? ?????? ?????)
???? ??? ????? 5 ???? ???? ??? ??????
52???? ????? ??? ????? ????? ?????
- ???? ????? ????, 3 ????????? ????? ????? ?????
???? ??? - int i,array10
- int ptr
- for (i0 ilt10 i)
- printf(d, arrayi)
- for (i0 ilt10 i)
- printf(d, (arrayi))
- for (ptrarray ptr lt array9 ptr)
- printf(d, ptr)
????? ??-??? ???? ????? ???? ?????
????? ??-??? ???? ??? ?? ??? ?????? ??? ????? ???
??????
????? ?"? ????? ????? ?????? ??? ?????? ?? ?????
??? ??????
53?????? ????????? - ????
- ????? ???? ?????????? ???? ???????? ??????? ?????
???????? ?????? ?? ????? ??????. - ?? ???? ??? ????????? ?????? ?????? ??????? ??
????? ??????, ???? ????? ?????? ?? ????? (??? ??
???? ????). - ????, ??? ??????, ???????? ???? ???? ???? ??????
???? - void zero_array(int a , int size)
-
- int i
- for(i0 iltsize i)
- ai0
54?????? ?????????
- ????? ???? ?????????? ???? ???????? ??????? ?????
???????? ?????? ?? ????? ??????. - ?? ???? ??? ????????? ?????? ?????? ??????? ??
????? ??????, ???? ????? ?????? ?? ????? (??? ??
???? ????). - ????, ??? ??????, ???????? ???? ???? ???? ??????
???? - void zero_array(int a, int size)
-
- int i
- for(i0 iltsize i)
- ai0
????? ??? ??????? ???? ???? ?????, ???? ??????
???? ???? ????? ???, ?? ???? ?????? ?? ?????? ???
????? ???????.
55?????? ?????????
- ???? ????????? ??????? ?? ??????? (??? strcmp,
strlen) ??????? ????? ???? ??????? ???? char . - ????????? ?????? ???? ???? ?? ?????? (????? ???
????? ??????? ?- '0\') ??? ??? ?? ????? ??? (????
?????? ?????? ?? ??? ?? ?? ?????). - ???-??, ?????, ?? ??????? ?????? ?? ???? ?????
??????, ???? ?????? ???? ?? ???? ????? ??? ??
???? ????? (?? ????? ?? ?????? ?? ?? ?????
??????). - ???, ?? ????????? ?????? ???????? ????? ???????
????? ??? ?? ???? ????? ??? ????? ????.
56?????? ????????? ????? ?????? ??
- ?? ???? ?????? ???????? ???? ??????? ????? ??
????? ?? ???? ???, ?? ???? ?????. - int zero_array()
-
- int array1000
- return array
-
- ?? ?????? ??????? ????? ?? ?????, ??? ?? ??
?????? ???? ???????? ???? ????? ???????.
57??????? ??????? - ?????
- ????? ???? ??? ??? ?? ????? ??? ???? ????? (??
??? ?????? ?????), ??? ??-???? ????? ????. - ?? ????? ??????? ???? ???????? ????? ??????
?????. - ???? ???? ??? ????? ?? ????? ????? ?????? ?????
?????? ????? ?????. ???? (array5)100 - ??????
58- ?????? ???? ??
- ?????? ???????
- ??????? ??????? ???
- ?????? ????????
- ?????? ?????????
59????? ???????
60?????? ?