ﳏﺘﻮﻳﺎﺕ ﺍﻟﻜﺘﺎﺏ ﺑﻨﻈﺮﺓ ﺳﺮﻳﻌﺔ ﺣﻮﻝ ﺍﻟﻜﺘﺎﺏ ١٨............................................................................................. ﺍﳌﻘﺪﻣﺔ ١٩................................................................................................... ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ........................................................................... C ١,١ﺍﻷﺩﻭﺍﺕ ﺍﻟﻼﺯﻣﺔ ٢٢................................................................................. ١,٢ﺍﻟﺒﺪﺀ ﻣﻊ ﻟﻐﺔ ٢٥.................................................................................. C ١,٣ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ ٣٤..................................................... Variables and Constants ١,٤ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ٤٥........................................................................... Comments ١,٥ﺍﻹﺩﺧﺎﻝ ٤٨.................................................................................. input ١,٦ﺍﳌﺆﺛﺮﺍﺕ ٥١............................................................................. Operators ١,٧ﺍﻟﻘﺮﺍﺭﺍﺕ ٦٠....................................................................... if, else, else…if ١,٨ﻋﻨﺎﺻﺮ ﻟﻐﺔ ٦٤.................................................................................... C ١,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻷﻭﻝ ،ﻣﻊ ﺇﺿﺎﻓﺎﺕ ٦٩............................................................... ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﱐ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ....................................................................... (٢) C ٢,١ﺍﻟﻘﺮﺍﺭ ٨١................................................................................... Switch ٢,٢ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ ٨٦.................................................................. Repeated loop ٢,٣ﺍﳌﺼﻔﻮﻓﺎﺕ ١٠٠............................................................................. Arrays ٢,٤ﺍﳌﺆﺷﺮﺍﺕ ١١٤............................................................................ Pointers ٢,٥ﺍﻟﺪﻭﺍﻝ ١٢٥............................................................................. Functions ٢,٦ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ١٣٥................................................................... Header files ٢,٧ﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ ﰲ ﺍﳌﻠﻔﺎﺕ ١٣٨........................................................ Files I/O ٢,٨ﺍﻟﺘﺮﺍﻛﻴﺐ ١٤٧........................................................................... structures ٢,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻟﺜﺎﱐ ،ﻣﻌﺎ ﺇﺿﺎﻓﺎﺕ ١٥٧.............................................................. ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﻟﺚ – ﺍﻟﺘﻘﺪﻡ ﰲ ﻟﻐﺔ .............................................................................. C ٣,١ﺍﳊﺴﺎﺏ ١٧٦......................................................................... Enumeration ٣,٢ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ١٨٢............................................... Command-line Arguments ٣,٣ﺍﻟﺘﻮﺟﻴﻬﺎﺕ )١٨٥.......................................................... Directives(Preprocessor ٣,٤ﺩﻭﺍﻝ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ ١٩٢................................................................... ٣,٥ﺍﳌﻜﺘﺒﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ١٩٥............................................................... Standard Library ﺍﳋﺎﲤﺔ ٢٤١.................................................................................................. ﺟﺪﻭﻝ ﺍﻷﺷﻜﺎﻝ )ﺍﻟﺼﻮﺭ( ..................................................................................... ﺟﺪﻭﻝ ﺍﳉﺪﺍﻭﻝ .............................................................................................. ﺟﺪﻭﻝ ﺍﻟﱪﺍﻣﺞ ............................................................................................... ﺃﻫﻢ ﺍﳌﺮﺍﺟﻊ .................................................................................................. ﺟﺪﻭﻝ ﺍﶈﺘﻮﻳﺎﺕ ﺣﻮﻝ ﺍﻟﻜﺘﺎﺏ ١٨............................................................................................. ﺍﳌﻘﺪﻣﺔ ١٩................................................................................................... ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ........................................................................... C ١,١ﺍﻷﺩﻭﺍﺕ ﺍﻟﻼﺯﻣﺔ ٢٢..................................................................................... ١,١,١ﳏﺮﺭ ﻧﺼﻮﺹ ٢٢..................................................................... texts editor ١,١,٢ﻣﺘﺮﺟﻢ ٢٢............................................................................. compiler ١,١,٣ﺍﳌﺮﺑﻂ ٢٤................................................................................. linker ١,٢ﺍﻟﺒﺪﺀ ﻣﻊ ﻟﻐﺔ ٢٥...................................................................................... C ١,٢,١ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻷﻋﺪﺍﺩ ٢٩............................................................................ ١,٢,٢ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٣٢.............................................................................. ١,٢,٣ﲤﺎﺭﻳﻦ ٣٣....................................................................................... ١,٣ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ ٣٤..................................................... Variables and Constants ١,٣,١ﻧﻮﻉ ﺍﳌﺘﻐﲑ ٣٥..................................................................... Variable Type ١,٣,١,١ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ٣٥............................................................. int ١,٣,١,٢ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ٣٥............................................................. float ١,٣,١,٣ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ٣٦........................................................... double ١,٣,١,٤ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ٣٦.......................................................... short ١,٣,١,٥ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ٣٦........................................................... long ١,٣,١,٥ﻣﺘﻐﲑ ﺍﻟﺮﻣﻮﺯ ٣٧...................................................................... char ١,٣,٢ﺍﺳﻢ ﺍﳌﺘﻐﲑ ٣٧.................................................................... Variable Name ١,٣,٣ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ٣٧.....................................................................Variable Value ١,٣,٤ﺃﻣﺜﻠﺔ ﺣﻮﻝ ﺍﳌﺘﻐﲑﺍﺕ ٣٧.......................................................................... ١,٣,٥ﺍﻷﻋﺪﺍﺩ ﺍﳌﻮﺟﺒﺔ ﻭ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺴﺎﻟﺒﺔ ٤٠............................................................... ١,٣,٦ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٤٣.............................................................................. ١,٣,٧ﲤﺎﺭﻳﻦ ٤٤....................................................................................... ١,٤ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ٤٥........................................................................... Comments ١,٤,١ﻓﺎﺋﺪﺓ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ٤٥............................................................................... ١,٤,٢ﺃﻧﻮﺍﻉ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ٤٥.............................................................................. ١,٤,٢,١ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻟﻨﺼﻮﺹ ﺍﻟﻄﻮﻳﻠﺔ ٤٥............................................................ ١,٤,٢,٢ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻷﺳﻄﺮ ٤٥..................................................................... ١,٤,٣ﻛﻴﻒ ﻳﺴﺘﻌﻤﻞ ﺍﳌﱪﳎﻮﻥ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ٤٦.............................................................. ١,٤,٤ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٤٦.............................................................................. ١,٤,٥ﲤﺎﺭﻳﻦ ٤٧....................................................................................... ١,٥ﺍﻹﺩﺧﺎﻝ ٤٨..................................................................................... Input ١,٥,١ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٥٠.............................................................................. ١,٥,٢ﲤﺎﺭﻳﻦ ٥٠....................................................................................... ١,٦ﺍﳌﺆﺛﺮﺍﺕ ٥١................................................................................ Operators ١,٦,١ﺍﳌﺆﺛﺮﺍﺕ ﺍﳊﺴﺎﺑﻴﺔ ٥١........................................................ arthimetic operators ١,٦,١,١ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ ٥١...........................................................(++) increment ١,٦,١,٢ﻣﺆﺛﺮ ﺍﻟﻨﻘﺼﺎﻥ ٥٢..........................................................(--) decrement ١,٦,١,٣ﻣﺆﺛﺮ ﺑﺎﻗﻲ ﺍﻟﻘﺴﻤﺔ )٥٣.................................................................(% ١,٦,٢ﺍﳌﺆﺛﺮﺍﺕ ﺍﻟﻌﻼﻗﻴﺔ ٥٣.......................................................... relational operators ١,٦,٣ﺍﳌﺆﺛﺮﺍﺕ ﺍﳌﻨﻄﻘﻴﺔ ٥٤............................................................. logical operators ١,٦,٤ﻣﺆﺛﺮﺍﺕ ﺃﺧﺮﻯ ٥٥............................................................................... ١,٦,٥ﻣﺆﺛﺮﺍﺕ ﺧﺎﺻﺔ ﺑﺎﻟﺒﺘﺎﺕ )٥٧.............................................................. (bitwize ١,٦,٦ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٥٩.............................................................................. ١,٦,٧ﲤﺎﺭﻳﻦ ٥٩....................................................................................... ١,٧ﺍﻟﻘﺮﺍﺭﺍﺕ ٦٠.......................................................................... if, else, else…if ١,٧,١ﺍﺳﺘﻌﻤﺎﻝ ٦٠................................................................................... if ١,٧,٢ﺍﺳﺘﻌﻤﺎﻝ ٦١................................................................................ else ١,٧,٣ﺍﺳﺘﻌﻤﺎﻝ ٦٢............................................................................. else…if ١,٧,٤ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٦٣.............................................................................. ١,٧,٥ﲤﺎﺭﻳﻦ ٦٣....................................................................................... ١,٨ﻋﻨﺎﺻﺮ ﻟﻐﺔ ٦٤........................................................................................ C ١,٨,١ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ٦٤......................................................................... Comments ١,٨,٢ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ ٦٤.................................................................. Keywords ١,٨,٣ﺍﳌﻌﺮﻓﺎﺕ ٦٤.......................................................................... Identifiers ٦٥............................................................................. Trigraphs ١,٨,٣,١ ١,٨,٤ﺍﻟﺜﻮﺍﺑﺖ ٦٥........................................................................... Constants ١,٨,٤,١ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﻨﺼﻴﺔ ٦٦......................................................................... ١,٨,٤,٢ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﺮﻗﻤﻴﺔ ٦٧........................................................................ ١,٨,٥ﺍﻟﺮﻣﻮﺯ ٦٨............................................................................... Tokens ١,٨,٦ﺍﻟﺴﻼﺳﻞ ﺍﻟﻨﺼﻴﺔ ٦٨................................................................ String literals ١,٨,٧ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٦٨.............................................................................. ١,٨,٨ﲤﺎﺭﻳﻦ ٦٨....................................................................................... ١,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻷﻭﻝ ،ﻣﻊ ﺇﺿﺎﻓﺎﺕ ٦٩.................................................................. ١,٩,١ﺑﺮﺍﻣﺞ ﺗﺪﺭﻳﺒﻴﺔ ٦٩................................................................................ ١,٩,١,١ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ،ﻋﻤﺮ ﺍﳌﺴﺘﺨﺪﻡ ٦٩.......................................................... ١,٩,١,٢ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺜﺎﱐ ،ﺁﻟﺔ ﺣﺎﺳﺒﺔ ﺑﺴﻴﻄﺔ ٧٠........................................................ ١,٩,١,٣ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺜﺎﻟﺚ ،ﺍﺳﺘﺨﺮﺍﺝ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻄﻠﻘﺔ ٧١................................................. ١,٩,١,٤ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺮﺍﺑﻊ ،ﺃﺧﺬ ﺍﻟﻌﺪﺩ ﺍﻟﻜﺒﲑ ٧٢........................................................ ١,٩,٢ﺍﻟﺪﺍﻟﺘﲔ putcharﻭ ٧٢................................................................... getchar ١,٩,٣ﺍﻟﺪﺍﻟﺘﲔ putsﻭ ٧٣.......................................................................... gets ١,٩,٤ﺍﻟﺪﺍﻟﺘﲔ wprintfﻭ ٧٤..................................................................... wscanf ١,٩,٥ﺍﻟﺪﺍﻟﺘﲔ putchﻭ getchﻭ ﺍﻟﺪﺍﻟﺔ ٧٤........................................................ getche ١,٩,٦ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ٧٦..................................................................... wchar_t ١,٩,٧ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ mainﻭ ٧٦................................................................. wmain ١,٩,٨ﺭﻣﻮﺯ ﺍﻹﺧﺮﺍﺝ ﻭ ﺍﻹﺩﺧﺎﻝ ٧٨..................................................................... ١,٩,٩ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٧٩.............................................................................. ١,٩,١٠ﲤﺎﺭﻳﻦ ٧٩...................................................................................... ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﱐ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ........................................................................ (٢) C ٢,١ﺍﻟﻘﺮﺍﺭ ٨١...................................................................................... Switch ٢,١,١ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ٨٣......................................................................... case ٢,١,٢ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ٨٤........................................................................ break ٢,١,٢ﺍﻟﻜﻠﻤﺔ ﺍﻮﺯﺓ ٨٤......................................................................... default ٢,٨,٧ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٨٤.............................................................................. ٢,٨,٨ﲤﺎﺭﻳﻦ ٨٥....................................................................................... ٢,٢ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ ٨٦.................................................................... Repeated loop ٢,٢,١ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٨٦......................................................................... while ٢,٢,٢ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٨٨.................................................................... do…while ٢,٢,٣ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٩٠........................................................................... for ٢,٢,٤ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٩٢......................................................................... goto ٢,٢,٥ﺍﳌﻔﻬﻮﻡ ﺍﻟﻌﺎﻡ ﳊﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ ٩٣................................................................... ٢,٢,٧ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ٩٧..................................................................... continue ٢,٢,٨ﺟﺪﻭﻝ ٩٨................................................................................ ASCII ٢,٢,٩ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ٩٨.............................................................................. ٢,٢,١٠ﲤﺎﺭﻳﻦ ٩٨...................................................................................... ٢,٣ﺍﳌﺼﻔﻮﻓﺎﺕ ١٠٠................................................................................ Arrays ٢,٣,١ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﺍﳌﺼﻔﻮﻓﺎﺕ ١٠١..................................................................... ٢,٣,٢ﺍﳌﺼﻔﻮﻓﺎﺕ ﺍﻟﺜﻨﺎﺋﻴﺔ ﺍﻷﺑﻌﺎﺩ ١٠٢.................................................................... ٢,٣,٢ﺍﳌﺼﻔﻮﻓﺎﺕ ﺍﻟﺜﻼﺛﻴﺔ ﺍﻷﺑﻌﺎﺩ ١٠٤.................................................................... ٢,٣,٣ﻣﺼﻔﻮﻓﺔ ﺫﺍﺕ ﺣﺠﻢ ﻏﲑ ﻣﻌﺮﻭﻑ ١٠٥............................................................. ٢,٣,٤ﺍﻟﺴﻼﺳﻞ ﺍﳊﺮﻓﻴﺔ )ﺍﻟﻨﺼﻮﺹ( ١٠٦................................................................. ٢,٣,٤,١ﺍﻟﺪﺍﻟﺔ ١٠٩........................................................................... gets ٢,٣,٤,٢ﺍﻟﺪﺍﻟﺔ strcpyﻭ ﺍﻟﺪﺍﻟﺔ ١٠٩......................................................... strncpy ٢,٣,٤,٣ﺍﻟﺪﺍﻟﺔ strcatﻭ ﺍﻟﺪﺍﻟﺔ ١١٠.......................................................... strncat ٢,٣,٥ﻃﺮﻕ ﺃﺧﺮﻯ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺼﻔﻮﻓﺎﺕ ١١١........................................................... ٢,٣,٦ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١١٢............................................................................. ٢,٣,٧ﲤﺎﺭﻳﻦ ١١٣...................................................................................... ٢,٤ﺍﳌﺆﺷﺮﺍﺕ ١١٤............................................................................... Pointers ٢,٤,١ﻧﻮﻉ ﺍﳌﺆﺷﺮ ١١٤................................................................... Pointer Type ٢,٤,٢ﺍﺳﻢ ﺍﳌﺆﺷﺮ ١١٤................................................................... Pointer Name ٢,٤,٣ﺍﳌﺆﺷﺮﺍﺕ ﻭ ﺍﳌﺼﻔﻮﻓﺎﺕ ١١٦...................................................................... ٢,٤,٤ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ١١٧........................................................................ ٢,٤,٥ﺍﳌﺮﺟﻊ ١٢٠........................................................................... reference ٢,٤,٦ﻣﺆﺷﺮ ﻟـ ١٢٠............................................................................. void ٢,٤,٧ﻣﺆﺷﺮ ﳌﺼﻔﻮﻓﺔ ١٢١.............................................................................. ٢,٤,٨ﻣﺆﺷﺮ ﳌﺆﺷﺮ ١٢٢................................................................................ ٢,٤,٩ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٢٣............................................................................. ٢,٤,١٠ﲤﺎﺭﻳﻦ ١٢٣.................................................................................... ٢,٥ﺍﻟﺪﻭﺍﻝ ١٢٥................................................................................ Functions ٢,٥,١ﻧﻮﻉ ﺍﻟﺪﺍﻟﺔ ١٢٨................................................................... Function Type ٢,٥,٢ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ١٣١.................................................................. Function Name ٢,٥,٣ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ ١٣١.......................................................... Function Parameters ٢,٥,٤ﺍﻷﻭﺍﻣﺮ ١٣١..................................................................................... ٢,٥,٥ﺍﳌﺨﺘﺼﺮﺍﺕ ١٣٢......................................................................... macros ٢,٥,٦ﺍﻟﻔﺮﻕ ﺑﲔ ﺍﻹﺟﺮﺍﺀ ﻭ ﺍﻟﺪﺍﻟﺔ ١٣٢................................................................... ٢,٥,٧ﺩﻭﺍﻝ ﳍﺎ ﻭﺳﺎﺋﻂ ﻣﻦ ﻧﻮﻉ ﺩﻭﺍﻝ ١٣٢............................................................... ٢,٥,٨ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٣٣............................................................................. ٢,٥,٩ﲤﺎﺭﻳﻦ ١٣٤...................................................................................... ٢,٦ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ١٣٥...................................................................... Header files ٢,٦,١ﺍﺳﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ١٣٦.......................................................................... ٢,٦,٢ﻣﱴ ﻧﺴﺘﻌﻤﻞ ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ١٣٦................................................................. ٢,٦,٣ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٣٦............................................................................. ٢,٦,٤ﲤﺎﺭﻳﻦ ١٣٧...................................................................................... ٢,٧ﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ ﰲ ﺍﳌﻠﻔﺎﺕ ١٣٨.......................................................... Files I/O ٢,٧,١ﺍﻹﺧﺮﺍﺝ ﰲ ﺍﳌﻠﻔﺎﺕ ١٣٨......................................................................... ٢,٧,١,١ﺍﻟﺪﺍﻟﺔ ١٤٠......................................................................... fopen ٢,٧,١,٢ﺍﻟﺪﺍﻟﺔ ١٤١......................................................................... fclose ٢,٧,١,٣ﺍﻟﺪﺍﻟﺔ ١٤١........................................................................... exit ٢,٧,٢ﺇﺿﺎﻓﺔ ﻧﺺ ﰲ ﺎﻳﺔ ﺍﳌﻠﻒ ١٤١.................................................................... ٢,٧,٣ﺍﻹﺩﺧﺎﻝ ﰲ ﺍﳌﻠﻔﺎﺕ ١٤٢......................................................................... ٢,٧,٤ﺍﻟﻨﻤﻂ w+ﻭ a+ﻭ ١٤٣....................................................................... r+ ٢,٧,٤,١ﺍﻟﻨﻤﻂ ١٤٣........................................................................... w+ ٢,٧,٤,٢ﺍﻟﻨﻤﻂ ١٤٣........................................................................... a+ ٢,٧,٤,٣ﺍﻟﻨﻤﻂ ١٤٣............................................................................ r+ ٢,٧,٥ﺩﻭﺍﻝ ﺃﺧﺮﻯ ﺧﺎﺻﺔ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﻠﻔﺎﺕ ١٤٣....................................................... ٢,٧,٥,١ﺍﻟﺪﺍﻟﺔ fprintfﻭ ﺍﻟﺪﺍﻟﺔ ١٤٣.......................................................... fscanf ٢,٧,٥,٢ﺍﻟﺪﺍﻟﺔ fgetsﻭ ﺍﻟﺪﺍﻟﺔ ١٤٤............................................................. fputs ٢,٧,٥,٣ﺍﻟﺪﺍﻟﺔ fgetcﻭ ﺍﻟﺪﺍﻟﺔ ١٤٥............................................................ fputc ٢,٧,٦ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٤٦............................................................................. ٢,٧,٧ﲤﺎﺭﻳﻦ ١٤٦...................................................................................... ٢,٨ﺍﻟﺘﺮﺍﻛﻴﺐ ١٤٧............................................................................. structures ٢,٨,١ﺍﺳﻢ ﺍﻟﺒﻨﻴﺔ ١٤٧..................................................................... Struct Name ٢,٨,٢ﺍﻟﺒﻨﻴﺎﺕ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٥١...................................................... union ٢,٨,٣ﺍﳌﺼﻔﻮﻓﺎﺕ ﻭ ﺍﳌﺆﺷﺮﺍﺕ ﻋﻠﻰ ﺍﻟﺒﻨﻴﺎﺕ ١٥٣.......................................................... ٣,٨,٤ﺇﻋﻼﻥ ﺑﻨﻴﺔ ﺩﺍﺧﻞ ﺑﻨﻴﺔ ١٥٥........................................................................ ٢,٨,٥ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٥٥............................................................................. ٢,٨,٦ﲤﺎﺭﻳﻦ ١٥٦...................................................................................... ٢,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻟﺜﺎﱐ ،ﻣﻌﺎ ﺇﺿﺎﻓﺎﺕ ١٥٧................................................................. ٢,٩,١ﻣﻌﲎ ﺩﺍﻟﺔ ﺎ ﻭﺳﻴﻂ ١٥٧.................................................................... void ٢,٩,٢ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٥٨....................................................................... static ٢,٩,٣ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٥٩.................................................................... typedef ٢,٩,٤ﺑﺮﺍﻣﺞ ﺗﺪﺭﻳﺒﻴﺔ ١٦١............................................................................... ٢,٩,٤,١ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ،ﺍﻟﻨﺴﺦ ١٦١................................................................ ٢,٩,٤,٢ﺗﺒﺎﺩﻝ ﻗﻴﻢ ﺑﲔ ﻭﺳﻴﻄﲔ ١٦٢................................................................ ٢,٩,٤,٣ﺍﻟﺘﻐﲑ ﰲ ﻗﻴﻢ ﺛﻮﺍﺑﺖ ١٦٣................................................................... ٢,٩,٤,٤ﻋﻜﺲ ﺳﻠﺴﻠﺔ ﻧﺼﻴﺔ ١٦٣.................................................................. ٢,٩,٤,٥ﺍﻟﺘﺤﻮﻳﻞ ﻣﻦ ﺍﻟﻨﻈﺎﻡ ﺍﻟﻌﺸﺮﻱ ﺇﱃ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺜﻨﺎﺋﻲ ١٦٤........................................... ٢,٩,٤,٦ﺍﻟﺘﺤﻮﻳﻞ ﻣﻦ ﺍﳊﺮﻭﻑ ﺍﻟﺼﻐﲑﺓ ﺇﱃ ﺍﳊﺮﻭﻑ ﺍﻟﻜﺒﲑﺓ ١٦٤....................................... ٢,٩,٥ﺍﻟﺪﺍﻟﺔ wcscpyﻭ ﺍﻟﺪﺍﻟﺔ ١٦٥.............................................................. wcsncpy ٢,٩,٦ﺍﻟﺪﺍﻟﺔ wcscatﻭ ﺍﻟﺪﺍﻟﺔ ١٦٦.............................................................. wcsncat ٢,٩,٧ﺍﻟﺪﺍﻟﺔ getwcharﻭ ١٦٦................................................................ putwchar ٢,٩,٨ﺍﻟﺪﺍﻟﺔ _getwsﻭ ١٦٧..................................................................... _putws ٢,٩,٩ﺟﺪﻭﻝ ) ASCIIﺻﻮﺭﺓ( ١٦٧...................................................................... ٢,٩,١٠ﻣﻌﻠﻮﻣﺎﺕ ﺃﻛﺜﺮ ﺣﻮﻝ ﺍﳌﺘﻐﲑﺍﺕ ١٦٨.............................................................. ٢,٩,١٠,١ﺍﳌﺘﻐﲑﺍﺕ ﺍﶈﻠﻴﺔ ١٦٨..................................................................... ٢,٩,١٠,٢ﺍﳌﺘﻐﲑﺍﺕ ﺍﳋﺎﺭﺟﻴﺔ )ﺍﻟﻌﺎﻣﺔ( ١٦٩.......................................................... ٢,٩,١٠,٣ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٦٩............................................................. extern ٢,٩,١٠,٤ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٧٠............................................................... auto ٢,٩,١٠,٥ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٧١............................................................ register ٢,٩,١١ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٧١..................................................................... sizeof ٢,٩,١٢ﺍﺳﺘﺪﻋﺎﺀ ﺩﺍﻟﺔ ﻟﻨﻔﺴﻬﺎ ١٧٢....................................................................... ٢,٩,١٣ﺍﻟﺘﺤﻜﻢ ﰲ ﻃﺒﺎﻋﺔ ﺍﻟﻨﺘﺎﺋﺞ ١٧٣................................................................... ٢,٩,١٤ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٧٣........................................................................... ٢,٩,١٥ﲤﺎﺭﻳﻦ ١٧٣.................................................................................... ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﻟﺚ – ﺍﻟﺘﻘﺪﻡ ﰲ ﻟﻐﺔ .............................................................................. C ٣,١ﺍﳊﺴﺎﺏ ١٧٦........................................................................... Enumeration ٣,١,١ﺍﺳﻢ ﺍﳊﺴﺎﺏ ١٨٦........................................................... Enumeration Name ٣,١,٢ﺛﻮﺍﺑﺖ ﺍﳊﺴﺎﺏ ١٨٦............................................................................. ٣,١,٣ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٨٠............................................................................. ٣,١,٤ﲤﺎﺭﻳﻦ ١٨٠...................................................................................... ٣,٢ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ١٨٢.............................................. Command-line Arguments ٣,٢,١ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ١٨٢................................................................. ٣,٢,٢ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ١٨٣.................................................................. ٣,٢,٣ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٨٤............................................................................. ٣,٢,٤ﲤﺎﺭﻳﻦ ١٨٤...................................................................................... ٣,٣ﺍﻟﺘﻮﺟﻴﻬﺎﺕ )١٨٥........................................................... Directives(Preprocessor ٣,٣,١ﺍﻟﺘﻮﺟﻴﻪ ١٨٥.......................................................................... #include ٣,٣,٢ﺍﻟﺘﻮﺟﻴﻪ ١٨٥........................................................................... #define ٣,٣,٣ﺍﻟﺘﻮﺟﻴﻪ ١٨٦............................................................................. #undef ٣,٣,٤ﺍﻟﺘﻮﺟﻴﻬﺎﺕ #else ،#elif ،#ifﻭ ١٨٧..................................................... #endif ٣,٣,٥ﺍﻟﺘﻮﺟﻴﻪ #ifdefﻭ ﺍﻟﺘﻮﺟﻴﻪ ١٨٧............................................................ #ifndef ٣,٣,٦ﺍﻟﺘﻮﺟﻴﻪ ١٨٩.............................................................................. #line ٣,٣,٧ﺍﻟﺘﻮﺟﻴﻪ ١٨٩............................................................................. #error ٣,٣,٨ﺍﻟﺘﻮﺟﻴﻪ ١٩٠.......................................................................... #pragma ٣,٣,٩ﺍﻷﲰﺎﺀ ﺍﳌﻌﺮﻓﺔ ١٩٠............................................................ Predefined Names ٣,٣,١٠ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٩٠........................................................................... ٣,٣,١١ﲤﺎﺭﻳﻦ ١٩١.................................................................................... ٣,٤ﺩﻭﺍﻝ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ ١٩٢...................................................................... ٣,٤,١ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ ١٩٤............................................................................. ٣,٤,٢ﲤﺎﺭﻳﻦ ١٩٤...................................................................................... ٣,٥ﺍﳌﻜﺘﺒﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ١٩٥................................................................ Standard Library ٣,٥,١ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ١٩٥...................................................................... assert.h ٣,٥,٢ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ١٩٥...................................................................... ctype.h ٣,٥,٢,١ﺍﻟﺪﺍﻟﺔ ١٩٥....................................................................... isalnum ٣,٥,٢,٢ﺍﻟﺪﺍﻟﺔ ١٩٦....................................................................... isalpha ٣,٥,٢,٣ﺍﻟﺪﺍﻟﺔ ١٩٦......................................................................... iscntrl ٣,٥,٢,٤ﺍﻟﺪﺍﻟﺔ ١٩٧........................................................................ isdigit ٣,٥,٢,٥ﺍﻟﺪﺍﻟﺔ ١٩٧....................................................................... isgraph ٣,٥,٢,٦ﺍﻟﺪﺍﻟﺔ ١٩٨....................................................................... islower ٣,٥,٢,٧ﺍﻟﺪﺍﻟﺔ ١٩٨........................................................................ isprint ٣,٥,٢,٨ﺍﻟﺪﺍﻟﺔ ١٩٩....................................................................... ispunct ٣,٥,٢,٩ﺍﻟﺪﺍﻟﺔ ١٩٩....................................................................... isspace ٣,٥,٢,١٠ﺍﻟﺪﺍﻟﺔ ٢٠٠..................................................................... isupper ٣,٥,٢,١١ﺍﻟﺪﺍﻟﺔ ٢٠٠..................................................................... isxdigit ٣,٥,٢,١٢ﺍﻟﺪﺍﻟﺘﲔ toupperﻭ ٢٠١......................................................... tolower ٣,٥,٣ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠١...................................................................... errno.h ٣,٥,٣,١ﺍﻟﺪﺍﻟﺔ ٢٠١........................................................................ perror ٣,٥,٤ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠٤....................................................................... float.h ٣,٥,٥ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠٤...................................................................... limits.h ٣,٥,٦ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠٥...................................................................... locale.h ٣,٥,٧ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠٥...................................................................... math.h ٣,٥,٧,١ﺍﻟﺪﺍﻟﺔ ٢٠٦........................................................................... sin ٣,٥,٧,٢ﺍﻟﺪﺍﻟﺔ ٢٠٦........................................................................... cos ٣,٥,٧,٣ﺍﻟﺪﺍﻟﺔ ٢٠٧........................................................................... tan ٣,٥,٧,٤ﺍﻟﺪﺍﻟﺔ ٢٠٧........................................................................... exp ٣,٥,٧,٥ﺍﻟﺪﺍﻟﺔ ٢٠٧........................................................................... log ٣,٥,٧,٥ﺍﻟﺪﺍﻟﺔ ٢٠٨.......................................................................... pow ٣,٥,٧,٦ﺍﻟﺪﺍﻟﺔ ٢٠٨.......................................................................... sqrt ٣,٥,٧,٧ﺍﻟﺪﺍﻟﺔ ٢٠٨........................................................................... ceil ٣,٥,٧,٨ﺍﻟﺪﺍﻟﺔ ٢٠٩.......................................................................... floor ٣,٥,٧,٩ﺍﻟﺪﺍﻟﺔ ٢٠٩.......................................................................... fabs ٣,٥,٧,١٠ﺍﻟﺪﺍﻟﺔ ٢٠٩....................................................................... ldexp ٣,٥,٧,١١ﺍﻟﺪﺍﻟﺔ ٢٠٩....................................................................... fmod ٣,٥,٨ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢١٠..................................................................... setjmp.h ٣,٥,٩ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢١١...................................................................... signal.h ٣,٥,٩,١ﺍﻟﺪﺍﻟﺔ ٢١١......................................................................... raise ٣,٥,١٠ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢١١.................................................................... stdarg.h ٣,٥,١١ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢١٢.................................................................... stddef.h ٣,٥,١٢ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢١٣..................................................................... stdio.h ٣,٥,١٢,١ﺍﻟﺪﺍﻟﺔ ٢١٣....................................................................... printf ٣,٥,١٢,٢ﺍﻟﺪﺍﻟﺔ ٢١٤...................................................................... sprintf ٣,٥,١٢,٣ﺍﻟﺪﺍﻟﺔ ٢١٤...................................................................... vprintf ٣,٥,١٢,٤ﺍﻟﺪﺍﻟﺔ ٢١٥..................................................................... vfprintf ٣,٥,١٢,٥ﺍﻟﺪﺍﻟﺔ ٢١٥..................................................................... vsprintf ٣,٥,١٢,٦ﺍﻟﺪﺍﻟﺔ ٢١٦....................................................................... scanf ٣,٥,١٢,٧ﺍﻟﺪﺍﻟﺔ ٢١٦...................................................................... fscanf ٣,٥,١٢,٨ﺍﻟﺪﺍﻟﺔ ٢١٦...................................................................... sscanf ٣,٥,١٢,٩ﺍﻟﺪﺍﻟﺔ ٢١٧....................................................................... fgetc ٣,٥,١٢,١٠ﺍﻟﺪﺍﻟﺔ ٢١٧....................................................................... fgets ٣,٥,١٢,١١ﺍﻟﺪﺍﻟﺔ ٢١٨...................................................................... fputc ٣,٥,١٢,١٢ﺍﻟﺪﺍﻟﺔ ٢١٨...................................................................... fputs ٣,٥,١٢,١٣ﺍﻟﺪﺍﻟﺔ ٢١٨....................................................................... getc ٣,٥,١٢,١٤ﺍﻟﺪﺍﻟﺔ ٢١٩................................................................... getchar ٣,٥,١٢,١٥ﺍﻟﺪﺍﻟﺔ ٢١٩...................................................................... gets ٣,٥,١٢,١٦ﺍﻟﺪﺍﻟﺔ ٢١٩...................................................................... putc ٣,٥,١٢,١٧ﺍﻟﺪﺍﻟﺔ ٢٢٠................................................................... putchar ٣,٥,١٢,١٨ﺍﻟﺪﺍﻟﺔ ٢٢٠...................................................................... puts ٣,٥,١٢,١٩ﺍﻟﺪﺍﻟﺔ ٢٢٠.................................................................... ungetc ٣,٥,١٢,٢٠ﺍﻟﺪﺍﻟﺔ ٢٢٠..................................................................... fopen ٣,٥,١٢,٢١ﺍﻟﺪﺍﻟﺔ ٢٢١................................................................... freopen ٣,٥,١٢,٢٢ﺍﻟﺪﺍﻟﺔ ٢٢٢..................................................................... fclose ٣,٥,١٢,٢٣ﺍﻟﺪﺍﻟﺔ ٢٢٢................................................................... remove ٣,٥,١٢,٢٤ﺍﻟﺪﺍﻟﺔ ٢٢٢................................................................... rename ٣,٥,١٢,٢٥ﺍﻟﺪﺍﻟﺔ ٢٢٣.................................................................... tmpfile ٣,٥,١٢,٢٦ﺍﻟﺪﺍﻟﺔ ٢٢٣...................................................................... fread ٣,٥,١٢,٢٧ﺍﻟﺪﺍﻟﺔ ٢٢٣..................................................................... fwrite ٣,٥,١٢,٢٨ﺍﻟﺪﺍﻟﺔ ٢٢٤...................................................................... fseek ٣,٥,١٢,٢٩ﺍﻟﺪﺍﻟﺔ ٢٢٥....................................................................... ftell ٣,٥,١٢,٣٠ﺍﻟﺪﺍﻟﺔ ٢٢٥.................................................................... rewind ٣,٥,١٢,٣١ﺍﻟﺪﺍﻟﺔ ٢٢٦....................................................................... feof ٣,٥,١٣ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٢٦..................................................................... stdlib.h ٣,٥,١٣,١ﺍﻟﺪﺍﻟﺔ ٢٢٦......................................................................... atof ٣,٥,١٣,٢ﺍﻟﺪﺍﻟﺔ ٢٢٧......................................................................... atoi ٣,٥,١٣,٣ﺍﻟﺪﺍﻟﺔ ٢٢٧......................................................................... atol ٣,٥,١٣,٤ﺍﻟﺪﺍﻟﺔ ٢٢٧........................................................................ rand ٣,٥,١٣,٥ﺍﻟﺪﺍﻟﺔ ٢٢٨....................................................................... srand ٣,٥,١٣,٦ﺍﻟﺪﺍﻟﺔ ٢٢٨....................................................................... abort ٣,٥,١٣,٧ﺍﻟﺪﺍﻟﺔ ٢٢٩......................................................................... exit ٣,٥,١٣,٨ﺍﻟﺪﺍﻟﺔ ٢٢٩....................................................................... atexit ٣,٥,١٣,٩ﺍﻟﺪﺍﻟﺔ ٢٢٩..................................................................... system ٣,٥,١٣,١٠ﺍﻟﺪﺍﻟﺔ ٢٣٠....................................................................... abs ٣,٥,١٣,١١ﺍﻟﺪﺍﻟﺔ ٢٣٠....................................................................... labs ٣,٥,١٣,١٢ﺍﻟﺪﺍﻟﺔ ٢٣٠........................................................................ div ٣,٥,١٣,١٣ﺍﻟﺪﺍﻟﺔ ٢٣١....................................................................... ldiv ٣,٥,١٤ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٣١.................................................................... string.h ٣,٥,١٤,١ﺍﻟﺪﺍﻟﺔ strcpyﻭ ﺍﻟﺪﺍﻟﺔ ٢٣١....................................................... strncpy ٣,٥,١٤,٢ﺍﻟﺪﺍﻟﺔ strcatﻭ ﺍﻟﺪﺍﻟﺔ ٢٣٢........................................................ strncat ٣,٥,١٤,٣ﺍﻟﺪﺍﻟﺔ strcmpﻭ ﺍﻟﺪﺍﻟﺔ ٢٣٣...................................................... strncmp ٣,٥,١٤,٤ﺍﻟﺪﺍﻟﺔ strchrﻭ ﺍﻟﺪﺍﻟﺔ ٢٣٣........................................................ strrchr ٣,٥,١٤,٥ﺍﻟﺪﺍﻟﺔ strspnﻭ ﺍﻟﺪﺍﻟﺔ ٢٣٤....................................................... strcspn ٣,٥,١٤,٦ﺍﻟﺪﺍﻟﺔ ٢٣٤..................................................................... strpbrk ٣,٥,١٤,٧ﺍﻟﺪﺍﻟﺔ ٢٣٥....................................................................... strstr ٣,٥,١٤,٨ﺍﻟﺪﺍﻟﺔ ٢٣٥....................................................................... strlen ٣,٥,١٤,٩ﺍﻟﺪﺍﻟﺔ ٢٣٥...................................................................... strerror ٣,٥,١٤,١٠ﺍﻟﺪﺍﻟﺔ ٢٣٦..................................................................... strtok ٣,٥,١٥ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٣٦..................................................................... time.h ٣,٥,١٥,١ﺍﻟﺪﺍﻟﺔ ٢٣٧........................................................................ clock ٣,٥,١٥,٢ﺍﻟﺪﺍﻟﺔ ٢٣٨......................................................................... time ٣,٥,١٥,٣ﺍﻟﺪﺍﻟﺔ ٢٣٩...................................................................... difftime ٣,٥,١٥,٤ﺍﻟﺪﺍﻟﺔ ٢٣٩.................................................................... localtime ٣,٥,١٥,٥ﺍﻟﺪﺍﻟﺔ ٢٤٠..................................................................... asctime ٣,٥,١٥,٦ﺍﻟﺪﺍﻟﺔ ٢٤٠........................................................................ ctime ﺍﳋﺎﲤﺔ ٢٤١.................................................................................................. ﺟﺪﻭﻝ ﺍﻷﺷﻜﺎﻝ )ﺍﻟﺼﻮﺭ( ..................................................................................... ﺟﺪﻭﻝ ﺍﳉﺪﺍﻭﻝ .............................................................................................. ﺟﺪﻭﻝ ﺍﻟﱪﺍﻣﺞ ............................................................................................... ﺃﻫﻢ ﺍﳌﺮﺍﺟﻊ .................................................................................................. 18 ﺍﳊﻤﺪ ﺍﷲ ﺭﺏ ﺍﻟﻌﺎﳌﲔ ﻭ ﺍﻟﺼﻼﺓ ﻭ ﺍﻟﺴﻼﻡ ﻋﻠﻰ ﺳﻴﺪ ﺍﳌﺮﺳﻠﲔ ﻧﺒﻴﻨﺎ ﳏﻤﺪ ﺻﻠﻰ ﺍﷲ ﻋﻠﻴﻪ ﻭ ﻋﻠـﻰ ﺁﻟـﻪ ﻭ ﺻـﺤﺒﻪ ﺃﲨﻌﲔ...ﺃﻣﺎ ﺑﻌﺪ ،ﺇﻗﺘﺮﺑﺖ ﺍﳌﺪﺓ ﻋﺎﻡ ﻣﻦ ﺇﻧﺸﺎﺀ ﺍﻟﻨﺴﺨﺔ ﺍﻷﻭﱃ ﻣﻦ ﻛﺘﺎﺏ ﻟﻐﺔ Cﺍﻟﺸﺎﻣﻞ ،ﻭ ﺍﻟﻴﻮﻡ ﻗﻤﺖ ﺑﺈﻧﺸﺎﺀ ﺍﻟﻠﻨـﺴﺨﺔ ﺍﻟﺜﺎﻧﻴﺔ ﻣﻨﻪ ،ﻭ ﻟﻜﻦ ﻫﺬﻩ ﺍﻟﻨﺴﺨﺔ ﱂ ﺃﺭﻛﺰ ﻋﻠﻰ ﺍﻟﺘﻮﺳﻴﻊ ﻓﻴﻬﺎ ﻋﻠﻰ ﺍﺳﺎﺑﻘﺔ ،ﺇﳕﺎ ﺭﻛﺰﺕ ﻋﻠﻰ ﺗﺼﺤﻴﺢ ﺃﺧﻄﺎﺀﻫﺎ ،ﺻـﺤﺤﺖ ﺍﻟﺬﻱ ﺍﺳﺘﻄﻌﺖ ﻣﻼﺣﻈﺘﻪ ،ﻭ ﻻﹶﺯِﻟﹾﺖ ﺃﻧﺘﻈﺮ ﻣﻼﺣﻈﺔ ﺃﺧﻄﺎﺀ ﺃﺧﺮﻯ ﻣﻦ ﻗﹸﺮﺍﺀ ﻫﺬﻩ ﺍﻟﻜﺘﺎﺏ ،ﻟﺬﺍ ﺃﺭﺟﻮ ﻟﻜﻞ ﻣﻦ ﻗﺮﺃ ﺍﻟﻜﺘﺎﺏ ﻭ ﻭﺟﺪ ﺑﻪ ﺃﺧﻄﺎﺀ ﺳﻮﺍﺀ ﻛﺎﻧﺖ ﺃﺧﻄﺎﺀ ﺇﻣﻼﺋﻴﺔ ﺃﻭ ﻣﻌﻨﻮﻳﺔ )ﻭ ﺧﺎﺻﺔ ﺍﳌﻌﻨﻮﻳﺔ( ﺃﻥ ﻳﻘﻮﻡ ﺑﺘﻨﺒﻴﻬﻲ ﻋﻠـﻰ ﺑﺮﻳـﺪﻱ ﺍﻹﻟﻴﻜﺘـﺮﻭﱐ ،khalil_ounis@yahoo.comﺃﻭ ﳝﻜﻦ ﺃﻥ ﻳﻮﺿﻊ ﺍﳋﻄﺄ ﰲ ﻣﻮﺿﻮﻉ ﻫﺬﺍ ﺍﻟﻜﺘﺎﺏ .ﺣﻴﺚ ﺳﻴﺘﻢ ﺇﻧﺸﺎﺀ ﻗﺎﺋﻤﺔ ﻷﲰﺎﺀ ﻣﻼﺣﻈﻲ ﺃﺧﻄﺎﺀ ﻫﺬﺍ ﺍﻟﻜﺘﺎﺏ ﻭ ﻭﺿﻌﻬﺎ ﰲ ﺍﻟﺼﻔﺤﺎﺕ ﺍﻷﻭﱃ ﻣﻦ ﺍﻟﻜﺘﺎﺏ )ﻳﻌﲏ ﻋﻤﻞ ﲨﺎﻋﻲ(. ﻭ ﻣﻦ ﺃﺧﻄﺎﺀ ﺍﻟﻨﺴﺨﺔ ﺍﻷﻭﱃ)ﻫﺬﺍ ﻟﻜﻲ ﺃﺑﲔ ﻟﻘﺮﺍﺀ ﺍﻟﻨﺴﺨﺔ ﺍﻷﻭﱃ ﻣﻦ ﻫﺬﺍ ﺍﻟﻜﺘﺎﺏ ﺃﻱ ﳝﻜﻨﻬﻢ ﺇﻋﺎﺩﺓ ﺍﻟﻘﺮﺍﺀﺓ( ﻣـﻦ ﻫـﺬﺍ ﺍﻟﻜﺘﺎﺏ ﻛﺎﻧﺖ ﰲ ﻛﻞ ﻣﻦ :ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ ،ﺑﻌﺾ ﺍﻷﺧﻄﺎﺀ ﰲ ﺍﳉﺰﺀ "ﺍﻟﺒﺪﺀ ﻣﻊ ﻟﻐﺔ ،"Cﻭ ﺑﻌﺾ ﺍﻷﻣﺎﻛﻦ ﺍﻟﱵ ﲡﺎﻫﻠﺘـﻬﺎ ﰲ ﻗﺴﻢ "ﺍﳌﺆﺛﺮﺍﺕ "Operatorsﻭ ﻗﺴﻢ "ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ" ،ﺃﻣﺎ ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﱐ ﻓﺘﻮﺟﺪ ﺃﺧﻄﺎﺀ ﰲ ﺟﺰﺀ "ﺍﳌﺆﺷﺮﺍﺕ" ،ﻭ ﺃﺧﲑﺍ ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﻟﺚ ﰲ ﻛﻞ ﻣﻦ " "Command-line Argumentsﻭ "ﺍﳌﻜﺘﺒﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ" .ﻭ ﻃﺒﻌﺎ ﺗﻮﺟﺪ ﺃﺧﻄﺎﺀ ﺃﺧﺮﻯ ﻣﺘﻔﺮﻗـﺔ ﰲ ﺍﻟﻜﺘﺎﺏ ﱂ ﺃﺫﻛﺮﻫﺎ .ﻭ ﺃﻛﻴﺪ ﻫﻨﺎﻙ ﺇﺿﺎﻓﺎﺕ ﰲ ﺍﻟﻜﺘﺎﺏ)ﻻﻛﻦ ﻻ ﺗﺘﻮﻗﻊ ﺍﻟﻜﺜﲑ(. ﻓﺼﻮﻝ ﻫﺬﻩ ﺍﻟﻨﺴﺨﺔ ﻣﺜﻞ ﺍﻟﻨﺴﺨﺔ ﺍﻟﺴﺎﺑﻘﺔ: § ﰲ ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ ﻣﻔﺎﻫﻴﻢ ﻭ ﻣﺒﺎﺩﺉ ﺃﺳﺎﺳﻴﺔ ﰲ ﻟﻐﺔ :Cﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ ،ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﻭ ﺍﳌﺆﺛﺮﺍﺕ ،ﺍﻟﻘـﺮﺍﺭﺍﺕ ﻭ ﻋﻨﺎﺻﺮ ﻟﻐﺔ ،Cﻣﻊ ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻷﻭﻝ. § ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﱐ ﻣﻜﻤﻞ ﻟﻠﻔﺼﻞ ﺍﻷﻭﻝ ﰲ ﻛﻞ ﻣﻦ ﺍﻟﻘﺮﺍﺭ ،Switchﺣﻠﻘﺎﺕ ﺍﻟﺘﻜـﺮﺍﺭ ،ﺍﳌـﺼﻔﻮﻓﺎﺕ ﻭ ﺍﳌﺆﺷـﺮﺍﺕ، ﺍﻟﺪﻭﺍﻝ ،ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ،ﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ ﰲ ﺍﳌﻠﻔﺎﺕ ﻭ ﺍﻟﺘﺮﺍﻛﻴﺐ ،ﻭ ﺃﺧﲑﺍ ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻟﺜﺎﱐ. § ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﻟﺚ ﻣﻜﻤﻞ ﻟﻠﻜﺘﺎﺏ ،ﻣﻊ ﺇﺿﺎﻓﺔ ﺃﻫﻢ ﺛﻮﺍﺑﺖ ،ﳐﺘﺼﺮﺍﺕ ﻭ ﺩﻭﺍﻝ ﺍﳌﻜﺘﺒﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ﻟﻠﻐﺔ .C ﻭ ﺍﻟﻜﺘﺎﺏ ﻣﻔﺘﻮﺡ ﻟﻜﻞ ﻣﻦ ﻳﺮﻳﺪ ﺇﺿﺎﻓﺔ ﺣﺮﻑ ،ﻛﻠﻤﺔ ،ﲨﻠﺔ ﺃﻭ ﺟﻤﻞ ،ﺃﺟﺰﺍﺀ ﺃﻭ ﺃﻱ ﺷﻲﺀ ﻣﻔﻴـﺪ)ﺷـﺎﺭﻛﻨﺎ ﺍﳋـﲑ( .ﺃﻱ ﺗﻌﻠﻴﻘﺎﺕ ﺃﻭ ﻣﻼﺣﻈﺎﺕ ﺃﻫﻼ ﻭ ﺳﻬﻼ. ﺧﻠﻴﻞ ﺃﻭﻧﻴﺲ ،ﺍﳉﺰﺍﺋﺮ ) ٠٦٤٥٧٦٦١٨ﻣﻦ ﺍﻟﺪﺍﺧﻞ(+٢١٣٦٤٥٧٦٦١٨ ، ﺗﺎﺭﻳﺦ ﺍﻹﻧﺘﻬﺎﺀ ﻣﻦ ﺍﻟﻨﺴﺨﺔ٢٠٠٦-٠٨-١٩ : 19 ﰲ ﺃﻳﺎﻡ ﺑﺪﺍﻳﺔ ﺍﳊﺎﺳﻮﺏ ﻛﺎﻧﺖ ﺍﻟﱪﳎﺔ ﺗﺘﻢ ﻋﻠﻰ ﻟﻐﺔ ﺑﺪﺍﺋﻴﺔ ﻣﻨﺨﻔﻀﺔ ﺍﳌﺴﺘﻮﻯ low-level languageﺗﺪﻋﻰ ﺑﻠﻐﺔ ﺍﻵﻟﺔ ،Machine languageﺣﻴﺚ ﻛﺎﻧﺖ ﺗﻔﻬﻤﻬﺎ ﺍﻵﻟﺔ ﻣﺒﺎﺷﺮﺓ ،ﻭ ﻳﺘﻢ ﺍﻟﱪﳎﺔ ﻋﻠﻴﻬﺎ ﺑﺄﻭﺍﻣﺮ ﺗﻤﺜﻞ ﲞﻴﻮﻁ ﻃﻮﻳﻠﺔ ﻣﻜﻮﻧﺔ ﻣﻦ ﺍﻟﻮﺍﺣﺪ ﻭ ﺍﻟﺼﻔﺮ )ﺍﻟﺼﻔﺮ ﺗﻌﲏ lowﻭ ﻫﻲ ﳏﺼﻮﺭﺓ ﺑﲔ -٠,٥ﻭ +٠,٥ﻓﻮﻟﺖ ،ﻭ ﺍﻟﻮﺍﺣﺪ ﻳﻌﲏ highﻭ ﻫﻮ ﳏﺼﻮﺭ ﺑـﲔ +٤,٥ﻭ +٥,٥ﻓﻮﻟﺖ( ﺃﻱ ﲟﺎ ﻳﺴﻤﻰ ﺑﺎﻟﻨﻈﺎﻡ ﺍﻟﺜﻨﺎﺋﻲ ،ﻭ ﻛﺎﻧﺖ ﺍﻟﱪﳎﺔ ﻋﻠﻴﻬﺎ ﺻﻌﺒﺔ ﻭ ﻣﻌﻘﺪﺓ ﺣﱴ ﰎ ﺗﻄﻮﻳﺮ ﻟﻐﺔ ﺍﻟﺘﺠﻤﻴﻊ assembly ،languageﻭ ﻫﻲ ﻣﻦ ﺍﻟﻠﻐﺎﺕ ﺍﳌﻨﺨﻔﻀﺔ ﺍﳌﺴﺘﻮﻯ low-level languagesﺃﻳﻀﺎ ،ﺣﻴﺚ ﻛﺎﻧﺖ ﺳﻬﻠﺔ ﺑﺎﻟﻨﺴﺒﺔ ﻟـﻠﻐﺔ ﺍﻵﻟـﺔ، ﻓﺒﺪﻝ ﺍﺳﺘﻌﻤﺎﻝ ﺳﻼﺳﻞ ﻣﻦ ﺍﻟﺼﻔﺮ ﻭ ﺍﻟﻮﺍﺣﺪ ﻧﺴﺘﻌﻤﻞ ﺃﻭﺍﻣﺮ ﺫﺍﺕ ﻛﻠﻤﺎﺕ ﻣﻔﻬﻮﻣﺔ ﻣﺜﻞ ADDﻭ .MOV ﻣﻊ ﻣﺮﻭﺭ ﺍﻟﻮﻗﺖ ﰎ ﺗﻄﻮﻳﺮ ﻟﻐﺎﺕ ﺑﺮﳎﺔ ﺃﺧﺮﻯ ﻣﺜﻞ BASIC ،COBOLﻭ ،Cﻭ ﻛﺎﻥ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﺑﺎﻟﻜﻠﻤﺎﺕ ﻭ ﺍﻟﻨﺼﻮﺹ ﳑﺎ ﺟﻌﻞ ﻫﺬﻩ ﺍﻟﻠﻐﺎﺕ ﻣﻘﺮﻭﺋﺔ .ﻭ ﻫﺬﻩ ﻣﻌﻠﻮﻣﺎﺕ ﳐﺘﺼﺮﺓ ﻋﻦ ﺑﻌﺾ ﺍﻟﻠﻐﺎﺕ: ﻟﻐﺔ ﺍﳉﻤﻴﻊ ،Assembly Languageﰎ ﺗﻄﻮﻳﺮﻫﺎ ﰲ ﻋﺎﻡ ١٩٥٦ﻣﻦ ﻗﺒﻞ ﺷﺮﻛﺔ .IBMﻟﻐﺔ ﻓﻮﺭﺗﺮﺍﻥ ،Fortran Language ﻭ ﻛﻠﻤﺔ Fortranﳐﺘﺼﺮﺓ ﻣﻦ Formula Translationﺃﻱ ﺻﻴﻐﺔ ﺍﻟﺘﺮﲨﺔ ،ﰎ ﺗﻄﻮﻳﺮﻫﺎ ﰲ ﻋﺎﻡ ١٩٥٤ﻣﻦ ﻗﺒﻞ ﻓﺮﻳﻖ ﻳﺘﺮﺃﺳـﻪ ﺟﻮﻥ ﺑﺎﻛﻮﺱ ،John Backusﺣﻴﺚ ﻛﺎﻧﺖ ﺗﺴﺘﺨﺪﻡ ﺑﻜﺜﺮﺓ ﰲ ﺍﻟﺘﻄﺒﻴﻘﺎﺕ ﺍﻟﺮﻳﺎﺿﻴﺔ .ﻟﻐـﺔ ﻛﻮﺑـﻮﻝ ،COBOL Language ﺇﺧﺘﺼﺎﺭ ﻟـ ،Common Business Oriented Languageﺃﻱ ﻟﻐﺔ ﻣﻮﺟﻬﺔ ﻟﻸﻋﻤﺎﻝ ﺍﻟﺘﺠﺎﺭﻳﺔ ،ﰎ ﺗﻄﻮﻳﺮﻫﺎ ﰲ ﻋـﺎﻡ ١٩٥٩ ﻣﻦ ﻗﺒﻞ ﳉﻨﺔ ﻗﺼﲑﺓ ﻣﻜﻮﻧﺔ ﻣﻦ ﺛﻼﺛﺔ ﺷﺮﻛﺎﺕ ﻣﻨﻬﺎ .IBMﻟﻐﺔ ﺍﻟﺒﺎﺯﻳﻚ ،Basic Languageﺇﺧﺘﺼﺎﺭ ﻟــ Beginner's All- ،Purpose Symbolic Instruction Codeﺃﻱ ﺷﻔﺮﺓ ﺭﻣﻮﺯ ﻟﺘﻌﻠﻴﻤﺎﺕ ﲨﻴﻊ ﺍﻷﻏﺮﺍﺽ ﻟﻠﻤﺒﺘـﺪﺃﻳﻦ ،ﻭ ﰎ ﺗﻄﻮﻳﺮﻫـﺎ ﰲ ﻋـﺎﻡ ١٩٦٣ﻣﻦ ﻗﺒﻞ ﺍﻷﺳﺘﺎﺫ ﺟﻮﻥ ﻛﻴﻤﲏ John Kemenyﻭ ﺍﻷﺳﺘﺎﺫ ﺗﻮﻣﺎﺱ ﻛﻮﺭﺯ ،Thomas Kurtzﻭ ﺃﺧﺬﺕ ﺷﻬﺮﺓ ﻛـﺒﲑﺓ )ﺇﱃ ﺣﺪ ﺍﻵﻥ( .ﻟﻐﺔ ﺁﻟﭭﻮﻝ ،Algol Languageﺇﺧﺘﺼﺎﺭ ﻟـ ،Algorithmic Languageﰎ ﺗﻄﻮﻳﺮﻫﺎ ﰲ ﻋﺎﻡ ١٩٥٨ﻣﻦ ﻗﺒﻞ ﳎﻤﻮﻋﺔ ﻣﻦ ﻋﻠﻤﺎﺀ ﺣﻮﺍﺳﻴﺐ ﺃﻭﺭﻭﺑﻴﲔ ﻭ ﺃﻣﺮﻳﻜﻴﲔ .ﻟﻐﺔ ﺑﺎﺳﻜﺎﻝ ،Pascal Languageﻭ ﺍﺳﻢ ﻫﺬﻩ ﺍﻟﻠﻐﺔ ﻣﺄﺧﻮﺫ ﻣﻦ ﺍﺳـﻢ ﺍﻟﻌﺎﱂ ﺍﻟﻔﺮﻧﺴﻲ ،Blaise Pascalﻭ ﰎ ﺗﻄﻮﻳﺮﻫﺎ ﻋﺎﻡ ١٩٧٠ﻣﻦ ﻗﺒﻞ ﻧﻴﻜﻠﻮﺱ ﻭﻳﺮﺙ .Niklaus Wirthﻭ ﺗﺬﻛﺮ ﺃﻧﺎ ﻛﻞ ﻣـﻦ ﺍﻟﻠﻐﺎﺕ ﺍﻟﺴﺎﺑﻘﺔ ﻫﻲ ﺃﻗﺪﻡ ﻟﻐﺎﺕ ﺑﺮﳎﺔ. ﻟﻐﺔ Cﻣﻦ ﻟﻐﺎﺕ ﺍﻷﻏﺮﺍﺽ ﺍﻟﻌﺎﻣﺔ ،ﻭ ﺗﺴﺘﻌﻤﻞ ﺑﻜﺜﺮﺓ ﰲ ﺑﺮﳎﺔ ﺍﻟﻨﻈﻢ Systems Programmingﻭ ﺃﻧﻈﻤﺔ ﺍﻟﺘﺸﻐﻴﻞ ،Systemsﰎ ﺗﻄﻮﻳﺮﻫﺎ ﰲ ﺍﻟﺴﺒﻌﻴﻨﺎﺕ ﻣﻦ ﻃﺮﻑ ﻛﲔ ﺗﻮﻣـﺴﻦ Ken Thompsonﻭ ﺩﻧـﻴﺲ ﺭﻳﺘـﺸﻲ Dennis Ritchieﰲ ﳐﺘﱪﺍﺕ .Bellﻟﻐﺔ Cﻣﻦ ﺍﻟﻠﻐﺎﺕ ﺍﳌﻨﺨﻔﻀﺔ ﺍﳌﺴﺘﻮﻯ low-level languagesﺣﻴﺚ ﺃﺎ ﻗﺮﻳﺒﺔ ﻣﻦ ﺍﻷﺟﻬﺰﺓ ﻭ ﺷـﺒﻴﻬﺎ ﺑﻠﻐـﺔ ﺍﻟﺘﺠﻤﻴﻊ assembly languageﰲ ﻋﻤﻠﻬﺎ ،ﻭ ﻟﻜﻦ ﺍﻟﺒﻌﺾ ﻳﻌﺘﱪﻫﺎ ﻟﻐﺔ ﻣﺘﻮﺳﻄﺔ ﺍﳌﺴﺘﻮﻯ mid-level languageﻷـﺎ ﻟﻐـﺔ ﲢﺎﻛﻲ ﻟﻐﺔ ﺍﻹﻧﺴﺎﻥ ﺑﻌﺾ ﺍﻟﺸﻲﺀ ،ﻭ ﻫﻲ ﻟﻐﺔ ﻣﺴﺘﻘﻠﺔ ﻋﻦ ﺍﻟﺒﻨﻴﺔ ﺍﻟﺼﻠﺒﺔ ﻟﻠﺤﺎﺳﻮﺏ. Operating 20 ﻗﺎﻡ ﻛﲔ ﺗﻮﻣﺴﻦ ﻭ ﺩﻧﻴﺲ ﺭﻳﺘﺸﻲ ﺑﺘﻄﻮﻳﺮ ﻟﻐﺔ Cﻟﱪﳎﺔ ﻧﻈﺎﻡ ﻳﻮﻧﻴﻜﺲ ،Unixﺣﻴﺚ ﺭﻛﺰﺍ ﻣﻄﻮﺭﻱ ﻫﺬﻩ ﺍﻟﻠﻐـﺔ ﻋﻠـﻰ ﺃﻥ ﺗﻜﻮﻥ ﻟﻐﺘﻬﻢ ﺳﻬﻠﺔ ﺍﻻﺳﺘﻌﻤﺎﻝ ﺣﻴﺚ ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺑﺮﺍﻣﺞ ﻛﺒﲑﺓ ﻣﻊ ﻗﻠﺔ ﺍﻷﺧﻄﺎﺀ ﻭ ﰲ ﻭﻗﺖ ﺃﻗـﺼﺮ .ﰲ ﻋـﺎﻡ ١٩٧٣ﰎ ﺇﻃﻼﻕ ﻟﻐﺔ Cﺑﺸﻜﻞ ﺭﲰﻲ ،ﻭ ﲰﻴﺖ ﺑﻠﻐﺔ Cﻷﺎ ﻛﺎﻧﺖ ﻣﺸﺘﻘﺔ ﻣﻦ ﻟﻐﺔ ﺍﻟـ ) Bﻭ ﻛﺎﻧﺖ ﻟﻐﺔ ﺍﻟـ Bﻧﻔﺴﻬﺎ ﻣﺸﺘﻘﺔ ﻣﻦ ﻟﻐﺔ BCPLﺍﻟﱵ ﻗﺎﻡ ﺑﺘﻄﻮﻳﺮﻫﺎ ﻣﺎﺭﺗﻦ ﺭﻳﺘﺸﺎﺭﺩﺯ Martin Richardsﰲ ﻋﺎﻡ ،١٩٦٧ﻭ ﻫـﻲ ﳐﺘـﺼﺮﺓ ﻣـﻦ Basic Combined ،Programming Languageﺣﻴﺚ ﻛﺎﻥ ﺍﻟﻔﺮﻕ ﺑﲔ ﺍﻟﻠﻐﺘﲔ ﻫﻮ ﻧﻮﻉ ﺍﻟﺒﻴﺎﻧﺎﺕ( ﺍﻟﱵ ﻗﺎﻡ ﺑﺘﻄﻮﻳﺮﻫﺎ ﻛﲔ ﺗﻮﻣـﺴﻦ ﰲ ﻋـﺎﻡ ١٩٦٩ﺣﻴﺚ ﺃﺧﺬ ﺍﳊﺮﻑ Bﻣﻦ ﺍﺳﻢ ﺍﳌﺨﺘﱪ Bellﺍﻟﺬﻱ ﻳﻌﻤﻞ ﺑﻪ ،ﻭ ﺍﻟﺬﻱ ﻳﻠﻲ ﺍﳊﺮﻑ Bﰲ ﺍﻷﲜﺪﻳﺔ ﻫﻮ ،Cﻭ ﺫﻟﻚ ﻫﻮ ﺳﺒﺐ ﺗﺴﻤﻴﺘﻬﺎ ﺑﻠﻐﺔ .Cﰲ ﻋﺎﻡ ١٩٧٨ﻗﺎﻡ ﺩﻧﻴﺲ ﺭﻳﺘﺸﻲ ﻭ ﺑﺮﺍﻳﻦ ﻛﺎﺭﻧﻴﻐﺎﻥ Brian Kernighanﺑـﺘﺄﻟﻴﻒ ﺃﻭﻝ ﻛﺘﺎﺏ ﳍﺬﻩ ﺍﻟﻠﻐﺔ ﻭ ﲰﻲ ﺑـ The C Programming Languageﻭ ﺍﻟﺬﻱ ﻳﻌﺘﱪ ﺍﳌﺮﺟﻊ ﺍﻷﺳﺎﺳﻲ ﳍﺬﻩ ﺍﻟﻠﻐﺔ ،ﻭ ﻛﺎﻥ ﺍﻟﻜﺘﺎﺏ ﻣﻌـﺮﻭﻑ ﺑﻨﺴﺨﺔ (Kernighan & Ritchie C) K&R Cﻭ ﺍﻟﺴﺒﺐ ﰲ ﺗﺴﻤﻴﺘﻪ ﺑـ K&R Cﻫﻮ ﻛﺜﺮﺓ ﺍﺳﺘﻌﻤﺎﻝ ﻟﻐﺔ Cﺑﺸﻜﻞ ﻛﺒﲑ ﻭ ﺍﻟﺬﻱ ﺃﺩﻯ ﺇﱃ ﺗﻄﻮﻳﺮ ﻣﻜﺘﺒﺎﺕ ﻭ ﺩﻭﺍﻝ ﰲ ﻧﺴﺦ ﳐﺘﻠﻔﺔ ﻣﻦ ﻟﻐﺔ Cﺣﱴ ﺃﺻﺒﺢ ﻛﻞ ﻣﻦ ﺗﻠﻚ ﺍﻟﻨﺴﺦ ﻏﲑ ﻣﺘﻮﺍﻓﻘﺔ ﻣـﻊ ﺑﻌـﻀﻬﺎ ﻭ ﻛﺎﺩﺕ ﺃﻥ ﺗﻜﻮﻥ ﻏﲑ ﻣﺘﺸﺎﺎ ،ﻭ ﻫﺬﺍ ﻣﺎ ﺃﺩﻯ ﺇﱃ ﺗﻌﺮﻳﻒ ﻧﺴﺨﺔ ﻗﻴﺎﺳﻴﺔ ﻟﻠﻐﺔ .Cﰲ ﻋﺎﻡ ١٩٨٩ﰎ ﺇﻃﻼﻕ ﺍﻟﻨﺴﺨﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ﻟﻠﻐﺔ Cﻭ ﲰﻴﺖ ﺑـ ANSI Cﻭ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣﻦ American National Standards Institute Cﺃﻱ ﺍﻟﻠﺠﻨﺔ ﺍﻟﻮﻃﻨﻴﺔ ﺍﻷﻣﲑﻛﻴﺔ ﻟﻠﻤﻌﺎﻳﺮ ،ﻭ ﺑﺘﻌﺎﻭﻥ ﺑﲔ ﺍﻟﻠﺠﻨﺔ ﺍﻟﻮﻃﻨﻴﺔ ﺍﻷﻣﲑﻛﻴﺔ ﻟﻠﻤﻌﺎﻳﺮ ﻭ ﺍﳌﻨﻈﻤﺔ ﺍﻟﻌﺎﳌﻴﺔ ﻟﻠﻤﻌﺎﻳﺮ ﰎ ﺇﻃﻼﻕ ﻟﻐﺔ Cﺍﻟﻘﻴﺎﺳﻴﺔ ﰲ ﳐﺘﻠﻒ ﺃﳓﺎﺀ ﺍﻟﻌﺎﱂ ﻭ ﲰﻴﺖ ﺑـ ISO Cﻭ ﻫﻲ ﺇﺧﺘﺼﺎﺭ ﻟــ .International Organization for Standardizationﻭ ﻛﺎﻧـﺖ ﺍﻟﻨـﺴﺨﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ﻟﻠﻐﺔ Cﳐﺘﻠﻔﺔ ﺑﻌﺾ ﺍﻟﺸﻲﺀ ﻋﻦ ﻧﺴﺨﺔ ) K&R Cﰲ ﻋﺎﻡ ١٩٨٨ﻗﺎﻡ ﺩﻧﻴﺲ ﺭﻳﺘﺸﻲ ﻭ ﺑـﺮﺍﻳﻦ ﻛﺎﺭﻧﻴﻐـﺎﻥ ﺑﻜﺘﺎﺑـﺔ ﺍﻟﻨﺴﺨﺔ ﺍﻟﺜﺎﻧﻴﺔ ﻣﻦ ﻛﺘﺎﺏ The C Programming Languageﻟﻨﺴﺨﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ﻟﻠﻐﺔ ،Cﺃﻱ .(ANSI C ﺩﻧﻴﺲ ﺭﻳﺘﺸﻲ ﻛﲔ ﺗﻮﻣﺴﻦ ١,١ﺍﻷﺩﻭﺍﺕ ﺍﻟﻼﺯﻣﺔ .................................................................................... ١,٢ﺍﻟﺒﺪﺀ ﻣﻊ ﻟﻐﺔ ...................................................................................... C ١,٣ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ .........................................................Variables and Constants ١,٤ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ............................................................................... Comments ١,٥ﺍﻹﺩﺧﺎﻝ ..................................................................................... Input ١,٦ﺍﳌﺆﺛﺮﺍﺕ ................................................................................. Operators ١,٧ﺍﻟﻘﺮﺍﺭﺍﺕ ........................................................................... if, else, else…if ١,٨ﻋﻨﺎﺻﺮ ﻟﻐﺔ ....................................................................................... C ١,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻷﻭﻝ،ﻣﻊ ﺇﺿﺎﻓﺎﺕ ................................................................... ﻣﻘﺪﻣﺔ :ﰲ ﻫﺬﺍ ﺍﻟﻔﺼﻞ ﺳﻨﺘﻌﻠﻢ ﺍﳌﺒﺎﺩﺉ ﺍﻷﻭﻟﻴﺔ ﻋﻠﻰ ﻛﻴﻔﻴﺔ ﺍﻟﱪﳎﺔ ﰲ ﻟﻐﺔ ،Cﻛﻴﻔﻴﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑـﺖ، ﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ ،ﻣﻊ ﺍﳉﻤﻞ ﺍﻟﺸﺮﻃﻴﺔ. ﺑﺎﻟﺘﻮﻓﻴﻖ ﺇﻥ ﺷﺎﺀ ﺍﷲ ﻗﺎﻝ ﺍﷲ ﺗﻌﺎﱃ: ﴿ ﻳﺮﻓﻊ ﺍﷲ ﺍﻟﺬﻳﻦ ﺁﻣﻨﻮﺍ ﻣﻨﻜﻢ ﻭﺍﻟﺬﻳﻦ ﺃﻭﺗﻮﺍ ﺍﻟﻌﻠﻢ ﺩﺭﺟﺎﺕ ﴾ ﺻﺪﻕ ﺍﷲ ﺗﻌﺎﱃ 22 ﺃﺩﻭﺍﺕ ﻟﻐﺔ Cﻫﻲ ﺛﻼﺛﺔ ﺃﺷﻴﺎﺀ ﻻ ﺃﻛﺜﺮ ،ﳏﺮﺭ ﻧﺼﻮﺹ ،texts editorﻣﺘـﺮﺟﻢ compilerﻭ ﻣـﺮﺑﻂ .linkerﻭ ﺃﻱ ﺑﺮﻧﺎﻣﺞ ﺗﺘﻢ ﻛﺘﺎﺑﺘﻪ ﳚﺐ ﺃﻥ ﳝﺮ ﻋﻠﻰ ﻫﺬﻩ ﺍﻷﺩﻭﺍﺕ ،ﻭ ﰲ ﺎﻳﺔ ﻳﻨﺘﺞ ﺍﳌﻠﻒ ﺍﻟﺘﻨﻔﻴﺬﻱ .ﻭ ﻻ ﳝﻜﻦ ﺍﻻﺳﺘﻐﻨﺎﺀ ﻋﻦ ﺃﺩﺍﺓ ﻣﻦ ﻫﺬﻩ ﺍﻷﺩﻭﺍﺕ .ﰲ ﺍﳌﺘﺮﲨﺎﺕ ﺍﳊﺪﻳﺜﺔ ﺃﺻﺒﺢ ﻛﻞ ﻣﻦ ﺍﻷﺩﻭﺍﺕ ﻣﺪﳎﺔ ﻣﻊ ﺑﻌﻀﻬﺎ ﳑﺎ ﺟﻌﻠﻬﺎ ﺃﻛﺜﺮ ﺳﻬﻮﻝ ﰲ ﺍﻻﺳﺘﻌﻤﺎﻝ ،ﻓﻤﺜﻼ ﻟﻮ ﺃﺭﺩﻧﺎ ﺗﺮﲨﺔ ﻭ ﺭﺑﻂ ﺑﺮﻧﺎﻣﺞ ،ﺯﺭ ﻭﺍﺣﺪ ﻣﻦ ﻟﻮﺣﺔ ﺍﳌﻔﺎﺗﻴﺢ ﺃﻭ ﻧﻘﺮﺓ ﻣﻦ ﺍﻟﻔﺄﺭﺓ ﺗﻘﻮﻡ ﺗﺮﲨﺔ ﻭ ﺭﺑﻂ ﺍﳌﺸﺮﻭﻉ ﰒ ﺗﻨﻔﻴﺬ ﺍﻟﱪﻧﺎﻣﺞ. ﺃﻣﺎ ﰲ ﺍﻟﺴﺎﺑﻘﺔ ﻓﻜﺎﻧﺖ ﺗﺘﻢ ﻫﺬﻩ ﺍﻟﻌﻤﻠﻴﺎﺕ ﻋﻠﻰ ﺷﻜﻞ ﺃﻭﺍﻣﺮ ﻣﻦ .Console ١,١,١ﳏﺮﺭ ﻧﺼﻮﺹ :texts editor ﺍﳋﻄﻮﺓ ﺍﻷﻭﻝ ﰲ ﺍﻟﱪﳎﺔ ﻫﻲ ﻛﺘﺎﺑﺔ ﺍﻟﱪﻧﺎﻣﺞ ،ﻭ ﻃﺒﻌﺎ ﺫﻟﻚ ﻳﺘﻢ ﻋﱪ ﳏﺮﺭﺍﺕ ﻧﺼﻮﺹ ،ﻭ ﰲ ﻟﻐﺔ Cﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺍﻟـﱪﺍﻣﺞ ﻋﻠﻰ ﺃﻱ ﳏﺮﺭ ﻧﺼﻮﺹ ،ﻓﻘﻂ ﻧﺮﺍﻋﻲ ﺃﻥ ﻳﺘﻢ ﺣﻔﻆ ﻣﺼﺪﺭ ﺍﻟﱪﻧﺎﻣﺞ ﻋﻠﻰ ﺻﻴﻐﺔ ،.cﻫﻨﺎﻙ ﺑﻌﺾ ﺍﳌﺘﺮﲨﺎﺕ )ﺍﻟﻘﺪﳝﺔ( ﺍﻟـﱵ ﻻ ﻳﻬﻤﻬﺎ ﺍﻣﺘﺪﺍﺩ ﺍﳌﻠﻒ ﺍﻟﻨﺼﻲ ﻟﻠﱪﻧﺎﻣﺞ ،ﻭ ﻟﻜﻦ ﻣﻦ ﺍﻷﻓﻀﻞ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺼﻴﻐﺔ ﺍﻟﺮﲰﻴﺔ .ﻭ ﻣﻦ ﺷﺮﻭﻁ ﺍﳌﻠﻔﺎﺕ ﺍﻟﻨﺼﻴﺔ ﻟﻠﻐﺔ Cﺃﻥ ﺗﻜﻮﻥ ﺍﻟﻨﺼﻮﺹ ﻣﻜﺘﻮﺑﺔ ﺑﻨﻈﺎﻡ ،ASCIIﻣﺜﻼ ﳏﺮﺭ KWriteﰲ ﺃﻧﻈﻤﺔ Linuxﻭ Notepadﰲ ﺃﻧﻈﻤﺔ ،Windowsﻛِـﻼ ﻣـﻦ ﳏﺮﺭﻳﻦ ﻳﻌﺘﻤﺪﺍﻥ ﻋﻠﻰ ﺷﻔﺮﺓ .ASCIIﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﶈﺮﺭ Wordﰲ ﺃﻧﻈﻤﺔ Windowsﺃﻭ KWordﰲ ﺃﻧﻈﻤﺔ .Linux ١,١,٢ﻣﺘﺮﺟﻢ :compiler ﺗﻘﻮﻡ ﺍﳌﺘﺮﲨﺎﺕ ﺑﺘﺮﲨﺔ ﺃﻭ ﲢﻮﻳﻞ ﺍﳌﻠﻔﺎﺕ ﺍﳌﺼﺪﺭﻳﺔ ﺇﱃ ﻟﻐﺔ ﻣﻨﺨﻔﻀﺔ ﺍﳌﺴﺘﻮﻯ ﺇﻥ ﱂ ﺗﻜﻮﻥ ﻫﻨﺎﻙ ﺃﺧﻄﺎﺀ ﰲ ﻗﻮﺍﻋﺪ ﺍﻟﻠﻐﺔ، ﳝﻜﻦ ﺃﻥ ﺗﺘﺮﺟﻢ ﺇﱃ ﻟﻐﺔ ﺍﻟﺘﺠﻤﻴﻊ Assembly Languageﺃﻭ ﺇﱃ ﻟﻐﺔ ﺍﻵﻟﺔ Machine Languageﻣﺒﺎﺷﺮﺓ ،ﺣﻴﺚ ﺑﻌﺪ ﺍﻟﺘﺮﲨـﺔ ﻳﺘﻢ ﺇﻧﺸﺎﺀ ﻣﻠﻔﺎﺕ ﺑﺼﻴﻐﺔ ..objﲢﺘﻮﻱ ﻫﺬﻩ ﺍﳌﻠﻔﺎﺕ ﻋﻠﻰ ﺗﻌﻠﻴﻤﺎﺕ ﺍﻟﺘﺠﻤﻴﻊ ﺃﻭ ﺍﻵﻟﺔ ﻣﻢ ﻳﺴﻬﻞ ﻋﻤﻠﻴﺔ ﺭﺑﻂ ﻟﻐﺘﲔ ﺃﻭ ﺃﻛﺜـﺮ ﻣﻊ ﺑﻌﻀﻬﺎ ،ﻓﻤﺜﻼ ﳝﻜﻨﻨﺎ ﺍﺳﺘﺪﻋﺎﺀ ﺩﻭﺍﻝ ﻣﻦ ﻟﻐﺔ Pascalﰲ ﻟﻐﺔ .C ﻳﻮﺟﺪ ﺍﻟﻌﺪﻳﺪ ﻣﻦ ﺍﳌﺘﺮﲨﺎﺕ ﰲ ﺃﻏﻠﺐ ﺍﻷﻧﻈﻤﺔ ،ﻣﺜﻼ ﰲ ﺃﻧﻈﻤﺔ Windowsﻳﻮﺟﺪ ﺍﳌﺘﺮﺟﻢ Visual C++ﺣﻴﺚ ﻳﻘﻮﻡ ﺑﺘﺮﲨـﺔ ﻛﻼ ﺍﻟﻠﻐﺘﲔ Cﻭ ،C++ﻭ ﻫﻮ ﻣﻘﺪﻡ ﻣﻦ ﻃﺮﻑ ﺷﺮﻛﺔ ،MicroSoftﻭ ﻳﻮﺟﺪ ﻛﺬﻟﻚ ﺍﳌﺘﺮﺟﻢ Dev-C++ﻭ ﺍﳌﻘﺪﻡ ﻣﻦ ﺷﺮﻛﺔ ،Bloodshedﻭ ﻣﺘﺮﲨﺎﺕ ﺃﺧﺮﻯ ﻣﺜﻞ .... ،Pelles C ،Quick C ،Turbo Cﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﻤﺘﺮﺟﻢ Visual C++ﻓﻬﻮ ﻏﲑ ﳎﺎﱐ. ﺍﳌﺘﺮﺟﻢ Dev-C++ﻣﻦ ﺍﳌﺘﺮﲨﺎﺕ ﺍﺎﻧﻴﺔ ﻭ ﳝﻜﻦ ﲢﻤﻴﻠﻪ ﻣﻦ ﺍﻟﺮﺍﺑﻂ ﺍﻟﺘﺎﱄ: http://www.bloodshed.net/devcpp.html 23 ﺍﳌﺘﺮﺟﻢ Turbo Cﺃﻳﻀﺎ ﻣﻦ ﺍﳌﺘﺮﲨﺎﺕ ﺍﺎﻧﻴﺔ ،ﻭ ﻫﻮ ﻣﻦ ﺃﻗﺪﻣﻬﺎ ،ﻭ ﺍﻷﻛﺜﺮ ﺍﺳﺘﻌﻤﺎﻟﻨﺎ ﰲ ﺍﳉﺎﻣﻌﺎﺕ ،ﺣﻴﺚ ﳝﻜﻦ ﲢﻤﻴﻠﻪ ﻣﻦ ﺍﻟﺮﺍﺑﻂ ﺍﻟﺘﺎﱄ: http://www.pitt.edu/~stephenp/misc/downloadTC.html ﺍﳌﺘﺮﺟﻢ Pelles Cﺃﻳﻀﺎ ﻣﻦ ﺍﳌﺘﺮﲨﺎﺕ ﺍﺎﻧﻴﺔ ﻭ ﻳﻌﺘﱪ ﻣﻦ ﺃﻓﻀﻠﻬﺎ ﻭ ﳝﻜﻦ ﲢﻤﻴﻠﻪ ﻣﻦ ﺍﻟﺮﺍﺑﻂ ﺍﻟﺘﺎﱄ: http://www.smorgasbordet.com/pellesc/download.htm ﺃﻣﺎ ﰲ ﺃﻧﻈﻤﺔ Unixﻭ ،Linuxﻓﻼ ﲢﺘﺎﺝ ﺇﱃ ﻣﺘﺮﲨﺎﺕ ﻷﺎ ﻣﺪﳎﺔ ﻣﻊ ﺃﻱ ﻧﺴﺨﺔ ﻣﻦ ﻧﺴﺦ Unixﻭ ،Linuxﻛﻞ ﻣﺎ ﲢﺘﺎﺟـﻪ ﻫﻮ ﳏﺮﺭ ﻧﺼﻮﺹ .ﻭ ﻫﺬﺍ ﻻ ﻳﻌﲏ ﺃﻧﻪ ﻻ ﻳﻮﺟﺪ ﻣﺘﺮﲨﺎﺕ ﻟﺘﻠﻚ ﺍﻷﻧﻈﻤﺔ ،ﺑﻞ ﻳﻮﺟﺪ ﻭ ﺭﲟﺎ ﻋﺪﺩﻫﺎ ﺃﻛﺜﺮ ﻣـﻦ ﺍﻟـﱵ ﻫـﻲ ﻣﻮﺟﻮﺩﺓ ﻋﻠﻰ ﻧﻈﺎﻡ .Windows ﺃﺩﺧﻞ ﻋﻠﻰ ﺍﻟﺮﺍﺑﻂ ﺍﻟﺘﺎﱄ ﺣﻴﺚ ﺗﻮﺟﺪ ﻣﺘﺮﲨﺎﺕ ﳎﺎﻧﻴﺔ ﻋﺪﻳﺪﺓ ﰲ ﻛﻞ ﻣﻦ ﺃﻧﻈﻤﺔ Windowsﻭ ﺃﻧﻈﻤﺔ :Linux http://www.thefreecountry.com/compilers/cpp.shtml ﲨﻴﻊ ﺍﳌﺘﺮﲨﺎﺕ ﺍﳊﺪﻳﺜﺔ ﻣﺘﻮﻓﺮﺓ ﺎ ،IDEﻣﺎﺫﺍ ﻳﻌﲏ ﻫـﺬﺍ ﺍﳌـﺼﻄﻠﺢ؟ ،ﺃﻭﻻ ﺍﻟﻜﻠﻤـﺔ IDEﳐﺘـﺼﺮﺓ ﻣـﻦ Development Environmentﺃﻱ ﺑﻴﺌﺔ ﺗﻄﻮﻳﺮ ﻣﺘﻜﺎﻣﻠﺔ ،ﺣﻴﺚ ﺗﺴﺎﻋﺪ ﺍﳌﺘﺮﲨﺎﺕ ﺫﺍﺕ ﺑﻴﺌﺔ ﺗﻄﻮﻳﺮ ﻣﺘﻜﺎﻣﻠﺔ ﻋﻠﻰ ﺍﳌـﱪﻣﺞ ﰲ ﻛﻞ ﻣﻦ ﺍﻟﺘﺤﺮﻳﺮ ،ﺍﻟﺘﺮﲨﺔ ﻭ ﺍﻟﺮﺑﻂ ،ﻓﻔﻲ ﺍﻟﺴﺎﺑﻖ ﻛﺎﻧﺖ ﺍﻟﺘﺮﲨﺔ ﻭ ﺍﻟﺮﺑﻂ ﺗﺘﻢ ﻋﻠﻰ ﺷﻜﻞ ﺃﻭﺍﻣﺮ ،ﺃﻣﺎ ﰲ ﺍﻟﺒﻴﺌـﺎﺕ ﺍﻟﺘﻄـﻮﻳﺮ ﺍﳌﺘﻜﺎﻣﻠﺔ ﻓﺄﺻﺒﺤﺖ ﻋﻤﻠﻴﺔ ﺍﻟﺮﺑﻂ ﻭ ﺍﻟﺘﺮﲨﺔ ﺗﺘﻢ ﻋﱪ ﺯﺭ ﻭﺍﺣﺪ ﻣﻦ ﻟﻮﺣﺔ ﺍﳌﻔﺎﺗﻴﺢ ﺃﻭ ﻋﱪ ﻧﻘﺮﺓ ﻣﻦ ﺍﻟﻔﺄﺭﺓ ،ﺃﻣﺎ ﻛﺘﺎﺑﺔ ﺍﻟﱪﺍﻣﺞ ﻓﺘﺘﻢ ﻋﱪ ﳏﺮﺭﺍﺕ ﻧﺼﻮﺹ ﻣﺴﺘﻘﻠﺔ ﻋﻦ ﺍﳌﺘﺮﺟﻢ ،ﻭ ﻫﺬﻩ ﺍﻟﻈﺎﻫﺮﺓ ﻣﻮﺟﻮﺩﺓ ﺇﱃ ﺣﺪ ﺍﻵﻥ ﰲ ﺃﻧﻈﻤﺔ ،Unix/Linuxﺣﱴ ﺃﺩﺍﺓ Qt ﺗﻌﺘﻤﺪ ﻋﻠﻰ ﺃﻭﺍﻣﺮ ﻟﺘﺮﲨﺔ ﻭ ﺍﻟﺮﺑﻂ .ﻭ ﻫﻨﺎ ﺃﻳﻀﺎ ﻛﻨﺖ ﺃﺭﻳﺪ ﺃﻥ ﻧﺮﻯ ﻛﻴﻒ ﺗﺘﻢ ﺍﻟﺘﺮﲨﺔ ﰲ ﻫﺬﺍ ﺍﻷﻧﻈﻤﺔ ،ﻭ ﻧﺄﺧـﺬ ﻣﺜـﺎﻻ ﻟﺬﻟﻚ ،ﻣﺜﻼ ﻟﺪﻳﻨﺎ ﺑﺮﻧﺎﻣﺞ ﳏﻔﻮﻅ ﺑﺈﺳﻢ ،cprog.cﻓﻤﻦ ﺧﻂ ﺍﻷﻭﺍﻣﺮ )ﻣﺜﻼ (Konsoleﻧﻜﺘﺐ: Integrated cc cprog.c ﻫﺬﻩ ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﻟﱪﻧﺎﻣﺞ ﻣﻌﺘﻤﺪ ﻋﻠﻰ ﻟﻐﺔ Cﻓﻘﻂ ،ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻥ ﻣﺪﻣﺞ ﻣﻊ ﻟﻐﺔ C++ﻓﺴﻨﻜﺘﺐ ﺍﻷﻣﺮ gccﺑﺪﻝ .ccﻭ ﻃﺒﻌﺎ ﺗﻮﺟﺪ ﻃﺮﻕ ﺃﺧﺮﻯ ﻣﺜﻞ: cc –o cprog cprog.c ﻫﻨﺎ ﺳﺘﻜﻮﻥ ﻟﺪﻳﻚ ﺇﻣﻜﺎﻧﻴﺔ ﺇﻋﺎﺩﺓ ﺗﺴﻤﻴﺔ ﺍﻟﱪﻧﺎﻣﺞ ،ﺃﻣﺎ ﻋﻤﻠﻴﺔ ﺗﻨﻔﻴﺬ ﺍﻟﱪﻧﺎﻣﺞ ﻓﺘﻜﻮﻥ ﻛﺘﺎﱄ: ./cprog 24 ١,١,٣ﺍﳌﺮﺑﻂ :linker ﻳﻘﻮﻡ ﺍﳌﺮﺑﻂ ﲜﻤﻊ ﺍﳌﻠﻔﺎﺕ ﺫﺍﺕ ﺍﻟﺼﻴﻐﺔ .objﰒ ﻳﻌﻄﻴﻨﺎ ﺍﻟﱪﺍﻣﺞ ﺍﻟﺘﻨﻔﻴﺬﻳﺔ ﻭ ﺍﻟﱵ ﺗﻜﻮﻥ ﻏﺎﻟﺒﺎ ﺑﺎﻣﺘﺪﺍﺩ ،.exeﺃﻭ ﻣﻠﻔـﺎﺕ ﻣﻜﺘﺒﺎﺕ ﺍﻟﺮﺑﻂ ﺍﻟﺪﻳﻨﺎﻣﻴﻜﻴﺔ ﻭ ﺍﻟﱵ ﺗﻜﻮﻥ ﺑﺈﻣﺘﺪﺍﺩ ،.dllﻭ ﳝﻜﻦ ﺃﻥ ﺗﻜﻮﻥ ﻫﺬﻩ ﺍﳌﻠﻔﺎﺕ ﻣﻜﺘﻮﺑﺔ ﲟﺨﺘﻠﻒ ﺍﻟﻠﻐﺎﺕ. ﺍﻟﺸﻜﻞ :١,١,١ﻣﺮﺣﻠﺔ ﺇﻧﺸﺎﺀ ﻣﻠﻒ ﺗﻨﻔﻴﺬﻱ 25 ﻗﻢ ﺑﺘﺤﻤﻴﻞ ﻭ ﺗﺜﺒﻴﺖ ﺃﺣﺪ ﺍﳌﺘﺮﲨﺎﺕ ﺍﻟﺴﺎﺑﻘﺔ ﻭ ﻗﻢ ﺑﺘﺸﻐﻴﻠﻬﺎ ﻛﺄﻱ ﺑﺮﻧﺎﻣﺞ ،ﰒ ﻗﻢ ﺑﺈﻧﺸﺎﺀ ﻣﺸﺮﻭﻉ ﺟﺪﻳﺪ ﻟﻠﻐﺔ Cﰲ ﺑﻴﺌﺔ ﺍﻟـ Consoleﻣﻊ ﺇﻧﺸﺎﺀ ﻣﻠﻒ ﻧﺼﻲ ﺟﺪﻳﺪ ﻭ ﺍﳊﺮﺹ ﻋﻠﻰ ﺃﻥ ﻳﺘﻢ ﺣﻔﻈﻪ ﺑﺎﻣﺘﺪﺍﺩ ،.cﳝﻜﻦ ﻛﺘﺎﺑـﺔ main.cﻛﺈﺳـﻢ ﻟﻠﻤﻠﻒ ﺍﻟﻨﺼﻲ ﻭ ﺍﻟﺬﻱ ﺳﻨﻘﻮﻡ ﺑﺎﻟﻜﺘﺎﺑﺔ ﻋﻠﻴﻪ ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﻭ ﻫﻮ: >#include<stdio.h )(main { ;)"!printf("Hello, World } ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ 1 2 3 4 5 6 C ﻣﻼﺣﻈﺔ: ﻗﻢ ﺑﻜﺘﺎﺑﺔ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺪﻭﻥ ﺍﻟﺘﺮﻗﻴﻤﺎﺕ ،ﺃﻱ ﻧﻜﺘﺐ ﺍﻟﱪﻧﺎﻣﺞ ﻋﻠﻰ ﺍﻟﺸﻜﻞ ﺍﻟﺘﺎﱄ: >#include<stdio.h )(main { ;)"!printf("Hello, World } ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ C ﻫﺬﺍ ﻣﻦ ﺃﺑﺴﻂ ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﱵ ﳝﻜﻦ ﻛﺘﺎﺑﺘﻬﺎ ،ﻳﻘﻮﻡ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﻋﻨﺪ ﺗﺮﲨﺘﻪ ﻭ ﺗﻨﻔﻴﺬﻩ ﺑﻄﺒﺎﻋﺔ ﺍﳉﻤﻠـﺔ Hello, Worldﻋﻠـﻰ ﺍﻟﺸﺎﺷﺔ ﰲ ﺑﻴﺌﺔ ﺍﻟـ .Consoleﺍﻟﺴﻄﺮ ﺍﻷﻭﻝ ﻣﻦ ﺍﻟﱪﻧﺎﻣﺞ ﺑﻪ ﺍﻟﺸﻔﺮﺓ ) #include<stdio.h> (Codeﻭ ﻫﻲ ﻣﻘﺴﻤﺔ ﺇﱃ ﻗﺴﻤﲔ ،ﺍﻷﻭﻝ ﻫﻮ >< ،#includeﻭ ﻏﺎﻟﺒﺎ ﻣﺎ ﺗﻜﻮﻥ ﺍﻟﻜﻠﻤﺔ #includeﺃﺯﺭﻗﺔ ﺍﻟﻠﻮﻥ. ﻭ ﺍﻟﻘﺴﻢ ﺍﻟﺜﺎﱐ ﻫﻮ ﻣﺎ ﺑﲔ ﺍﻟﺮﻣﺰﻳﻦ ﺃﻛﱪ ﻣﻦ ﻭ ﺃﺻﻐﺮ ﻣﻦ > < ،ﺣﻴﺚ ﻳﻮﺟﺪ ﺍﳌﻠﻒ ،stdio.hﰲ ﻫﺬﺍ ﺍﻟﻘﺴﻢ ﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺃﲰﺎﺀ ﳌﻠﻔﺎﺕ ﺗﺴﻤﻰ ﺑﺎﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ )ﳝﻜﻨﻚ ﺃﻥ ﺗﺮﺍﻫﺎ ﰲ ﺍﻠﺪ includeﻣﻦ ﺍﳌﺘﺮﺟﻢ ﺍﻟﺬﻱ ﺗﺴﺘﻌﻤﻠﻪ( ،ﻭ ﻫﻲ ﻋﺪﻳﺪﺓ ﻭ ﻛﻞ ﻣﻠﻒ ﻣﻨﻬﺎ ﻟﻪ ﳎﺎﻟﻪ ﺍﳋﺎﺹ ،ﺣﻴﺚ ﳛﺘﻮﻱ ﻋﻠﻰ ﺛﻮﺍﺑﺖ ﻭ ﺩﻭﺍﻝ ﺗﺴﻬﻞ ﻋﻠﻴﻨﺎ ﺍﻟﱪﳎﺔ .ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ stdio.hﳐﺘﺼﺮ ﻣـﻦ ،Standard Input Outputﺃﻣﺎ .hﻓﻬﻮ ﺍﻣﺘﺪﺍﺩ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﻭ ﻫﻮ ﳐﺘﺼﺮ ﻣﻦ .Header Fileﻓﺎﺋﺪﺓ ﺍﻟﻜﻠﻤـﺔ #include ﻫﻮ ﺿﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﺍﳌﻮﺟﻮﺩ ﺑﲔ ﺍﻟﺮﻣﺰﻳﻦ ﺃﻛﱪ ﻣﻦ ﻭ ﺃﺻﻐﺮ ﻣﻦ > < ﺇﱃ ﻣﺸﺮﻭﻋﻨﺎ .ﻳﻮﺟﺪ ﺍﻟﻌﺪﻳﺪ ﻣﻦ ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ، ﺳﻨﺘﻄﺮﻕ ﺇﻟﻴﻬﺎ ﻓﻴﻤﺎ ﺑﻌﺪ. 26 ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﻳﻮﺟﺪ ﺍﺳﻢ ﺩﺍﻟﺔ ﻭ ﻫﻲ )( mainﻭ ﻫﻲ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﻷﻱ ﻣﺸﺮﻭﻉ ﻭ ﻻ ﳝﻜﻦ ﺍﻻﺳﺘﻐﻨﺎﺀ ﻋﻨـﻬﺎ ،ﻭ ﻻ ﳝﻜﻦ ﺍﻟﺘﻐﲑ ﰲ ﺍﲰﻬﺎ ﺇﻻ ﰲ ﺣﺎﻻﺕ .ﻭ ﻣﻦ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻳﺒﺪﺃ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺎﻟﺘﻨﻔﻴﺬ ﺑﺸﻜﻞ ﻣﺘﺮﺗﺐ ،ﺃﻣﺎ ﺍﻟﻘﻮﺳﲔ ﺑﻌﺪ ﺍﺳﻢ ﺍﻟﺪﺍﻟـﺔ ﻓﻬﻤﺎ ﺍﻟﻠﺬﺍﻥ ﻳﺒﻴﻨﺎﻥ ﻋﻠﻰ ﺃﺎ ﺩﺍﻟﺔ )ﻭ ﺃﺎ ﺩﺍﻟﺔ ﺑﺪﻭﻥ ﻭﺳﺎﺋﻂ( ﻭ ﻟﻴﺴﺖ ﻣﺘﻐﲑ ﺃﻭ ﺛﺎﺑﺖ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺮﺍﺑﻊ ﺗﻮﺟﺪ ﺍﳊﺎﺿﻨﺔ { ﻭ ﺍﻟﱵ ﺗﻌﲏ ﺑﺪﺍﻳﺔ ﺍﻟﺪﺍﻟﺔ .main ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﺗﻮﺟﺪ ﺍﻟﻜﻠﻤﺔ printfﻭ ﻫﻲ ﻋﺒﺎﺭﺓ ﻋﻦ ﺩﺍﻟﺔ ﻣﻮﺟﻮﺩﺓ ﰲ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،stdio.hﻭ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣﻦ ،print formatﺃﻱ ﺻﻴﻐﺔ ﺍﻟﻄﺒﻊ ،ﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﻄﺒﻊ )ﺇﺧﺮﺍﺝ( ﻣﺎ ﻫﻮ ﺑﺪﺍﺧﻞ ﺃﻗﻮﺍﺱ ﺍﻟﺪﺍﻟﺔ ﺇﱃ ﺍﻟﺸﺎﺷﺔ ،ﻭ ﰲ ﻣﺜﺎﻟﻨـﺎ ﻫـﺬﺍ ﻳﻮﺟﺪ ﺍﻟﻨﺺ ! Hello, Worldﻭ ﻫﻲ ﺍﳉﻤﻠﺔ ﺍﻟﱵ ﺳﻴﺘﻢ ﺇﺧﺮﺍﺟﻬﺎ ﺇﱃ ﺍﻟﺸﺎﺷﺔ ،ﻭ ﺗﻜﻮﻥ ﺍﳉﻤﻞ ﺩﺍﺋﻤﺎ ﺩﺍﺧﻞ ﺍﻗﺘﺒﺎﺳﻴﲔ " "، ﻭ ﰲ ﺎﻳﺔ ﺍﻟﺴﻄﺮ ﻧﻜﺘﺐ ﺍﻟﻔﺎﺻﻠﺔ ﺍﳌﻨﻘﻮﻃﺔ ﻭ ﻫﻲ ﺗﻌﲏ ﺎﻳﺔ ﺍﻟﺴﻄﺮ ﺍﻟﺘﻌﻠﻴﻤﺔ )ﺃﻭ ﺍﻟﺘﻌﻠﻴﻤﺎﺕ( .ﺗﺴﺘﻌﻤﻞ ﺍﻟﺪﺍﻟﺔ printfﺑﺼﻔﺔ ﻋﺎﻣﺔ ﰲ ﻋﺮﺽ ﺃﻭ ﺇﺧﺮﺍﺝ ﻣﻌﻠﻮﻣﺎﺕ ﺇﱃ ﺃﺩﺍﺓ ﺍﻹﺧﺮﺍﺝ ﻭ ﻫﻲ ﺍﻟﺸﺎﺷﺔ Screenﺍﳋﺎﺻﺔ ﺑﺎﳊﺎﺳﻮﺏ. ﻭ ﺃﺧﲑﺍ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ﺣﻴﺚ ﻣﻮﺟﻮﺩ ﺑﻪ ﺍﳊﺎﺿﻨﺔ } ﻭ ﺍﻟﱵ ﺗﻌﲏ ﺎﻳﺔ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ .mainﻭ ﺗﺴﻤﻰ ﺣﺎﺿﻨﺔ ﺍﻟﺒﺪﺍﻳﺔ { ﻭ ﺣﺎﺿﻨﺔ ﺍﻟﻨﻬﺎﻳﺔ } ﻭ ﻣﺎ ﺑﻴﻨﻬﻤﺎ ﺑﺎﻟـ ،blockﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ: ﺍﻟﺸﻜﻞ :١,٢,١ block ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺍﻟﱪﺍﻣﺞ ﺍﻟﺴﺎﺑﻖ ﺑﻄﺮﻕ ﳐﺘﻠﻔﺔ ،ﺣﻴﺚ ﳝﻜﻦ ﺗﻘﺴﻴﻢ ﺍﳉﻤﻠﺔ ! Hello, World ﺇﱃ ﻗﺴﻤﲔ ﻣﺜﻞ: >#include<stdio.h )(main { ;)" printf("Hello, ;)"!printf("World } 1 2 3 4 5 6 7 ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٢ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٢) C ﻭ ﻫﻨﺎ ﺳﻴﺘﻢ ﻃﺒﻊ ﺍﳉﻤﻠﺔ ﻛﺎﻣﻠﺔ ﰲ ﺳﻄﺮ ﻭﺍﺣﺪ ،ﻭ ﺗﻘﺴﻴﻤﻬﺎ ﻻ ﻳﻌﲏ ﺃﻥ ﻛﻞ ﻛﻠﻤﺔ ﰲ ﺳﻄﺮ .ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻛﺘﺎﺑـﺔ ﺍﳉﻤﻠـﺔ ﺣﺮﻓﻴﺎ ،ﻛﻞ ﺣﺮﻑ ﺑﺪﺍﻟﺔ ﻣﻦ .printfﺃﻭ ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺍﻟﺪﺍﻟﲔ ﰲ ﺳﻄﺮ ﻭﺍﺣﺪ ،ﻣﺜﺎﻝ: 27 >#include<stdio.h )(main { ;)"!printf("Hello, "), printf("World } ﺃﻭ: ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٣ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٣) C 1 2 3 4 5 6 >#include<stdio.h 1 2 3 4 5 6 >#include<stdio.h 1 2 3 4 5 6 7 )(main { ;)"!printf("Hello, "); printf("World } ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٤ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٤) C ﻭ ﺗﻮﺟﺪ ﻃﺮﻳﻘﺔ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻭ ﻫﻲ: )(main { printf("Hello, ;)"!World } ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٥ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٥) C ﻋﻨﺪ ﺗﺮﲨﺔ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺳﻴﻨﺒﻬﻚ ﺍﳌﺘﺮﺟﻢ ﻋﻦ ﻭﺟﻮﺩ ﺃﺧﻄﺎﺀ ،ﻣﻨﻬﺎ ﻧﺴﻴﺎﻥ ﻗﻮﺱ ﺍﻟﻨﻬﺎﻳﺔ ﻟﺪﺍﻟـﺔ ،printfﻭ ﻟﺘﻔـﺎﺩﻱ ﻫـﺬﻩ ﺍﻷﺧﻄﺎﺀ ﻧﻘﻮﻡ ﺑﻮﺿﻊ anti-slashﰲ ﺎﻳﺔ ﺍﻟﺴﻄﺮ ﺍﻷﻭﻝ ﻣﻦ ﺍﻟﺪﺍﻟﺔ ،printfﻭ ﺗﺼﺒﺢ ﺍﻟﺪﺍﻟﺔ ﻛﺎﻵﰐ: \ printf("Hello, ;)"!World ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٦ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٦) C ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺇﻥ ﻛﺘﺒﻨﺎ ﺍﻟﺴﻄﺮ ﺍﻷﻭﻝ )ﺍﻟﺬﻱ ﻳﺘﻤﺜﻞ ﰲ ﺿﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ (stdio.hﰲ ﺎﻳﺔ ﺍﻟﱪﻧﺎﻣﺞ ﻓﺈﻥ ﺍﳌﺘﺮﺟﻢ ﻟـﻦ ﳚﺪ ﺍﻟﺪﺍﻟﺔ ،printfﻭ ﺳﺘﻨﺠﻢ ﺃﺧﻄﺎﺀ ﻋﻦ ﺫﻟﻚ ،ﻟﺬﺍ ﳚﺐ ﺩﺍﺋﻤﺎ ﺃﻥ ﻳﻜﻮﻥ ﺿﻢ ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ﻗﺒـﻞ ﺍﻟـﺪﻭﺍﻝ ﺍﳌـﺮﺍﺩ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻭ ﻳﺴﺘﺤﺴﻦ ﺩﺍﺋﻤﺎ ﺃﻥ ﻳﺘﻢ ﺿﻢ ﺍﳌﻠﻔﺎﺕ ﰲ ﺑﺪﺍﺑﺔ ﻛﻞ ﻣﺸﺮﻭﻉ. ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ Hello,ﰲ ﺳﻄﺮ ﻭ ﺍﻟﻜﻠﻤﺔ ! Worldﰲ ﺳﻄﺮ ﺁﺧﺮ ﻭ ﺫﻟﻚ ﺑﺈﺿﺎﻓﺔ ﺍﻟﺮﻣﺰ \nﺑﲔ ﺍﻟﻜﻠﻤﺘﲔ ،ﻣﺜﺎﻝ: >#include<stdio.h )(main { 1 2 3 4 28 ;)"!printf("Hello, \nWorld } ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٧ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٧) C ﺃﻭ ﻛﺘﺎﺑﺔ ﻛﻞ ﻣﻦ ﺍﻟﻜﻠﻤﺎﺕ ﰲ ﺩﺍﻟﺔ ﻣﺜﻞ: >#include<stdio.h )(main { ;)" printf("Hello, ;)"printf("\n ;)"!printf("World } ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٨ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٨) C ﻋﻨﺪ ﺗﺮﲨﺔ ﺍﻟﱪﻧﺎﻣﺞ ﻭ ﺗﻨﻔﻴﺬﻩ ﻓﻠﻦ ﲡﺪ ﺍﻟﺮﻣﺰ \nﻭ ﺳﺘﺠﺪ ﺃﻥ ﻛﻞ ﻣﻦ ﺍﻟﻜﻠﻤﺘﲔ ﰲ ﺳﻄﺮ ،ﻳﺘﻢ ﺍﺳﺘﺒﺪﺍﻝ ﺍﻟﺮﻣﺰ ﺟﺪﻳﺪ ﺣﻴﺚ ﻻ ﻳﺘﻢ ﻃﺒﺎﻋﺔ ﺍﻟﺮﻣﺰ ،ﻭ ﺍﳊﺮﻑ nﻳﻌﲏ .New line ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺍﳌﺜﺎﻝ ﺍﻷﻭﻝ ﰲ ﺛﻼﺛﺔ ﺃﺳﻄﺮ ﻛﻤﺎ ﰲ ﻳﻠﻲ: \n 5 6 1 2 3 4 5 6 7 8 ﺑـﺴﻄﺮ >#include<stdio.h 1 2 3 >#include<stdio.h 1 2 3 4 {)(#include<stdio.h> main };)"!printf("Hello, World 1 2 };)"!main(){printf("Hello, World ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٩ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (٩) C ﰎ ﲨﻊ ﲨﻴﻊ ﺍﻷﺳﻄﺮ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ،ﻭ ﺍﻟﱪﻧﺎﻣﺞ ﻳﻌﻤﻞ ﻣﺜﻞ ﺍﻟﺴﺎﺑﻖ ﺑﺪﻭﻥ ﺃﺧﻄﺎﺀ ،ﺣﻴﺚ ﺳﺘﻼﺣﻆ ﺃﻧﻪ ﳝﻜﻦ ﺍﺳـﺘﻌﻤﺎﻝ ﺍﳊﺎﺿﻨﺔ { )ﺑﺪﺍﻳﺔ ﺍﻟﺪﺍﻟﺔ( ﻭ ﺍﳊﺎﺿﻨﺔ } )ﺎﻳﺔ ﺍﻟﺪﺍﻟﺔ( ﰲ ﻧﻔﺲ ﺍﻟﺴﻄﺮ ،ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺃﻛﺜﺮ ﻣﻦ ﺫﻟﻚ ﻣﺜﻞ: {)(main };)"!printf("Hello, World ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٠ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (١٠) C ﻭ ﻃﺮﻕ ﺃﺧﺮﻯ ،ﻭ ﻟﻜﻦ ﳚﺐ ﺃﻥ ﺗﻜﻮﻥ ﺍﻷﻭﺍﻣﺮ ،ﺍﻟﻮﻇﺎﺋﻒ ﻭ ﺍﻟﺪﻭﺍﻝ ﺍﳌﺮﺍﺩ ﺇﺳﺘﻌﻤﺎﳍﺎ ﺩﺍﺧﻞ ﺍﳊﺎﺿﻨﺘﲔ } { ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ. ﻭ ﻣﺜﻞ ﻫﺬﻩ ﺍﻟﻄﺮﻕ ﻻ ﻳﻔﻀﻞ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻭ ﺧﺎﺻﺔ ﺇﺫﺍ ﻛﺎﻥ ﺍﻟﱪﻧﺎﻣﺞ ﻛﺒﲑ .ﻭ ﺗﻮﺟﺪ ﻃﺮﻳﻘﺔ ﻻ ﳝﻜﻦ ﺇﺳﺘﻌﻤﺎﳍﺎ ﻭ ﻫﻲ ﻣﻮﺿﺤﺔ ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١١ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (١١) C 29 ﺇﺫﺍ ﺗﺮﲨﺔ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﻓﺴﻴﻨﺒﻬﻚ ﺍﳌﺘﺮﺟﻢ ﻋﻦ ﻭﺟﻮﺩ ﺧﻄﺄ ﻷﻥ ﺍﻟﻜﻠﻤﺔ #includeﺗﺘﻄﻠﺐ ﺳﻄﺮﺍ ﻛﺎﻣﻼ ﳍﺎ )ﻣـﻦ ﻗﻮﺍﻋـﺪ ﺍﻟﻠﻐﺔ( .ﺗﺪﻋﻰ ﺍﻟﻜﻠﻤﺔ #includeﺑﺎﻟﺘﻮﺟﻴﻪ directiveﺃﻭ ﻗﺒﻞ ﺍﳌﻌﺎﰿ preprocessorﻭ ﲰﻴﺖ ﺑﻘﺒﻞ ﺍﳌﻌﺎﰿ ﻷﻧﻪ ﻳﺘﻢ ﺗﻨﻔﻴﺬﻫﺎ ﻗﺒﻞ ﺍﻟﺘﺮﲨﺔ ،ﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﻀﻢ ﳏﺘﻮﻳﺎﺕ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﺍﳌﻄﻠﻮﺏ ﺇﱃ ﺍﳌﺸﺮﻭﻉ ،ﺣﻴﺚ ﳛﺘﻮﻱ ﺫﻟﻚ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳـﻲ ﻋﻠـﻰ ﳎﻤﻮﻋﺔ ﻣﻦ ﺛﻮﺍﺑﺖ ،ﺑﻨﻴﺎﺕ ﻭ ﺩﻭﺍﻝ ﺗﺴﺎﻋﺪﻧﺎ ﰲ ﺑﺮﳎﺔ ﺑﺮﺍﳎﻨﺎ .ﺗﻮﺟﺪ ﺍﻟﻜﺜﲑ ﻣﻦ ﺍﻟﺘﻮﺟﻴﻬﺎﺕ directiveﻭ ﳝﻜﻦ ﲤﻴﺰﻫﺎ ﺑﺎﻟﺮﻣﺰ ،#ﺳﻨﻌﺮﻓﻬﺎ ﰲ ﺍﻟﺪﺭﻭﺱ ﺍﻟﻘﺎﺩﻣﺔ. ﳝﻜﻦ ﺃﻳﻀﺎ ﻭﺿﻊ blockﺩﺍﺧﻞ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ،mainﻣﺜﺎﻝ: >#include<stdio.h )(main { ;)"printf("Hello, World!\n { ;)"printf("Hello, World!\n } ;)"printf("Hello, World!\n } 1 2 3 4 5 6 7 8 9 10 ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٢ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ (١٢) C ﻭ ﻳﺘﻢ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﻛﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ blockﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ،ﻭ ﳝﻜﻦ ﺇﻧﺸﺎﺀ ﺃﻛﺜﺮ ﻣﻦ blockﺩﺍﺧﻞ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ،ﺃﻭ ﺍﺳﺘﻌﻤﺎﻝ blockﺩﺍﺧﻞ blockﺁﺧﺮ. ١,٢,١ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻷﻋﺪﺍﺩ: ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻷﻋﺪﺍﺩ ﻫﻮ ﻃﺒﺎﻋﺔ ﺍﻷﻋﺪﺍﺩ ﻋﻠﻰ ﺍﻟﺸﺎﺷﺔ ﻭ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮﺍﺕ ﻋﻠﻴﻬﺎ ﻣﺜﻞ ﺍﳉﻤﻊ ،ﺍﻟﻄﺮﺡ ،ﺍﻟﻘﺴﻤﺔ ﻭ ﺍﻟﻀﺮﺏ، ﻭ ﺳﻨﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻷﻋﺪﺍﺩ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﺍﻟﺔ ،printfﻭ ﺭﲟﺎ ﺗﻘﻮﻝ ﺃﻥ ﺍﻷﻣﺮ ﺳﻬﻞ ﻓﻘﻂ ﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺍﻷﻋﺪﺍﺩ ﺍﻟـﱵ ﻧﺮﻳـﺪﻫﺎ ﺩﺍﺧﻞ ﺍﻻﻗﺘﺒﺎﺳﺎﺕ ﰲ ﺍﻟﺪﺍﻟﺔ ،printfﺻﺤﻴﺢ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺗﻠﻚ ﺍﻟﻄﺮﻳﻘﺔ ﻭ ﻟﻜﻦ ﺍﳌﺘﺮﺟﻢ ﻫﻨﺎ ﺳﻴﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻷﻋﺪﺍﺩ ﻋﻠﻰ ﺃﺎ ﻧﺺ ﺛﺎﺑﺖ ﻭ ﻟﻴﺴﺖ ﺃﻋﺪﺍﺩ ،ﻫﺬﻩ ﺍﳊﺎﻟﺔ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻋﻤﻠﻴﺎﺕ ﺭﻳﺎﺿﻴﺔ ﻋﻠﻴﻬﺎ. ﰲ ﻟﻐﺔ Cﻟﻜﻞ ﻧﻮﻉ ﻣﻦ ﺍﻷﻋﺪﺍﺩ ﺭﻣﺰ ﻟﺘﻌﺎﻣﻞ ﻣﻌﻪ ،ﻣﺜﻼ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﻳﺘﻢ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﺑﺎﻻﺳﺘﻌﻤﺎﻝ ﺍﻟﺮﻣـﺰ %dﺃﻭ ،%i ﺍﻟﺮﻣﺰ ﺍﻷﻭﻝ ﳐﺘﺼﺮ ﻣﻦ Decimalﻭ ﺍﻟﺮﻣﺰ ﺍﻟﺜﺎﱐ ﳐﺘﺼﺮ ﻣﻦ ،Integerﻫﺬﺍ ﺑﺎﻟﻨﺴﺒﺔ ﻟﻸﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺢ ،ﺃﻣﺎ ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴـﺔ ﻓﻴﺘﻢ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺮﻣﺰ ،%fﻭ ﺍﳊﺮﻑ fﳐﺘﺼﺮ ﻣﻦ ،floatﻭ ﺃﻳﻀﺎ ﺗﻮﺟﺪ ﺭﻣﻮﺯ ﺃﺧﺮﻯ ﺧﺎﺻﺔ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ ﻛﻞ ﻣﻦ ﺍﳊﺮﻭﻑ ﻭ ﺍﻟﻨﺼﻮﺹ ،ﺳﻨﺘﻄﺮﻕ ﺇﻟﻴﻬﺎ ﻓﻴﻤﺎ ﺑﻌﺪ. ﻧﺬﻫﺐ ﺇﱃ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ،ﻟﻜﺘﺎﺑﺔ ﻋﺪﺩ ﻣﻦ ﻧﻮﻉ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﻧﻜﺘﺐ ﻛﻤﺎ ﻳﻠﻲ: 30 >#include<stdio.h ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٣ﻃﺒﺎﻋﺔ ﻋﺪﺩ ﺻﺤﻴﺢ )(main { ;)printf("%d", 20 } 1 2 3 4 5 6 ﻫﻨﺎ ﻭﺿﻌﻨﺎ ﺭﻣﺰ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﺩﺍﺧﻞ ﺍﻟﺪﺍﻟﺔ printfﻭ ﺑﲔ ﺍﻻﻗﺘﺒﺎﺳﻴﲔ ،ﻭ ﺑﻌﺪ ﺍﻻﻗﺘﺒﺎﺳﻴﲔ ﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺍﻟﻌﺪﺩ ﺍﳌـﺮﺍﺩ ﻃﺒﻌﻪ ،ﻭ ﺍﳊﺮﺹ ﻋﻠﻰ ﺃﻥ ﻳﻜﻮﻥ ﺑﲔ ﺍﻻﻗﺘﺒﺎﺳﻴﲔ ﻭ ﺍﻟﻌﺪﺩ ﻓﺎﺻﻠﺔ ،ﻭ ﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻋﻤﻠﻴﺎﺕ ﻣﺜﻞ ﺍﳉﻤﻊ ﻣﺜﻼ ﻭ ﺫﻟﻚ ﺑﺈﺿﺎﻓﺔ ﻣﺆﺛﺮ ﺍﳉﻤﻊ ﻣﻊ ﺍﻟﻌﺪﺩ ﺍﳌﺮﺍﺩ ﺍﳉﻤﻊ ﻣﻌﻪ ﻣﺜﻞ ﻣﺎ ﻫﻮ ﻣﻮﺿﺢ ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: >#include<stdio.h ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٤ﺍﺳﺘﻌﻤﺎﻝ ﺍﳉﻤﻊ )(main { ;)printf("%d", 20+5 } 1 2 3 4 5 6 ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺑﺎﻗﻲ ﺍﳌﺆﺛﺮﺍﺕ ﻣﺜﻞ ﺍﻟﻄﺮﺡ ،ﺍﻟﻘﺴﻤﺔ ﻭ ﺍﻟﻀﺮﺏ ﺑﻨﻔﺲ ﺍﻟﻄﺮﻳﻘﺔ .ﻭ ﳝﻜﻦ ﺇﻇﻬﺎﺭ ﺃﻛﺜﺮ ﻣﻦ ﺭﻗـﻢ ﻭ ﺫﻟـﻚ ﺑﺰﻳﺎﺩﺓ ﺍﻟﺮﻣﺰ %dﻣﻊ ﻓﺼﻠﻪ ﻣﻦ ﺍﻟﺮﻣﺰ ﺍﻟﺴﺎﺑﻖ ﺣﱴ ﺗﻜﻮﻥ ﺍﻷﺭﻗﺎﻡ ﻭﺍﺿﺤﺔ ﻣﺜﻞ ﻣﺎ ﻳﻠﻲ: >#include<stdio.h )(main { ;)printf("%d %d", 20+5, 87 } ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٥ﻃﺒﻊ ﻋﺪﺩﻳﻦ 1 2 3 4 5 6 ﻛﻠﻤﺎ ﻧﻈﻴﻒ ﺭﻣﺰ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺍﻟﺮﻗﻢ ﺍﻹﺿﺎﰲ ﺑﻌﺪ ﺍﻟﺮﻗﻢ ﺍﻟﺴﺎﺑﻖ ﻭ ﻧﻔﺼﻠﻬﻤﺎ ﺑﻔﺎﺻﻠﺔ ،ﳝﻜـﻦ ﺍﺳـﺘﻌﻤﺎﻝ ﺃﻛﺜﺮ ﻣﻦ ﻋﺪﺩﻳﻦ ﻭ ﺑﻄﺮﻳﻘﺔ ﻣﻨﻈﻤﺔ ﻓﻤﺜﻼ ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﺃﻥ ﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﻋﻤﻠﻴﺔ ﺍﳉﻤﻊ ﻓﺴﻨﻜﺘﺐ ﻛﻤﺎ ﻳﻠﻲ: >#include<stdio.h )(main { ;)printf("%d + %d = %d\n", 20, 5, 20+5 } ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٦ﻋﻤﻠﻴﺔ ﲨﻊ 1 2 3 4 5 6 31 ﻭ ﻧﻔﺲ ﺍﻟﻄﺮﻳﻘﺔ ﻣﻊ ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ﻓﻘﻂ ﻧﺴﺘﻌﻤﻞ ﺍﻟﺮﻣﺰ %fﺑﺪﻝ ﺍﻟﺮﻣﺰ .%dﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻟﻜﻴﻔﻴﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ: >#include<stdio.h )(main { ;)printf("%f + %f = %f\n", 1.0, 2.14, 1.0+2.14 } ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٧ﲨﻊ ﻭ ﺇﻇﻬﺎﺭ ﺃﻋﺪﺍﺩ ﺣﻘﻴﻘﻴﺔ 1 2 3 4 5 6 ﻣﻼﺣﻈﺔ: ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻘﺔ ﻭﺿﻌﻨﺎ ﺍﻟﻨﻘﻄﺔ ﰲ ﻣﻜﺎﻥ ﺍﻟﻔﺎﺻﻠﺔ ،ﻫﻜﺬﺍ ﻛﻲ ﳝﻴﺰ ﺍﳌﺘﺮﺟﻢ ﻋﻠﻰ ﺃﺎ ﻗﻴﻢ ﻟﻸﻋﺪﺍﺩ ﺣﻘﻴﻘﻴﺔ ﺃﻱ ﺃﺎ ﺃﻋﺪﺍﺩ ﳍﺎ ﻓﻮﺍﺻﻞ ،ﺃﻣﺎ ﺇﺫﺍ ﻭﺿﻌﺖ ﺍﻟﻔﺎﺻﻠﺔ ﰲ ﻣﻜﺎﻥ ﺍﻟﻨﻘﻄﺔ ﻓﺴﻴﻌﺘﱪﻫﺎ ﺍﳌﺘﺮﺟﻢ ﻣﻨﻔﺼﻠﺔ ﻋﻦ ﺍﻷﺧﺮﻯ ﻭ ﻫﻜﺬﺍ ﺳـﺘﻨﺠﻢ ﺃﺧﻄـﺎﺀ ﻛﺜﲑﺓ ،ﻭ ﺗﺬﻛﺮ ﺃﻥ ﺍﻟﻔﺎﺻﻠﺔ ﺗﺴﺘﻌﻤﻞ ﰲ ﻓﺼﻞ ﻭﺳﺎﺋﻂ ﺩﺍﻟﺔ. ﺃﻣﺎ ﺭﻣﻮﺯ ﻃﺒﻊ ﺍﻷﺣﺮﻑ ﻭ ﺍﻟﻨﺼﻮﺹ ﻓﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻣﺜﻞ ﺍﻟﻄﺮﻕ ﺍﻟﺴﺎﺑﻘﺔ ﻓﻘـﻂ ﺑـﺪﻝ ﺍﻟﺮﻣـﺰﻳﻦ %dﻭ %fﻧـﻀﻊ %c ﻟﻸﺣﺮﻑ ،ﺣﻴﺚ ﺣﺮﻑ cﳐﺘﺼﺮ ﻣﻦ characterﻭ ﻧﻀﻊ ﺍﻟﺮﻣﺰ %sﻟﻠﻨﺼﻮﺹ ،ﻭ ﺍﳊﺮﻑ sﳐﺘﺼﺮ ﻣﻦ Stringﺃﻱ ﺳﻠـﺴﻠﺔ ﺣﺮﻭﻑ .ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﺤﺮﻭﻑ ﻓﻬﺬﺍ ﻣﺜﺎﻝ ﻳﻮﺿﺢ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ: >#include<stdio.h ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺃﻳﻀﺎ: ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٨ﻃﺒﺎﻋﺔ ﺣﺮﻑ ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٩ﻃﺒﺎﻋﺔ ﺣﺮﻑ )(٢ ﻫﻨﺎ ﺳﻴﻄﺒﻊ ﺍﻟﱪﻧﺎﻣﺞ ﺍﳊﺮﻑ ،aﻭ ﰲ ﺣﺎﻟﺔ ﺃﺭﺩﻧﺎ ﻃﺒﻊ ﻧﺺ ﻧﻜﺘﺐ ﻛﻤﺎ ﻳﻠﻲ: )(main { ;)"printf("%c", "a } 1 2 3 4 5 6 >#include<stdio.h 1 2 3 4 5 6 >#include<stdio.h 1 2 3 4 )(main { ;)'printf("%c", 'a } )(main { 32 5 6 ;)"!printf("%s\n", "Hello, World } ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٢٠ﻃﺒﺎﻋﺔ ﻧﺺ ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻛﺘﺎﺑﺔ ﻛﻞ ﻛﻠﻤﺔ ﺃﻭ ﺣﺮﻑ ﰲ ﺇﻗﺘﺒﺎﺳﲔ ﻣﺜﻞ: 1 2 3 4 5 6 >#include<stdio.h )(main { ;)"printf("%s", "Hello, " "\n" "World } ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٢١ﻃﺒﺎﻋﺔ ﻧﺺ )(٢ ﻭ ﺗﻮﺟﺪ ﺭﻣﻮﺯ ﺃﺧﺮﻯ ﻣﻨﻬﺎ ﻣﻦ ﻫﻲ ﺧﺎﺻﺔ ﺑﺄﺭﻗﺎﻡ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺴﺪﺍﺳﻲ ﻋﺸﺮ ﻭ ﺍﻟﱵ ﻳﻜﻮﻥ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺮﻣﺰ %xﺃﻭ %Xﺣﻴﺚ ﺗﺒﺪﺃ ﻣﻦ 0xﺃﻭ ،0Xﻣﺜﻼ ﺍﻟﺮﻗﻢ ،0x000Fﻭ ﺍﻟﺮﻣﺰ %oﻷﻋﺪﺍﺩ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺜﻤﺎﱐ ،ﻭ ﺭﻣﻮﺯ ﺃﺧـﺮﻯ ﺳـﻨﻌﺮﻓﻬﺎ ﰲ ﺍﻟﺪﺭﻭﺱ ﺍﻟﻘﺎﺩﻣﺔ. ١,٢,٢ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: .١ﰲ ﻟﻐﺔ Cﺍﳌﺘﺮﲨﺎﺕ ﺗﻔﺮﻕ ﺑﲔ ﺍﳊﺮﻭﻑ ﺍﻟﻜﺒﲑﺓ ﻭ ﺍﳊﺮﻭﻑ ﺍﻟﺼﻐﲑﺓ ،ﻣﺜﻼ ﺍﻟﺪﺍﻟﺔ mainﻻ ﳝﻜﻦ ﻛﺘﺎﺑﺘﻬﺎ Mainﺃﻭ .MAIN .٢ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ printfﺃﻭ ﺩﻭﺍﻝ ﺃﺧﺮﻯ ﺧﺎﺭﺝ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ،mainﻣﺜﻼ ﻻ ﳝﻜﻦ ﻛﺘﺎﺑﺔ: >#include<stdio.h ;)"printf("Hello, World!\n )(main { ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٢٢ﺍﳋﻄﺄ ١ } 1 2 3 4 5 6 7 8 ﺇﻻ ﰲ ﺣﺎﻟﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺩﻭﺍﻝ ﺎ ﺩﻭﺍﻝ ﺃﺧﺮﻯ ﰒ ﺭﺑﻄﺘﻬﺎ ﺑﺎﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ،ﺳﻨﺘﻌﺮﻑ ﻋﻠﻰ ﺫﻟﻚ ﰲ ﺍﻟﺪﺭﻭﺱ ﺍﻟﻘﺎﺩﻣﺔ. .٣ﻛﺜﲑﺍ ﻣﺎ ﻳﺘﻢ ﻧﺴﻴﺎﻥ ﺍﻟﻔﺎﺻﻠﺔ ﺍﳌﻨﻘﻮﻃﺔ ،ﻭ ﺇﻥ ﰎ ﻧﺴﻴﺎﺎ ﻻ ﳝﻜﻦ ﺇﻧﺸﺎﺀ ﺍﳌﻠﻒ ﺍﻟﺘﻨﻔﻴﺬﻱ ﻟﻠﱪﻧﺎﻣﺞ ﺣﱴ ﻳﺘﻢ ﺗـﺼﺤﻴﺢ ﺍﳋﻄﺄ. 33 .٤ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﻔﺎﺻﻠﺔ ﺍﳌﻨﻘﻮﻃﺔ ﰲ ﺎﻳﺔ ﺳﻄﺮ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ )( ،mainﻭ ﺳﺒﺐ ﺫﻟﻚ ﻫﻮ ﻋﻨﺪﻣﺎ ﻳﺘﻢ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﻭ ﺇﻋﻄﺎﺀﻫﺎ ﺃﻭﺍﻣﺮ ﻻ ﳚﺐ ﺃﻥ ﻧﻜﺘﺐ ﺍﻟﻔﺎﺻﻠﺔ ﺍﳌﻨﻘﻮﻃﺔ ،ﻟﻴﺴﺖ ﻣﺜﻞ ﺩﻭﺍﻝ ﻣﻌﺮﻓﺔ ﺳـﺎﺑﻘﺎ ﻣﺜـﻞ ﺍﻟﺪﺍﻟـﺔ .printf .٥ﰲ ﺩﺍﻟﺔ ﺍﻟﻄﺒﻊ ،printfﺇﻥ ﻛﺘﺒﻨﺎ ﺍﻟﻨﺺ ﺍﳌﺮﺍﺩ ﻃﺒﻌﻪ ﺑﺪﻭﻥ ﺭﻣﻮﺯ ﺍﻻﻗﺘﺒﺎﺱ " " ﻓﺈﻥ ﺍﳌﺘﺮﺟﻢ ﺳﻴﻨﺒﻬﻚ ﻋﻦ ﻭﺟـﻮﺩ ﺧﻄﺄ. ١,٢,٣ﲤﺎﺭﻳﻦ: .١ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﳉﻤﻠﺔ ! Hello, Worldﻣﺮﺗﲔ ،ﺍﻷﻭﱃ ﰲ ﺳﻄﺮ ﻭ ﺍﻟﺜﺎﻧﻴﺔ ﰲ ﺳﻄﺮ ﺁﺧﺮ. .٢ .٣ .٤ .٥ ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﳉﻤﻠﺔ ! ،Hello, Worldﻛﻞ ﺣﺮﻑ ﰲ ﺳﻄﺮ. ﻫﻞ ﳝﻜﻦ ﺗﻐﲑ ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ mainﺇﱃ ﺍﺳﻢ ﻣﻦ ﺍﺧﺘﻴﺎﺭﻧﺎ؟ ﻫﻞ ﳝﻜﻦ ﺍﻻﺳﺘﻐﻨﺎﺀ ﻋﻦ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ main؟ ﻫﻞ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﺃﻛﺜﺮ ﻣﻦ ﻣﺮﺓ؟ .٦ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﻊ ﻧﺘﻴﺠﺔ ﻃﺮﺡ ﺍﻟﻌﺪﺩ ٢ﻣﻦ .٣,٥ .٧ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﻟﻜﻠﻤﺔ Helloﺑﺎﺳﺘﺨﺪﺍﻡ ﺭﻣﻮﺯ ﺍﻷﺣﺮﻑ ).(%c .٨ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﻧﺼﻴﲔ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﻟﺮﻣﺰ ﺍﳋﺎﺹ ﺑﻄﺒﻊ ﺍﻟﻨﺼﻮﺹ ﻣﺮﺗﲔ ).(%s%s 34 ﺍﳌﺘﻐﲑﺍﺕ ﻫﻲ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻟﺒﺎﻳﺘﺎﺕ ﻳﺘﻢ ﺣﺠﺰﻫﺎ ﰲ ﺍﻟﺬﺍﻛﺮﺓ ﺍﻟﻌﺸﻮﺍﺋﻴﺔ Random Access Memoryﺃﻱ ،RAMﺣﻴﺚ ﻳﺘﻢ ﻭﺿﻊ ﻗِﻴﻢ ﻣﺘﻐﲑﺓ ﰲ ﺗﻠﻚ ﺍﻟﺒﺎﻳﺘﺎﺕ ﺍﶈﺠﻮﺯﺓ ،ﳝﻜﻦ ﺍﺳﺘﺮﺟﺎﻋﻬﺎ ﰲ ﺃﻱ ﻭﻗﺖ .ﻛﻞ ﺑﺎﻳﺖ ﻳﺘﻢ ﺍﻟﻮﺻﻮﻝ ﺇﻟﻴﻬﺎ ﻋﱪ ﻋﻨﻮﺍﻥ. ﻭ ﺗﻔﻘﺪ ﻫﺬﻩ ﺍﻟﺬﺍﻛﺮﺓ ﲨﻴﻊ ﺑﻴﺎﻧﺎﺎ ﻋﻨﺪ ﻗﻄﻊ ﺍﻟﺘﻴﺎﺭ .ﺍﻟـ RAMﻋﺒﺎﺭﺓ ﻋﻦ ﺭﻗﺎﻗﺔ Chipﲢﺘﻮﻱ ﻋﻠﻰ ﻋﺪﺩ ﻣﻦ ﺍﻟﺘﺮﺍﻧﺰﺳﺘﻮﺭﺍﺕ Transistorsﻭ ﺍﳌﻜﺜﻔﺎﺕ Capacitorﺗﻘﺪﺭ ﺑﺎﳌﻼﻳﲔ ،ﺣﻴﺚ ﻭﺍﺣﺪ ﺗﺮﺍﻧﺰﺳﺘﻮﺭ ﻭ ﻣﻜﺜﻒ ﻳﺸﻜﻼﻥ ﻭﺣـﺪﺓ ﺫﺍﻛـﺮﺓ ﺗﻘـﺪﺭ ﺑﺎﻟـﺒﺖ ،Bitﳛﻞ ﻫﺬﺍ ﺍﻟﺒﺖ ﺇﻣﺎ ﺍﻟﻘﻴﻤﺔ ٠ﺃﻭ ﺍﻟﻘﻴﻤﺔ ،١ﺣﻴﺚ ٨ﺑﺘﺎﺕ ﺗﺸﻜﻞ ﻭﺍﺣﺪ ﺑﺎﻳﺖ ،Byteﻭ ﻛﻞ ﺑﻴﺎﺕ ﻣﻦ ﻫـﺬﻩ ﺍﻟﺬﺍﻛﺮﺓ ﳝﺜﻞ ﺑﻌﻨﻮﺍﻥ)ﻳﺘﻢ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﻫﺬﻩ ﺍﻟﻌﻨﺎﻭﻳﻦ ﺑﺎﻟﻨﻈﺎﻡ ﺍﻟﺴﺪﺍﺳﻲ ﺍﻟﻌﺸﺮ( ﳝﻜﻦ ﺍﻟﻮﺻﻮﻝ ﺇﻟﻴﻪ ﻭ ﺍﻟﺘﻐﲑ ﰲ ﳏﺘﻮﺍﻩ ،ﳑﺎ ﻧﻔﻬﻢ ﺃﻥ ﺍﻟﺬﺍﻛﺮﺓ ﻋﺒﺎﺭﺓ ﻋﻦ ﻋﻨﺎﻭﻳﻦ ﻣﺘﺴﻠﺴﻠﺔ ،ﻟﻜﻞ ﻋﻨﻮﺍﻥ ﻗﻴﻤﺔ ﻣﺘﻐﲑﺓ .ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ: ﺍﻟﺸﻜﻞ :١,٣,١ﺍﻟﺬﺍﻛﺮﺓ ﻭ ﺍﻟﻌﻨﺎﻭﻳﻦ ﰲ ﺍﻟﻨﻤﻂ ﺍﳊﻘﻴﻘﻲ real mode ﰲ ﻟﻐﺔ Cﻳﻮﺟﺪ ﻋﺪﺕ ﺃﻧﻮﺍﻉ ﻣﻦ ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ ،ﻣﻨﻬﺎ ﻣﺘﻐﲑﺍﺕ ﺧﺎﺹ ﺑﺎﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺢ ﻭ ﺃﺧﺮﻯ ﺑﺎﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ﻭ ﺃﺧﺮﻯ ﺑﺎﻷﺣﺮﻑ ﻭ ،...ﻭ ﺩﺍﺋﻤﺎ ﻧﻘﻮﻡ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ ﻗﺒﻞ ﺍﺳﺘﻌﻤﺎﳍﺎ)ﻭ ﻛﺄﻧﻚ ﲢﺠﺰ ﻣﻜﺎﻧـﺎ ﺃﻭﻻ ﰒ ﺗﻘﻮﻡ ﺑﺎﳉﻠﻮﺱ )ﺃﻱ ﻭﺿﻊ ﻗﻴﻤﺔ(( .ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻫﻲ ﻛﺘﺎﺑﺔ ﻧﻮﻉ ﺍﳌﺘﻐﲑ ﰒ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﰒ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﺳـﻴﺤﺘﻮﻳﻬﺎ )ﻫﺬﺍ ﰲ ﺣﺎﻟﺔ ﺇﻋﻄﺎﺀﻩ ﻗﻴﻤﺔ ﻣﺒﺎﺷﺮﺓ( ﺍﳌﺘﻐﲑ ،ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ: 35 ﺍﻟﺸﻜﻞ :١,٣,٢ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ١,٣,١ﻧﻮﻉ ﺍﳌﺘﻐﲑ :Variable Type ﻛﻤﺎ ﻗﻠﻨﺎ ﺳﺎﺑﻘﺎ ،ﺗﻮﺟﺪ ﻋﺪﺓ ﺃﻧﻮﺍﻉ ﻟﻠﻤﺘﻐﲑﺍﺕ ،ﻭ ﻟﻜﻦ ﺍﻟﺬﻱ ﳚﺐ ﺃﻥ ﻧﻌﺮﻓﻪ ﻫﻮ ﺃﻥ ﺗﻠﻚ ﺍﻷﻧﻮﺍﻉ ﻻ ﲣﺘﻠﻒ ﻋﻦ ﺑﻌﻀﻬﺎ ﺇﻻ ﰲ ﺍﳊﺠﻢ ،ﻭ ﻫﺬﺍ ﻳﻌﲏ ﻟﻮ ﺃﻋﻠﻨﺎ ﻋﻦ ﻣﺘﻐﲑ ﻷﻋﺪﺍﺩ ﺻﺤﻴﺢ ﳝﻜﻨﻨﺎ ﺃﻥ ﻧﻌﻄﻴﻪ ﺣﺮﻓﺎ ﺑﺪﻝ ﻣﻦ ﻗﻴﻤﺔ ﺻﺤﻴﺢ ،ﻭ ﻋﻜـﺲ .ﻭ ﺗﻮﺟﺪ ﺣﺎﻟﺔ ﺧﺎﺻﺔ ﻫﻨﺎ ﻭ ﻫﻲ ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ﻷﺎ ﻟﻴﺴﺖ ﻛﻐﲑﻫﺎ .ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ ﻫﻲ: ١,٣,١,١ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ :int ﻧﻘﻮﻡ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﺑﻜﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ intﰲ ﻣﻜﺎﻥ ،Variable_Typeﺣﻴﺚ ﻳﺄﺧﺬ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ Integerﻣﺴﺎﺣﺔ ﻗﺪﺭﻫﺎ ٢ﺑﺎﻳﺖ ﻭ ﺍﻟﱵ ﺗﺴﺎﻭﻱ ١٦ﺑﺖ ﻭ ﺗﺴﺎﻭﻱ ٦٥٥٣٦ﺍﺣﺘﻤﺎﻝ ،ﺃﻱ ﺃﻥ ﺃﻗﺼﻰ ﻗﻴﻤﺔ ﳝﻜﻦ ﺃﻥ ﳛﻤﻠﻬﺎ ﺍﳌﺘﻐﲑ ﻫﻲ ،٦٥٥٣٥ﺍﺑﺘﺪﺍﺀ ﻣﻦ ﺍﻟﺼﻔﺮ ،ﺃﻭ ﺍﺑﺘﺪﺍﺀ ﻣﻦ -٣٢،٧٦٨ﺇﱃ ٣٢،٧٦٧ﰲ ﺣﺎﻟـﺔ ﺿـﻢ ﺍﻷﻋـﺪﺍﺩ ﺍﻟﺴﺎﻟﺒﺔ .ﻭ ﳝﻜﻦ ﺃﻥ ﻳﻜﻮﻥ ﺣﺠﻤﻬﺎ ٤ﺑﺎﻳﺖ )ﺣﺴﺐ ﺍﳌﺘﺮﺟﻢ ﻭ ﳕﻄﻪ( ﺃﻱ ﺗﺴﺎﻭﻱ ٣٢ﺑﺖ ،ﺣﻴﺚ ﺃﻗﺼﻰ ﻗﻴﻤﺔ ﳝﻜـﻦ ﺃﻥ ﲢﻤﻠﻬﺎ ﻫﻲ ،٤٢٩٤٩٦٧٢٩٦ﺍﺑﺘﺪﺍﺀ ﻣﻦ ﺍﻟﺼﻔﺮ)ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﳌﺘﻐﲑ ﻻ ﳛﺘﻮﻱ ﺇﻻ ﻋﻠﻰ ﻗﻴﻢ ﻣﻮﺟﺒﺔ( .ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;int Variable_Name = 0 } ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ 1 2 3 4 5 6 ١,٣,١,٢ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ :float ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ﻫﻲ ﺍﻷﻋﺪﺍﺩ ﺍﻟﱵ ﳍﺎ ﻓﻮﺍﺻﻞ ،ﻭ ﻳﺘﻢ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ،floatﺣﺠﻤﻬﺎ ٤ﺑﺎﻳﺖ ،ﺣﻴﺚ ﺗﺒﺪﺃ ﻣﻦ 1.2E-38ﺇﱃ .3.4E+38ﻣﺜﺎﻝ: >#include<stdio.h )(main { 1 2 3 4 36 ;float Variable_Name = 0.0 ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٢ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺣﻘﻴﻘﻲ } 5 6 ١,٣,١,٣ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ :double doubleﻫﻲ ﺿﻌﻒ ،floatﻭ ﻳﺘﻢ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ،doubleﺣﻴﺚ ﺣﺠﻤﻬﺎ ٨ﺑﺎﻳﺖ ﻭ ﺗﺒﺪﺃ ﻣـﻦ 2.3E-308ﺇﱃ .1.7E+308ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;double Variable_Name = 0.0 } ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٣ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺣﻘﻴﻘﻲ )(٢ 1 2 3 4 5 6 ١,٣,١,٤ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ :short ﻫﻮ ﺃﻳﻀﺎ ﻣﻦ ﻣﺘﻐﲑﺍﺕ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﺣﻴﺚ ﻧﻘﻮﻡ ﺑﺎﻹﻋﻼﻥ ﻋﻨﻪ ﺑﻜﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ shortﰲ ﻣﻜـﺎﻥ ،Variable_Type ﺣﺠﻤﻪ ٢ﺑﺎﻳﺖ ﻭ ﺍﻟﱵ ﺗﺴﺎﻭﻱ ١٦ﺑﺖ ﻭ ﺗﺴﺎﻭﻱ ٦٥٥٣٦ﺍﺣﺘﻤﺎﻝ ،ﺃﻱ ﺃﻥ ﺃﻗﺼﻰ ﻗﻴﻤﺔ ﳝﻜﻦ ﺃﻥ ﳛﻤﻠﻬﺎ ﺍﳌـﺘﻐﲑ ﻫـﻲ ٦٥٥٣٥ﺍﺑﺘﺪﺍﺀ ﻣﻦ ﺍﻟﺼﻔﺮ ،ﺃﻭ ﺍﺑﺘﺪﺍﺀ ﻣﻦ -٣٢،٧٦٨ﺇﱃ ٣٢،٧٦٧ﰲ ﺣﺎﻟﺔ ﺿﻢ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺴﺎﻟﺒﺔ .ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;short Variable_Name = 0 } ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٤ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ )(٢ 1 2 3 4 5 6 ١,٣,١,٥ﻣﺘﻐﲑ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ :long ﻫﻮ ﺃﻳﻀﺎ ﻣﻦ ﻣﺘﻐﲑﺍﺕ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﺣﻴﺚ ﻧﻘﻮﻡ ﺑﺎﻹﻋﻼﻥ ﻋﻨﻪ ﺑﻜﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ longﰲ ﻣﻜـﺎﻥ ،Variable_Type ﺣﺠﻤﻪ ٤ﺑﺎﻳﺖ ﺃﻱ ﻳﺴﺎﻭﻱ ٣٢ﺑﺖ ،ﺣﻴﺚ ﺃﻗﺼﻰ ﻗﻴﻤﺔ ﳝﻜﻦ ﺃﻥ ﳛﻤﻠﻬﺎ ﻫﻲ ،٤٢٩٤٩٦٧٢٩٦ﺍﺑﺘﺪﺍﺀ ﻣﻦ ﺍﻟـﺼﻔﺮ)ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﳌﺘﻐﲑ ﻻ ﳛﺘﻮﻱ ﺇﻻ ﻋﻠﻰ ﻗﻴﻢ ﻣﻮﺟﺒﺔ( .ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;long Variable_Name = 0 } ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٥ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ )(٣ 1 2 3 4 5 6 37 ١,٣,١,٥ﻣﺘﻐﲑ ﺍﻟﺮﻣﻮﺯ :char ﻣﻦ ﺃﺻﻐﺮ ﺍﳌﺘﻐﲑﺍﺕ ،ﻳﺘﻢ ﺍﻹﻋﻼﻥ ﻋﻨﻪ ﺑﻜﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ charﰲ ﻣﻜﺎﻥ ،Variable_Typeﺣﺠﻤﻪ ١ﺑﺎﻳـﺖ ﺃﻱ ٨ﺑـﺖ ﺣﻴﺚ ﳛﻤﻞ ٢٥٦ﺍﺣﺘﻤﺎﻝ ﺍﺑﺘﺪﺍﺀ ﻣﻦ ٠ﺇﱃ ٢٥٥ﺃﻭ ﻣﻦ -١٢٨ﺇﱃ ،١٢٧ﺣﻴﺚ ﻛﻞ ﺭﻗﻢ ﳝﺜﻞ ﺑﺮﻣﺰ ﰲ ﺟﺪﻭﻝ .ASCII ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;'char Variable_Name = 'A } ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٦ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﺣﺮﰲ 1 2 3 4 5 6 ١,٣,٢ﺍﺳﻢ ﺍﳌﺘﻐﲑ :Variable Name ﲢﺪﺛﻨﺎ ﺳﺎﺑﻘﺎ ﻋﻦ ﻋﻨﺎﻭﻳﻦ ،ﺗﻮﺟﺪ ﻣﻼﺣﻈﺔ ﻗﻮﻳﺔ ﻫﻨﺎ ﳚﺐ ﺍﻟﺘﻨﺒﻪ ﺎ ،ﻭ ﻫﻲ ﺃﻧﻨﺎ ﻧﺮﻯ ﺍﳌﺘﻐﲑﺍﺕ ﺃﲰﺎﺀ ،ﺃﻣﺎ ﺍﳉﻬـﺎﺯ ﻓـﲑﺍﻩ ﻋﻨﺎﻭﻳﻦ ،ﺍﻹﺳﻢ ﳎﺮﺩ ﺃﺩﺍﺓ ﺍﺳﺘﻌﻤﻠﺖ ﻟﺘﺴﻬﻴﻞ ﻋﻤﻠﻴﺔ ﺍﻟﻮﺻﻮﻝ ﺇﱃ ﺗﻠﻚ ﺍﻟﻌﻨﺎﻭﻳﻦ ﺑﺪﻭﻥ ﺍﻟﻠﺠﻮﺀ ﺇﱃ ﻋﻨﺎﻭﻳﻦ ،ﺇﳕﺎ ﺃﲰﺎﺀ ﻭﺍﺿﺤﺔ ﺗﻮﺿﺢ ﺳﺒﺐ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ .ﻭ ﻻﺳﻢ ﺍﳌﺘﻐﲑ ﺣﺪﻭﺩ ﻻ ﳚﺐ ﲡﺎﻭﺯﻫﺎ ﻭ ﻫﻲ: § § § § § § ﺃﻥ ﻻ ﻳﺘﺠﺎﻭﺯ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﺃﻛﺜﺮ ﻣﻦ ٣١ﺣﺮﻑ. ﺃﻥ ﻻ ﻳﺒﺪﺃ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﺑﺄﺭﻗﺎﻡ. ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﳛﺘﻮﻱ ﻋﻠﻰ ﻣﺆﺛﺮﺍﺕ ﻣﺜﻞ ﺍﳉﻤﻊ ﻭ ﺍﻟﻄﺮﺡ ﻭ.... ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﳛﺘﻮﻱ ﻋﻠﻰ ﺭﻣﻮﺯ ﻣﺜﻞ %ﻭ #ﻭ { ﻭ)...ﺑﺎﺳﺘﺜﻨﺎﺀ ﺍﻟﺮﻣﺰ _(. ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﻣﺴﺘﻌﻤﻞ ﺳﺎﺑﻘﺎ ﰲ ﺩﺍﻟﺔ ﺃﻭ ﻣﺘﻐﲑ ﺁﺧﺮ. ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﻣﻦ ﺃﲰﺎﺀ ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ. ١,٣,٣ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ :Variable Value ﳚﺐ ﻣﺮﺍﻋﺎﺓ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ﺣﺴﺐ ﻧﻮﻋﻪ ،ﻓﻤﺜﻼ ﻻ ﳝﻜﻦ ﺃﻥ ﻧﻌﻄﻲ ﻟﻠﻤﺘﻐﲑ intﻗﻴﻤﺔ ﻋﺪﺩ ﺣﻘﻴﻘﻲ .floatﻭ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ﳝﻜﻦ ﺃﻥ ﻧﻌﻄﻴﻬﺎ ﻟﻪ ﻣﺒﺎﺷﺮﺓ ﺑﻌﺪ ﺍﻹﻋﻼﻥ ﻋﻨﻪ ،ﺃﻭ ﻧﻘﻮﻡ ﺑﺎﻹﻋﻼﻥ ﻋﻨﻪ ﻭ ﻧﻀﻊ ﺑﻪ ﻗﻴﻤﺔ ﻓﻴﻤﺎ ﺑﻌﺪ)ﺃﻭ ﻧﻀﻊ ﺑﻪ ﻗﻴﻤﺔ ﺇﺳﺘﻘﺒﻠﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﻣﺜﻼ(. ١,٣,٤ﺃﻣﺜﻠﺔ ﺣﻮﻝ ﺍﳌﺘﻐﲑﺍﺕ: 38 ﺳﺄﻗﺪﻡ ﺃﻣﺜﻠﺔ ﳐﺘﻠﻔﺔ ﺣﻮﻝ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﳌﺘﻐﲑﺍﺕ ،ﻭ ﻧﺒﺪﺃ ﲟﺘﻐﲑﺍﺕ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ﺣﻴﺚ ﻧﻘﻮﻡ ﺑﺈﻋﻼﻥ ﻋـﻦ ﻣـﺘﻐﲑ ﺑﺎﺳﻢ Varﻭ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ،٥ﰒ ﻧﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻮﺟﻮﺩﺓ ﰲ ﺍﳌﺘﻐﲑ Varﻋﻠﻰ ﺍﻟﺸﺎﺷﺔ ،ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;int Var = 5 ;)printf("%d\n", Var } ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٧ﻃﺮﻳﻘﺔ ﻃﺒﺎﻋﺔ ﳏﺘﻮﻯ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ 1 2 3 4 5 6 7 8 ﰲ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ،ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﰎ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﺑﺎﺳﻢ Varﻭ ﻣﻦ ﻧﻮﻉ ) intﻋﺪﺩ ﺻﺤﻴﺢ( ﻭ ﺑﻪ ﺍﻟﻘﻴﻤـﺔ ،٥ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﺪﺍﻟﺔ printfﻟﻄﺒﺎﻋﺔ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ،Varﻭ ﺗﻮﺟﺪ ﻃﺮﻕ ﺃﺧﺮﻯ ﻹﻋﻄﺎﺀ ﻟﻠﻤﺘﻐﲑﺍﺕ ﻗﻴﻢ ،ﺳـﺄﻋﻄﻲ ﻃﺮﻳﻘﺘﲔ ،ﺍﻷﻭﱃ ﻫﻲ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﳌﺘﻐﲑ ﰲ ﺳﻄﺮ ﰒ ﺇﻋﻄﺎﺀﻩ ﻗﻴﻤﺔ ﰲ ﺳﻄﺮ ﺁﺧﺮ ﻣﺜﻞ: >#include<stdio.h )(main { ;int Var ;Var = 5 ;)printf("%d\n", Var ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٨ﻃﺮﻳﻘﺔ ﲢﺪﻳﺚ ﻗﻴﻤﺔ ﻣﺘﻐﲑ ﻭ ﻃﺒﻌﻬﺎ } 1 2 3 4 5 6 7 8 9 ﻭ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﺜﺎﻧﻴﺔ ﻫﻲ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑﻳﻦ ،ﺍﻷﻭﻝ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ٥ﻭ ﺍﻟﺜﺎﱐ ﺑﻪ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ﺍﻷﻭﻝ ،ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;int Var_1 = 5 ;int Var_2 = Var_1 ;)printf("%d\n", Var_2 ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٩ﻃﺮﻳﻘﺔ ﲢﺪﻳﺚ ﻗﻴﻤﺔ ﻣﺘﻐﲑ ﻣﻌﻄﺎﺓ ﻣﻦ ﻣﺘﻐﲑ ﺁﺧﺮ } 1 2 3 4 5 6 7 8 9 ﻣﺜﺎﻝ ﺁﺧﺮ: >#include<stdio.h )(main 1 2 3 39 { ;int Num1, Num2, Num3 ;Num1 = 5 ;Num2 = 7 ;Num3 = Num1 + Num2 ;)printf("%d + %d = %d\n", Num1, Num2, Num3 ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٠ﻧﺎﺗﺞ ﲨﻊ ﺑﲔ ﻋﺪﺩﻳﻦ ﺻﺤﻴﲔ ﰲ ﻣﺘﻐﲑ } 4 5 6 7 8 9 10 11 ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﰎ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﻼﺛﺔ ﻣﺘﻐﲑﺍﺕ ﰲ ﻧﻔﺲ ﺍﻟﺴﻄﺮ ﺣﻴﺚ ﻧﻘﻮﻡ ﺑﻔﺼﻞ ﺑﲔ ﺍﺳﻢ ﻣﺘﻐﲑ ﻭ ﺁﺧﺮ ﺑﻔﺎﺻﻠﺔ ،ﻭ ﻫﻨﺎ ﺳﺘﻜﻮﻥ ﲨﻴﻊ ﺍﳌﺘﻐﲑﺍﺕ ﻣﻦ ﻧﻮﻉ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ) ،(intﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ﻭ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺃﻋﻄﻴﻨﺎ ﻟﻠﻤـﺘﻐﲑ Num1 ﺍﻟﻘﻴﻤﺔ ٥ﻭ ﺍﳌﺘﻐﲑ Num2ﺍﻟﻘﻴﻤﺔ ،٧ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺃﻋﻄﻴﻨﺎ ﻟﻠﻤﺘﻐﲑ Num3ﻧﺘﻴﺠﺔ ﺍﳉﻤﻊ ﺑﲔ ﺍﳌـﺘﻐﲑ Num1ﻭ ﺍﳌـﺘﻐﲑ ،Num2ﻭ ﺃﺧﲑﺍ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﻭ ﺍﻟﺬﻱ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﻧﺘﺎﺋﺞ ﺍﻟﱪﻧﺎﻣﺞ .ﻭ ﻧﻔﺲ ﺍﻟﻄﺮﻕ ﺍﻟﺴﺎﺑﻘﺔ ﳝﻜﻦ ﺇﺳﺘﻌﻤﺎﳍﺎ ﻣﻊ ﻣـﺘﻐﲑﺍﺕ ﻣﻦ ﻧﻮﻉ floatﻭ shortﻭ ،longﺃﻣﺎ ﺍﳌﺘﻐﲑ charﻓﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻟﻪ ﻟﻴﺴﺖ ﳐﺘﻠﻔﺔ ﻛﺜﲑ ،ﺣﻴﺚ ﳝﻜﻨﻨﺎ ﺃﻳﻀﺎ ﺃﻥ ﻧﻌﻄﻴﻪ ﻋﺪﺩ ﺑﺪﻝ ﺍﳊﺮﻑ ﺣﻴﺚ ﻋﻨﺪ ﻃﺒﺎﻋﺘﻪ ﻻ ﻳﻄﺒﻊ ﻋﺪﺩﺍ ،ﺇﳕﺎ ﺍﳊﺮﻑ ﺍﻟﺬﻱ ﳛﻤﻞ ﺫﻟﻚ ﺍﻟﺮﻗﻢ ﰲ ﺟﺪﻭﻝ ،ASCIIﻭ ﻟﻜﻲ ﺗﻔﻬـﻢ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺘﻐﲑﺍﺕ ﻣﻦ ﻧﻮﻉ charﺇﻟﻴﻚ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: >#include<stdio.h )(main { ;'char ch = 'a ;)printf("%c\n", ch ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١١ﻃﺮﻳﻘﺔ ﻃﺒﺎﻋﺔ ﺣﺮﻑ ﻣﻮﺟﻮﺩ ﰲ ﻣﺘﻐﲑ ﺣﺮﰲ ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﺃﻋﻄﲔ ﻟﻠﻤﺘﻐﲑ chﺍﳊﺮﻑ ﺍﻟﺬﻱ aﻣﻊ ﻣﺮﺍﻋﺎﺓ ﺃﻥ ﻳﻜﻮﻥ ﺩﺍﺧﻞ ﻟﻨﺎ ﺍﳊﺮﻑ aﻓﻬﻮ ﺍﻟﺮﻗﻢ ٩٧ﰲ ﺟﺪﻭﻝ ،ASCIIﻭ ﺳﻴﺼﺒﺢ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻘﺔ ﻛﻤﺎ ﻳﻠﻲ: ‘ } 1 2 3 4 5 6 7 8 ‘ ،ﺃﻣﺎ ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﺃﻥ ﻧﻌﻄﻴﻪ ﻋﺪﺩﺍ ﻳﻄﺒﻊ >#include<stdio.h )(main { ;char ch = 97 ;)printf("%c\n", ch ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٢ﻃﺮﻳﻘﺔ ﻃﺒﺎﻋﺔ ﺣﺮﻑ ﺑﺎﻹﻋﺘﻤﺎﺩ ﻋﻠﻰ ﺭﻗﻤﻪ ﰲ ﺟﺪﻭﻝ ﺃﺳﻜﻲ } 1 2 3 4 5 6 7 8 ﻭ ﻛﻤﺎ ﻗﻠﻨﺎ ﺳﺎﺑﻘﺎ ﺃﻥ ﺃﻗﺼﻰ ﻗﻴﻤﺔ ﳝﻜﻦ ﺃﻥ ﳛﻤﻠﻬﺎ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ charﻫﻲ ٢٥٥ﺍﺑﺘﺪﺍﺀ ﻣﻦ ﺍﻟﺼﻔﺮ ،ﻭ ﻛﻞ ﺭﻗـﻢ ﳝﺜـﻞ ﺑﺮﻣﺰ. 40 ١,٣,٥ﺍﻷﻋﺪﺍﺩ ﺍﳌﻮﺟﺒﺔ ﻭ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺴﺎﻟﺒﺔ: ﰲ ﺣﺎﻟﺔ ﺃﻧﻚ ﺃﺭﺩﺕ ﺍﺳﺘﻌﻤﺎﻝ ﺃﻋﺪﺍﺩ ﻣﻮﺟﺒﺔ ﻭ ﺃﻋﺪﺍﺩ ﺳﺎﻟﺒﺔ ﳌﺘﻐﲑ ﻓﺘﻮﺟﺪ ﻃﺮﻳﻘﺘﲔ ﻟﺬﻟﻚ ﺍﻷﻭﱃ ﺗﻜﻮﻥ ﺍﻓﺘﺮﺍﺿﻴﺔ ﻋﻨـﺪ ﻛﺘﺎﺑﺔ ﻧﻮﻉ ﻭ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ،ﺃﻱ ﺃﻧﻪ ﻋﻨﺪﻣﺎ ﻧﻘﻮﻡ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﺜﻼ int Numﳝﻜﻨﻪ ﺃﻥ ﳛﻤﻞ ﻛﻼ ﻣﻦ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺴﺎﻟﺒﺔ ﻭ ﺍﳌﻮﺟﺒﺔ ،ﺃﻭ ﳝﻜﻦ ﻛﺘﺎﺑﺔ signed Numﻭ ﻫﻲ ﻣﺜﻞ int Numﻣﻦ ﻧﺎﺣﻴﺔ ﺍﳊﺠﻢ ﻭ ﺍﻻﺳﺘﻌﻤﺎﻝ ،ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;signed Num = 5 ;)printf("%d\n", Num } ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٣ﻣﺘﻐﲑ ﺫﺍﺕ ﺇﺷﺎﺭﺓ 1 2 3 4 5 6 7 8 ﻫﺬﺍ ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﻤﺘﻐﲑﺍﺕ ﺍﻟﱵ ﲢﺘﻮﻱ ﻋﻠﻰ ﺃﻋﺪﺍﺩ ﻣﻮﺟﺒﺔ ﻭ ﺃﻋﺪﺍﺩ ﺳﺎﻟﺒﺔ ،ﺃﻣﺎ ﰲ ﺣﺎﻟﺔ ﺃﺭﺩﻧﺎ ﺃﻋﺪﺍﺩ ﻣﻮﺟﺒﺔ ﻓﻘﻂ ﻓﺴﻨـﺴﺘﻌﻤﻞ ﺍﻟﻜﻠﻤﺔ unsignedﻗﺒﻞ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ،ﻣﺜﻠﻤﺎ ﻫﻮ ﻣﻮﺿﺢ ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: >#include<stdio.h )(main { ;unsigned Num = 5 ;)printf("%u\n", Num ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٤ﻣﺘﻐﲑ ﺑﺪﻭﻥ ﺇﺷﺎﺭﺓ } 1 2 3 4 5 6 7 8 ﰎ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﳌﺘﻐﲑ ﺍﻟﺬﻱ ﻻ ﳛﺘﻮﻱ ﻋﻠﻰ ﺃﻋﺪﺍﺩ ﺳﺎﻟﺒﺔ ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻭ ﻛﻤﺎ ﺃﻥ ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﳍﺎ ﻛﺎﺳﺘﻌﻤﺎﻝ ﻣـﺘﻐﲑ ﻃﺒﻴﻌﻲ ،ﻭ ﻫﻨﺎ ﻧﺘﻌﺮﻑ ﻋﻠﻰ ﺍﻟﺮﻣﺰ ﺍﳉﺪﻳﺪ %uﺍﻟﺬﻱ ﳜﱪ ﺍﳌﺘﺮﺟﻢ ﺃﻧﺎ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﺳﻴﺘﻢ ﻃﺒﻌﻬﺎ ﻣﻦ ﻧﻮﻉ unisgnedﺃﻱ ﺃﻋﺪﺍﺩ ﺑﺪﻭﻥ ﺇﺷﺎﺭﺓ. ﻣﻼﺣﻈﺔ: ﻋﻨﺪ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻃﺒﻴﻌﻲ ﻣﺜﻼ charﻓﺈﻧﻪ ﺳﻴﺤﺘﻮﻱ ٢٥٦ﺍﺣﺘﻤﺎﻝ ﻛﻤﺎ ﻗﻠﻨﺎ ﺳﺎﺑﻘﺎ،ﺣﻴﺚ ﳝﻜﻦ ﺃﻥ ﻳﺒﺪﺃ ﻣﻦ ٠ﺇﱃ ٢٥٥ﰲ ﺣﺎﻟﺔ ﻋﺪﻡ ﺍﳊﺎﺟﺔ ﺇﱃ ﺃﻋﺪﺍﺩ ﺳﺎﻟﺒﺔ ،ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﺃﻥ ﻳﺒﺪﺃ ﻣﻦ -١٢٨ﺇﱃ ١٢٧ﰲ ﺣﺎﻟﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺃﻋﺪﺍﺩ ﺳﺎﻟﺒﺔ، ﻭ ﻟﻜﻲ ﺗﻌﺮﻑ ﺍﻟﺴﺒﺐ ﰲ ﺫﻟﻚ ﺇﻟﻴﻚ ﺍﻟﺸﺮﺡ: ﻟﻜﻞ ﻣﺘﻐﲑ ﺣﺠﻤﻪ ،ﻣﺜﻼ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ charﺣﺠﻤﻪ ١ﺑﺎﻳﺖ ﺃﻣﺎ intﻓﺤﺠﻤﻪ ﻫﻮ ٢ﺑﺎﻳﺖ ،ﻭ ﻛﻤﺎ ﻧﻌﺮﻑ ﺃﻥ ١ﺑﺎﻳـﺖ ﻳﺴﺎﻭﻱ ٨ﺑﺖ ،ﺃﻱ ﺃﻥ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ charﺣﺠﻤﻪ ٨ﺑﺖ ،ﻭ ١ﺑﺖ ﻳﺴﺎﻭﻱ ﺇﻣﺎ ١ﺃﻭ ٠ﺣﻴﺚ ﻫﺬﺍ ﻳﻌﲏ ﺃﻥ ١ﺑـﺖ 41 ﻟﺪﻳﻪ ﺍﺣﺘﻤﺎﻟﲔ ) ٠ﺃﻭ ،(١ﺃﻣﺎ ٨ﺑﺖ ﻓﻠﺪﻳﻬﺎ ٢٥٦ﺍﺣﺘﻤﺎﻝ ﺗﺒﺪﺃ ﻣﻦ ٠ﻭ ﺗﻨﺘﻬﻲ ﻋﻨﺪ ٢٥٥ﺇﻥ ﱂ ﺗﻜﻦ ﲢﺘﻮﻱ ﻋﻠﻰ ﺃﻋﺪﺍﺩ ﺳﺎﻟﺒﺔ ،ﺃﻣﺎ ﰲ ﺣﺎﻟﺔ ﺃﺭﺩﻧﺎ ﺃﻋﺪﺍﺩ ﺳﺎﻟﺐ ﻓﺴﻴﺘﻢ ﺳﺤﺐ ١ﺑﺖ ﻣﻦ ٨،ﺃﻱ ﺳﻴﺼﺒﺢ ﺣﺠﻢ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ٧ charﺑﺖ ﺃﻣـﺎ ﺍﻟﺒﺖ ﺍﻟﺜﺎﻣﻦ ﺳﻨﺘﺮﻛﻪ ﻟﻺﺷﺎﺭﺓ ،ﻭ ﺳﻴﺤﻤﻞ ﺇﻣﺎ ﺍﻹﺷﺎﺭﺓ +ﺃﻭ ﺍﻹﺷﺎﺭﺓ ،-ﻭ ٧ﺑﺖ ﺗﺴﺎﻭﻱ ١٢٨ﺍﺣﺘﻤﺎﻝ .ﻭ ﻫﺬﺍ ﺟﺪﻭﻝ ﺑﻪ ﺍﻟﻘﻴﻢ ﺍﶈﺘﻤﻠﺔ ﻟﻜﻞ ﻧﻮﻉ ﻣﻦ ﺍﳌﺘﻐﲑﺍﺕ: ﺍﳊﺠﻢ ﺍﻟﻘﻴﻢ ﺍﻟﻨﻮﻉ charﻭ signed char ١ﺑﺎﻳﺖ ﻣﻦ -١٢٧ﺇﱃ ١٢٧ charﻭ char unsigned ١ﺑﺎﻳﺖ ﻣﻦ ٠ﺇﱃ ٢٥٥ intﻭ signed int ٢ﺑﺎﻳﺖ ﻣﻦ -٣٢،٧٦٨ﺇﱃ ٣٢،٧٦٧ intﻭ unsigned int ٢ﺑﺎﻳﺖ ﻣﻦ ٠ﺇﱃ ٦٥٥٣٥ shortﻭ signed short ٢ﺑﺎﻳﺖ ﻣﻦ -٣٢،٧٦٨ﺇﱃ ٣٢،٧٦٧ shortﻭ unsigned short ٢ﺑﺎﻳﺖ ﻣﻦ ٠ﺇﱃ ٦٥٥٣٥ longﻭ signed long ٤ﺑﺎﻳﺖ ﻣﻦ -٢،١٤٧،٤٨٣،٦٤٨ﺇﱃ ٢،١٤٧،٤٨٣،٦٤٧ longﻭ unsigned long ٤ﺑﺎﻳﺖ ﻣﻦ ٠ﺇﱃ ٤،٢٩٤،٩٦٧،٢٩٥ ﺍﳉﺪﻭﻝ :١,٣,١ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺃﺣﺠﺎﻣﻬﺎ ﺍﻟﺜﻮﺍﺑﺖ ،ﻫﻲ ﻋﻜﺲ ﺍﳌﺘﻐﲑﺍﺕ ،ﳝﻜﻦ ﺃﻥ ﺗﻜﻮﻥ ﻋﺪﺩ ،ﺣﺮﻑ ،ﺃﻭ ﻧﺺ ،ﺣﻴﺚ ﻻ ﳝﻜﻦ ﺍﻟﺘﻐﲑ ﻗﻴﻤﺘﻬﺎ ﺃﻱ ﺗـﺼﺒﺢ ﻗﺎﺑﻠـﺔ ﻟﻠﻘﺮﺍﺀﺓ ﻓﻘﻂ ،ﺳﺄﻋﻄﻲ ﻣﺜﺎﻝ ،ﺣﻴﺚ ﻫﺬﺍ ﻣﺜﺎﻝ ﺑﻪ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ،ﻭ ﻧﻌﻄﻴﻪ ﺍﻟﻘﻴﻤﺔ ٥ﰒ ﻧﻘﻮﻡ ﺑﻄﺒﻊ ﺍﳌـﺘﻐﲑ ﻋﻠﻰ ﺍﻟﺸﺎﺷﺔ ﰒ ﻧﻘﻮﻡ ﺑﺘﺤﺪﻳﺚ ﺍﳌﺘﻐﲑ ﺇﱃ ﺍﻟﻘﻴﻤﺔ ٨ﰒ ﻧﻌﻴﺪ ﻃﺒﺎﻋﺔ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ﻭ ﻫﺎ ﻫﻮ ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;int num ;num = 5 ;)printf("%d\n", num ;num = 8 ;)printf("%d\n", num ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٥ﻃﺮﻳﻘﺔ ﲢﺪﻳﺚ ﻗﻴﻤﺔ ﻣﺘﻐﲑ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 42 ﻫﻨﺎ ﺳﻴﺘﻢ ﺗﻐﲑ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ numﻣﻦ ٥ﺇﱃ ،٨ﻭ ﻫﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ﺻﺤﻴﺢ .ﻭ ﺍﻵﻥ ﺳﻨﻜﺘﺐ ﻧﻔﺲ ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺴﺎﺑﻖ ﻣﻊ ﺇﺿـﺎﻓﺔ ﺑﺴﻴﻄﺔ ،ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;const int num ;num = 5 ;)printf("%d\n", num ;num = 8 ;)printf("%d\n", num ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٦ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ ﻭ ﺍﻟﺘﺤﺪﻳﺚ ﰲ ﻗﻴﻤﺘﻪ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ﺍﻹﺿﺎﻓﺔ ﻣﻮﺟﻮﺩﺓ ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ،ﻭ ﻫﻲ ﺇﺿﺎﻓﺔ ﺍﻟﻜﻠﻤﺔ constﺇﱃ ﺍﳌﺘﻐﲑ int numﻭ ﺍﻟﱵ ﺗﻌﲏ ﺃﻥ ﺍﳌﺘﻐﲑ numﺛﺎﺑﺖ، ﻭ ﻫﻨﺎ ﺍﻟﱪﻧﺎﻣﺞ ﻟﻦ ﻳﻌﻤﻞ ﻭ ﺍﻟﺴﺒﺐ ﻫﻮ ﺃﻧﻪ ﻻ ﳝﻜﻦ ﲢﺪﻳﺚ ﺍﻟﻘﻴﻤﺔ ﺍﻷﻭﱃ ﻟﺜﻮﺍﺑﺖ ،ﻭ ﰲ ﻣﺜﺎﻟﻨﺎ ﺍﻟﺴﺎﺑﻘﺔ ﻻ ﺗﻮﺟﺪ ﻗﻴﻤﺔ ﻟﻠﻤﺘﻐﲑ numﺑﻌﺪﻣﺎ ﺃﻥ ﰎ ﺍﻹﻋﻼﻥ ﻋﻨﻪ ،ﻭ ﳚﺐ ﺩﺍﺋﻤﺎ ﺇﻋﻄﺎﺀ ﻗﻴﻢ ﻟﺜﻮﺍﺑﺖ ﻣﺒﺎﺷﺮﺓ ﺑﻌﺪ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ ﻭ ﺇﻻ ﺳﺘﻜﻮﻥ ﻋﺒﺎﺭﺓ ﻋﻦ ﺛﻮﺍﺑﺖ ﺫﺍﺕ ﺃﻋﺪﺍﺩ ﻋﺸﻮﺍﺋﻴﺔ ﺛﺎﺑﺘﺔ ﻻ ﳝﻜﻦ ﺍﻟﺘﺤﺪﻳﺚ ﻓﻴﻬﺎ ،ﻭ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺑﻌﺪ ﺍﻟﺘﺼﺤﻴﺢ: >#include<stdio.h )(main { ;const int num = 5 ;)printf("%d\n", num } ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٧ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ 1 2 3 4 5 6 7 8 ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻛﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ constﻣﺒﺎﺷﺮﺓ ﺑﻌﺪ ﻧﻮﻉ ﺍﳌﺘﻐﲑ ﻣﺜﻞ: >#include<stdio.h )(main { ;int const num = 5 ;)printf("%d\n", num ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٨ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ )(٢ } 1 2 3 4 5 6 7 8 43 ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻧﻔﺲ ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ ﻋﻠﻰ ﺍﻟﺜﻮﺍﺑﺖ .ﻭ ﻳﻮﺟﺪ ﻧﻮﻉ ﺁﺧﺮ ﻣﻦ ﺍﻟﺜﻮﺍﺑﺖ ،ﻭ ﻫﻲ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﻭ ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﳍﺎ ﻣﻮﺿﺤﺔ ﻛﻤﺎ ﰲ ﺍﻟﺼﻮﺭﺓ ﺍﻟﺘﺎﻟﻴﺔ: #define ﺍﻟﺸﻜﻞ :١,٣,٣ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ ﺣﻴﺚ ﺳﻴﺼﺒﺢ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻘﺔ ﻛﻤﺎ ﻳﻠﻲ: >#include<stdio.h #define num 5 )(main { ;)printf("%d\n", num } 1 2 3 4 5 6 7 8 ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٩ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ )(٣ ﰎ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﻟﺜﺎﺑﺖ numﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ،ﰒ ﻃﺒﺎﻋﺔ ﻗﻴﻤﺘﻪ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ .ﻭ ﻛﻤﺎ ﻗﻠﺖ ﺳـﺎﺑﻘﺎ ،ﺃﻥ preprocessor ﺗﺒﺪﺃ ﺑﺎﻟﺮﻣﺰ ،#ﻭ ﻫﺬﺍ ﻳﻌﲏ ﺃﻥ #defineﻣﻦ ﺍﻟـ ،preprocessorsﻭ ﲨﻴﻊ preprocessorsﻻ ﺗﻨﺘﻬﻲ ﺑﻔﻮﺍﺻﻞ ﻣﻨﻘﻮﻃﺔ. ١,٣,٦ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: .١ﻻ ﳝﻜﻦ ﻭﺿﻊ ﻗﻴﻤﺔ ﺃﻛﺜﺮ ﻣﻦ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ﺍﻟﻘﺼﻮﻯ. .٢ﻻ ﳝﻜﻦ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﳌﺘﻐﲑﺍﺕ ﺇﻻ ﰲ ﺑﺪﺍﻳﺔ ﻛﻞ .block .٣ﰲ ﺣﺎﻟﺔ ﱂ ﻳﺘﻢ ﺗﻌﲔ ﻗﻴﻤﺔ ﳌﺘﻐﲑ ،ﻭ ﺃﺭﺩﺕ ﻃﺒﻊ ﻗﻴﻤﺔ ﺫﻟﻚ ﺍﳌﺘﻐﲑ ﻋﻠﻰ ﺍﻟﺸﺎﺷﺔ ﻓﺴﺘﺄﰐ ﺃﻋﺪﺍﺩ ﻋﺸﻮﺍﺋﻴﺔ ﲣﺘﻠﻒ ﻣـﻦ ﺟﻬﺎﺯ ﻵﺧﺮ. .٤ .٥ .٦ .٧ ﳚﺐ ﺍﳊﺮﺹ ﻋﻠﻰ ﺃﻥ ﺑﲔ ﻧﻮﻉ ﺍﳌﺘﻐﲑ ﻭ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﻣﺴﺎﻓﺔ ﻭﺍﺣﺪﺓ ﻋﻠﻰ ﺍﻷﻗﻞ. ﻻ ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ constﺑﻌﺪ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﺃﻭ ﺑﻌﺪ ﺍﻹﻋﻼﻥ ﻋﻨﻪ. ﻻ ﳝﻜﻦ ﺗﻐﲑ ﺍﺳﻢ ﻣﺘﻐﲑ ﺃﻭ ﺛﺎﺑﺖ. ﻻ ﳝﻜﻦ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑﻳﻦ ﺑﻨﻔﺲ ﺍﻻﺳﻢ. 44 ١,٣,٧ﲤﺎﺭﻳﻦ: .١ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﻟﻌﺪﻳﺪﻳﻦ ٣,١٤ﻭ ،١٥ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺮﻣﻮﺯ ﺍﳋﺎﺻﺔ ﺑﻄﺒﺎﻋﺘﻬﺎ. .٢ .٣ .٤ .٥ .٦ ﻣﺎﺫﺍ ﳛﺪﺙ ﺇﻥ ﺃﻋﻄﲔ ﳌﺘﻐﲑ ﻣﻦ ﻧﻮﻉ intﻗﻴﻤﺔ ﺃﻛﺜﺮ ﻣﻦ ٦٥٥٣٥؟ ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﳊﺮﻑ Aﺑﺪﻝ ﺍﻟﺮﻗﻢ ،٦٥ﺑﺪﻭﻥ ﺍﺳﺘﺨﺪﺍﻡ ﻣﺘﻐﲑﺍﺕ ﺃﻭ ﺛﻮﺍﺑﺖ. ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﳊﺮﻑ Aﺑﺪﻝ ﺍﻟﺮﻗﻢ ،٦٥ﺑﺎﺳﺘﺨﺪﺍﻡ .char ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﺑﻪ ﺛﻼﺛﺔ ﻣﺘﻐﲑﺍﺕ ،ﺍﳌﺘﻐﲑ ﺍﻷﻭﻝ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ١٨ﻭ ﺍﻟﺜﺎﱐ ،٨٩ﺃﻣﺎ ﺍﻟﺜﺎﻟﺚ ﻳﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ﺍﳊﺎﺻﻞ ﺑـﲔ ﺍﳌﺘﻐﲑ ﺍﻷﻭﻝ ﻭ ﺍﻟﺜﺎﱐ ﰲ ﻛﻞ ﻣﻦ ﺍﳉﻤﻊ ،ﺍﻟﻄﺮﺡ ،ﺍﻟﻘﺴﻤﺔ ﻭ ﺍﻟﻀﺮﺏ. ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﺑﻪ ﺛﻼﺛﺔ ﻣﻦ preprocessor #defineﺣﻴﺚ ﺍﻟﺜﺎﻟﺜﺔ ﻫﻲ ﻧﺘﻴﺠﺔ ﺍﳉﻤﻊ ﺑﲔ ﺍﻷﻭﱃ ﻭ ﺍﻟﺜـﺎﱐ ،ﺍﻷﻭﱃ ﺎ ﺍﻟﻘﻴﻤﺔ ٥ﻭ ﺍﻟﺜﺎﱐ ﺎ ﺍﻟﻘﻴﻤﺔ .١٥ 45 ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﻫﻲ ﳎﻤﻮﻋﺔ ﻣﻦ ﺳﻼﺳﻞ ﻧﺼﻴﺔ ﻧﺴﺘﻌﻤﻠﻬﺎ ﻟﺘﻮﺿﻴﺢ ﺃﻭﺍﻣﺮ ﰲ ﻣﺼﺎﺩﺭ ﺑﺮﺍﳎﻨﺎ ،ﻭ ﳝﻜﻦ ﺃﻥ ﲢﺘـﻮﻱ ﺗﻠـﻚ ﺍﻟﻨﺼﻮﺹ ﻋﻠﻰ ﺃﺭﻗﺎﻡ ،ﺃﺣﺮﻑ ،ﺃﻭ ﺭﻣﻮﺯ ﻳﻘﻮﻡ ﺍﳌﺘﺮﺟﻢ ﺑﺘﺠﺎﻫﻠﻬﺎ. ١,٤,١ﻓﺎﺋﺪﺓ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ: ﻓﺎﺋﺪﺓ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﳝﻜﻨﻚ ﺃﻥ ﺗﻼﺣﻈﻬﺎ ﰲ ﺍﻟﻜﺜﲑ ﻣﻦ ﺍﻷﻣﺜﻞ ﺍﳌﻔﺘﻮﺣﺔ ﺍﳌﺼﺪﺭ ﺍﳌﻮﺟﻮﺩﺓ ﻋﻠﻰ ﺍﻹﻧﺘﺮﻧﺖ ،ﻣﺜﻼ ﲡـﺪ ﻣﺜـﺎﻝ ﻟﱪﻧﺎﻣﺞ ﻣﺎ ﻛﺒﲑ ﻭ ﻏﲑ ﻭﺍﺿﺢ ،ﻭ ﻫﻨﺎ ﻳﻠﺠﺊ ﺍﳌﱪﻣﺞ ﺇﱃ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﳉﻌﻠﻬﺎ ﺃﻛﺜﺮ ﻭﺿﻮﺡ. ١,٤,٢ﺃﻧﻮﺍﻉ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ: ﻳﻮﺟﺪ ﻧﻮﻋﲔ ﻣﻦ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﳘﺎ: ١,٤,٢,١ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻟﻨﺼﻮﺹ ﺍﻟﻄﻮﻳﻠﺔ: ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻟﻨﺼﻮﺹ ﺍﻟﻄﻮﻳﻠﺔ ﻫﻲ ﻧﺼﻮﺹ ﺎ ﺃﻛﺜﺮ ﻣﻦ ﺳﻄﺮ ،ﻭ ﻃﺮﻳﻘﺔ ﺍﺳﺘﺨﺪﺍﻣﻬﺎ ﻫﻲ ﲢﺪﻳﺪ ﺑﺪﺍﻳﺔ ﺍﻟﺘﻌﻠﻴﻖ ﻭ ﺍﻟﱵ ﺗﺒﺪﺃ ﺑـ */ﻭ ﻧﻀﻊ * /ﰲ ﺎﻳﺔ ﺍﻟﺘﻌﻠﻴﻖ ،ﻣﺜﺎﻝ: */ My First Program: !Hello, World */ #include<stdio.h> /* Standart Input Output Header File*/ )(main /*main function*/ {/*Start of main function*/ printf("Hello, World!");/*to print Hello, World!*/ }/*End of main function*/ ﺍﻟﱪﻧﺎﻣﺞ :١,٤,١ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻟﻨﺼﻮﺹ ﺍﻟﻄﻮﻳﻠﺔ 1 2 3 4 5 6 7 8 9 10 11 ١,٤,٢,٢ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻷﺳﻄﺮ: ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻷﺳﻄﺮ ﻫﻲ ﲡﺎﻫﻞ ﺍﻟﺴﻄﺮ ﺍﻟﺘﻌﻠﻴﻘﻲ ﺣﻴﺚ ﺗﺒﺪﺃ ﺑـ ،//ﲤﺖ ﺇﺿﺎﻓﺘﻬﺎ ﰲ ﻟﻐﺔ C++ﺍﻟﻘﻴﺎﺳﻴﺔ ،ﻫـﺬﺍ ﻣﺜـﺎﻝ ﻳﻮﺿﺢ ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﳍﺎ: //My First Program: !//Hello, World 1 2 3 46 #include<stdio.h> //Standart Input Output Header File )(main //main function {//Start of main function !printf("Hello, World!");//to print Hello, World }//End of main function ﺍﻟﱪﻧﺎﻣﺞ :١,٤,٢ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺍﻟﺴﻄﺮﻳﺔ 4 5 6 7 8 9 ﻭ ﻫﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ﻟﻴﺴﺖ ﻣﻦ ﻃﺮﻕ ﻟﻐﺔ Cﺍﻟﻘﻴﺎﺳﻴﺔ ﰲ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ،ﻭ ﻟﻜﻦ ﺍﻟﻜﺜﲑ ﻣﻦ ﺍﳌﺘﺮﲨﺎﺕ ﺗﺪﻋﻤﻬﺎ. ١,٤,٣ﻛﻴﻒ ﻳﺴﺘﻌﻤﻞ ﺍﳌﱪﳎﻮﻥ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ: ﻻ ﺗﺴﺘﻌﻤﻞ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﰲ ﺗﺒﲔ ﺃﻭ ﺗﻮﺿﻴﺢ ﺗﻌﻠﻴﻤﺎﺕ ﰲ ﺍﻟﱪﺍﻣﺞ ،ﻓﻤﺜﻼ ﻳﺴﺘﻌﻤﻞ ﻣﱪﳎﻮﻥ ﺁﺧﺮﻭﻥ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﻟﺘﺒﲔ ﺍﺳـﻢ ﺍﳌﻠﻒ ،ﻛﺎﺗﺒﻪ ،ﺷﺮﺡ ﳐﺘﺼﺮ ﰒ ﺗﺎﺭﻳﺦ ﺇﻧﺸﺎﺀ ﺍﳌﻠﻒ ،ﻣﺜﺎﻝ: /*****************************************************************************/ /*author : Khalil Ounis */ /*Date : 2006/01/01 */ /*Information : This is small program show */ */ how programmers use comments */ */ All rights reserved (c) 2006/2007 */ /*****************************************************************************/ /*****************************************************************************/ /*Function : Principal function */ /*Input : None */ /*Output : None */ /*****************************************************************************/ )(main { /*Empty project*/ }/*Main function end*/ ﺍﻟﱪﻧﺎﻣﺞ :١,٤,٣ﻛﻴﻔﻴﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ١,٤,٤ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: .١ﰲ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻟﻨﺼﻮﺹ ﺍﻟﻄﻮﻳﻠﺔ ﺇﻥ ﱂ ﻳﺘﻢ ﲢﺪﻳﺪ ﺎﻳﺔ ﺍﻟﺘﻌﻠﻴﻖ ﻓﺈﻥ ﻛﻞ ﻣﺎ ﻫﻮ ﺑﻌﺪ ﺑﺪﺍﻳﺔ ﺍﻟﺘﻌﻠﻴﻖ ﻳﻌﺘﱪ ﺗﻌﻠﻴﻖ ،ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﺗﻮﺿﻴﺤﻲ: /*comment >#include<stdio.h )(main { ;)"!printf("Hello, World } ﺍﻟﱪﻧﺎﻣﺞ :١,٤,٤ﺍﳋﻄﺄ ١ 1 2 3 4 5 6 7 47 ﻫﻨﺎ ﺍﻟﱪﻧﺎﻣﺞ ﻛﻠﻪ ﻋﺒﺎﺭﺓ ﻋﻦ ﺗﻌﻠﻴﻖ ،ﺃﻱ ﺃﻥ ﺍﳌﺸﺮﻭﻉ ﻓﺎﺭﻍ. .٢ﰲ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺍﻟﺴﻄﺮﻳﺔ ﳚﺐ ﺍﻻﻧﺘﺒﺎﻩ ﺇﱃ ﻣﺎ ﻧﻀﻌﻪ ﺗﻌﻠﻴﻖ ﻓﻤﺜﻼ: >//#include<stdio.h )(main { ;)"!printf("Hello, World } ﺍﻟﱪﻧﺎﻣﺞ :١,٤,٥ﺍﳋﻄﺄ ٢ ﻫﻨﺎ ﺳﻴﺨﱪﻙ ﺍﳌﺘﺮﺟﻢ ﻋﻠﻰ ﺃﻥ ﺍﻟﺪﺍﻟﺔ printfﻏﲑ ﻣﻌﺮﻓﺔ ﺳﺎﺑﻘﺎ ،ﻭ ﻫﺬﺍ ﺍﳋﻄﺄ ﺳﺒﺒﻪ ﻫﻮ ﺟﻌﻞ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ﺍﳋﺎﺻﺔ ﺑﻀﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ stdio.hﻋﺒﺎﺭﺓ ﻋﻦ ﺗﻌﻠﻴﻖ ،ﻭ ﻫﻨﺎ ﺳﻴﺘﻢ ﲡﺎﻫﻞ ﺿﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ .stdio.h ١,٤,٥ﲤﺎﺭﻳﻦ: ﻻ ﺗﻮﺟﺪ ﲤﺎﺭﻳﻦ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ. 1 2 3 4 5 6 #include 48 ﰲ ﺍﻟﺪﺭﻭﺱ ﺍﻟﺴﺎﺑﻘﺔ ﱂ ﻧﺪﺭﺱ ﺇﻻ ﺍﻹﺧﺮﺍﺝ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﺍﻟﺔ ،printfﺍﻵﻥ ﺳﻨﻌﺮﻑ ﻛﻴﻔﻴﺔ ﺍﻹﺩﺧﺎﻝ ﺑﻮﺍﺳﻄﺔ ﺍﻟﺪﺍﻟﺔ ﺩﻭﺍﻝ ﺧﺎﺻﺔ ﺑﺎﻹﺧﺮﺍﺝ ،ﺣﺎﻟﻴﺎ ﺳﻨﺮﻯ ﺍﻟﺪﺍﻟﺔ ،scanfﺍﻟﺘﺸﺎﺑﻪ ﻛﺒﲑ ﺟﺪﺍ ﺑﲔ ﺍﻟـﺪﺍﻟﻴﺘﲔ printfﻭ ،scanfﻓﻘـﻂ ﺍﻷﻭﱃ ﺧﺎﺻﺔ ﺑﺎﻹﺧﺮﺍﺝ ﻭ ﺍﻟﺜﺎﻧﻴﺔ ﺧﺎﺻﺔ ﺑﺎﻹﺩﺧﺎﻝ .ﺗﺴﺘﻌﻤﻞ ﺍﻟﺪﺍﻟﺔ scanfﻟﻘﺮﺍﺀﺓ ﺃﻭ ﺍﺳﺘﻘﺒﺎﻝ ﺍﳌﻌﻠﻮﻣﺎﺕ ﻣﻦ ﺃﺩﺍﺀﻩ ﺍﻹﺩﺧﺎﻝ ﻟﻮﺣﺔ ﺍﳌﻔﺎﺗﻴﺢ .keyboardﺍﻵﻥ ﺳﻨﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻳﻄﻠﺐ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﻗﻴﻤﺔ ﰒ ﻧﻌﻄﻴﻪ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﻗﺎﻡ ﺑﺈﺩﺧﺎﳍﺎ: */اﻹدﺧﺎل*/ >#include<stdio.h */ﻫﻨﺎ ﺳﻨﻀﻊ اﻟﻘﯿﻤﺔ اﻟﱵ ﺳﯿﺪﺧﻠﻬﺎ اﳌﺴﺘﺨﺪم*/ )(main { ;int usr_val */ﻫﻨﺎ ﻧﻄﻠﺐ ﻣﻦ اﳌﺴﺘﺨﺪم إدﺧﺎل ﻗﯿﻤﺔ*printf("Enter a value: ");/ */ﯾﻘﻤﻮم اﳉﻬﺎز ﺑﺈﻧﺘﻈﺎر دﺧﻮل ﻗﯿﻤﺔ ﻣﻦ اﳌﺴﺘﺨﺪم *scanf("%d", &usr_val); / */و ﻫﻨﺎ ﻧﻄﺒﻊ اﻟﻘﯿﻤﺔ اﻟﱵ أدﺧﻠﺖ *printf("Your value is: %d\n", usr_val);/ ﺍﻟﱪﻧﺎﻣﺞ :١,٥,١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ scanfﻹﺩﺧﺎﻝ ﻗﻴﻤﺔ ﺻﺤﻴﺤﺔ } 1 2 3 4 5 6 7 8 9 10 11 ﺍﻟﱪﻧﺎﻣﺞ ﻣﻮﺿﺢ ﺑﺎﻟﺘﻌﻠﻴﻘﺎﺕ ،ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ﻗﻤﻨﺎ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﺍﻟﺔ scanfﻭ ﺩﺍﺧﻠﻬﺎ ﺳﺘﺠﺪ ﻭﺳﻴﻄﲔ ،ﺍﻷﻭﻝ ﻧﻘﻮﻡ ﻓﻴـﻪ ﺑﺘﺤﺪﻳﺪ ﻧﻮﻉ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﺳﻴﺪﺧﻠﻬﺎ ﺍﳌﺴﺘﺨﺪﻡ ﺣﻴﺚ ﻫﻨﺎ ﻭﺿﻌﻨﺎ ﺍﻟﺮﻣﺰ %dﻭ ﺍﻟﺬﻱ ﺩﺭﺳﻨﻪ ﺳﺎﺑﻘﺎ ﰲ ﺍﻟﺪﺍﻟﺔ printfﺣﻴـﺚ ﻗﻠﻨﺎ ﺃﺎ ﺧﺎﺹ ﺑﺎﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ،ﻭ ﰲ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻳﻮﺟﺪ ،&usr_valﻭ ﺍﻟﺮﻣﺰ & ﻳﻌﲏ ﻭﺿﻊ ﺍﻟﻘﻴﻤﺔ ﺍﻟـﱵ ﺃﺩﺧﻠـﻬﺎ ﺍﳌﺴﺘﺨﺪﻡ ﰲ ﻋﻨﻮﺍﻥ ﺍﳌﺘﻐﲑ ،usr_valﻭ ﺳﺘﻔﻬﻢ ﺍﻟﺴﺒﺐ ﺇﺿﺎﻓﺔ ﺍﻟﺮﻣﺰ & ﰲ ﺍﻟﺪﺭﻭﺱ ﺍﻟﻘﺎﺩﻣﺔ ، .ﺇﻻ ﻫﻨـﺎ ﺗﻜـﻮﻥ ﻗﻴﻤـﺔ usr_valﻗﺪ ﺃﺻﺒﺤﺖ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﺃﺩﺧﻠﻬﺎ ﺍﳌﺴﺘﺨﺪﻡ ﰒ ﻧﻘﻮﻡ ﺑﻄﺒﺎﻋﺘﻬﺎ ﻋﻠﻰ ﺍﻟﺸﺎﺷﺔ. ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺧﺎﺹ ﺑﺈﺩﺧﺎﻝ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ،ﺃﻣﺎ ﺑﺎﻟﻨﺴﺒﺔ ﻟﺒﺎﻗﻲ ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ ﻓﺴﻨﺴﺘﻌﻤﻞ ﻧﻔﺲ ﺍﻟﻄﺮﻳﻘﺔ ﻓﻘﻂ ﻧﻘـﻮﻡ ﺑﺘﻐﲑ ﺍﻟﺮﻣﺰ %dﺇﱃ ﻧﻮﻉ ﺍﳌﺘﻐﲑ ﺍﻟﺬﻱ ﻧﺮﻳﺪ ﺇﺳﺘﻘﺒﺎﻟﻪ ،ﻓﻤﺜﻼ ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺃﻥ ﻳﻘﻮﻡ ﺑﺈﺩﺧﺎﻝ ﺭﻣﺰ ﺑﺪﻝ ﺭﻗـﻢ ﻧـﻀﻊ ﺍﻟﺮﻣﺰ %cﰲ ﺍﻟﺪﺍﻟﺔ ،scanfﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻳﻮﺿﺢ ﺫﻟﻚ: >#include<stdio.h )(main { ;char usr_char ;)" printf("Enter a character: ;)scanf("%c", &usr_char ;)printf("Your character is: %c\n", usr_char } 1 2 3 4 5 6 7 8 9 10 49 ﺍﻟﱪﻧﺎﻣﺞ :١,٥,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ scanfﻹﺩﺧﺎﻝ ﺣﺮﻑ ﺍﻵﻥ ﺳﻨﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻳﻄﻠﺐ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﻗﻴﻤﺔ ،ﰒ ﻳﻄﻠﺐ ﻣﻨﻪ ﺇﺩﺧﺎﻝ ﻗﻴﻤﺔ ﺛﺎﻧﻴﺔ ،ﻭ ﻧﻌﻄﻴﻪ ﺍﻟﻨﺘـﺎﺋﺞ ﲜﻤﻴـﻊ ﺍﳌﺆﺛﺮﺍﺕ ﺍﻷﺳﺎﺳﻴﺔ: >#include<stdio.h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 >#include<stdio.h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 )(main { ;int val1, val2 ;)" printf("1)Enter a value: ;)scanf("%d", &val1 ;)" printf("2)Enter a value: ;)scanf("%d", &val2 ;)val1+val2 ;)val1-val2 ;)val1*val2 ;)val1/val2 val2, val2, val2, val2, val1, val1, val1, val1, %d\n", %d\n", %d\n", %d\n", = = = = %d %d %d %d + * / printf("%d printf("%d printf("%d printf("%d } ﺍﻟﱪﻧﺎﻣﺞ :١,٥,٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ scanfﻹﺩﺧﺎﻝ ﻗﻴﻤﺔ ﺻﺤﻴﺤﺔ )(٢ ﺍﳌﺜﺎﻝ ﻭﺍﺿﺢ ،ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑﻳﻦ ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ،ﰒ ﻃﻠﺒﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﻗﻴﻤﺔ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﻭ ﻗﻤﻨﺎ ﺑﺄﺧﺬ ﺍﻟﻘﻴﻤﺔ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ،ﻭ ﺑﻌﺪﻫﺎ ﻃﻠﺒﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﺍﻟﻘﻴﻤﺔ ﺍﻟﺜﺎﻧﻴﺔ ﰒ ﺃﺧﺬﻧﺎ ﺍﻟﻘﻴﻤﺔ ﺍﻟﺜﺎﻧﻴﺔ ﰲ ﺍﻟﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ،ﰒ ﻃﺒﻌﻨﺎ ﺍﻟﻨﺘﺎﺋﺞ ﰲ ﻛﻞ ﻣﻦ ﺍﻟﺴﻄﺮ ١٥ ،١٤ ،١٣ﻭ .١٦ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺇﺩﺧﺎﻝ ﻣﺘﻌﺪﺩ ﰲ ﺍﻟﺪﺍﻟـﺔ ،scanfﻭ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻘﺔ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻹﺩﺧﺎﻝ ﺍﳌﺘﻌﺪﺩ: )(main { ;int val1, val2 ;)" printf("Enter two value: ;)scanf("%d%d", &val1, &val2 ;)val1+val2 ;)val1-val2 ;)val1*val2 ;)val1/val2 val2, val2, val2, val2, val1, val1, val1, val1, %d\n", %d\n", %d\n", %d\n", = = = = %d %d %d %d + * / printf("%d printf("%d printf("%d printf("%d ﺍﻟﱪﻧﺎﻣﺞ :١,٥,٤ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ scanfﻹﺩﺧﺎﻝ ﻗﻴﻤﺔ ﺻﺤﻴﺤﺔ )(٣ } 50 ﺍﻟﺘﻌﺪﺩ ﻫﻨﺎ ﻣﻮﺟﻮﺩ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ،ﰲ ﺍﻟﺪﺍﻟﺔ ،scanfﻭ ﳝﻜﻦ ﺃﻥ ﻧﺰﻳﺪ ﺃﻛﺜﺮ ﻣﻦ ﺫﻟﻚ ،ﻓﻘﻂ ﻧﻀﻴﻒ ﺍﻟﺮﻣﺰ ﺍﳋﺎﺹ ﺑﻨﻮﻉ ﺍﳌﺘﻐﲑ ﰒ ﺇﺿﺎﻓﺔ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﰲ ﺁﺧﺮ ﺍﻟﺪﺍﻟﺔ. ١,٥,١ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: .١ﻻ ﳝﻜﻦ ﺍﺳﺘﺨﺪﺍﻡ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻣﻦ ﺍﻟﺪﺍﻟﺔ scanfﻟﻄﺒﺎﻋﺔ)ﺍﻹﺧﺮﺍﺝ( ،ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻣﻦ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺧﺎﺹ ﺑﻨﻮﻉ ﺍﻟﺮﻣﻮﺯ ﺍﻟﱵ ﺳﻴﺴﺘﻘﺒﻠﻬﺎ ﺍﻟﱪﻧﺎﻣﺞ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ. .٢ﰲ ﺣﺎﻟﺔ ﺍﻻﺳﺘﻐﻨﺎﺀ ﻋﻦ ﺍﻟﺮﻣﺰ & ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﺎﺋﺞ ﻏﲑ ﺻﺤﻴﺤﺔ. .٣ﳚﺐ ﺍﻻﻧﺘﺒﺎﻩ ﺇﱃ ﻋﺪﺩ ﺍﳌﺘﻐﲑﺍﺕ ﺍﳌﺮﺍﺩ ﻓﺤﺼﻬﺎ ،ﳚﺐ ﺃﻥ ﻳﻜﻮﻥ ﻋﺪﺩ ﺭﻣﻮﺯ ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ ﻧﻔﺴﻪ ﻋﺪﺩ ﺍﳌـﺘﻐﲑﺍﺕ ﺍﳌﺮﺍﺩ ﻓﺤﺼﻬﺎ. ١,٥,٢ﲤﺎﺭﻳﻦ: .١ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻄﻠﺐ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﺍﳊﺮﻑ ﺍﻷﻭﻝ ﻭ ﺍﻷﺧﲑ ﻣﻦ ﺍﲰﻪ ﰒ ﻳﻘﻮﻡ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺈﺧﺒﺎﺭ ﺍﳌﺴﺘﺨﺪﻡ ﺃﻥ ﺇﺳﻢ ﻳﺒﺪﺃ ﺑـ "ﺍﳊﺮﻑ ﺍﻷﻭﻝ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ" ﻭ ﻳﻨﺘﻬﻲ ﺑﺎﳊﺮﻑ "ﺍﳊﺮﻑ ﺍﻷﺧﲑ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ". 51 ﻟﻠﻤﺆﺛﺮﺍﺕ ﺃﻧﻮﺍﻉ ﺃﳘﻬﻤﺎ ﺛﻼﺛﺔ ﻭ ﻫﻲ: ١,٦,١ﺍﳌﺆﺛﺮﺍﺕ ﺍﳊﺴﺎﺑﻴﺔ ):(arthimetic operators ﻫﻲ ﺍﳌﺆﺛﺮﺍﺕ ﺍﳊﺴﺎﺑﻴﺔ ﺍﻷﺳﺎﺳﻴﺔ ﻭ ﺍﻟﱵ ﺗﺘﻤﺜﻞ ﰲ ﻛﻞ ﻣﻦ ﺍﳉﻤﻊ) ،(+ﺍﻟﻄﺮﺡ) ،(-ﺍﻟﻘﺴﻤﺔ) (/ﻭ ﺍﻟﻀﺮﺏ)*(،ﻭ ﺗﻮﺟـﺪ ﻣﺆﺛﺮﺍﺕ ﺃﺧﺮﻯ ﺧﺎﺹ ﺑﻠﻐﺔ Cﻭ ﻫﻲ :ﺍﻟﺰﻳﺎﺩﺓ) ،(++ﺍﻟﻨﻘﺼﺎﻥ) (--ﻭ ﺑﺎﻗﻲ ﺍﻟﻘﺴﻤﺔ).(% ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﺠﻤﻊ ،ﺍﻟﻄﺮﺡ ،ﺍﻟﻘﺴﻤﺔ ﻭ ﺍﻟﻀﺮﺏ ﻓﻘﺪ ﺃﺧﺬﻧﺎ ﺃﻣﺜﻠﺔ ﻋﻨﻬﺎ ﺳﺎﺑﻘﺎ .ﺳﻨﺄﺧﺬ ﺃﻣﺜﻠﺔ ﻋﻦ ﻛﻞ ﻣﻦ ﻣـﺆﺛﺮﺍﺕ ﺍﻟﺰﻳـﺎﺩﺓ ﻭ ﺍﻟﻨﻘﺼﺎﻥ ﻭ ﺑﺎﻗﻲ ﺍﻟﻘﺴﻤﺔ: ١,٦,١,١ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ :(++) increment ﺗﻌﺘﱪ ﻣﺆﺛﺮﺍﺕ ﺍﻟﺰﻳﺎﺩﺓ ﻭ ﺍﻟﻨﻘﺼﺎﻥ ﻣﻦ ﺃﻫﻢ ﺍﳌﺆﺛﺮﺍﺕ ،ﺗـﺴﺘﻌﻤﻞ ﰲ ﺍﻟﻜـﺜﲑ ﻣـﻦ ﺍﻟـﱪﺍﻣﺞ ﻭ ﺧﺎﺻـﺔ ﰲ ﺣﻠﻘـﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ)ﺳﻨﺪﺭﺳﻬﺎ ﰲ ﺍﻟﺪﺭﻭﺱ ﺍﻟﻘﺎﺩﻣﺔ( .ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ ﻳﻌﲏ ﺯﻳﺎﺩﺓ ﺭﻗﻢ ﻭﺍﺣﺪ ﺇﱃ ﺍﳌﺘﻐﲑ ﺍﻟﺬﻱ ﻧﺮﻳﺪ ﺍﻟﺰﻳﺎﺩﺓ ﺇﻟﻴﻪ ،ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻳﻮﺿﺢ ﺫﻟﻚ: >#include<stdio.h )(main { ;int Inc ;Inc = 0 ;)printf("Inc = %d\n", Inc ;Inc++ ;)printf("Inc = %d\n", Inc ;++Inc ;)printf("Inc = %d\n", Inc ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ﻗﻤﻨﺎ ﺑﺎﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ ﰲ ﻛﻼ ﻣﻦ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﻭ ﺍﻟﺴﻄﺮ ﺍﻟﺮﺍﺑﻊ ﻋﺸﺮ ،ﻭ ﻧﺘﺎﺋﺞ ﺍﻟﱪﻧﺎﻣﺞ ﺗﻜـﻮﻥ ٠ﰒ ١ﰒ .٢ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻃﺮﻕ ﺃﺧﺮﻯ ﻣﺜﻞ: ;)printf("Inc = %d\n", Inc 1 2 52 ;Inc = Inc+1 ;)printf("Inc = %d\n", Inc ;Inc += 1 ;)printf("Inc = %d\n", Inc 3 4 5 6 7 8 9 ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ )(٢ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻷﻭﱃ ﻫﻲ Inc = Inc+1ﻭ ﺍﻟﱵ ﻣﻮﺟﻮﺩ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ،ﻫﻲ ﻣﻄﺎﺑﻘﺔ ﲤﺎﻣﺎ ﻟـ Inc++ﻭ ﻟﻜﻦ ﰲ ﺍﻟـﺴﺎﺑﻘﺔ ﳝﻜﻦ ﺃﻥ ﻧﻘﻮﻡ ﺑﺰﻳﺎﺩﺓ ﺃﻛﺜﺮ ﻣﻦ ١ﻳﻌﲏ ﺇﻥ ﻛﺘﺒﻨﺎ Inc = Inc+3ﻓﺴﻴﺘﻢ ﺍﻹﺿﺎﻓﺔ ﺇﱃ ﺍﳌﺘﻐﲑ Incﺛﻼﺛﺔ ﺃﺭﻗـﺎﻡ ،ﻛـﺬﻟﻚ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﺜﺎﻧﻴﺔ ،Inc += 1ﻫﻲ ﻣﺜﻞ Inc = Inc+1ﲤﺎﻡ .ﻭ ﻟﻜﻦ ﻳﺴﺘﺤﺴﻦ ﺩﺍﺋﻤﺎ ﺍﺳﺘﻌﻤﺎﻝ ++ﻋﻨﺪ ﺍﻟﺰﻳﺎﺩﺓ ﺑﺎﻟﻮﺍﺣﺪ ،ﻭ ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺯﻳﺎﺩﺓ ﺳﺘﻜﻮﻥ ﺃﻛﺜﺮ ﻣﻦ ﻭﺍﺣﺪ ﻓﺴﻨﺴﺘﻌﻤﻞ ﺍﻟﻄﺮﻕ ﺍﻷﺧﺮﻯ .ﻭ ﺍﻟﻔﺮﻕ ﺑﲔ ﺃﻥ ﻳﻜﻮﻥ ﺍﳌﺆﺛﺮﻳﻦ ++ﰲ ﺑﺪﺍﻳﺔ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﺃﻭ ﺎﻳﺘﻪ ﻫﻮ ﻣﻮﺿﺢ ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: >#include<stdio.h )(main { ;int Inc ;Inc = 0 ;)Inc ;)Inc++ ;)Inc ;)++Inc ;)Inc %d\n", %d\n", %d\n", %d\n", %d\n", = = = = = printf("Inc printf("Inc printf("Inc printf("Inc printf("Inc } 1 2 3 4 5 6 7 8 9 10 11 12 13 ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ )(٣ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺳﻴﺘﻢ ﻃﺒﺎﻋﺔ ﺍﻟﻌﺪﺩ ،٠ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ﺃﻳﻀﺎ ﻭ ﻣﻌﻨﺎ ﺫﻟﻚ ﻋﻨﺪ ﻛﺘﺎﺑﺔ ﻣﺘﻐﲑ ﻗﻢ ﺍﳌﺆﺛﺮ ++ﻳﻌﲏ ﻃﺒﺎﻋﺘﻪ ﰒ ﺗﻨﻔﻴﺬ ﻣﺆﺛﺮ ﺍﻟﺘﺰﺍﻳﺪ .ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﺳﻴﺘﻢ ﻃﺒﻊ ﺍﻟﻌﺪﺩ ١ﻷﻧﻨﺎ ﻗﻤﻨﺎ ﺑﺎﻟﺰﻳﺎﺩﺓ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ .ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﳊـﺎﺩﻱ ﻋﺸﺮ ﺳﻴﺘﻢ ﺗﻨﻔﺬ ﻣﺆﺛﺮ ﺍﻟﺘﺰﺍﻳﺪ ﺃﻭﻻ ﱘ ﻃﺒﺎﻋﺔ ﺍﻟﻨﺘﻴﺠﺔ ﺍﻟﱵ ﻫﻲ ،٢ﻭ ﻛﺬﻟﻚ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﱐ ﻋﺸﺮ ﺳﻴﺘﻢ ﻃﺒﺎﻋﺔ ﺍﻟﻌﺪﺩ .٢ ١,٦,١,٢ﻣﺆﺛﺮ ﺍﻟﻨﻘﺼﺎﻥ :(--) decrement ﺳﻨﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺆﺛﺮ ﺍﻟﻨﻘﺼﺎﻥ ﻣﺜﻠﻤﺎ ﺗﻌﺎﻣﻠﻨﺎ ﻣﻊ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ ﻓﻘﻂ ﺑﺪﻝ ++ﻧﻀﻊ --ﻭ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺑﺎﺳﺘﺨﺪﺍﻡ ﻣﺆﺛﺮ ﺍﻟﻨﻘﺼﺎﻥ: >#include<stdio.h )(main 1 2 3 53 { ;int Dec ;Dec = 2 ;)printf("Dec = %d\n", Dec ;Dec-- ;)printf("Dec = %d\n", Dec ;--Dec ;)printf("Dec = %d\n", Dec ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٤ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﻨﻘﺼﺎﻥ } 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﺍﺳﺘﻌﻤﺎﻝ ﻧﻔﺲ ﺍﻟﻄﺮﻕ ﺍﻟﺴﺎﺑﻘﺔ ﰲ ﺍﻟﻨﻘﺼﺎﻥ: ;)printf("Dec = %d\n", Dec ;Dec = Dec-1 ;)printf("Dec = %d\n", Dec ;Dec -= 1 ;)printf("Dec = %d\n", Dec ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٥ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﻨﻘﺼﺎﻥ )(٢ 1 2 3 4 5 6 7 8 9 ١,٦,١,٣ﻣﺆﺛﺮ ﺑﺎﻗﻲ ﺍﻟﻘﺴﻤﺔ ):(% ﺃﻳﻀﺎ ﳝﻜﻦ ﺍﻋﺘﺒﺎﺭﻩ ﻣﻦ ﺍﳌﺆﺛﺮﺍﺕ ﺍﳌﻬﻤﺔ ،ﻭ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻟﻪ ﺳﻬﻞ ﻓﻤﺜﻼ ﻟﻮ ﺃﺭﺩﻧﺎ ﺃﻥ ﳒﺪ ﺑﺎﻗﻲ ﺍﻟﻘﺴﻤﺔ ﺑﲔ ﺍﻟﻌـﺪﺩ ٥ﻭ ﺍﻟﻌﺪﺩ ٣ﻧﻜﺘﺐ ،5%3ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﺗﻮﺿﻴﺤﻲ: >#include<stdio.h )(main { ;)printf("%d\n", 5%3 } ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٦ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺑﺎﻗﻲ ﺍﻟﻘﺴﻤﺔ 1 2 3 4 5 6 ١,٦,٢ﺍﳌﺆﺛﺮﺍﺕ ﺍﻟﻌﻼﻗﻴﺔ ):(relational operators ﻫﻲ ﻣﺆﺛﺮﺍﺕ ﺗﻌﺘﻤﺪ ﻋﻠﻰ ﺍﳌﻘﺎﺭﻧﺔ ﺑﲔ ﻗﻴﻤﺔ ﻭ ﻗﻴﻤﺔ ﺃﺧﺮﻯ ،ﺣﻴﺚ ﺗﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﺇﻣﺎ ﺻﺤﻴﺤﺔ ) (trueﺃﻭ ﺧﺎﻃﺌﺔ )،(false ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻳﻮﺿﺢ ﺫﻟﻚ: >#include<stdio.h 1 54 )(main { ;)printf("%d\n", 5<3 ;)printf("%d\n", 5==3 ;)printf("%d\n", 5>3 } ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٧ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮﺍﺕ ﺍﻟﻌﻼﻗﻴﺔ 2 3 4 5 6 7 8 ﻫﻨﺎ ﺳﺘﺠﺪ ﻧﺘﺎﺋﺞ ﺍﻟﱪﻧﺎﻣﺞ: :٠ﻷﻥ ﺍﻟﻌﺪﺩ ٥ﻟﻴﺲ ﺃﻗﻞ ﻣﻦ .٣ :٠ﻷﻥ ﺍﻟﻌﺪﺩ ٥ﻻ ﻳﺴﺎﻭﻱ ﺍﻟﻌﺪﺩ .٣ :١ﻷﻥ ﺍﻟﻌﺪﺩ ٥ﺃﻛﺒﲑ ﻣﻦ .٣ ﺣﻴﺚ ٠ﺗﻌﲏ ﺧﻄﺄ ) (trueﻭ ١ﺗﻌﲏ ﺻﺤﻴﺢ ) ،(falseﻭ ﺃﻳﻀﺎ ﺳﺘﻼﺣﻆ ﺃﻧﻪ ﻛﺘﺒﻨﺎ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟـﺴﺎﺩﺱ ٣==٥ﻭ ﻟـﻴﺲ ٣=٥ﻭ ﺫﻟﻚ ﻷﻧﻨﺎ ﻧﻘﺎﺭﻥ ﻭ ﻋﻨﺪ ﺍﳌﻘﺎﺭﻧﺔ ﻧﻜﺘﺐ == ،ﻭ ﺇﺫﺍ ﻭﺿﻌﺖ = ﻣﻜﺎﻥ == ﻓﺴﻴﺨﱪﻙ ﺍﳌﺘﺮﺟﻢ ﻋﻦ ﻭﺟﻮﺩ ﺧﻄـﺄ .ﻭ ﻳﻮﺟﺪ ﻛﺬﻟﻚ ﺍﳌﺆﺛﺮ ﺃﻛﱪ ﻣﻦ ﺃﻭ ﻳﺴﺎﻭﻱ ﻭ ﳝﺜﻞ ﰲ ﻟﻐﺔ Cﺑـ => ،ﻭ ﻣﺆﺛﺮ ﺃﺻﻐﺮ ﻣﻦ ﺃﻭ ﻳﺴﺎﻭﻱ ﺑــ =< ،ﻭ ﺍﳌـﺆﺛﺮ ﻻ ﻳﺴﺎﻭﻱ ﺑـ =!. ١,٦,٣ﺍﳌﺆﺛﺮﺍﺕ ﺍﳌﻨﻄﻘﻴﺔ ):(logical operators ﻭ ﻫﻲ ﻣﺆﺛﺮﺍﺕ ﺗﻌﺘﻤﺪ ﻋﻠﻰ ﺍﳌﺆﺛﺮﺍﺕ ﺍﻟﻌﻼﻗﻴﺔ ﰲ ﻧﺘﻴﺠﺘﻬﺎ ﻭ ﻟﻜﻦ ﳍﺎ ﺭﻣﻮﺯﻫﺎ ﺍﳋﺎﺻﺔ ﻭ ﻫﻲ: && ﻭ ﺍﻟﱵ ﺗﻌﲏ "ﻭ" || ﻭ ﺍﻟﱵ ﺗﻌﲏ "ﺃﻭ" ! ﻭ ﺍﻟﱵ ﻳﻌﲏ "ﻻ" ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻳﻮﺿﺢ ﺫﻟﻚ: >#include<stdio.h )(main { ;)printf("%d\n", 5<3 && 5>3 ;)printf("%d\n", 5==3 && 3==5 ;)printf("%d\n", 5>3 && 5<3 ;)printf("%d\n", 5<3 || 5>3 ;)printf("%d\n", 5==3 || 3==5 ;)printf("%d\n", 5>3 || 5<3 1 2 3 4 5 6 7 8 9 10 11 12 55 ;))printf("%d\n", !(5<3 ;))printf("%d\n", !(5==3 ;))printf("%d\n", !(5>3 ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٨ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮﺍﺕ ﺍﳌﻨﻄﻘﻴﺔ } 13 14 15 16 ﻧﺘﺎﺋﺞ ﺍﻟﱪﻧﺎﻣﺞ ﻫﻲ: :٠ﻷﻧﻪ ﺗﻮﺟﺪ ﻋﻼﻗﺔ ﺧﺎﻃﺌﺔ ﻭ ﻫﻲ .5<3 :٠ﻷﻥ ﻛﻼ ﺍﻟﻌﻼﻗﺘﲔ ﺧﻄﺎﺀﺗﲔ. :٠ﻷﻧﻪ ﺗﻮﺟﺪ ﻋﻼﻗﺔ ﺧﺎﻃﺌﺔ ﻭ ﻫﻲ .5<3 :١ﻷﻧﻪ ﺗﻮﺟﺪ ﻋﻼﻗﺔ ﺻﺤﻴﺤﺔ ﻭ ﻫﻲ .5>3 :٠ﻷﻥ ﻛﻼ ﺍﻟﻌﻼﻗﺘﲔ ﺧﻄﺎﺀﺗﲔ. :١ﻷﻧﻪ ﺗﻮﺟﺪ ﺍﻟﻌﻼﻗﺔ ﺻﺤﻴﺤﺔ ﻭ ﻫﻲ .5>3 :١ﻷﻥ ٥ﻟﻴﺴﺖ ﺃﺻﻐﲑ ﻣﻦ .٣ :١ﻷﻥ ٥ﻻ ﺗﺴﺎﻭﻱ .٣ :٠ﻷﻥ ٥ﺃﻛﱪ ﻣﻦ .٣ ١,٦,٤ﻣﺆﺛﺮﺍﺕ ﺃﺧﺮﻯ: ﺗﻮﺟﺪ ﻣﺆﺛﺮﺍﺕ ﺃﺧﺮﻯ ﺧﺎﺹ ﺑﻠﻐﺔ Cﻣﻨﻬﺎ :ﺍﳌﺆﺛﺮ << ﻭ ﻳﺴﻤﻰ ﲟﺆﺛﺮ ﺍﻹﺯﺍﺣﺔ ﺍﻟﻴﺴﺎﺭ ،Left Shiftﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﺈﺯﺍﺣﺔ ﺑﺖ ﻭﺍﺣﺪﺓ ﻣﻦ ﺑﻴﺎﺕ )ﺃﻭ ﺑﻴﺘﺎﺕ( ﺇﱃ ﺍﻟﻴﺴﺎﺭ ،ﻣﺜﺎﻝ ﺗﻮﺿﻴﺤﻲ ﻟﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻟﻪ: >#include<stdio.h )(main { ;)printf("%d\n", 1<<7 } ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٩ﻣﺆﺛﺮ ﺍﻹﺯﺍﺣﺔ ﺇﱃ ﺍﻟﻴﺴﺎﺭ ﻫﻨﺎ ﺍﻟﻨﺎﺗﺞ ﺳﻴﻜﻮﻥ ،١٢٨ﻭ ﺍﻟﺼﻮﺭﺓ ﺍﻟﺘﺎﻟﻴﺔ ﺗﻮﺿﺢ ﺫﻟﻚ: 1 2 3 4 5 6 56 ﺍﻟﺸﻜﻞ :١,٦,١ﺍﻹﺯﺍﺣﺔ ﺇﱃ ﺍﻟﻴﺴﺎﺭ ﺍﳌﺆﺛﺮ ﺍﳌﻌﺎﻛﺲ ﻟﺴﺎﺑﻖ ﻫﻮ >> ،ﻭ ﻳﺴﻤﻰ ﲟﺆﺛﺮ ﺍﻹﺯﺍﺣﺔ ﺇﱃ ﺍﻟﻴﻤﲔ ،Right Shiftﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﺗﻮﺿﻴﺤﻲ ﻟﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻟﻪ: >#include<stdio.h )(main { ;)printf("%d\n", 128>>7 } ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ: ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٠ﻣﺆﺛﺮ ﺍﻹﺯﺍﺣﺔ ﺇﱃ ﺍﻟﻴﻤﲔ 1 2 3 4 5 6 ﺍﻟﺸﻜﻞ :١,٦,٢ﺍﻹﺯﺍﺣﺔ ﺇﱃ ﳝﲔ ﺍﳌﺆﺛﺮ ،#ﻭ ﻫﻮ ﻳﺴﺘﻌﻤﻞ ﻣﻊ ﺍﻟﺘﻮﺟﻴﻪ ،#defineﻣﺜﺎﻝ: >#include<stdio.h )"#define printer(str) printf(#str "\n ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ )(main { ;)printer(Hello } # 1 2 3 4 5 6 7 8 9 57 ﺍﳌﺆﺛﺮﻳﻦ ##ﻣﻌﺎ ،ﺃﻳﻀﺎ ﻳﺘﻢ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﻤﺎ ﻣﻊ ﺍﻟﺘﻮﺟﻴﻪ ،#defineﻭ ﳝﻜﻦ ﺗﺴﻤﻴﺘﻬﻤﺎ ﺑﺎﻟـ Mergeﺃﻱ ﺍﻟﺪﻣﺞ ،ﻣﺜﺎﻝ: >#include<stdio.h #define MergingName(str, strplus) str##strplus ;''H ;''e ;''l ;''l ;''o = = = = = )1 )2 )3 )4 )5 MergingName(ch, MergingName(ch, MergingName(ch, MergingName(ch, MergingName(ch, )(main { char char char char char ;)printf("%c%c%c%c%c\n", ch1, ch2, ch3, ch4, ch5 ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮﻳﻦ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ## ١,٦,٥ﻣﺆﺛﺮﺍﺕ ﺧﺎﺻﺔ ﺑﺎﻟﺒﺘﺎﺕ ):(bitwize ﻫﻲ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﳌﺆﺛﺮﺍﺕ ﺧﺎﺻﺔ ﺑﺎﻟﺒﺘﺎﺕ ،bitsﺗﻘﻮﻡ ﺑﺎﳌﻘﺎﺭﻧﺔ ﺑﲔ ﺑﺘﺎﺕ ﺑﺪﻝ ﺍﻟﺒﻴﺘﺎﺕ ،ﻭ ﻫﻲ ﻣﺸﺎﺑﻪ ﻟﻠﻤﺆﺛﺮﺍﺕ ﺍﻟﺴﺎﺑﻘﺔ. ﻧﺒﺪﺃ ﺑﺎﳌﺆﺛﺮ "ﺃﻭ" ORﻭ ﺍﻟﺬﻱ ﻫﻮ ﺍﻟﺮﻣﺰ | ﻭﺣﺪﻩ ،ﻭ ﻗﻠﻨﺎ ﺳﺎﺑﻘﺎ ﺃﻥ ﺍﳌﺆﺛﺮ "ﺃﻭ" ﳛﺘﺎﺝ ﺇﱃ ﺷﺮﻁ ﻭﺍﺣﺪ ﺻـﺤﻴﺢ ،ﺻـﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ: ﺍﻟﺸﻜﻞ :١,٦,٣ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﺃﻭ | OR ﺍﻟﻌﻤﻠﻴﺔ ﻫﻲ ﺇﺫﺍ ﻛﺎﻥ ﺑﺖ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ٠ﻳﻘﺎﺭﻥ ﻣﻊ ﺑﺖ ﺑﻪ ﻗﻴﻤﺔ ٠ﻓﺴﻴﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ﺻﻔﺮ ﻷﻥ ﻛﻼ ﺍﻟﺒﺘﺎﺕ ﳛﺘﻮﻱ ﻋﻠﻰ ﺍﻟﻘﻴﻤـﺔ ٠ﺃﻱ ﺧﻄﺄ ،ﻭ ﺇﺫﺍ ﻛﺎﻥ ﺑﺖ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ٠ﻳﻘﺎﺭﻥ ﻣﻊ ﺑﺖ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ١ﻓﺴﻴﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ﻭﺍﺣﺪ ﻷﻧﻪ ﺗﻮﺟـﺪ ﺍﻟﻘﻴﻤـﺔ ١ﺃﻱ ﺻﺤﻴﺢ ﺣﻴﺚ ﻗﻠﻨﺎ ﺃﻥ ﺍﳌﺆﺛﺮ "ﺃﻭ" ﳛﺘﺎﺝ ﺇﱃ ﻗﻴﻤﺔ ﺻﺤﻴﺤﺔ ﻭﺍﺣﺪﺓ ﺣﱴ ﻳﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ﺻﺤﻴﺢ .ﻣﺜﺎﻝ: >#include<stdio.h )(main { int x = 1; /* 1 decimal = 00000001 Binary*/ ;x = x|4 /* 4 decimal = 00000100 Binary*/ */ = 00000101 Binary, x = 5 decimal*/ ;)printf("x = %d\n", x } 1 2 3 4 5 6 7 8 9 58 ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﺃﻭ | OR ﺑﻌﺪ ﻫﺬﺍ ﺍﳌﺆﺛﺮ ﻳﺄﰐ ﺍﳌﺆﺛﺮ "ﻭ" ANDﻭ ﻳﻜﻮﻥ ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﻟﺮﻣﺰ & ،ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ: ﺍﻟﺸﻜﻞ :١,٦,٤ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﻭ & AND ﳛﺘﺎﺝ ﺍﳌﺆﺛﺮ "ﻭ" ﺇﱃ ﺃﻥ ﺗﻜﻮﻥ ﻛﻼ ﺍﻟﻘﻴﻤﺘﲔ ﺻﺤﻴﺤﺘﲔ ،ﺣﻴﺚ ﺇﺫﺍ ﻛﺎﻧﺖ ﻗﻴﻤﺔ ﺑﺖ ٠ﻭ ﻗﻴﻤﺔ ﺍﻟﺒﺖ ﺍﻟﺜـﺎﱐ ٠ﻓـﺴﻴﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ٠ﻷﻥ ﻛﻼ ﺑﺘﺎﺕ ﺧﺎﻃﺌﲔ ،ﻭ ﺇﺫﺍ ﻛﺎﻧﺖ ﻗﻴﻤﺔ ﺑﺖ ١ﻭ ﺍﻵﺧﺮ ٠ﻓﺄﻳﻀﺎ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ﻷﻥ ﺍﳌـﺆﺛﺮ "ﻭ" ﳛﺘﺎﺝ ﺇﱃ ﻗﻴﻤﺘﲔ ﺻﺤﻴﺤﺘﲔ ،ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻥ ﺑﺖ ١ﻭ ﺍﻵﺧﺮ ١ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻫﻨﺎ ١ﺃﻱ ﺻﺤﻴﺢ .ﻣﺜﺎﻝ: >#include<stdio.h )(main { int x = 1; /* 1 decimal = 00000001 Binary*/ ;x = x&4 /* 4 decimal = 00000100 Binary*/ */ = 00000000 Binary, x = 0*/ ;)printf("x = %d\n", x } ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٤ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﻭ 1 2 3 4 5 6 7 8 9 & AND ﻭ ﺑﻌﺪ ﻫﺬﺍ ﺍﳌﺆﺛﺮ ﺳﻨﺮﻯ ﺍﳌﺆﺛﺮ ،XORﻭ ﻫﻮ ﻟﻴﺲ ﻛﺴﺎﺑﻘﻪ ،ﻭ ﻟﻜﻨﻪ ﻣﺸﺎﺑﻪ ﻟﻠﻤﺆﺛﺮ ORﺇﻻ ﺃﻧﻪ ﺳﻴﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ٠ﺇﺫﺍ ﻛـﺎﻥ ﻛﻼ ﺍﻟﺒﺘﺎﺕ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ،١ﻭ ﺫﻟﻚ ﻋﱪ ﺍﻟﺮﻣﺰ ^ ،ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ: ﺍﻟﺸﻜﻞ :١,٦,٥ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ^ XOR 59 ﻫﻨﺎ ﺇﺫﺍ ﻛﺎﻥ ﺑﺖ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ٠ﻭ ﺍﻟﺜﺎﱐ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ٠ﻓﺴﻴﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ،٠ﻭ ﺇﺫﺍ ﻛﺎﻥ ﺑﺖ ﺑﻪ ﻗﻴﻤﺔ ١ﻭ ﺍﻵﺧﺮ ﺑـﻪ ﺍﻟﻘﻴﻤـﺔ ٠ ﻓﺴﻴﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ،١ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻥ ﻛﻼ ﺍﻟﺒﺘﺎﺕ ﺑﻪ ﺍﻟﻘﻴﻤﺔ ١ﻓﺴﻴﻜﻮﻥ ﺍﻟﻨﺎﺗﺞ ٠ﺃﻱ ﺧﺎﻃﺊ ﻭ ﻫﺬﺍ ﻫﻮ ﺍﻟﻔﺮﻕ ﺑﲔ ﻫﺬﺍ ﺍﳌﺆﺛﺮ ﻭ ﻣﺆﺛﺮ .ORﻣﺜﺎﻝ: >#include<stdio.h )(main { int x = 4; /* 4 decimal = 00000100 Binary*/ ;x = x^4 /* 4 decimal = 00000100 Binary*/ */ = 00000000 Binary, x = 0*/ ;)printf("x = %d\n", x } ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٥ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ 1 2 3 4 5 6 7 8 9 ^ XOR ﻭ ﺃﺧﲑﺍ ﺍﳌﺆﺛﺮ "ﻻ" NOTﻋﱪ ﺍﻟﺮﻣﺰ ~ ،ﻭ ﻻ ﻳﺴﺘﻌﻤﻞ ﻫﺬﺍ ﺍﳌﺆﺛﺮ ﻟﻮﺣﺪﻩ ،ﻭ ﻳﺴﺘﻌﻤﻞ ﺑﻜﺜﺮ ﻣﻊ ﺍﳌﺆﺛﺮ "ﻭ" ANDﻟﺘﺜﺒﻴﺖ ﺑﺖ ﻣﺎ ﻋﻠﻰ ٠ﺑﺪﻭﻥ ﺍﻟﺘﺄﺛﲑ ﻋﻠﻰ ﺑﺎﻗﻲ ﺍﻟﺒﺘﺎﺕ .ﻭ ﻣﺜﺎﻻ ﻋﻠﻰ ﺫﻟﻚ ﺇﺫﺍ ﻛﺎﻥ ﻟﺪﻳﻦ ﺍﻟﻘﻴﻤﺔ ١ﰲ ﺑﺖ ﺛﺎﻟﺚ ﻧﺮﻳﺪ ﺗﺼﻔﲑﻩ ﻓﺴﻴﻜﻮﻥ ﺫﻟﻚ ﻛﺘﺎﱄ: >#include<stdio.h )(main { int x = 5; /* 5 decimal = 101 Binary*/ x = x& ~4; /* 4 decimal = 100 Binary*/ */ = 001 Binary, x = 1*/ ;)printf("x = %d\n", x } ١,٦,٦ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٦ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﻻ ﻻ ﺗﻮﺟﺪ ﺃﺧﻄﺎﺀ ﳏﺘﻤﻠﺔ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ. ١,٦,٧ﲤﺎﺭﻳﻦ: .١ﻫﻞ ﳝﻜﻦ ﺃﻥ ﻧﻘﻮﻡ ﺑﺎﻟﺘﺰﺍﻳﺪ ﻭ ﺍﻟﺘﻨﺎﻗﺺ ﺩﺍﺧﻞ ﺍﻟﺪﺍﻟﺔ printf؟ .٢ﻣﺎﺫﺍ ﺗﻌﲏ ﺍﻟﻘﻴﻤﺔ ٠ﻭ ﺍﻟﻘﻴﻤﺔ ١ﰲ ﺍﳌﺆﺛﺮﺍﺕ ﺍﻟﻌﻼﻗﻴﺔ ؟ .٣ﻣﺎﺫﺍ ﺗﻌﲏ ﻛﻞ ﻣﻦ && ﻭ || ﻭ ! ؟ ~ NOT 1 2 3 4 5 6 7 8 9 60 ﺗﺴﺘﻌﻤﻞ ﺍﻟﻘﺮﺍﺭﺍﺕ )ﻭ ﳝﻜﻦ ﺗﺴﻤﻴﺘﻬﺎ ﺑﺎﳉﻤﻞ ﺍﻟﺸﺮﻃﻴﺔ( ﻟﻠﻤﻘﺎﺭﻧﺔ ﺑﲔ ﻋﻼﻗﺔ ﺣﻴﺚ ﺗﻜﻮﻥ ﺇﻣﺎ ﺻﺤﻴﺤﺔ ﺃﻭ ﺧﺎﻃﺌﺔ ،ﰲ ﻛﻞ ﻣﻦ ﺣﺎﻟﺔ ﳍﺎ ﺃﻭﺍﻣﺮ ﺧﺎﺻﺔ ﻧﻘﻮﻡ ﺑﺘﺤﺪﻳﺪﻫﺎ ،ﻣﺜﻼ ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﳌﻘﺎﺭﻧﺔ ﺻﺤﻴﺢ ﻓﺴﻴﺘﻢ ﺗﻨﻔﻴﺬ ﺍﻷﻭﺍﻣﺮ ﺍﻟﱵ ﺣﺪﺩﻧﺎﻫﺎ ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﳌﻘﺎﺭﻧﺔ ﺻﺤﻴﺤﺔ ،ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﳌﻘﺎﺭﻧﺔ ﺧﺎﻃﺌﺔ ﻓﺴﻴﺘﻢ ﺗﻨﻔﻴﺬ ﺍﻷﻭﺍﻣﺮ ﺍﳌﻌﺎﻛﺴﺔ. ١,٧,١ﺍﺳﺘﻌﻤﺎﻝ :if ﻟﻜﻲ ﺗﻔﻬﻢ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ifﺃﻟﻘﻲ ﻧﻈﺮﺓ ﻋﻠﻰ ﺍﻟﺼﻮﺭﺓ ﺍﻟﺘﺎﻟﻴﺔ: ﺍﻟﺸﻜﻞ :١,٧,١ﻃﺮﻳﻘﺔ ﺇﻋﻼﻥ ﺷﺮﻁ ﺫﺍﺕ ﺃﻣﺮ ﻭﺍﺣﺪ ﺍﻟﺼﻮﺭﺓ ﺍﻟﺴﺎﺑﻘﺔ ﻳﻮﺟﺪ ﺎ ﻣﺜﺎﻝ ﺑﺪﻭﻥ ﺍﻟﺮﻣﺰ { ﻭ } ﻷﻧﻪ ﻻ ﻳﻮﺟﺪ ﺳﻮﻯ ﺃﻣﺮ ﻭﺍﺣﺪ ﻟﺘﻨﻔﻴﺬﻩ ،ﻭ ﻫﺬﻩ ﺻﻮﺭﺓ ﰲ ﺣﺎﻟﺔ ﻭﺟـﻮﺩ ﺃﻛﺜﺮ ﻣﻦ ﺃﻣﺮ: ﺍﻟﺸﻜﻞ :١,٧,٢ﻃﺮﻳﻘﺔ ﺇﻋﻼﻥ ﺷﺮﻁ ﺫﺍﺕ ﻋﺪﺓ ﺃﻭﺍﻣﺮ ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;int usr_val ;)" printf("Enter a value: ;)scanf("%d", &usr_val 1 2 3 4 5 6 7 8 61 )if(usr_val <100 { ;)printf("%d are less than 100\n", usr_val } )if(usr_val >100 { ;)printf("%d are great than 100\n", usr_val } ﺍﻟﱪﻧﺎﻣﺞ :١,٧,١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ } 9 10 11 12 13 14 15 16 17 18 19 if ﰲ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﻃﻠﺒﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﻗﻴﻤﺔ ،ﰒ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﺸﺮﻁ ﺃﻭ ﺍﳌﻘﺎﺭﻧﺔ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﻭ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻋﺸﺮ ﻭ ﻫﻮ ﺍﳌﻘﺎﺭﻧﺔ ﺑﲔ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﺃﺩﺧﻠﻬﺎ ﺍﳌﺴﺘﺨﺪﻡ ﻭ ،١٠٠ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﳌﻘﺎﺭﻧﺔ ﺻﺤﻴﺤﺔ ﻓﺴﻴﻘﻮﻡ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺘﻨﻔﻴﺬ ﻣﺎ ﻫﻮ ﺩﺍﺧﻞ ﺍﻟـ blockﺍﳋﺎﺹ ﺑـ ،ifﻭ ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﳌﻘﺎﺭﻧﺔ ﺧﺎﻃﺌﺔ ﻓﺴﻴﺘﻢ ﲡﺎﻫﻞ ﻣﺎ ﻫﻮ ﺩﺍﺧﻞ ﺍﻟـ blockﺍﻟﺬﻱ ﻳﻠﻲ .ifﻭ ﳝﻜـﻦ ﻛﺘﺎﺑﺔ ﺍﻟﱪﻧﺎﻣﺞ ﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ: >#include<stdio.h )(main { ;int usr_val ;)" printf("Enter a value: ;)scanf("%d", &usr_val )if(usr_val <100 ;)printf("%d are less than 100\n", usr_val )if(usr_val >100 ;)printf("%d are great than 100\n", usr_val ﺍﻟﱪﻧﺎﻣﺞ :١,٧,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ (٢) if ﻷﻧﻪ ﰲ ﻛﻼ ﺍﻟﺸﺮﻃﲔ ﻻ ﻳﻮﺟﺪ ﻤﺎ ﺇﻻ ﺃﻣﺮ ﻭﺍﺣﺪ. } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ١,٧,٢ﺍﺳﺘﻌﻤﺎﻝ :else ﺗﺴﺘﻌﻤﻞ ﺍﻟﻜﻠﻤﺔ elseﻣﻊ ﺍﻟﻜﻠﻤﺔ ifﺩﺍﺋﻤﺎ ﺣﻴﺚ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻟﻮﺣﺪﻫﺎ ،ﺳـﻨﻜﺘﺐ ﺍﻵﻥ ﺍﻟﱪﻧـﺎﻣﺞ ﺍﻟـﺴﺎﺑﻖ ﺑﺎﺳﺘﺨﺪﺍﻡ :else >#include<stdio.h )(main { 1 2 3 4 62 ;int usr_val ;)" printf("Enter a value: ;)scanf("%d", &usr_val )if(usr_val<100 ;)printf("%d are less than 100\n", usr_val else ;)printf("%d are great than 100\n", usr_val ﺍﻟﱪﻧﺎﻣﺞ :١,٧,٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ } 5 6 7 8 9 10 11 12 13 14 else ﺍﺳﺘﻌﻤﻠﻨﺎ elseﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﱐ ﻋﺸﺮ ﻭ ﺳﺘﺮﻯ ﺃﻥ ﺍﳌﺜﺎﻝ ﺳﻴﻌﻤﻞ ﻣﺜﻞ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﻭ ﻫﻨﺎ ﲡﺪ ﻓﺎﺋﺪﺓ .elseﺇﻥ ﱂ ﺗﻜـﻦ ﺍﳌﻘﺎﺭﻧﺔ ﺻﺤﻴﺢ ﰲ ifﻓﺴﻴﺘﻢ ﺗﻨﻔﻴﺬ .elseﻭ ﻫﺬﻩ ﺻﻮﺭﺓ ﺗﻮﺿﺢ ﻟﻄﺮﻳﻘﺔ ﻋﻤﻠﻬﻤﺎ: ﺍﻟﺸﻜﻞ :١,٧,٣ﻃﺮﻳﻘﺔ ﻋﻤﻞ ifﻭ else ١,٧,٣ﺍﺳﺘﻌﻤﺎﻝ :else…if ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﻟﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ elseﺇﺫﺍ ﻗﻤﺖ ﺑﺘﻨﻔﻴﺬ ﺍﻟﱪﻧﺎﻣﺞ ﻭ ﺃﻋﻄﻴﺘﻪ ﺍﻟﻘﻴﻤﺔ ١٠٠ﻓﺴﻴﻘﻮﻝ ﻟﻚ ﺃﻥ ﺍﻟﻨﺘﻴﺠﺔ ﺍﻟـﱵ ﺃﺩﺧﻠﺘﻬﺎ ﺃﻛﱪ ﻣﻦ ،١٠٠ﻭ ﻟﺘﻔﺎﺩﻱ ﻫﺬﺍ ﺍﳌﺸﻜﻠﺔ ﻧﺴﺘﻌﻤﻞ ﺍﻟﻜﻠﻤﺘﲔ else…ifﻣﻌﺎ ،ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻳﻮﺿﺢ ﺫﻟﻚ: >#include<stdio.h 1 2 63 )(main { ;int usr_val ;)" printf("Enter a value: ;)scanf("%d", &usr_val )if(usr_val<100 ;)printf("%d are less than 100\n", usr_val )else if(usr_val==100 ;)printf("%d are equal 100\n", usr_val else ;)printf("%d are great than 100\n", usr_val ﺍﻟﱪﻧﺎﻣﺞ :١,٧,٤ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ } 3 4 5 6 7 8 9 10 11 12 13 14 15 16 else…if ﻭ ﻃﺮﻳﻘﺔ ﻋﻤﻞ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﻫﻮ ﺍﳌﻘﺎﺭﻧﺔ ﺑﲔ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﺃﺩﺧﻠﻬﺎ ﺍﳌﺴﺘﺨﺪﻡ ﻭ ١٠٠ﻓﺈﺫﺍ ﻛﺎﻧﺖ ﺃﻗﻞ ﻣﻦ ١٠٠ﻓﺴﻨﻄﺒﻊ ﻣﺎ ﻫـﻮ ﻣﻮﺟﻮﺩ ﰲ blockﺍﳋﺎﺹ ﺑﺎﳌﻘﺎﺭﻧﺔ ،ﻭ ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﻟﻘﻴﻤﺔ ﺃﻛﱪ ﻣﻦ ١٠٠ﻓﺴﻴﺘﻢ ﺍﻻﻧﺘﻘﺎﻝ ﺇﱃ ﺍﳌﻘﺎﺭﻧﺔ ﺍﻟﺜﺎﻧﻴﺔ ﻭ ﻫﻲ ﺇﺫﺍ ﻛـﺎﻥ ﺍﻟﻌﺪﺩ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ ﻳﺴﺎﻭﻱ ،١٠٠ﰲ ﺣﺎﻟﺔ ﺃﺎ ﺻﺤﻴﺢ ﻳﻘﻮﻡ ﺍﻟﱪﻧﺎﻣﺞ ﺑﻄﺒﺎﻋﺔ ﻣﺎ ﻫﻮ ﻣﻮﺟﻮﺩ ﰲ blockﺍﳋـﺎﺹ ﺑﺎﳌﻘﺎﺭﻧﺔ ﺍﻟﺜﺎﻧﻴﺔ ،ﰲ ﺣﺎﻟﺔ ﺃﻥ ﻛﻼ ﺍﳌﻘﺎﺭﻧﺘﲔ ﺧﺎﻃﺌﺔ ﻓﺴﻴﺘﻢ ﺗﻨﻔﻴﺬ ﻣﺎ ﻫﻮ ﻣﻮﺟﻮﺩ ﰲ ﺍﻟـ blockﺍﳋﺎﺹ ﺑـ .else ١,٧,٤ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: .١ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ elseﻣﺮﺗﲔ ﳌﻘﺎﺭﻧﺔ ﻭﺍﺣﺪﺓ. .٢ﻻ ﳝﻜﻦ ﺍﺳﺘﺨﺪﺍﻡ elseﺑﺪﻭﻥ .if ١,٧,٥ﲤﺎﺭﻳﻦ: .١ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﺎﳌﻘﺎﺭﻧﺔ ﺑﲔ ﻋﻤﺮ ﺍﳌﺴﺘﺨﺪﻡ ﻭ ﺍﻟﻌﺪﺩ ،٤٠ﺇﺫﺍ ﻛﺎﻥ ﻋﻤﺮ ﺍﳌﺴﺘﺨﺪﻡ ﺃﻗﻞ ﻣﻦ ٤٠ﳜﱪﻩ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺄﻥ ﻋﻤﺮﻩ ﺃﻗﻞ ﻣﻦ ﺍﻷﺭﺑﻌﲔ ،ﻭ ﰲ ﺣﺎﻟﺔ ﺍﻟﻌﻜﺲ ﳜﱪﻩ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺄﻥ ﻋﻤﺮﻩ ﺃﻛﱪ ﻣﻦ ،٤٠ﻭ ﺇﺫﺍ ﻛﺎﻥ ﻋﻤﺮﻩ ﺃﺭﺑﻌﲔ ﳜﱪﻩ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺄﻥ ﻋﻤﺮﻩ ٤٠ﺳﻨﺔ. .٢ﺃﻛﺘﺐ ﻧﻔﺲ ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺴﺎﺑﻘﺔ ﻭ ﻟﻜﻦ ﺑﺪﻭﻥ ﺍﺳﺘﻌﻤﺎﻝ .else .٣ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻄﻠﺐ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﻗﻴﻤﺔ ﻻ ﺗﺘﻌﺪﻯ ﺍﻟﻌﺪﺩ ،٩ﻭ ﻋﻨﺪ ﺇﺩﺧﺎﻝ ﺃﻱ ﻋﺪﺩ ﳜﱪﻩ ﺍﻟﱪﻧﺎﻣﺞ ﺃﻧﻪ ﻗﺪ ﺃﺩﺧﻞ ﺫﻟﻚ ﺍﻟﻌﺪﺩ )ﺑﺎﺳﺘﻌﻤﺎﻝ .(else…if 64 ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ ﺳﻨﺘﻌﺮﻑ ﻋﻠﻰ ﻋﻨﺎﺻﺮ ﻟﻐﺔ Cﻭ ﺍﻟﱵ ﻫﻲ: ١,٨,١ﺍﻟﺘﻌﻠﻴﻘﺎﺕ :Comments ﻫﻲ ﻣﻦ ﻋﻨﺎﺻﺮ ﻟﻐﺔ Cﻭ ﻗﺪ ﺩﺭﺳﻨﻬﺎ ﺳﺎﺑﻘﺎ .ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﻫﻲ ﺳﻠﺴﻠﺔ ﻣﻦ ﺍﻟﺮﻣﻮﺯ ﺗﺒﺪﺃ ﺑﺎﻟﺮﻣﺰ / slashﻭ ﺍﻟﻨﺠﻤﺔ * ﻭ ﺗﻨﺘﻬﻲ ﺑﻨﺠﻤﺔ ﻭ ،/* slashﻭ ﳝﻜﻦ ﺃﻥ ﳛﻤﻞ ﺍﻟﺘﻌﻠﻴﻖ ﺃﻱ ﺭﻣﻮﺯ ﺃﻭ ﺃﺭﻗﺎﻡ .ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﺴﺎﺑﻘﺔ ﻫﻲ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﻮﺣﻴﺪﺓ ﰲ ﻟﻐﺔ ،Cﻭ ﻟﻜـﻦ ﺍﻟﻜﺜﲑ ﻣﻦ ﺍﳌﺘﺮﲨﺎﺕ ﺗﺪﻋﻢ ﻃﺮﻳﻘﺔ ﺃﺧﺮﻯ ﻣﻦ ﺍﻟﺘﻌﻠﻴﻖ ﻭ ﻫﻲ ﺍﻟﺘﻌﻠﻴﻖ ﺍﻟﺴﻄﺮﻱ ﺣﻴﺚ ﻳﺒﺪﺃ ﺑﺎﻟﺮﻣﺰﻳﻦ .// ١,٨,٢ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ :Keywords ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ ﻫﻲ ﻛﻠﻤﺎﺕ ﺃﺳﺎﺳﻴﺔ ﰲ ﺍﻟﻠﻐﺔ ﻭ ﺍﻟﱵ ﻳﻜﻮﻥ ﻟﻮﺎ ﰲ ﺃﻏﻠﺐ ﺍﳌﺘﺮﲨﺎﺕ ﺃﺯﺭﻕ ،ﻭ ﲰﻴﺖ ﺑﺎﻟﻜﻠﻤـﺎﺕ ﺍﶈﺠﻮﺯﺓ ﻷﺎ ﳏﺠﻮﺯﺓ ﺳﺎﺑﻘﺎ ،ﻛﻞ ﻣﻦ if ،double ،char ،intﻭ elseﺗﻌﺘﱪ ﻛﻠﻤﺎﺕ ﳏﺠﻮﺯﺓ ﻭ ﺍﻟﻜﺜﲑ ﻣﻨﻬﺎ ،ﻭ ﻫﺬﺍ ﺟﺪﻭﻝ ﳉﻤﻴﻊ ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ ﺍﻷﺳﺎﺳﻴﺔ ﰲ ﻟﻐﺔ :C float static default goto struct case switch extern void typedef union enum return continue break sizeof volatile for while do else register auto const ﺍﳉﺪﻭﻝ :١,٨,١ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ ﻟﻠﻐﺔ char signed unsigned if int short long double C ﻭ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ،asmﻋﺪﺩﻫﺎ ،٣٣ﻭ ﺳﻨﺪﺭﺱ ﲨﻴﻊ ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ ﰲ ﺍﻟﺪﺭﻭﺱ ﺍﻟﻘﺎﺩﻣﺔ. ١,٨,٣ﺍﳌﻌﺮﻓﺎﺕ :Identifiers ﺍﳌﻌﺮﻓﺎﺕ ﻫﻲ ﺳﻠﺴﻠﺔ ﻣﻦ ﺣﺮﻭﻑ ﺃﻭ ﺃﺭﻗﺎﻡ ،ﺑﺪﺍﻳﺘﻬﺎ ﳚﺐ ﺃﻥ ﺗﻜﻮﻥ ﺣﺮﻓﺎ ،ﻭ ﻻ ﳝﻜﻦ ﺃﻥ ﻳﺒﺪﺃ ﺍﺳﻢ ﺍﳌﻌﺮﻑ ﺑﺮﻗﻢ ،ﺍﻟﺮﻣﺰ _ ﻭ ﺍﻟﺬﻱ ﻳﺪﻋﻰ underscoreﻳﻌﺘﱪ ﺣﺮﻓﺎ ،ﻭ ﻻ ﳝﻜﻦ ﺃﻥ ﻳﺘﻌﺪﻯ ﺍﺳﻢ ﺍﳌﻌﺮﻑ ﺃﻛﺜﺮ ﻣﻦ ٣١ﺣﺮﻓﺎ ،ﻛﻞ ﻣـﻦ ﺍﻷﺣـﺮﻑ ﺍﻟﺼﻐﲑ ﻭ ﺍﻷﺧﺮ ﺍﻟﻜﺒﲑﺓ ﳐﺘﻠﻔﺔ ،ﻭ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻣﻌﺮﻑ ﻣﺮﺗﲔ .ﺟﺪﻭﻝ ﻟﻸﺣﺮﻑ ﺍﻟﱵ ﳝﻜﻦ ﺃﻥ ﺗـﺴﺘﻌﻤﻞ ﰲ ﺃﲰـﺎﺀ ﺍﳌﻌﺮﻓﺎﺕ: ﺍﻷﺣﺮﻑ a b c d e f g h i j k l m n o p q r s t u v w x _ y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ﺍﻷﺭﻗﺎﻡ ٩٨٧٦٥٤٣٢١٠ 65 ١,٨,٣,١ﺳﻼﺳﻞ :Trigraphs ﺍﳉﺪﻭﻝ :١,٨,٢ﺣﺪﻭﺩ ﺃﲰﺎﺀ ﺍﳌﻌﺮﻓﺎﺕ ﻫﻲ ﺳﻼﺳﻞ ﻣﻜﻮﻧﺔ ﻣﻦ ﺛﻼﺛﺔ ﺭﻣﻮﺯ ﻳﻘﻮﻡ ﺍﳌﺘﺮﺟﻢ ﺑﺎﺳﺘﺒﺪﺍﳍﺎ ﺇﱃ ﺭﻣﻮﺯ ﺑﺪﻳﻠﻴﻪ ،ﻭ ﻫﺬﺍ ﺟﺪﻭﻝ ﺗﻮﺿﻴﺤﻲ ﳍﺬﻩ ﺍﻟﺮﻣﻮﺯ: Trigraphs ﺍﻟﺮﻣﺰ ﺍﻟﺬﻱ ﻳﻘﺎﺑﻠﻪ =?? <?? >?? (?? )?? ??/ ’?? !?? ??- # { } [ ] \ ^ | ~ ﺍﳉﺪﻭﻝ :١,٨,٣ Trigraphs ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻳﻮﺿﺢ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺗﻠﻚ ﺍﻟﺮﻣﻮﺯ: >??=include<stdio.h )(main <?? ;)"printf("Hello, World!\n >?? ﺍﻟﱪﻧﺎﻣﺞ :١,٨,١ﺇﺳﺘﻌﻤﺎﻝ ﺭﻣﻮﺯ 1 2 3 4 5 6 Trigraphs ﻭ ﺍﻟﱪﻧﺎﻣﺞ ﻳﻌﻤﻞ ﺑﺪﻭﻥ ﺃﺧﻄﺎﺀ ،ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﺍﺳﺘﻌﻤﺎﻝ ﺗﻠﻚ ﺍﻟﺮﻣﻮﺯ ﺩﺍﺧﻞ ﺍﻟﻨﺼﻮﺹ ﻣﺜﻞ: >#include<stdio.h )(main { ;)"printf("??=\n ;)"printf("??<\n ;)"printf("??>\n ;)"printf("??(\n ;)"printf("??)\n ;)"printf("??//\n ;)"printf("??'\n ;)"printf("??!\n ;)"printf("??-\n } ١,٨,٤ﺍﻟﺜﻮﺍﺑﺖ :Constants ﺍﻟﱪﻧﺎﻣﺞ :١,٨,٢ﺇﺳﺘﻌﻤﺎﻝ ﺭﻣﻮﺯ (٢) Trigraphs 1 2 3 4 5 6 7 8 9 10 11 12 13 14 66 ﺍﻟﺜﻮﺍﺑﺖ ﺗﻜﻮﻥ ﺇﻣﺎ ﺃﺭﻗﺎﻡ ﺃﻭ ﺃﺣﺮﻑ ﺃﻭ ﺳﻼﺳﻞ ﺣﺮﻓﻴﺔ ،ﻻ ﳝﻜﻦ ﺍﻟﺘﻐﲑ ﻓﻴﻬﺎ ﺃﺛﻨﺎﺀ ﺍﻟﱪﻧﺎﻣﺞ ،ﻭ ﺗﻮﺟﺪ ﻧﻮﻋﺎﻥ ﻣﻨﻬﺎ ﻭ ﻫﻲ: ١,٨,٤,١ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﻨﺼﻴﺔ: ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﻨﺼﻴﺔ ﻫﻲ ﺗﻜﻮﻥ ﺇﻣﺎ ﺑﺎﻻﺳﺘﻌﻤﺎﻝ ﺍﳌﻮﺟﻪ #defineﺃﻭ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ،constﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﻤﻮﺟﻪ ﻓﻬﺬﺍ ﻣﺜﺎﻝ ﻟﻪ: #define >#include<stdio.h "#define Const_Str "Hello, World!\n )(main { ;)printf(Const_Str /*can't write Const_Str = "Hello, World2!\n"*/ } ﺍﻟﱪﻧﺎﻣﺞ :١,٨,٣ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﻨﺼﻴﺔ 1 2 3 4 5 6 7 8 9 10 ﻭ ﺃﻱ ﻧﺼﻮﺹ ﺃﻭ ﺃﺣﺮﻑ ﻣﻌﺮﻓﺔ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﳌﻮﺟﻪ #defineﻓﻬﻲ ﺛﺎﺑﺘﺔ ﻭ ﻻ ﳝﻜﻦ ﺍﻟﺘﻐﲑ ﻓﻴﻬﺎ .ﺃﻣﺎ ﺍﻟﺜﻮﺍﺑـﺖ ﺑﺎﺳـﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ constﻓﺴﺄﻋﻄﻲ ﻣﺜﺎﻝ ﳊﺮﻑ ﺛﺎﺑﺖ ،ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;'const char ch = 'a ;)printf("%c\n", ch /*you can't use this: ;'ch = 'b ;)printf("%c\n", ch because it's a constant*/ } ﺍﻟﱪﻧﺎﻣﺞ :١,٨,٤ﺛﺎﺑﺖ ﺣﺮﰲ 1 2 3 4 5 6 7 8 9 10 11 12 13 ﺃﻣﺎ ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﻨﺼﻴﺔ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ constﻓﺴﻨﺪﺭﺳﻬﺎ ﻓﻴﻤﺎ ﺑﻌﺪ .ﻭ ﺗﻮﺟﺪ ﺭﻣﻮﺯ ﺛﺎﺑﺘﺔ ﺃﺧﺮﻯ ﺧﺎﺻﺔ ﺑﻠﻐﺔ Cﻭ ﻫﻲ ﻣﻮﺿﺤﺔ ﻋﻠﻰ ﺍﳉﺪﻭﻝ ﺍﻟﺘﺎﱄ: ﺍﻟﺘﺄﺛﲑ ﻃﺒﺎﻋﺔ ﺍﻟﺮﻣﺰ ' ﺍﻟﺮﻣﺰ ﺍﻟﺘﺄﺛﲑ ﺍﻟﺮﻣﺰ ’\ ﺍﻹﻧﺬﺍﺭ ،ﺗﻘﻮﻡ ﺑﺈﺻﺪﺍﺭ ﺻﻮﺕ ﻣﻦ \a 67 ﺍﻟﻠﻮﺣﺔ ﺍﻷﻡ، Alert ﻃﺒﺎﻋﺔ ﺍﻟﺮﻣﺰ " "\ ﺍﻟﻔﻀﺎﺀ ﺍﳋﻠﻔﻲ، Backspace \b ﻃﺒﺎﻋﺔ ﺍﻟﺮﻣﺰ ? ?\ ﺻﻔﺤﺔ ﺟﺪﻳﺪﺓ، Form feed \f ﻃﺒﺎﻋﺔ ﺍﻟﺮﻣﺰ \ \\ ﺳﻄﺮ ﺟﺪﻳﺪ، New line \n ﻷﻋﺪﺍﺩ ﻧﻈﺎﻡ ﺍﻟﺜﻤﺎﱐ \0oo ﻷﻋﺪﺍﺩ ﻧﻈﺎﻡ ﺍﻟﺴﺪﺍﺳﻲ ﻋﺸﺮ \xhh ﺍﻟﻌﻮﺩﺓ ﲟﺆﺷﺮ ﺍﻟﻜﺘﺎﺑﺔ ﺇﱃ ﺑﺪﺍﻳﺔ ﺍﻟﺴﻄﺮ، Carriage return \r ٨ﻓﺮﺍﻏﺎﺕ ﰲ ﺍﻻﲡﺎﻩ ﺍﻷﻓﻘﻲ \t ٨ﻓﺮﺍﻏﺎﺕ ﰲ ﺍﻻﲡﺎﻩ ﺍﻟﻌﻤﻮﺩﻱ \v ﺍﳉﺪﻭﻝ :١,٨,٤ﺛﻮﺍﺑﺖ ﺧﺎﺻﺔ ﺑﻠﻐﺔ C ١,٨,٤,٢ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﺮﻗﻤﻴﺔ: ﻫﻲ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﻮﺍﺑﺖ ﺎ ﻗﻴﻢ ﺛﺎﺑﺘﺔ ﻻ ﳝﻜﻦ ﺍﻟﺘﺤﺪﻳﺚ ﻓﻴﻬﺎ ﺃﺛﻨﺎﺀ ﺍﻟﱪﻧﺎﻣﺞ ،ﻭ ﳝﻜﻦ ﺃﻥ ﺗﻜﻮﻥ ﺃﻱ ﻧﻮﻉ ﻣـﻦ ﺍﻷﻋـﺪﺍﺩ ،short, long, int, unsigned, signed, float, doubleﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ ﰲ ﻛـﻞ ﻣـﻦ ﺍﳌﻮﺟـﻪ #defineﻭ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ،constﻣﺜﺎﻝ ﺣﻮﻝ ﺍﳌﻮﺟﻪ :#define >#include<stdio.h #define Const_Num 5 )(main { ;)printf("%d\n", Const_Num /*can't write Const_Num = 6;*/ ﺍﻟﱪﻧﺎﻣﺞ :١,٨,٥ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﺮﻗﻤﻴﺔ } 1 2 3 4 5 6 7 8 9 10 ﻋﻨﺪ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﻮﺍﺑﺖ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﳌﻮﺟﻪ #defineﻓﺈﻧﻨﺎ ﻻ ﻧﻘﻮﻡ ﺑﺘﺤﺪﻳﺪ ﻧﻮﻋﻪ ،ﺍﳌﻮﺟﻪ ﻧﻔﺴﻪ ﻳﻘﻮﻡ ﺑﺘﺤﺪﻳﺪ ﻧﻮﻉ ﺍﻟﻘﻴﻤﺔ ﺍﳌﺪﺧﻠﺔ .ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ :const >#include<stdio.h )(main { ;int Const_Num = 5 ;)printf("%d\n", Const_Num /*can't write Const_Num = 6;*/ } 1 2 3 4 5 6 7 8 9 68 ١,٨,٥ﺍﻟﺮﻣﻮﺯ :Tokens ﺍﻟﱪﻧﺎﻣﺞ :١,٨,٦ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﺮﻗﻤﻴﺔ )(٢ ﻫﻲ ﺳﺘﺔ ﻓﺌﺎﺕ ﻭ ﻫﻲ :ﺍﳌﻌﺮﻓﺎﺕ ،ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ ،ﺍﻟﺜﻮﺍﺑﺖ ،ﺍﻟﺴﻼﺳﻞ ﺍﻟﻨﺼﻴﺔ ،ﺍﳌﺆﺛﺮﺍﺕ ﻭ ﺍﻟﻔﻮﺍﺻﻞ. ١,٨,٦ﺍﻟﺴﻼﺳﻞ ﺍﻟﻨﺼﻴﺔ :String literals ﺍﻟﺴﻼﺳﻞ ﺍﻟﻨﺼﻴﺔ ﺃﻱ ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﻨﺼﻴﺔ ،ﻫﻲ ﺳﻼﺳﻞ ﻣﻦ ﺣﺮﻭﻑ ﳏﺎﻃﺔ ﺑﺎﻗﺘﺒﺎﺳﻴﲔ " ،"...ﺳﺘﻔﻬﻢ ﻫﺬﺍ ﺍﳉﺰﺀ ﻣﻦ ﺍﻟﺪﺭﻭﺱ ﺍﻟﻘﺎﺩﻣﺔ. ١,٨,٧ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: ﻻ ﺗﻮﺟﺪ ﺃﺧﻄﺎﺀ ﳏﺘﻤﻠﺔ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ. ١,٨,٨ﲤﺎﺭﻳﻦ: ﻻ ﺗﻮﺟﺪ ﲤﺎﺭﻳﻦ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ. 69 ﻣﺎ ﺩﺭﺳﻨﺎﻩ ﺣﱴ ﺍﻵﻥ ﻫﻮ ﺟﺰﺀ ﺷﺒﻪ ﻛﺒﲑ ﻣﻦ ﻟﻐﺔ ،Cﻭ ﰲ ﻫﺬﺍ ﺍﳌﻠﺨﺺ ﺳﻨﺤﺎﻭﻝ ﺗﻐﻄﻴﺔ ﻭ ﻓﻬﻢ ﺃﻛﺜﺮ ﳌﺎ ﺩﺭﺳﻨﺎﻩ. ﺩﺭﺳﻨﺎ ﻣﻦ ﻗﺒﻞ ﺍﻟﺪﺍﻟﺔ ،printfﻭ ﻗﻠﻨﺎ ﺃﺎ ﺧﺎﺻﺔ ﺑﺎﻹﺧﺮﺍﺝ ،ﻭ ﻫﻨﺎ ﺗﻮﺟﺪ ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ ﻟﻄﺮﻳﻘﺔ ﺗﻌﺎﻣﻞ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻣـﻊ ﺭﻣﻮﺯ ﻣﺜﻞ ،%dﺍﻟﺼﻮﺭﺓ: ﺍﻟﺸﻜﻞ :١,٩,١ﻃﺮﻳﻘﺔ ﻋﻤﻞ ﺍﻟﺪﺍﻟﺔ printf ﻣﻦ ﺍﻟﺼﻮﺭﺓ ﻧﻔﻬﻢ ﺃﻧﻪ ﻋﻨﺪ ﺗﺸﻐﻴﻞ ﺍﻟﱪﻧﺎﻣﺞ ﻳﺘﻢ ﺍﺳﺘﺒﺪﺍﻝ ﺍﻟﻘﻴﻢ ﺍﳌﺪﺧﻞ ﺃﻭ ﺍﻟﻘﻴﻢ ﺍﳌﻌﻄﺎﺓ ﰲ ﻣﻜﺎﻥ ﺍﻟﺮﻣﺰ ،%dﻭ ﺃﻳﻀﺎ ﻧﻔـﺲ ﺍﻟﻔﻜﺮﺓ ﻣﻊ ﺍﻟﺪﺍﻟﺔ ،scanfﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ: ﺍﻟﺸﻜﻞ :١,٩,٢ﻃﺮﻳﻘﺔ ﻋﻤﻞ ﺍﻟﺪﺍﻟﺔ scanf ١,٩,١ﺑﺮﺍﻣﺞ ﺗﺪﺭﻳﺒﻴﺔ: ﰲ ﻫﺬﺍ ﺍﳉﺰﺀ ﻣﻦ ﺍﻟﺪﺭﺱ ﺳﻨﺮﻯ ﺑﻌﺾ ﺍﻟﱪﺍﻣﺞ ﺍﻟﱵ ﻳﺴﺘﻌﻤﻠﻬﺎ ﻛﺜﲑﺍ ﺍﳌﺒﺘﺪﺃﻳﻦ ﰲ ﻟﻐﺔ ،Cﻣﻊ ﺷﺮﺡ ﺳﺮﻳﻊ ﻟﻜﻞ ﺑﺮﻧﺎﻣﺞ: ١,٩,١,١ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ،ﻋﻤﺮ ﺍﳌﺴﺘﺨﺪﻡ: ﻳﻘﻮﻡ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺈﻋﻄﺎﺀ ﺍﳌﺴﺘﺨﺪﻡ ﻋﻤﺮﻩ ،ﻭﺫﻟﻚ ﻋﱪ ﺇﺩﺧﺎﻝ ﺍﻟﻌﺎﻡ ﺍﳊﺎﱄ ﻭ ﺍﻟﻌﺎﻡ ﺍﻟﺬﻱ ﻭﻟﺪ ﺑﻪ ﺍﳌﺴﺘﺨﺪﻡ ،ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;int num1, num2 ;)" printf("the year currently: ;)scanf("%d", &num1 1 2 3 4 5 6 7 8 70 ;)" printf("the year of your born: ;)scanf("%d", &num2 ;)printf("You have %d years!\n", num1-num2 } ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١ﻋﻤﺮ ﺍﳌﺴﺘﺨﺪﻡ 9 10 11 12 13 14 ﰎ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ،ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﻃﻠﺒﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﺍﻟﺴﻨﺔ ﺍﳊﺎﻟﻴﺔ ،ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺃﺧﺬﻧﺎ ﺍﻟﺴﻨﺔ ﻋﻠﻰ ﺷﻜﻞ ﻋﺪﺩ ﺣﻘﻴﻘﻲ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﻃﻠﺒﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﺳﻨﺘﻪ ،ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﳊـﺎﺩﻱ ﻋـﺸﺮ ﺃﺧﺬﻧﺎ ﺍﻟﺴﻨﺔ ﺃﻳﻀﺎ ﻋﻠﻰ ﺷﻜﻞ ﻋﺪﺩ ﺻﺤﻴﺢ .ﻭ ﺃﺧﲑﺍ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﻄﺒﺎﻋﺔ ﺍﻟﻨﺘﻴﺠﺔ ﻭ ﺍﻟﱵ ﻫﻲ ﻃﺮﺡ ﺍﻟـﺴﻨﺔ ﺍﳊﺎﻟﻴﺔ ﻋﻠﻰ ﺳﻨﺔ ﺍﳌﺴﺘﺨﺪﻡ. ١,٩,١,٢ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺜﺎﱐ ،ﺁﻟﺔ ﺣﺎﺳﺒﺔ ﺑﺴﻴﻄﺔ: ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﻋﺒﺎﺭﺓ ﻋﻦ ﺁﻟﺔ ﺣﺎﺳﺒﺔ ﺑﺴﻴﻄﺔ ﺫﺍﺕ ﺣﺪﻭﺩ ﻻ ﳝﻜﻦ ﲡﺎﻭﺯﻫﺎ ،ﻳﻄﻠﺐ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺍﺧﺘﻴﺎﺭ ﺇﺷﺎﺭﺓ ﻟﻠﻌﻤﻠﻴـﺔ ﺍﻟﱵ ﺳﻴﻘﻮﻡ ﺎ ،ﰒ ﺇﺩﺧﺎﻝ ﻗﻴﻤﺘﲔ ﺍﻟﻠﺬﺍﻥ ﺳﻴﺠﺮﻱ ﻋﻠﻴﻬﻤﺎ ﺍﻟﻌﻤﻠﻴﺔ ،ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;int num1, num2 ;char Char ;)" printf("1:(+)\n2:(-)\n3:(/)\n4:(*)\nEnter a choice: ;)scanf("%c", &Char ;)" printf("Enter the first number: ;)scanf ("%d", &num1 ;)" printf("Enter the second number: ;)scanf("%d", &num2 )'if(Char == '+' || Char == '1 ;)printf("%d + %d = %d\n", num1, num2, num1+num2 )'else if(Char == '-' || Char == '2 ;)printf("%d - %d = %d\n", num1, num2, num1-num2 )'else if(Char == '/' || Char == '3 ;)printf("%d / %d = %d\n", num1, num2, num1/num2 )'else if(Char == '*' || Char == '4 ;)printf("%d * %d = %d\n", num1, num2, num1*num2 else ;)"printf("Error in choice!\nExiting...\n } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 71 ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٢ﺁﻟﺔ ﺣﺎﺳﺒﺔ ﺑﺴﻴﻄﺔ ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑﻳﻦ ﻣﻦ ﻧﻮﻉ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ،ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋـﻦ ﻣـﺘﻐﲑ ﺣﺮﰲ ﻭ ﺍﻟﺬﻱ ﺳﻴﻜﻮﻥ ﺍﻹﺷﺎﺭﺓ ﺍﻟﱵ ﺳﻨﻘﻮﻡ ﺑﺎﺳﺘﻌﻤﺎﳍﺎ ﰲ ﺍﻟﻌﻤﻠﻴﺎﺕ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﻃﻠﺒﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺑﺈﺧﺘﻴﺎﺭ ﺍﻹﺷﺎﺭﺓ ﺃﻭ ﺍﳌﺆﺛﺮ ﺍﻟﺬﻱ ﻳﺮﻳﺪ ﺍﺳﺘﻌﻤﺎﻟﻪ ،ﻭ ﺃﺧﺬﻧﺎ ﺍﳌﺆﺷﺮ ﺍﻟﺬﻱ ﺇﺧﺘﺎﺭﻩ ﺍﳌﺴﺘﺨﺪﻡ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ﻋﻠﻰ ﺷﻜﻞ ﺭﻣﺰ .ﻣـﻦ ﺍﻟـﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ﺇﱃ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻋﺸﺮ ،ﻗﻤﻨﺎ ﺑﺄﺧﺬ ﺍﻷﻋﺪﺍﺩ ﺍﻟﱵ ﺃﺩﺧﻠﻬﺎ ﺍﳌﺴﺘﺨﺪﻡ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺷﺮﻁ ﻭ ﻫﻮ ﺇﺫﺍ ﻛﺎﻥ ﺍﻟﺮﻣﺰ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ ﰲ ﺍﳌﺘﻐﲑ Charﻳﺴﺎﻭﻱ ﺍﳌﺆﺛﺮ +ﺃﻭ ﺍﻟﺮﻗﻢ ،١ﰲ ﺣﺎﻟـﺔ ﺃﻥ ﺍﻟـﺸﺮﻁ ﺻﺤﻴﺢ ﻳﺘﻢ ﺗﻄﺒﻴﻖ ﻋﻤﻠﻴﺔ ﺍﳉﻤﻊ ،ﻭ ﻫﻜﺬﺍ ﺑﺎﻟﻨﺴﺒﺔ ﻟﻜﻞ ﻣﻦ ﺍﻷﺳﻄﺮ ﺍﻟﻌﺸﺮﻳﻦ ،ﺍﻟﺜﺎﻟﺚ ﻭ ﺍﻟﻌﺸﺮﻳﻦ ،ﺍﻟﺴﺎﺩﺱ ﻭ ﺍﻟﻌﺸﺮﻳﻦ ،ﺃﻣﺎ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ﻭ ﺍﻟﻌﺸﺮﻳﻦ ﻓﺴﻴﺘﻢ ﺗﻨﻔﻴﺬﻩ ﺇﺫﺍ ﻛﺎﻥ ﺍﻟﺮﻣﺰ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ ﻏﲑ ﻣﺘﻮﺍﻓﻖ ﻣﻊ ﺍﻟﺮﻣﻮﺯ ﺍﳌﻄﻠﻮﺑﺔ. ١,٩,١,٣ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺜﺎﻟﺚ ،ﺍﺳﺘﺨﺮﺍﺝ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻄﻠﻘﺔ: ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﺎﺳﺘﺨﺮﺍﺝ ﻗﻴﻤﺔ ﻣﻄﻠﻘﺔ ﻟﻌﺪﺩ ﻳﻘﻮﻡ ﺑﺈﺩﺧﺎﻟﻪ ﺍﳌﺴﺘﺨﺪﻡ ،ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;int num, x ;)" printf("Enter a number: ;)scanf ("%d", &num )if(num<0 ;x = -num else ;x = num ;)printf("|%d|=%d\n", num, x ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٣ﺍﺳﺘﺨﺮﺍﺝ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻄﻠﻘﺔ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑﻳﻦ ،ﺍﻷﻭﻝ ﻟﻠﻌﺪﺩ ﺍﻟﺬﻱ ﺳﻴﻘﻮﻡ ﺑﺈﺩﺧﺎﻟﻪ ﺍﳌﺴﺘﺨﺪﻡ ،ﻭ ﺍﳌﺘﻐﲑ ﺍﻟﺜﺎﱐ ﻫـﻮ ﺍﻟـﺬﻱ ﺳﻴﺤﻤﻞ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻄﻠﻘﺔ ﻟﻠﻌﺪﺩ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﻃﻠﺒﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﻋﺪﺩ ،ﻭ ﺃﺧﺬﻧﺎ ﺍﻟﻌـﺪﺩ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ ﻋﻠﻰ ﺷﻜﻞ ﻋﺪﺩ ﺻﺤﻴﺢ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﻗﻤﻨﺎ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺷﺮﻁ ﻭ ﻫﻮ ﺇﺫﺍ ﻛـﺎﻥ ﺍﻟﻌﺪﺩ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ ﺃﻗﻞ ﻣﻦ ﺍﻟﺼﻔﺮ ﺃﻱ ﺍﻟﻌﺪﺩ ﺳﺎﻟﺐ ﻓﺈﻥ ﺍﳌﺘﻐﲑ xﻳﺴﺎﻭﻱ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ numﻣﻊ ﻋﻜﺲ ﺍﻹﺷﺎﺭﺓ ،ﻭ ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﻟﺸﺮﻁ ﻛﺎﻥ ﺧﺎﻃﺊ ﻓﻬﺬﺍ ﻳﻌﲏ ﺃﻥ ﺍﻟﻌﺪﺩ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ ﻋﺪﺩ ﺃﻛﱪ ﻣﻦ ﺍﻟﺼﻔﺮ ﺃﻱ ﻋـﺪﺩ ﻣﻮﺟـﺐ .ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﻄﺒﺎﻋﺔ ﺍﻟﻨﺘﺎﺋﺞ. 72 ١,٩,١,٤ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺮﺍﺑﻊ ،ﺃﺧﺬ ﺍﻟﻌﺪﺩ ﺍﻟﻜﺒﲑ: ﻳﻘﻮﻡ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺄﺧﺬ ﺍﻟﻌﺪﺩ ﺍﻷﻛﱪ ﺑﲔ ﻋﺪﺩﻳﻦ ﻳﻘﻮﻡ ﺑﺈﺩﺧﺎﳍﻤﺎ ﺍﳌﺴﺘﺨﺪﻡ ،ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;int num1, num2, max ;)" printf("Enter a number: ;)scanf("%d", &num1 ;)" printf("Enter another number: ;)scanf("%d", &num2 )if(num1>num2 ;max = num1 else ;max = num2 ;)printf("max = %d\n", max ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٤ﺃﺧﺬ ﺍﻟﻌﺪﺩ ﺍﻟﻜﺒﲑ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﺛﻼﺛﺔ ﻣﺘﻐﲑﺍﺕ ،ﺍﻷﻭﻝ ﻭ ﺍﻟﺜﺎﱐ ﻷﻋﺪﺍﺩ ﺍﻟﱵ ﺳﻴﻘﻮﻡ ﺑﺈﺩﺧﺎﳍﺎ ﺍﳌـﺴﺘﺨﺪﻡ ،ﻭ ﺍﳌـﺘﻐﲑ ﺍﻟﺜﺎﻟﺚ ﻟﻌﺪﺩ ﺍﻷﻛﱪ ﺑﲔ ﺍﻟﻌﺪﺩﻳﻦ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻬﻤﺎ ﺍﳌﺴﺘﺨﺪﻡ .ﻣﻦ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺇﱃ ﺍﻟﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋـﺸﺮ ،ﻃﻠﺒﻨـﺎ ﻣـﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﻋﺪﺩﻳﻦ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺷﺮﻁ ﻭ ﻫﻮ ﺇﺫﺍ ﻛﺎﻥ ﺍﻟﻌﺪﺩ ﺍﻷﻭﻝ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ ﺃﻛﱪ ﻣﻦ ﺍﻟﻌﺪﺩ ﺍﻟﺜﺎﱐ ﻓﺈﻥ ﺍﳌﺘﻐﲑ maxﻳﺴﺎﻭﻱ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ num1ﻷﺎ ﺍﻷﻛﱪ ،ﻭ ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﻟﺸﺮﻁ ﺧﺎﻃﺊ ﻓﻬﺬﺍ ﻳﻌـﲏ ﺃﻥ ﺍﻟﻌﺪﺩ ﺍﻟﺜﺎﱐ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ ﺃﻛﱪ ﻣﻦ ﺍﻷﻭﻝ ﻭ ﻫﻨﺎ ﺳﺘﻜﻮﻥ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ maxﻫﻲ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ num2ﻷﻧﻪ ﺍﻷﻛـﱪ .ﻭ ﺃﺧﲑﺍ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﻋﺸﺮ ﻭ ﻫﻮ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﻟﻨﺘﺎﺋﺞ. ١,٩,٢ﺍﻟﺪﺍﻟﺘﲔ putcharﻭ :getchar ﺍﻵﻥ ﺳﻨﺮﻯ ﺩﺍﻟﺘﲔ ﺟﺪﻳﺪﺗﲔ ﻭ ﳘﺎ putcharﻭ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣﻦ put characterﻭ ﺍﻟﺪﺍﻟﺔ getcharﻭ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣﻦ ،get characterﺍﻟﺪﺍﻟﺘﲔ ﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ .stdio.hﺍﻟﺪﺍﻟﺔ putcharﺗﺴﺘﻌﻤﻞ ﻹﺧﺮﺍﺝ ﺍﻷﺣﺮﻑ ،ﻣﺜﻼ ﻟﻮ ﺃﺭﺩﻧـﺎ ﺃﻥ ﻧﻜﺘﺐ ﺍﳉﻤﻠﺔ ! Hello, Worldﺳﻨﻜﺘﺐ: >#include<stdio.h )(main { ;)'putchar('H 1 2 3 4 5 73 ;)'putchar('e ;)'putchar('l ;)'putchar('l ;)'putchar('o ;)'putchar(', ;)' '(putchar ;)'putchar('w ;)'putchar('o ;)'putchar('r ;)'putchar('l ;)'putchar('d ;)'putchar('\n ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٥ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ } 6 7 8 9 10 11 12 13 14 15 16 17 18 putchar ﻭ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻟﻄﺒﺎﻋﺔ ﺍﻟﻨﺼﻮﺹ ،ﻭ ﰲ ﻫﺬﻩ ﺍﳊﺎﻟﺔ ﺳﺘﻔﻀﻞ ﺍﺳﺘﻌﻤﺎﻝ .printfﺃﻣﺎ ﺍﻟﺪﺍﻟﺔ getcharﻓﻬﻲ ﺗﺄﺧﺬ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺣﺮﻑ ﻭ ﺗﻀﻌﻪ ﰲ ﻣﺘﻐﲑ ،ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;char ch ;)'putchar(': ;)(ch = getchar ;)putchar(ch ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٦ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 12 getchar ﻭ ﻫﻨﺎ ﻛﺘﺒﻨﺎ )( ch = getcharﻷﻥ ﺍﻟﺪﺍﻟﺔ getcharﻻ ﲢﺘﻮﻱ ﻋﻠﻰ ﻭﺳﺎﺋﻂ ،ﻭ ﻫﻨﺎ ﺍﻟﻄﺮﻳﻘـﺔ ﺻـﺤﻴﺤﺔ ﻷﻥ ﺍﻟﺪﺍﻟـﺔ getcharﺗﻘﻮﻡ ﺑﺈﺭﺟﺎﻉ ﻗﻴﻤﺔ ﻭ ﻫﻲ ﺍﳊﺮﻑ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ. ١,٩,٣ﺍﻟﺪﺍﻟﺘﲔ putsﻭ :gets ﺍﻟﺪﺍﻟﺘﲔ putsﻭ getsﺃﻳﻀﺎ ﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠﻒ ،stdio.hﻭ ﺍﻷﻭﱃ ﳐﺘﺼﺮﺓ ﻣﻦ put stringﻭ ﺍﻟﺜﺎﻧﻴﺔ .get stringﺍﻟﺪﺍﻟﺔ putsﻣﺸﺎﺑﻪ ﻟﺪﺍﻟﺔ printfﻣﻊ ﺑﻀﻊ ﺍﻻﺧﺘﻼﻓﺎﺕ ،ﻭ ﻫﻲ ﺗﺴﺘﻌﻤﻞ ﻟﻄﺒﺎﻋﺔ ﺍﻟﻨﺼﻮﺹ ،ﻭ ﲣﺘﻠﻒ ﻋﻦ ﺍﻟﺪﺍﻟﺔ printfﰲ: -١ﳝﻜﻨﻚ ﲡﺎﻫﻞ ﻭﺿﻊ ﺭﻣﺰ ﺍﻟﺴﻄﺮ ﺍﳉﺪﻳﺪ ،\nﻷﻥ ﺍﻟﺪﺍﻟﺔ putsﺗﻀﻊ ﻛﻞ ﻧﺺ ﰲ ﺳﻄﺮ. -٢ﺍﻟﺪﺍﻟﺔ putsﻻ ﳝﻜﻨﻬﺎ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﻣﺘﻐﲑﺍﺕ ﻣﻦ ﻧﻮﻉ ﺃﺭﻗﺎﻡ ﺃﻭ ﺃﺣﺮﻑ ،ﺃﻱ ﺃﺎ ﻻ ﺗﺘﻌﺎﻣﻞ ﻣﻊ ﺭﻣﻮﺯ ﻣﺜﻞ .%d 74 ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻋﻦ ﺍﻟﺪﺍﻟﺔ :puts >#include<stdio.h )(main { ;)"!puts("Hello, World ;)"!puts("Goodbay, World } ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٧ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ 1 2 3 4 5 6 7 puts ﺃﻣﺎ ﻋﻦ ﺍﻟﺪﺍﻟﺔ getsﻓﻬﻲ ﺗﻘﻮﻡ ﺑﺈﺩﺧﺎﻝ ﻧﺼﻮﺹ ،ﻭ ﻻ ﳝﻜﻦ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﺑﺎﻷﺭﻗﺎﻡ ﻭ ﺍﻷﺣﺮﻑ ،ﺳﻨﺘﻄﺮﻕ ﺇﻟﻴﻬﺎ ﰲ ﺍﻟﺪﺭﻭﺱ ﺍﻟﻘﺎﺩﻣﺔ ،ﻷﻧﻨﺎ ﱂ ﻧﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ﺑﻌﺪ. ١,٩,٤ﺍﻟﺪﺍﻟﺘﲔ wprintfﻭ :wscanf ﳘﺎ ﻧﻔﺲ ﺍﻟﺪﺍﻟﺘﲔ printfﻭ scanfﻭ ﻟﻜﻨﻬﺎ ﻋﺮﻳﻀﺔ ﻭ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣﻦ ﻫﺬﺍ ﻣﺜﺎﻝ ﻳﻮﺿﺢ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﻤﺎ: printf format wideﻭ ،wide scan format >#include<stdio.h )(main { ;int num, x ;)" wprintf(L"Enter a number: ;)wscanf(L"%d", &num )if(num<0 ;x = -num else ;x = num ;)wprintf(L"|%d|=%d\n", num, x ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٨ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ wprintﻭ ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 wscanf ﻭ ﺍﳊﺮﻑ Lﻳﻌﲏ .long ١,٩,٥ﺍﻟﺪﺍﻟﺘﲔ putchﻭ getchﻭ ﺍﻟﺪﺍﻟﺔ :getche ﺍﻟﺪﺍﻟﺘﲔ putcheﻭ getcheﳘﺎ ﻣﻦ ﺍﻟﺪﻭﺍﻝ ﺍﻟﻘﻴﺎﺳﻴﺔ ﰲ ﻟﻐﺔ ،Cﰲ ﺃﻧﻈﻤﺔ linuxﲡﺪ ﺍﻟـﺪﺍﻟﺘﲔ ﰲ ﺍﳌﻠـﻒ ﺍﻟﺮﺃﺳـﻲ ،stdio.hﺃﻣﺎ ﰲ ﺃﻧﻈﻤﺔ Windowsﻓﺴﺘﺠﺪﻫﺎ ﰲ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ) conio.hﳐﺘﺼﺮ ﻣﻦ ،(Console Input Outputﺃﻣـﺎ 75 ﺍﻟﺪﺍﻟﺔ getchﻓﻬﻲ ﻟﻴﺲ ﻣﻦ ﺍﻟﺪﻭﺍﻝ ﺍﻟﻘﻴﺎﺳﻴﺔ ﻟﻠﻐﺔ Cﻭ ﻟﻜﻨﻬﺎ ﻣﺘﻮﻓﺮ ﰲ ﲨﻴﻊ ﺍﳌﺘﺮﲨﺎﺕ ﺗﻘﺮﻳﺒﺎ ﻋﻠـﻰ ﺃﻧﻈﻤـﺔ ،Windowsﻭ ﺗﺴﺘﻌﻤﻞ ﺑﻜﺜﺮﺓ. ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﻟﻨﺴﺨﺔ ﺍﻟﱵ ﻟﺪﻳﻚ ﻣﻦ ﻟﻐﺔ Cﻫﻲ ﺍﻟﻨﺴﺨﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ANSI Cﻓﻴﻤﻜﻨﻚ ﺍﻹﻋﺘﻤﺎﺩ ﻋﻠﻰ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،stdio.hﻭ ﰲ ﺍﻟﻨﺴﺨﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ﻻ ﺗﻮﺟﺪ ﺍﻟﺪﺍﻟﺔ .getchﺍﻟﺪﺍﻟﺔ putchﻫﻲ ﻧﻔﺲ ﺍﻟﺪﺍﻟﺔ ،putcharﻭ ﺍﻟﺪﺍﻟﺔ getchﻣﺘﺸﺎﺎ ﻟـﺪﺍﻟﺔ getcharﻣﻊ ﺑﻌﺾ ﺍﻻﺧﺘﻼﻓﺎﺕ: -١ﺍﻟﺪﺍﻟﺔ getcharﺗﺴﻤﺢ ﻟﻚ ﺑﺮﺅﻳﺔ ﻣﺎ ﻗﻤﺖ ﺑﺈﺩﺧﺎﻟﻪ ،ﺃﻣﺎ getchﻓﻼ ﺗﺴﻤﺢ ﻟﻚ ﺑﺬﻟﻚ. -٢ﳝﻜﻦ ﺇﺩﺧﺎﻝ ﺃﻛﺜﺮ ﻣﻦ ﺣﺮﻑ ﰲ ﺍﻟﺪﺍﻟﺔ getcharﺣﻴﺚ ﺳﻴﺘﻢ ﺃﺧﺬ ﺍﳊﺮﻑ ﺍﻷﻭﻝ ﻣﻦ ﺍﳊﺮﻭﻑ ﺍﳌﺪﺧﻠـﺔ ،ﺃﻣـﺎ getchﻓﻼ ﺗﺴﺘﻄﻴﻊ ﺇﺩﺧﺎﻝ ﺃﻛﺜﺮ ﻣﻦ ﺣﺮﻑ. ﻣﺜﺎﻝ ﺣﻮﻝ putchﻭ :getch /* Just in Windows and DOS OS compilers */ >#include<stdio.h >#include<conio.h )(main { ;char ch ;)(ch = getch ;)putch(c ;)'putch('\n ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٩ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ getchﻭ ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 putch ﻗﻤﻨﺎ ﺑﻀﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ conio.hﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﱐ ،ﰒ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﺪﺍﻟﺔ getchﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺣﻴـﺚ ﺳـﺘﻼﺣﻆ ﺃﻥ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻣﺜﻞ ﺍﻟﺪﺍﻟﺔ ،getcharﰒ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﺪﺍﻟﺔ ﰲ ﻛﻼ ﺍﻟﺴﻄﺮﻳﻦ ﺍﻟﺘﺎﺳﻊ ﻭ ﺍﻟﻌﺎﺷﺮ ،ﻭ ﺑﺎﻟﻨﺴﺒﺔ ﻟﺮﻣﺰ \nﻓﻬﻮ ﻳﻌﺘﱪ ﺭﻣﺰ ﻭﺍﺣﺪ .ﻭ ﰲ ﺍﻟﻜﺜﲑ ﻣﻦ ﺍﻟﱪﺍﻣﺞ ﺳﺘﺠﺪ ﺃﻥ ﺍﻟﺪﺍﻟﺔ getchﻣﺴﺘﻌﻤﻠﺔ ﺑﻜﺜﺮﺓ ﻭ ﺧﺎﺻﺔ ﰲ ﺎﻳﺔ ﺍﻟﱪﻧﺎﻣﺞ ﻭ ﺫﻟـﻚ ﻷـﺎ ﺗﺘﻮﻗﻒ ﺑﺎﻧﺘﻈﺎﺭ ﺍﳌﺴﺘﺨﺪﻡ ﺑﺎﻟﻀﻐﻂ ﻋﻠﻰ ﺯﺭ ﻣﻦ ﺍﻷﺯﺭﺍﺭ ﻭ ﻃﺮﻳﻘﺔ ﻫﻲ: /* Just in Windows and DOS OS compilers */ >#include<stdio.h >#include<conio.h )(main { ;char ch ;)(ch = getch ;)putch(ch ;)'putch('\n 1 2 3 4 5 6 7 8 9 10 76 ;)"printf("Press any key to exit\n getch(); /*pause */ } 11 12 13 14 ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١٠ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ getchﻭ ﺍﻟﺪﺍﻟﺔ (٢) putch ﺣﻴﺚ ﻫﻨﺎ ﻟﻦ ﳜﺮﺝ ﺍﻟﱪﻧﺎﻣﺞ ﻣﺒﺎﺷﺮﺓ ،ﺳﻴﻨﺘﻈﺮ ﺃﻥ ﻳﻘﻮﻡ ﺍﳌﺴﺘﺨﺪﻡ ﺑﺎﻟﻀﻐﻂ ﻋﻠﻰ ﺃﻱ ﺯﺭ ﻛﻲ ﻳﻘﻮﻡ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺎﳋﺮﻭﺝ .ﺃﻣـﺎ ﺍﻟﺪﺍﻟﺔ getcheﻓﻬﻲ ﻧﻔﺴﻬﺎ getchﻓﻘﻂ ﻋﻨﺪ ﺍﺳﺘﻌﻤﺎﳍﺎ ﺗﻈﻬﺮ ﻟﻠﻤﺴﺘﺨﺪﻡ ﺍﻟﺮﻣﺰ ﺍﻟﺬﻱ ﻗﺎﻡ ﺑﺈﺩﺧﺎﻟﻪ ،ﻣﺜﺎﻝ: /* Just in Windows and DOS OS compilers */ >#include<stdio.h >#include<conio.h )(main { ;char c ;)(c = getche ;)'putch('\n ;)putch(c ;)'putch('\n ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 12 getche ١,٩,٦ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ :wchar_t ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻣﺜﻞ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ،charﺣﻴﺚ ﺍﻟﻜﻠﻤﺔ wchar_tﳐﺘﺼﺮﺓ ﻣﻦ typeﻭ ﺣﺠﻤﻬﺎ ٢ﺑﺎﻳﺖ ،ﻣﺜﺎﻝ ﻟﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ: wide-character >#include<stdio.h )(main { ;'wchar_t wch = 'a ;)printf("%c\n", wch ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ } 1 2 3 4 5 6 7 8 wchar_t ١,٩,٧ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ mainﻭ :wmain ﺍﻟﺪﺍﻟﺔ mainﻫﻲ ﺩﺍﻟﺔ ﺭﺋﻴﺴﻴﺔ ﺣﻴﺚ ﻳﺒﺪﺃ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺘﻨﻔﻴﺬ ﺍﻷﻭﺍﻣﺮ ﻣﻨﻬﺎ ،ﺑﺎﲡﺎﻩ ﻭﺍﺣﺪ ﻭ ﺑﻄﺮﻳﻘﺔ ﻣﻨﻈﻤﺔ ،ﺍﻟﺪﺍﻟـﺔ )ﻟﻴﺴﺖ ﻣﻦ ﺍﻟﺪﻭﺍﻝ ﺍﻟﻘﻴﺎﺳﻴﺔ ﻟﻠﻐﺔ (Cﻫﻲ ﻧﻔﺴﻬﺎ mainﻭ ﻟﻜﻨﻬﺎ ﻋﺮﻳﻀﺔ ،ﻭ ﻛﻞ ﺍﻟﺪﻭﺍﻝ ﻭ ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠـﻮﺯﺓ ﺍﻟﻌﺮﻳـﻀﺔ ﺗﺴﺘﻌﻤﻞ ﰲ ﺍﻟﻨﻈﺎﻡ ﺍﳊﺮﻭﻑ ﺍﻟﺪﻭﱄ ﺍﳌﻮﺣﺪ ﺃﻭ ﲟﺎ ﻳﺴﻤﻰ ﺑـ .Unicodeﻭ ﻃﺮﻗﺔ ﺍﺳﺘﻌﻤﺎﻝ wmainﻣﺜﻞ mainﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﺑﺴﻴﻂ ﺣﻮﳍﺎ: wmain 77 >#include<stdio.h )(wmain { ;)"wprintf(L"Hello, World!\n } ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١٣ﺍﻟﺪﺍﻟﺔ 1 2 3 4 5 6 wmain ﰲ ﺑﻌﺾ ﺍﳌﺘﺮﲨﺎﺕ ﺇﻥ ﻛﺘﺒﺖ ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺘﺎﱄ: >#include<stdio.h )(main { ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١٤ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 main ﳛﺬﺭﻙ ﺑﺄﻥ ﺍﻟﺪﺍﻟﺔ mainﳚﺐ ﺃﻥ ﺗﺮﺟﻊ ﻗﻴﻤﺔ ،ﻭ ﻹﺭﺟﺎﻉ ﻗﻴﻤﺔ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﻧﻜﺘﺐ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ returnﻣﻊ ﺍﻟﻘﻴﻤﺔ ﺻﻔﺮ ﻭ ﺍﻟﱵ ﺗﻌﲏ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺪﻭﻥ ﺃﺧﻄﺎﺀ ،ﻭ ﻫﺬﺍ ﻟﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ: >#include<stdio.h ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١٥ﺇﺭﺟﺎﻉ ﻗﻴﻤﺔ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ )(main { ;return 0 } 1 2 3 4 5 6 ﻭ ﺳﺒﺐ ﺇﺭﺟﺎﻉ ﻗﻴﻤﺔ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﻫﻮ ﺍﻟﻮﺿﻊ ﺍﻻﻓﺘﺮﺍﺿﻲ ﳍﺎ ﻭ ﻫﻮ ،intﻭ ﲨﻴﻊ ﺍﻟﺪﻭﺍﻝ ﻣﻦ ﻧﻮﻉ intﳚﺐ ﺇﺭﺟﺎﻉ ﻗﻴﻤﺔ ﳍﺎ ،ﻭ ﻫﺬﺍ ﻳﻌﲏ ﺃﻧﻪ ﳝﻜﻦ ﻛﺘﺎﺑﺔ: >#include<stdio.h 1 2 3 4 5 6 >#include<stdio.h 1 2 )(int main { ;return 0 } ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١٦ﺇﺭﺟﺎﻉ ﻗﻴﻤﺔ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ )(٢ ﺃﻣﺎ ﺇﺫﺍ ﺃﺭﺩﺕ ﻋﺪﻡ ﺇﺭﺟﺎﻉ ﻗﻴﻤﺔ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﻓﻴﻤﻜﻦ ﻛﺘﺎﺑﺔ voidﺑﺪﻝ ،intﺣﻴﺚ ﺗﺴﺘﻌﻤﻞ voidﻟﻠﻘﻴﺎﻡ ﺑـﺈﺟﺮﺍﺀﺍﺕ ﻭ ﻻ ﳝﻜﻦ ﺇﺭﺟﺎﻉ ﳍﺎ ﻗﻴﻤﺔ ،ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ: 78 )(void main { } ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١٧ﺗﻔﺎﺩﻱ ﺇﺭﺟﺎﻉ ﻗﻴﻤﺔ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ١,٩,٨ﺭﻣﻮﺯ ﺍﻹﺧﺮﺍﺝ ﻭ ﺍﻹﺩﺧﺎﻝ: ﺭﻣﻮﺯ ﺍﻹﺧﺮﺍﺝ ﺍﳋﺎﺻﺔ ﺑﺎﻟﺪﺍﻟﺔ printfﻣﻮﺿﺤﺔ ﻋﻠﻰ ﺍﳉﺪﻭﻝ ﺍﻟﺘﺎﱄ: ﺍﻟﺮﻣﺰ ﺍﻟﺸﺮﺡ %d, %i ﻟﻸﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﻤﺎ ﻟﻜﻞ ﻣﻦ ﺍﻷﻧﻮﺍﻉ %f, %e, %g ﻟﻸﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﻢ ﻟﻜﻞ ﻣﻦ ﺍﻷﻧﻮﺍﻉ %u ﻟﻸﻋﺪﺍﺩ ﺑﺪﻭﻥ ﺇﺷﺎﺭﺓ ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻟﻪ ﻟﻜﻞ ﻣـﻦ ﺍﻷﻧـﻮﺍﻉ int, short, long float, double unsigned, int, short, long %c ﻟﻠﺮﻣﻮﺯ ﻭ ﺍﻷﺣﺮﻑ ﻭ ﻳﺴﺘﻌﻤﻞ ﻣﻊ ﺍﳌﺘﻐﲑﺍﺕ ﺍﳊﺮﻓﻴﺔ %s ﻟﻠﻨﺼﻮﺹ ﺃﻭ ﺍﻟﺴﻼﺳﻞ ﺍﳊﺮﻓﻴﺔ ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻟﻪ ﻣﻊ ][ charﻭ %o ﻷﻋﺪﺍﺩ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺜﻤﺎﱐ %x ﻷﻋﺪﺍﺩ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺴﺪﺍﺳﻲ %p ﻟﻠﻤﺆﺷﺮﺍﺕ %ld ﻷﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ﻃﻮﻳﻠﺔ Long Decimalﻭ ﺗﺴﺘﻌﻤﻞ ﰲ %lu ﻷﻋﺪﺍﺩ ﻃﻮﻳﻠﺔ ﺑﺪﻭﻥ ﺇﺷﺎﺭﺓ char *char long int long unsigned ﺍﳉﺪﻭﻝ :١,٩,١ﺭﻣﻮﺯ ﺍﻟﺪﺍﻟﺔ printf ﻭ ﺭﻣﻮﺯ ﺍﻹﺩﺧﺎﻝ ﺍﳋﺎﺻﺔ ﺑﺎﻟﺪﺍﻟﺔ scanfﻋﻠﻰ ﺍﳉﺪﻭﻝ ﺍﻟﺘﺎﱄ: ﺍﻟﺮﻣﺰ ﺍﻟﺸﺮﺡ %d, %i ﻟﻸﻋﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﻤﺎ ﻟﻜﻞ ﻣﻦ ﺍﻷﻧﻮﺍﻉ %f, %e, %g ﻟﻸﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﻢ ﻟﻜﻞ ﻣﻦ ﺍﻷﻧﻮﺍﻉ %u ﻟﻸﻋﺪﺍﺩ ﺑﺪﻭﻥ ﺇﺷﺎﺭﺓ ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻟﻪ ﻟﻜﻞ ﻣـﻦ ﺍﻷﻧـﻮﺍﻉ int, short, long float, double unsigned, int, short, long %c ﻟﻠﺮﻣﻮﺯ ﻭ ﺍﻷﺣﺮﻑ ﻭ ﻳﺴﺘﻌﻤﻞ ﻣﻊ ﺍﳌﺘﻐﲑﺍﺕ ﺍﳊﺮﻓﻴﺔ %s ﻟﻠﻨﺼﻮﺹ ﺃﻭ ﺍﻟﺴﻼﺳﻞ ﺍﳊﺮﻓﻴﺔ ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻟﻪ ﻣﻊ ][ charﻭ char *char 3 4 5 6 79 %o ﻷﻋﺪﺍﺩ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺜﻤﺎﱐ %x ﻷﻋﺪﺍﺩ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺴﺪﺍﺳﻲ %ld ﻷﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ﻃﻮﻳﻠﺔ Long Decimalﻭ ﺗﺴﺘﻌﻤﻞ ﰲ %lu ﻷﻋﺪﺍﺩ ﻃﻮﻳﻠﺔ ﺑﺪﻭﻥ ﺇﺷﺎﺭﺓ long int long unsigned ﺍﳉﺪﻭﻝ :١,٩,٢ﺭﻣﻮﺯ ﺍﻟﺪﺍﻟﺔ scanf ١,٩,٩ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: ﻻ ﺗﻮﺟﺪ ﺃﺧﻄﺎﺀ ﳏﺘﻤﻠﺔ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ. ١,٩,١٠ﲤﺎﺭﻳﻦ: .١ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻄﻠﺐ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﻋﺪﺩ ،ﰒ ﻳﻘﻮﻡ ﺑﺎﻟﱪﻧﺎﻣﺞ ﺑﺈﺧﺒﺎﺭﻩ ﺇﻥ ﻛﺎﻥ ﺍﻟﻌﺪﺩ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﻓﺮﺩﻱ ﺃﻭ ﺯﻭﺟﻲ. .٢ .٣ .٤ .٥ ﺃﻳﻬﻤﺎ ﺃﻓﻀﻞ ﰲ ﺍﻹﺧﺮﺍﺝ ﺍﻟﺪﺍﻟﺔ printfﺃﻭ ﺍﻟﺪﺍﻟﺔ puts؟ ﻭ ﳌﺎﺫﺍ؟ ﻣﺎﺫﺍ ﺗﻌﲏ ﺍﻟﻜﻠﻤﺔ ،conioﻭ ﻣﺎ ﻫﻲ ﺍﻟﺪﻭﺍﻝ ﺍﻟﱵ ﺩﺭﺳﺘﻬﺎ ﻣﻦ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ conio.h؟ ﻓﻴﻤﺎ ﺗﺴﺘﻌﻤﻞ ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ ﻭ ﺍﻟﺪﻭﺍﻝ ﺍﻟﻌﺮﻳﻀﺔ؟ ﳌﺎﺫﺍ ﻧﻘﻮﻡ ﺑﺈﺭﺟﺎﻉ ﻗﻴﻤﺔ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﰲ ﺣﺎﻟﺔ ﺃﺎ ﰲ ﺍﻟﻮﺿﻊ ﺍﻻﻓﺘﺮﺍﺿﻲ ،ﻭ ﻣﺎﺫﺍ ﺗﻌﲔ ﺗﻠﻚ ﺍﻟﻘﻴﻤـﺔ ﰲ ﺍﻟﺪﺍﻟـﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ؟ ٢,١ﺍﻟﻘﺮﺍﺭ ...................................................................................... switch ٢,٢ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ ..................................................................... repeated loops ٢,٣ﺍﳌﺼﻔﻮﻓﺎﺕ .................................................................................. arrays ٢,٤ﺍﳌﺆﺷﺮﺍﺕ ................................................................................. pointers ٢,٥ﺍﻟﺪﻭﺍﻝ .................................................................................. Functions ٢,٦ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ........................................................................ Header files ٢,٧ﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ ﰲ ﺍﳌﻠﻔﺎﺕ ............................................................. Files I/O ٢,٨ﺍﻟﺘﺮﺍﻛﻴﺐ ............................................................................... structures ٢,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻟﺜﺎﱐ ،ﻣﻌﺎ ﺇﺿﺎﻓﺎﺕ ................................................................... ﻣﻘﺪﻣﺔ :ﰲ ﻫﺬﺍ ﺍﻟﻔﺼﻞ ﺳﻨﻨﺘﻘﻞ ﺇﱃ ﺍﳌﺮﺣﻠﺔ ﺍﻟﺜﺎﻧﻴﺔ ﻣﻦ ﻟﻐﺔ ،Cﺣﻴﺚ ﺳﻨﺘﻌﺮﻑ ﺇﱃ ﻛﻴﻔﻴﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻘﺮﺍﺭ ،switchﻃﺮﻳﻘﺔ ﺗﻜﺮﺍﺭ ﺃﻣﺮ ﺇﱃ ﻋﺪﺓ ﻣﺮﺍﺕ )ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ( ،ﻣﺼﻔﻮﻓﺎﺕ ﺫﺍﺕ ﺑﻌﺪ ،ﺑﻌﺪﻳﻦ ،ﺛﻼﺛﺔ ﺃﺑﻌﺎﺩ ﻭ ﺃﻛﺜﺮ ،ﺍﻟﺬﺍﻛﺮﺓ ﻭ ﺍﳌﺆﺷـﺮﺍﺕ، ﺍﻟﺪﻭﺍﻝ ﻭ ﺍﻹﺟﺮﺍﺀﺍﺕ ،ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ،ﻃﺮﻳﻘﺔ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﻠﻔﺎﺕ ﺳﻮﺍﺀ ﻗﺮﺍﺀﺓ ،ﻛﺘﺎﺑﺔ ،ﺇﻧﺸﺎﺀ ﻭ ﺣﺬﻑ ،ﻭ ﺃﺧﲑﺍ ﺍﻟﱪﳎـﺔ ﺍﻟﺘﺮﻛﻴﺒﻴﺔ ،ﻭ ﺇﺎﺀ ﻫﺬﺍ ﺍﻟﻔﺼﻞ ﻳﻌﲏ ﺇﺎﺀ ﺃﺳﺎﺳﻴﺎﺕ ﻟﻐﺔ .C ﺑﺎﻟﺘﻮﻓﻴﻖ ﺇﻥ ﺷﺎﺀ ﺍﷲ ﻗﺎﻝ ﺍﷲ ﺗﻌﺎﱃ: ﴿ ﻭﻗﺎﻝ ﺍﻟﺬﻳﻦ ﺃﻭﺗﻮﺍ ﺍﻟﻌﻠﻢ ﻭﻳﻠﻜﻢ ﺛﻮﺍﺏ ﺍﷲ ﺧﲑ ﳌﻦ ﺁﻣﻦ ﻭﻋﻤﻞ ﺻﺎﳊﺎ ﴾ ﺻﺪﻕ ﺍﷲ ﺗﻌﺎﱃ 81 ﻭ. ﺣﻴﺚ ﻛﻞ ﻗﻴﻤﺔ ﺛﺎﺑﺘﺔ ﺗﻌﺘﱪ ﻛﺸﺮﻁ ﺃﻭ ﻣﻘﺎﺭﻧﺔ، ﻹﺧﺘﺒﺎﺭ ﻗﻴﻤﺔ ﻣﺘﻐﲑﺓ ﻣﻊ ﻗﻴﻢ ﺛﺎﺑﺘﺔ ﺻﺤﻴﺤﺔswitch ﻳﺴﺘﻌﻤﻞ ﺍﻟﻘﺮﺍﺭ : ﺳﻴﻐﻨﻴﻨﺎ ﻋﻦ ﺑﺎﻗﻲ ﻫﺬﻩ ﺍﻟﻘﺮﺍﺭﺍﺕ ﰲ ﺍﻟﻜﺜﲑ ﻣﻦ ﺍﳊﺎﻻﺕ ﻣﻨﻬﺎ،else…if ﻭelse ،if ﻣﺸﺎﺑﻪ ﻟﻠﻘﺮﺍﺭﺍﺕswitch ﺍﻟﻘﺮﺍﺭ :ﺇﻟﻴﻚ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺍﻟﺬﻱ ﻛﺘﺒﻨﺎﻩ ﺳﺎﺑﻘﺎ ﻭ ﺍﻟﺬﻱ ﻫﻮ ﻋﺒﺎﺭﺓ ﻋﻦ ﺁﻟﺔ ﺣﺎﺳﺒﺔ ﺑﺴﻴﻄﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 #include<stdio.h> main() { int num1, num2; char Char; printf("1:(+)\n2:(-)\n3:(/)\n4:(*)\nEnter a choice: "); scanf("%c", &Char); printf("Enter the first number: "); scanf ("%d", &num1); printf("Enter the second number: "); scanf("%d", &num2); if(Char == '+' || Char == '1') printf("%d + %d = %d\n", num1, num2, num1+num2); else if(Char == '-' || Char == '2') printf("%d - %d = %d\n", num1, num2, num1-num2); else if(Char == '/' || Char == '3') printf("%d / %d = %d\n", num1, num2, num1/num2); else if(Char == '*' || Char == '4') printf("%d * %d = %d\n", num1, num2, num1*num2); else } printf("Error in choice!\nExiting...\n"); if, else, else…if ﺁﻟﺔ ﺣﺎﺳﺒﺔ ﺑﺴﻴﻄﺔ ﺑﺈﺳﺘﺨﺪﺍﻡ:٢,١,١ ﺍﻟﱪﻧﺎﻣﺞ : ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﺑﺎﺳﺘﺨﺪﺍﻣﻬﺎ، ﺃﻓﻀﻞswitch ﻫﻨﺎ ﳝﻜﻨﻨﺎ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﻘﺮﺍﺭ 1 2 3 4 5 6 7 8 9 #include<stdio.h> main() { int num1, num2; char Char; printf("1:(+)\n2:(-)\n3:(/)\n4:(*)\nEnter a choice: "); scanf("%c", &Char); 82 ;)" printf("Enter the first number: ;)scanf ("%d", &num1 ;)" printf("Enter the second number: ;)scanf("%d", &num2 )switch(Char { case '+': case '1': ;)printf("%d + %d = %d\n", num1, num2, num1+num2 ;break case '-': case '2': ;)printf("%d - %d = %d\n", num1, num2, num1-num2 ;break case '/': case '3': ;)printf("%d / %d = %d\n", num1, num2, num1/num2 ;break case '*': case '4': ;)printf("%d * %d = %d\n", num1, num2, num1*num2 ;break default: ;)"printf("Error in choice!\nExiting...\n ;break } ﺍﻟﱪﻧﺎﻣﺞ :٢,١,٢ﺁﻟﺔ ﺣﺎﺳﺒﺔ ﺑﺴﻴﻄﺔ ﺑﺈﺳﺘﺨﺪﺍﻡ } 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 switch ﻫﻨﺎ ﺳﻨﻼﺣﻆ ﺃﻥ ﻋﺪﺩ ﺃﺳﻄﺮ ﺍﻟﱪﻧﺎﻣﺞ ﺃﻛﺜﺮ ﻣﻦ ﺍﻟﺴﺎﺑﻖ ،ﻭ ﻫﺬﺍ ﻻ ﻳﻬﻢ ،ﺍﻟﺬﻱ ﻳﻬﻢ ﻫﻮ ﻃﺮﻳﻘﺔ ﻛﺘﺎﺑﺔ ﺍﻟﱪﻧﺎﻣﺞ ﺣﻴﺚ ﺗﻜـﻮﻥ ﻣﻨﻈﻤﺔ ﻭ ﻣﻔﻬﻮﻣﺔ .ﻟﻠﻘﺮﺍﺭ switchﻭﺳﻴﻂ ،ﻭ ﺍﻟﺬﻱ ﻳﻘﻮﻡ ﺑﺘﺘﺒﻊ ﻧﺘﻴﺠﺔ ﺍﳌﺘﻐﲑ ﺍﳌﻮﺟﻮﺩ ﺩﺍﺧﻞ ﺍﻟﻮﺳﻴﻂ ،ﰲ ﻣﺜﺎﻟﻨـﺎ ﺍﻟـﺴﺎﺑﻘﺔ ﺍﺳﺘﻌﻤﺎﻟﻨﺎ ﺍﳌﺘﻐﲑ ،Charﻭ ﻟﻠﻘﺮﺍﺭ switchﺣﺎﻻﺕ ،ﻭ ﻳﺘﻢ ﺗﻨﻔﻴﺬﻫﺎ ﺣﺴﺐ ﻧﺘﻴﺠﺔ ﺍﳌﺘﻐﲑ ﺍﳌﻮﺟﻮﺩ ﰲ ﺍﻟﻮﺳﻴﻂ .ﺍﻵﻥ ﺳﺄﺷﺮﺡ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺑﺎﻟﺘﻔﺼﻴﻞ: ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﻃﻠﺒﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﻧﻮﻉ ﺍﻟﻌﻤﻠﺔ ﺍﻟﱵ ﻳﺮﻳﺪ ﺍﺳﺘﺨﺪﺍﻣﻬﺎ ،ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ﻳﺄﺧﺬ ﺍﻟﱪﻧﺎﻣﺞ ﻧﻮﻉ ﺍﻟﻌﻤﻠﻴﺔ ،ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ﻭ ﺍﻟﺮﺍﺑﻊ ﻋﺸﺮ ﻃﻠﺒﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﺍﻟﻌﺪﺩ ﺍﻷﻭﻝ ﰒ ﺍﻟﻌﺪﺩ ﺍﻟﺜﺎﱐ ﻹﺟﺮﺍﺀ ﺍﻟﻌﻤﻠﻴـﺔ ﺑﻴﻨﻬﻤﺎ ،ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﻋﺸﺮ ﻳﺄﰐ ﺍﻟﻘﺮﺍﺭ switchﻭ ﺑﻪ ﻭﺳﻴﻂ ﰲ ﺩﺍﺧﻠﻪ ﺍﳌﺘﻐﲑ Charﺣﻴﺚ ﻫﻨﺎ ﺳﺘﺘﻢ ﺍﳌﻘﺎﺭﻧﺔ ﺑـﲔ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻮﺟﺪ ﺩﺍﺧﻞ ﺍﳌﺘﻐﲑ Charﻭ ﺍﳊﺎﻻﺕ ﺍﳌﻮﺟﻮﺩﺓ ،ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ﻋﺸﺮ ﻭ ﺍﻟﻌﺸﺮﻳﻦ ﺳﻴﻘﻮﻡ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺎﳌﻘﺎﺭﻧﺔ ﺑـﲔ ﺍﻹﺷﺎﺭﺓ +ﻭ ﺍﻟﺮﻗﻢ ١ﺑﺎﳌﺘﻐﲑ Charﻓﺈﺫﺍ ﻛﺎﻧﺖ ﻣﻘﺎﺭﻧﺔ ﻭﺍﺣﺪﺓ ﺻﺤﻴﺤﺔ ﻓﺴﻴﺘﻢ ﺗﻨﻔﻴﺬ ﺍﻟﺴﻄﺮ ﺍﻟﻮﺍﺣﺪ ﻭ ﺍﻟﻌﺸﺮﻳﻦ ﻗﻢ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﻟﻘﺮﺍﺭ switchﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﱐ ﻭ ﺍﻟﻌﺸﺮﻳﻦ ﺑﺪﻭﻥ ﻣﺘﺎﺑﻌﺔ ﺍﳌﻘﺎﺭﻧﺔ ﻣﻊ ﺍﳊﺎﻻﺕ ﺍﻷﺧﺮﻯ ،ﻭ ﰲ ﺣﺎﻟـﺔ ﺃﻥ ﺍﳌﻘﺎﺭﻧـﺔ ﺃﻭ 83 ﺍﻟﺸﺮﻁ ﱂ ﻳﺘﺤﻘﻖ ﻓﺴﻴﺘﻢ ﺍﻻﻧﺘﻘﺎﻝ ﺇﱃ ﺍﳊﺎﻟﺔ ﺍﻟﱵ ﺑﻌﺪﻫﺎ ﻭ ﺗﺄﰐ ﺍﳌﻘﺎﺭﻧﺔ ﻣﻌﻬﺎ ﻭ ﻣﻌﺎ ﺍﳌﺘﻐﲑ Charﻭ ﻫﻜﺬﺍ ،...ﻭ ﰲ ﺍﻟـﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﻭ ﺛﻼﺛﲔ ﲡﺪ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ defaultﻭ ﺳﻴﺘﻢ ﺗﻨﻔﻴﺬ ﻣﺎ ﻫﻮ ﺑﻌﺪﻫﺎ ﺇﻥ ﱂ ﻳﺘﺤﻘﻖ ﺃﻱ ﺷﺮﻁ ﻣﻦ ﺍﻟﺸﺮﻭﻁ ﺍﻟﺴﺎﺑﻘﺔ. ﺳﺄﺟﻌﻞ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﻣﻔﻬﻮﻡ ﺃﻛﺜﺮ ،ﻟﺬﺍ ﺳﺄﻗﻮﻡ ﺑﺎﳌﻘﺎﺭﻧﺔ ﺑﻴﻨﻪ ﻭ ﺑﲔ ﺍﳌﺜﺎﻝ ﺍﻟﺬﻱ ﻗﺒﻠﻪ ﰲ ﺍﳌﻘﺎﺭﻧﺔ ﺍﻷﻭﱃ ﻭ ﺍﻷﺧﲑﺓ. case '+': case '1': ;)printf("%d + %d = %d\n", num1, num2, num1+num2 ;break ﻫﺬﺍ ﰲ ﺍﻟﻘﺮﺍﺭ ،switchﺃﻣﺎ ﰲ ﺍﻟﻘﺮﺍﺭﺍﺕ else, else…if 19 20 21 22 if,ﻓﻬﻮ: )'if(Char == '+' || Char == '1 ;)printf("%d + %d = %d\n", num1, num2, num1+num2 17 18 ﻭ ﻫﻨﺎ ﺳﺘﻼﺣﻆ ﺃﻥ ﺍﻟﺴﻄﺮﻳﻦ: case '+': case '1': 19 20 ﻫﻮ ﻧﻔﺴﻪ: 'Char == '+' || Char == '1 ﺃﻣﺎ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ :default default: ;)"printf("Error in choice!\nExiting...\n 38 39 ﻓﻬﻲ elseﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ: else ;)"printf("Error in choice!\nExiting...\n 29 30 ﻭ ﰲ ﺍﻟﻘﺮﺍﺭ switchﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﺃﻋﺪﺍﺩ ﺣﻘﻴﻘﻴﺔ ﻣﺜﻞ floatﻭ )doubleﻫﻨﺎ ﺳﺘﻔﻀﻞ ifﻭ .(else ٢,١,١ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ :case 84 ﻫﻲ ﻣﻦ ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ ﻭ ﺍﻟﱵ ﺗﻌﻠﻤﻨﻬﺎ ﻣﺆﺧﺮ ،ﻭ ﻫﻲ ﻻ ﺗﺴﺘﻌﻤﻞ ﺇﻻ ﰲ ﺍﻟﻘﺮﺍﺭ ،switchﻭ ﻫﻲ ﺗﻌﲏ ﻛﻠﻤﺔ ﺣﺎﻟﺔ، ﺑﻌﺪ ﺍﺳﻢ ﺍﳊﺎﻟﺔ ﻳﺄﰐ ﺍﻟﺸﺮﻁ ،ﻓﻤﺜﻼ ’ case ‘1ﻫﻨﺎ ﺳﻴﺘﻢ ﺍﳌﻘﺎﺭﻧﺔ ﺑﲔ ﺍﻟﺮﻗﻢ ١ﻭ ﺍﳌﺘﻐﲑ ﺍﳌﻮﺟﻮﺩ ﰲ ﻭﺳﻴﻂ ﺍﻟﻘﺮﺍﺭ ،switch ﻓﺈﺫﺍ ﻛﺎﻧﺖ ﺍﳌﻘﺎﺭﻧﺔ ﺻﺤﻴﺤﺔ ﻓﺴﻴﺘﻢ ﺗﻨﻔﻴﺬ ﻣﺎ ﻫﻮ ﺑﻌﺪ ﺍﳊﺎﻟﺔ ﻣﻦ ﺃﻭﺍﻣﺮ ،ﻭ ﰲ ﺣﺎﻟﺔ ﺃﺎ ﺧﺎﻃﺌﺔ ﻓﺴﻴﺘﻢ ﺍﻻﻧﺘﻘﺎﻝ ﺇﱃ ﺍﳊـﺎﻻﺕ ﺍﻷﺧﺮﻯ .ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻧﺺ ﻟﻠﻤﻘﺎﺭﻧﺔ ﰲ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ،caseﻷﺎ ﺗﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻷﺭﻗﺎﻡ ﻭ ﺍﻷﺣﺮﻑ ﻓﻘـﻂ ،ﺣـﱴ ﺍﻟﻘﺮﺍﺭ switchﻻ ﳝﻜﻦ ﺇﻋﻄﺎﺋﻪ ﻣﺘﻐﲑ ﻣﻨﺖ ﻧﻮﻉ ﺳﻠﺴﻠﺔ ﺣﺮﻭﻑ ،ﻫﻮ ﺃﻳﻀﺎ ﻻ ﻳﻘﺒﻞ ﺇﻻ ﲟﻐﲑﺍﺕ ﺍﻷﺣﺮﻑ ﻭ ﺍﻷﺭﻗﺎﻡ. ٢,١,٢ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ :break ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﺩﺍﺧﻞ ﺍﻟﻘﺮﺍﺭ switchﻭ ﻫﻲ ﺗﻌﲏ ﺍﻻﻧﻘﻄﺎﻉ ،ﻭ ﻫﻲ ﺗﺴﺘﻌﻤﻞ ﻣﻊ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠـﻮﺯﺓ ،caseﰲ ﺣﺎﻟـﺔ ﺍﻻﺳﺘﻐﻨﺎﺀ ﻋﻨﻬﺎ ﻓﺴﺘﺄﰐ ﻧﺘﺎﺋﺞ ﻏﲑ ﻣﺮﻏﻮﺏ ﺎ ،ﻭ ﻋﻤﻠﻬﺎ ﻫﻮ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﳊﻠﻘﺔ ﺍﻟﻘﺮﺍﺭ .switch ٢,١,٣ﺍﻟﻜﻠﻤﺔ ﺍﻮﺯﺓ :default ﺃﻳﻀﺎ ﺗﺴﺘﻌﻤﻞ ﻣﻊ ﺍﻟﻘﺮﺍﺭ switchﻭ ﻫﻲ ﺍﻟﻮﺿﻊ ﺍﻻﻓﺘﺮﺍﺿﻲ ،ﺃﻱ ﺃﻧﻪ ﺇﻥ ﱂ ﺗﺘﺤﻘﻖ ﺃﻱ ﺣﺎﻟﺔ ﻣﻦ ﺍﳊﺎﻻﺕ ﺍﻟﺴﺎﺑﻘﺔ ﻓﺴﻴﺘﻢ ﺗﻨﻔﻴﺬ ﻣﺎ ﻫﻮ ﺑﻌﺪﻫﺎ. ٢,١,٤ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: .١ﰲ ﺣﺎﻟﺔ ﺃﻧﻚ ﺃﺭﺩﺕ ﺍﺳﺘﻌﻤﺎﻝ ﺍﳊﺎﻟﺔ ﻣﺒﺎﺷﺮﺓ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺮﻗﻢ ﺑﻌﺪ caseﻓﻴﺠﺐ ﻋﻠﻴﻚ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺘﻐﲑ ﻣﻦ ﻧـﻮﻉ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ،ﻭ ﻟﻴﺲ ﻣﺘﻐﲑ ﺃﺣﺮﻑ ﻭ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺳﻴﺼﺒﺢ ﻋﻠﻰ ﻫﺬﺍ ﺍﻟﺸﻜﻞ: >#include<stdio.h )(main { ;int num1, num2 ;int Char ;)" printf("1:(+)\n2:(-)\n3:(/)\n4:(*)\nEnter a choice: ;)scanf("%d", &Char ;)" printf("Enter the first number: ;)scanf ("%d", &num1 ;)" printf("Enter the second number: ;)scanf("%d", &num2 )switch(Char { case 1: ;)printf("%d + %d = %d\n", num1, num2, num1+num2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 85 ;break case 2: ;)printf("%d - %d = %d\n", num1, num2, num1-num2 ;break case 3: ;)printf("%d / %d = %d\n", num1, num2, num1/num2 ;break case 4: ;)printf("%d * %d = %d\n", num1, num2, num1*num2 ;break default: ;)"printf("Error in choice!\nExiting...\n } ﺍﻟﱪﻧﺎﻣﺞ :٢,١,٣ﺍﳋﻄﺄ ١ } 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 .٢ﳚﺐ ﺩﺍﺋﻤﺎ ﺍﻻﻧﺘﺒﺎﻩ ﺇﱃ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ breakﻭ ﻣﻜﺎﻥ ﺍﺳﺘﻌﻤﺎﳍﺎ. ٢,١,٥ﲤﺎﺭﻳﻦ: -١ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﺑﻪ ﻗﺎﺋﻤﺔ ﺭﺋﻴﺴﻴﺔ ﻟﻠﻌﺒﺔ ،ﺣﻴﺚ ﺳﻴﻜﻮﻥ ﳍﺎ ﺃﺭﺑﻊ ﺧﻴﺎﺭﺍﺕ ﻭ ﻫﻲ: ﺍﳋﻴﺎﺭ ﺍﻷﻭﻝ ﻫﻮ Start Gameﻭ ﻋﻨﺪ ﺍﺳﺘﻌﻤﺎﻝ ﻫﺬﺍ ﺍﳋﻴﺎﺭ ﳐﱪﻩ ﺑﺄﻥ ﺍﻟﻠﻌﺒﺔ ﻗﺪ ﺑﺪﺃ .ﻭ ﺍﳋﻴﺎﺭ ﺍﻟﺜﺎﱐ ﻫـﻮ Optionﻭ ﺍﻟﱵ ﺑﻪ ﻫﻲ ﺃﻳﻀﺎ ﺃﺭﺑﻊ ﺧﻴﺎﺭﺍﺕ ﻟﻜﻞ ﻣﻦ ﺗﻌﺪﻳﻞ ﺍﻟﺼﻮﺕ ﻭ ﺍﻟﺼﻮﺭﺓ ﻭ ﺍﻟﻔﺄﺭﺓ ﻭ ﻟﻮﺣﺔ ﺍﻟﺘﺤﻜﻢ .ﺍﳋﻴﺎﺭ ﺍﻟﺜﺎﻟﺚ ﻫﻮ About Gameﻭ ﺍﻟﱵ ﺳﺘﻀﻊ ﻓﻴﻬﺎ ﻣﻌﻠﻮﻣﺎﺕ ﻋﻨﻚ .ﻭ ﺍﳋﻴﺎﺭ ﺍﻷﺧﲑ ﻫﻮ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﻟﻠﻌﺒﺔ .Exit Game 86 ﻣﻌﲎ ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ ﺑﺼﻔﺔ ﻋﺎﻣﺔ ﻫﻲ ﺗﻜﺮﺍﺭ ﺷﻲﺀ ،ﻭ ﰲ ﺍﻟﱪﳎﺔ ﺍﻟﺘﻜﺮﺍﺭ ﻳﻜﻮﻥ ﳊﻠﻘﺔ ﻳﺘﻢ ﺗﻜﺮﺍﺭﻫﺎ ﳌـﺮﺍﺕ ﻳﻘـﻮﻡ ﺑﺘﺤﺪﻳﺪﻫﺎ ﺍﳌﱪﻣﺞ ،ﺗﻮﺟﺪ ﺛﻼﺛﺔ ﻃﺮﻗﺔ ﺃﺳﺎﺳﻴﺔ ﰲ ﺍﻟﺘﻜﺮﺍﺭ ،ﻭ ﺗﻮﺟﺪ ﻃﺮﻳﻘﺔ ﺭﺍﺑﻌﺔ ﻭ ﻟﻜﻨﻬﺎ ﻻ ﺗﻌﺘﱪ ﻣﻦ ﻃﺮﻕ ﺍﻟﺘﻜﺮﺍﺭ ،ﺍﻟﻄﺮﻕ ﻫﻲ: ٢,٢,١ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ :while ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻣﺸﺎﺑﻪ ﻗﻠﻴﻼ ﻟﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ،ifﻭ ﻫﺬﻩ ﺻﻮﺭﺓ ﺎ ﺷﺮﺡ ﻟﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ: ﺍﻟﺸﻜﻞ :٢,٢,١ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ while ﺳﻴﺘﻢ ﺗﻨﻔﻴﺬ ﺍﻷﻭﺍﻣﺮ ﺑﺪﻭﻥ ﺗﻮﻗﻒ ﺣﱴ ﻳﺼﺒﺢ ﺍﻟﺸﺮﻁ ﺧﺎﻃﺊ ،ﻭ ﺇﻥ ﻛﺎﻥ ﺷﺮﻁ ﺛﺎﺑﺖ ﺃﻭ ﺃﻥ ﻗﻴﻤﺘﻪ ﻻ ﺗﺘﻐﲑ ﻓـﺴﻴﺘﻢ ﺗﻨﻔﻴـﺬ ﺍﻷﻭﺍﻣﺮ ﻣﺮﺍﺕ ﻻ ﺣﺪﻭﺩ ﳍﺎ ،ﺃﻱ ﺳﻴﺒﻘﻰ ﺗﻨﻔﻴﺬ ﺍﻷﻭﺍﻣﺮ ﺑﺪﻭﻥ ﺗﻮﻗﻒ ﻟﺬﺍ ﳚﺐ ﺃﻥ ﻧﺴﺘﻌﻤﻞ ﻣﺆﺛﺮﺍﺕ ﺍﻟﺰﻳﺎﺩﺓ ﺃﻭ ﺍﻟﻨﻘـﺼﺎﻥ ﺃﻭ ﻧﻌﻄﻲ ﺍﳊﺮﻳﺔ ﻟﻠﻤﺴﺘﺨﺪﻡ ﺑﺈﻳﻘﺎﻑ ﺍﳊﻠﻘﺔ ﻣﱴ ﺃﺭﺍﺩ .ﺍﻵﻥ ﺳﺄﻋﻄﻲ ﻣﺜﺎﻝ ﺑﺴﻴﻂ ﺣﻮﻝ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ whileﺣﻴﺚ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﻋﺪ ﺗﺼﺎﻋﺪﻱ ﻣﻦ ١ﺇﱃ :٣ >#include<stdio.h )(main { ;int i ;i = 1 )while(i!=4 { ;)printf("\a%d ,", i ;i++ } ;)"printf(" Go!\n } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 87 ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ while ﰲ ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ ﺩﺍﺋﻤﺎ ﻧﺴﺘﻌﻤﻞ ﻣﺘﻐﲑﺍﺕ ﻭ ﺇﱃ ﺳﺘﻜﻮﻥ ﺍﳊﻠﻘﺔ ﺑﻼ ﺎﻳﺔ ،ﻭ ﻫﻨﺎ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﳌﺘﻐﲑ iﻭ ﺍﻟﺬﻱ ﺳﻴﻜﻮﻥ ﺍﻟﻌﺪﺍﺩ ﻟﻠﺤﻠﻘﺔ ،ﻭ ﳚﺐ ﺃﻳﻀﺎ ﺇﻋﻄﺎﺀ ﻟﻠﻤﺘﻐﲑ ﻗﻴﻤﺔ ﻳﺒﺪﺃ ﺎ ،ﰲ ﻣﺜﺎﻟﻨﺎ ﺃﻋﻄﻴﻨﺎﻩ ﺍﻟﻘﻴﻤﺔ ١ﺣﻴﺚ ﺳﻴﺒﺪﺃ ﺍﻟﻌﺪ ﻣﻦ ﺍﻟﺮﻗﻢ ،١ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﻭﺿﻌﻨﺎ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ whileﻣﻊ ﺷﺮﻁ )ﻣﻘﺎﺭﻧﺔ( ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﳌﺘﻐﲑ iﻳﺴﺎﻭﻱ ٤ﺣﻴﺚ ﺳﻴﺘﻢ ﺗﻨﻔﻴﺬ ﻣﺎ ﻫﻮ ﺩﺍﺧﻞ ﺍﻟـ blockﺍﳋﺎﺹ ﺑـ whileﺇﱃ ﺃﻥ ﺗﺼﺒﺢ ﺍﳌﻘﺎﺭﻧﺔ ﺧﺎﻃﺌﺔ )ﺣﻴﺚ ﺳﻴﺘﻢ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﳊﻠﻘﺔ ﺇﻥ ﻛﺎﻥ ﺍﳌﺘﻐﲑ iﻳﺴﺎﻭﻱ ٤ﻭ ﻫﺬﺍ ﻳﻌﲏ ﺃﻥ ﺍﻟﺸﺮﻁ i !=4ﺳﻴﻜﻮﻥ ﺧﺎﻃﺊ( ،ﻭ ﺳﺘﺠﺪ ﺃﻳﻀﺎ ﺃﻧﻪ ﺍﺳﺘﻌﻤﻠﻨﺎ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ ﰲ ﺍﻟﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ،ﻭ ﻋـﺪﻡ ﺍﺳﺘﻌﻤﺎﻟﻪ ﻳﻌﻄﻴﻨﺎ ﻧﺘﺎﺋﺞ ﺛﺎﺑﺖ ﻭ ﻏﲑ ﻣﻨﺘﻬﻴﺔ .ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﳌﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ ،ﺍﻵﻥ ﺳﺄﻋﻄﻲ ﻣﺜﺎﻝ ﺑﺴﻴﻂ ﻟﻄﺮﻳﻘـﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻜﺮﺍﺭ ﳌﺘﻐﲑ ﺣﺮﰲ: // Just in Windows and DOS OS compilers >#include<stdio.h >#include<conio.h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 >#include<stdio.h >#include<conio.h 1 2 3 4 )(main { ;char ch ;)" printf("Press any key(q=exit): ;)(ch = getche )'while(ch != 'q { ;)" printf("\nPress any key(q=exit): ;)(ch = getche } ;)"printf("\nExiting...\n } ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٢ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ (٢) while ﺍﺳﺘﻌﻤﻠﻨﺎ ﻣﺘﻐﲑ ﺣﺮﰲ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ﰒ ﻃﻠﺒﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﺃﻱ ﺣﺮﻑ ،ﻭ ﺍﺳﺘﻌﻤﺎﻟﻨﺎ ﺍﻟﺪﺍﻟﺔ getcheﻟﻜـﻲ ﻻ ﻧﺴﻤﺢ ﻟﻠﻤﺴﺘﺨﺪﻡ ﺑﺈﺩﺧﺎﻝ ﺃﻛﺜﺮ ﻣﻦ ﺣﺮﻑ ،ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ﺍﺳﺘﻌﻤﺎﻟﻨﺎ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ whileﻣﻊ ﺷﺮﻁ ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﳌﺘﻐﲑ chﻳﺴﺎﻭﻱ ﺍﳊﺮﻑ ،qﺣﻴﺚ ﻫﻨﺎ ﺳﻴﺒﻘﻰ ﺍﻟﱪﻧﺎﻣﺞ ﻳﻌﻤﻞ ﺑﻼ ﺎﻳﺔ ﺇﻻ ﺇﺫﺍ ﺿﻐﻂ ﺍﳌﺴﺘﺨﺪﻡ ﻋﻠﻰ ﺍﳊـﺮﻑ .q ﳝﻜﻨﻨﺎ ﺍﻻﺳﺘﻐﻨﺎﺀ ﻋﻦ ﺍﻟﺸﺮﻁ ﰲ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ whileﻭ ﻛﺘﺎﺑﺘﻪ ﺩﺍﺧﻞ ﺍﻟـ blockﺍﳋﺎﺹ ﺎ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﳌﻘﺎﺭﻧـﺔ ﻋـﱪ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ifﺣﻴﺚ ﺳﻴﻜﻮﻥ ﺩﺍﺧﻞ ﺍﻟـ blockﺍﳋﺎﺹ ﺎ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ breakﻭ ﺍﻟﱵ ﻗﻠﻨﺎ ﻋﻠﻴﻬﺎ ﺳﺎﺑﻘﺎ ﺃﺎ ﺗﻨﻬﻲ ﺍﳊﻠﻘﺎﺕ ،ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺑﻌﺪ ﺍﻟﺘﻌﺪﻳﻞ: /* Just in Windows and DOS OS compilers */ )(main 88 { 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 >#include<stdio.h >#include<conio.h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ;char ch ;)" printf("Press any key(q=exit): ;)(ch = getche )while(1 { )'if(ch == 'q ;break ;)" printf("\nPress any key(q=exit): ;)(ch = getche } ;)"printf("\nExiting!\n } ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٣ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ (٣) while ﻭ ﻫﻨﺎ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﺮﻗﻢ )١ﻭ ﺍﻟﺬﻱ ﻳﻌﲏ trueﰲ ﻟﻐﺔ (Cﰲ ﻭﺳﻴﻂ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ whileﻛﻲ ﺗﻜﻮﻥ ﺍﳊﻠﻘﺔ ﺑﻼ ﺎﻳﺔ ،ﻭ ﻫﻨﺎ ﺳﺘﻼﺣﻆ ﺃﻥ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ breakﻻ ﺗﺴﺘﻌﻤﻞ ﻓﻘﻂ ﰲ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ .switchﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﳝﻜﻨﻨﺎ ﺍﻻﺳﺘﻐﻨﺎﺀ ﻋﻦ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﻭ ﺍﻟﺘﺎﺳﻊ ﻭ ﳒﻌﻞ ﺍﻟﺸﺮﻁ ﺍﳌﻮﺟﻮﺩ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﻋﺸﺮ ﰲ ﺁﺧﺮ ﺍﳊﻠﻘﺔ ﺣﻴﺚ ﺳﻴﺼﺒﺢ ﺍﳌﺜﺎﻝ ﻛﻤﺎ ﻳﻠﻲ: /* Just in Windows and DOS OS compilers */ )(main { ;char ch )while(1 { ;)" printf("\nPress any key(q=exit): ;)(ch = getche )'if(ch == 'q ;break } ;)"printf("\nExiting!\n } ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٤ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ (٤) while ﰲ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺳﻴﺘﻢ ﺗﻨﻔﻴﺬ ﺍﻷﻭﺍﻣﺮ ﺍﳌﻮﺟﻮﺩ ﰲ ﺍﻟـ blockﺍﳋﺎﺹ ﺑـ whileﻣﺮﺓ ﻭﺍﺣﺪﺓ ﻋﻠﻰ ﺍﻷﻗﻞ ،ﺣـﱴ ﻭ ﺇﻥ ﲢﻘـﻖ ﺍﻟﺸﺮﻁ ،ﻭ ﻟﻜﻨﻬﺎ ﻟﻴﺴﺖ ﻣﻦ ﻣﻴﺰﺍﺕ ﺍﳊﻠﻘﺔ ،whileﺣﻴﺚ ﺗﺴﺘﻌﻤﻞ ﻫﺬﻩ ﻃﺮﻳﻘﺔ ﻏﺎﻟﺒﺎ ﺃﻭ ﺭﲟﺎ ﻻ ﺗﺴﺘﻌﻤﻞ ﺃﺻﻼ. ٢,٢,٢ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ :do…while 89 ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻣﺜﻞ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﺴﺎﺑﻘﺔ ﻟـ whileﻣﻊ ﺑﻌﺾ ﺍﻹﺿﺎﻓﺎﺕ ،ﻭ ﺍﻟﻔﺮﻕ ﺑﲔ do…whileﻭ whileﻫـﻮ ﺃﻥ ﺍﻟﺘﻜﺮﺍﺭ ﺑﺎﺳﺘﺨﺪﺍﻡ whileﻻ ﻳﻘﻮﻡ ﺑﺘﻨﻔﻴﺬ ﺍﻷﻭﺍﻣﺮ ﺍﳌﻮﺟﻮﺩ ﻓﻴﻪ ﻭ ﻻ ﻣﺮﺓ ﻭﺍﺣﺪﺓ ﺇﻻ ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﻟﺸﺮﻁ ﺻﺤﻴﺢ ﻣﺮﺓ ﻭﺍﺣﺪﺓ، ﺃﻣﺎ ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ do…whileﻓﺴﻴﺘﻢ ﺗﻨﻔﻴﺬ ﺍﻷﻭﺍﻣﺮ ﺍﳌﻮﺟﻮﺩ ﺑﺎﻟـ blockﺍﳋﺎﺹ ﺑﻪ ﻣﺮﺓ ﻭﺍﺣﺪﺓ ﻋﻠﻰ ﺍﻷﻗﻞ ﺣـﱴ ﻭ ﺇﻥ ﻛﺎﻥ ﺍﻟﺸﺮﻁ ﺧﺎﻃﺊ .ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻫﻲ ﻛﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ doﰒ ﻧﻘﻮﻡ ﺑﻮﺿﻊ blockﺧﺎﺹ ﺎ ﺣﻴﺚ ﺳﺘﻜﻮﻥ ﺑـﻪ ﺍﻷﻭﺍﻣﺮ ﺍﳌﺮﺍﺩ ﺗﻨﻔﻴﺬﻫﺎ ،ﻭ ﰲ ﺭﻣﺰ ﺎﻳﺔ ﺍﻟـ blockﻭ ﺍﻟﺬﻱ ﻫﻮ } ﻧﻜﺘﺐ whileﻣﻊ ﺍﻟﺸﺮﻁ ،ﻭ ﻫﺬﻩ ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ: ﺍﻟﺸﻜﻞ :٢,٢,٢ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ do…while ﻭ ﻫﺬﻩ ﺍﻷﻣﺜﻠﺔ ﺍﻟﺴﺎﺑﻖ ﺑﺎﺳﺘﺨﺪﺍﻡ :do…while ﻣﺜﺎﻝ ﺍﻟﻌﺪ ﺍﻟﺘﺼﺎﻋﺪﻱ: /* Just in Windows and DOS OS compilers */ >#include<stdio.h >#include<conio.h )(main { ;int i ;i = 1 do { ;)printf("\a%d ,", i ;i++ ;)}while(i != 4 ;)"printf(" Go!\n ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﺍﳌﺘﻐﲑ ﺍﳊﺮﰲ: ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٥ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ do…while } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 90 /* Just in Windows and DOS OS compilers */ >#include<stdio.h >#include<conio.h )(main { ;char ch do { ;)" printf("\nPress any key(q=exit): ;)(ch = getche ;)'}while(ch != 'q ;)"printf("\nExiting...\n } ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٦ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ (٢) do…while ﻫﻨﺎ ﺳﺘﺠﺪ ﺃﻥ ﻋﺪﺩ ﺍﻷﺳﻄﺮ ﻗﺪ ﻗﻞ ،ﻭ ﻟﻜﻦ ﻻ ﺗﻮﺟﺪ ﻃﺮﻳﻘﺔ ﺃﺣﺴﻦ ﻣﻦ ﺍﻷﺧﺮﻯ ﻷﻥ ﻛﻞ ﻃﺮﻳﻘﺔ ﻭ ﻣﻜﺎﻥ ﺍﺳﺘﻌﻤﺎﳍﺎ. ٢,٢,٣ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ :for 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ﺗﻌﺘﱪ ﻫﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ﻣﻦ ﺃﺳﻬﻞ ﺍﻟﻄﺮﻕ ﺍﻟﺴﺎﺑﻘﺔ ﰲ ﺍﻻﺳﺘﻌﻤﺎﻝ ،ﻫﻲ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻷﻛﺜﺮ ﺍﺳـﺘﻌﻤﺎﻻ ﻟﺒـﺴﺎﻃﺘﻬﺎ ﻭ ﺳـﻬﻮﻟﺘﻬﺎ. ﻟﻠﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ forﺛﻼﺛﺔ ﻭﺳﺎﺋﻂ ﻭ ﻳﺘﻢ ﺍﻟﻔﺼﻞ ﺑﻴﻨﻬﺎ ﺑﻔﺎﺻﻠﺔ ﻣﻨﻘﻮﻃﺔ ﲝﻴﺚ: .١ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻧﻀﻊ ﺑﻪ ﻗﻴﻤﺔ ﺍﻟﱵ ﺳﻴﺒﺪﺃ ﺎ ﺍﻟﻌﺪﺍﺩ. .٢ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻫﻮ ﺍﻟﺸﺮﻁ ،ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﻟﺸﺮﻁ ﻛﺎﻥ ﺧﺎﻃﺊ ﻳﺘﻢ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﳊﻠﻘﺔ. .٣ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﻟﺚ ﻫﻮ ﺍﳌﺆﺛﺮ )ﻏﺎﻟﺒﺎ ﻣﺎ ﻳﻜﻮﻥ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ ﺃﻭ ﻣﺆﺛﺮ ﺍﻟﻨﻘﺼﺎﻥ(. ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ: 91 ﺍﻟﺸﻜﻞ :٢,٢,٣ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ for ﻣﺜﺎﻝ ﺍﻟﻌﺪ ﺍﻟﺘﺼﺎﻋﺪﻱ ﺳﻴﻜﻮﻥ ﻋﻠﻰ ﻫﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ: /* Just in Windows and DOS OS compilers */ >#include<stdio.h >#include<conio.h )(main { ;int i )for(i=1;i<=3;i++ { ;)printf("\a%d ,", i } ;)"printf(" Go!\n ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٧ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 for ﻫﻨﺎ ﻧﻘﻮﻡ ﺃﻭﻻ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﺍﳌﺘﻐﲑ ﰲ ﺑﺪﺍﻳﺔ ﺍﻟﱪﻧﺎﻣﺞ ﰒ ﻧﻌﻄﻲ ﺍﳌﺘﻐﲑ ﻗﻴﻤﺔ ﺩﺍﺧﻞ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ forﺃﻱ ﰲ ﺃﻭﻝ ﻭﺳـﻴﻂ ﳍﺎ ﺣﻴﺚ ﺳﺘﻜﻮﻥ ﺗﻠﻚ ﺍﻟﻘﻴﻤﺔ ﻫﻲ ﺑﺪﺍﻳﺔ ﺍﻟﻌﺪﺍﺩ ،ﰒ ﺍﳌﻘﺎﺭﻧﺔ ﰲ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﺣﻴﺚ ﳚﺐ ﺃﻥ ﻻ ﻳﺘﻌﺪﻯ ﺍﳌﺘﻐﲑ iﺍﻟﻌـﺪﺩ ٣ )ﺇﺫﺍ ﺗﻌﺪﻯ ﺍﳌﺘﻐﲑ iﺍﻟﻌﺪﺩ ٣ﻓﺴﻴﺼﺒﺢ ﺍﻟﺸﺮﻁ ﺧﺎﻃﺊ ﻭ ﺳﻴﺘﻢ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﳊﻠﻘﺔ( ،ﻭ ﰲ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﻟﺚ ﺍﺳﺘﻌﻤﻠﻨﺎ ﻣـﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ. ﺃﻣﺎ ﺑﺎﻟﻨﺴﺒﺔ ﳌﺜﺎﻝ ﺍﳌﺘﻐﲑ ﺍﳊﺮﰲ ﻓﺎﻟﻄﺮﻳﻘﺔ ﲣﺘﻠﻒ ﻗﻠﻴﻼ ،ﺣﻴﺚ ﺳﻨﻘﻮﻡ ﺑﺎﻻﺳﺘﻐﻨﺎﺀ ﻋﻦ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻭ ﺍﻷﺧﲑ ،ﻭ ﺳﻨﺴﺘﻌﻤﻞ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻟﻮﺿﻊ ﺍﻟﺸﺮﻁ ﺣﻴﺚ ﺇﻥ ﻛﺎﻥ ﺍﻟﺸﺮﻁ ﺧﺎﻃﺊ ﻳﺘﻢ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﳊﻠﻘﺔ ،ﻭ ﺍﻟﺸﺮﻁ ﻫﻨﺎ ﻫﻮ ﺃﻥ ﻻ ﻳﺴﺎﻭﻱ ﺍﳌﺘﻐﲑ chﺍﳊﺮﻑ ) qﺳﻴﺼﺒﺢ ﺍﻟﺸﺮﻁ ﺧﺎﻃﺊ ﺇﺫﺍ ﻛﺎﻥ ﺍﳌﺘﻐﲑ chﻳﺴﺎﻭﻱ ﺍﳊﺮﻑ ،(qﻭ ﺍﻟﱪﻧﺎﻣﺞ ﺳﻴﻜﻮﻥ ﻋﻠﻰ ﻫﺬﺍ ﺍﻟﺸﻜﻞ: /* Just in Windows and DOS OS compilers */ >#include<stdio.h >#include<conio.h )(main { ;char ch ;)" printf("Press any key(q=exit): ;)(ch = getche );'for(;ch!='q { ;)" printf("\nPress any key(q=exit): ;)(ch = getche } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 92 ;)"printf("\nExiting...\n } 17 18 ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٨ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ (٢) for ﰲ ﺍﻟﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﺘﻜﺮﺍﺭ ﻣﻊ ﲡﺎﻫﻞ ﺍﻟﻮﺳﻴﻄﲔ ﺍﻷﻭﻝ ﻭ ﺍﻷﺧﲑ ﻭ ﻟﻜﻦ ﳚﺐ ﺃﻥ ﻧﺘـﺮﻙ ﻣﻜﺎﻧـﺎ ﳍﻤـﺎ ،ﻭ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻭ ﻫﻮ ﺍﻟﺸﺮﻁ ﺍﻟﺬﻱ ﰲ ﺣﺎﻟﺔ ﻛﺎﻥ ﺧﺎﻃﺊ ﻳﺘﻢ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﳊﻠﻘﺔ. ٢,٢,٤ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ :goto ﻫﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ﺇﺿﺎﻓﻴﺔ ،ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ gotoﺗﺴﺘﻌﻤﻞ ﻟـ ﺍﻟﺘﻨﻘﻞ ﻣﻦ ﻣﻜﺎﻥ ﻵﺧﺮ ﰲ ﻣﺼﺪﺭ ﺍﻟﱪﻧﺎﻣﺞ ،ﺳﺄﺷـﺮﺡ ﺃﻭﻻ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ ﰒ ﻧﺬﻫﺐ ﺇﱃ ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺘﻬﺎ .ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ ﺑﺴﻴﻄﺔ ﺟﺪﺍ ،ﻧﻜﺘﺐ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ gotoﰒ ﺍﺳـﻢ ﺍﳌﻜﺎﻥ ﺍﻟﺬﻱ ﻧﺮﻳﺪ ﺍﻟﺬﻫﺎﺏ ﺇﻟﻴﻪ ،ﻫﺬﻩ ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ: ﺍﻟﺸﻜﻞ :٢,٢,٤ﻃﺮﻳﻘﺔ ﺍﻟﺬﻫﺎﺏ ﺇﱃ ﻣﻜﺎﻥ ﻣﺎ ﰲ ﺍﻟﱪﻧﺎﻣﺞ ﻋﱪ goto ﻭ ﻟﻜﻦ ﻫﺬﺍ ﺍﻟﻜﻮﺩ ﻻ ﻳﻜﻔﻲ ،ﳚﺐ ﺃﻥ ﻧﻀﻊ ﺍﺳﻢ ﺍﳌﻜﺎﻥ ﺣﻴﺚ ﺳﻴﻜﻮﻥ ﻋﻠﻰ ﺍﻟﺸﻜﻞ ﺍﻟﺘﺎﱄ: ﺍﻟﺸﻜﻞ :٢,٢,٥ﺇﻧﺸﺎﺀ ﺇﺳﻢ ﳌﻜﺎﻥ ﳝﻜﻦ ﺍﻟﺬﻫﺎﺏ ﺇﻟﻴﻪ ﻋﱪ goto ﺍﻵﻥ ﺳﺄﺿﻊ ﻣﺜﺎﻝ ﺑﺴﻴﻂ ﻣﻔﻬﻮﻡ: >#include<stdio.h )(main { ;goto fin ;)"printf("Begin!\n fin: ;)"printf("End!\n ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٩ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ goto } 1 2 3 4 5 6 7 8 9 10 93 ﻫﻨﺎ ﻋﻨﺪ ﺗﻨﻔﻴﺬ ﺍﻟﱪﻧﺎﻣﺞ ﺳﻴﺘﻢ ﲡﺎﻫﻞ ﻛﻞ ﻣﺎ ﺑﲔ goto the_name_of_placeﻭ ﺍﺳﻢ ﺍﳌﻜﺎﻥ ،ﻭ ﻫﻨﺎ ﺍﺳﻢ ﺍﳌﻜﺎﻥ ﺍﻟﺬﻱ ﻧﺮﻳﺪ ﺍﻻﻧﺘﻘﺎﻝ ﺇﻟﻴﻪ ﻫﻮ finﻭ ﻫﻮ ﻣﻮﺟﻮﺩ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ،ﻭ ﺃﺭﺩﻧﺎ ﺍﻟﺬﻫﺎﺏ ﺇﱃ ﺍﳌﻜﺎﻥ finﰲ ﺑﺪﺍﻳﺔ ﺍﻟﱪﻧﺎﻣﺞ .ﺇﺫﺍ ﺃﺭﺩﻧـﺎ ﺍﻟﺮﺟﻮﻉ ﺇﱃ ﺑﺪﺍﻳﺔ ﺍﻟﱪﻧﺎﻣﺞ ﻓﺎﻟﻄﺮﻳﻘﺔ ﺳﻬﻠﺔ ،ﻧﻜﺘﺐ ﻛﻤﺎ ﻳﻠﻲ: >#include<stdio.h 1 2 3 4 5 6 7 8 9 10 11 12 >#include<stdio.h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 )(main { begin: ;goto fin ;)"printf("Begin!\n ;)"printf("End!\n ;goto begin fin: } ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١٠ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ (٢) goto ﻫﻨﺎ ﺳﺘﺠﺪ ﺗﺄﺛﺮ ﺍﻟﺘﻜﺮﺍﺭ ،ﺣﻴﺚ ﻫﻨﺎ ﺣﻠﻘﺘﻨﺎ ﻟﻦ ﺗﻨﺘﻬﻲ ،ﻭ ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﺃﻥ ﳒﻌﻞ ﺍﻟﱪﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﺘﻜﺮﺍﺭ ﳓـﺪﺩﻩ ﳓـﻦ ﻓـﺴﻨﻘﻮﻡ ﺑﺎﺳﺘﻌﻤﺎﻝ ﻣﺘﻐﲑ ﻭ ﺍﻟﺬﻱ ﺳﻴﻜﻮﻥ ﺍﻟﻌﺪﺍﺩ ﰒ ﻣﺆﺛﺮ ﰒ ﺍﻟﺸﺮﻁ ،ﻭ ﺳﻴﺼﺒﺢ ﺍﳌﺜﺎﻝ ﻋﻠﻰ ﻫﺬﺍ ﺍﻟﺸﻜﻞ: )(main { ;int i ;i = 0 ;)"printf("Begin!\n begin: ;)printf("%d ,", i ;i++ )if(i==10 ;goto fin else ;goto begin fin: ;)"printf("\nEnd!\n ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١١ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ﻭ ﻫﻨﺎ ﻧﻜﻮﻥ ﻗﺪ ﻭﺿﻌﻨﺎ ﺗﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ .goto ٢,٢,٥ﺍﳌﻔﻬﻮﻡ ﺍﻟﻌﺎﻡ ﳊﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ: } goto 94 ﻟﻜﻲ ﺗﻔﻬﻢ ﺍﻟﺘﻜﺮﺍﺭ ﺑﺼﻔﺔ ﻋﺎﻣﺔ ﻓﻜﻞ ﻣﺎ ﻋﻠﻴﻚ ﻣﻌﺮﻓﺘﻪ ﻫﻮ: .١ﻟﻜﻞ ﺣﻠﻘﺔ ﺗﻜﺮﺍﺭ ﺑﺪﺍﻳﺔ ﻭ ﺍﻟﱵ ﺗﺴﻤﻰ ﺑﺒﺪﺍﻳﺔ ﺍﻟﻌﺪﺍﺩ ،ﻫﻨﺎ ﺗﻮﺟﺪ ﺣﺎﻻﺕ ﳝﻜﻦ ﻓﻴﻬﺎ ﲡﺎﻫﻞ ﻭﺿﻊ ﺑﺪﺍﻳﺔ ﺍﻟﺘﻜﺮﺍﺭ ،ﻣﺜﻞ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺘﻐﲑﺍﺕ ﺣﺮﻓﻴﺔ. .٢ﻟﻜﻞ ﺣﻠﻘﺔ ﺗﻜﺮﺍﺭ ﺷﺮﻁ ،ﰲ ﺣﺎﻟﺔ ﻛﺎﻥ ﺧﺎﻃﺊ ﻳﺘﻢ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﳊﻠﻘﺔ ،ﺣﻴﺚ ﲡﺎﻫﻞ ﻭﺿﻊ ﺍﻟﺸﺮﻁ ﻳﻨﺘﺞ ﺣﻠﻘﺔ ﻏﲑ ﻣﻨﺘﻬﻴﺔ. .٣ﻟﻜﻞ ﺣﻠﻘﺔ ﻣﺆﺛﺮ ﺳﻮﺍﺀ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ ﺃﻭ ﺍﻟﻨﻘﺼﺎﻥ ،ﻫﻨﺎ ﺃﻳﻀﺎ ﺗﻮﺟﺪ ﺣﺎﻻﺕ ﳝﻜﻦ ﻓﻴﻬﺎ ﲡﺎﻫﻞ ﻭﺿﻊ ﻣـﺆﺛﺮ ،ﻣﺜـﻞ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺘﻐﲑﺍﺕ ﺣﺮﻓﻴﺔ. ﻣﺜﺎﻟﻨﺎ ﺍﻷﻭﻝ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ ﻫﻮ: >#include<stdio.h )(main { ;int i ;i = 1 )while(i!=4 { ;)printf("\a%d ,", i ;i++ } ;)"printf(" Go!\n ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١٢ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ (٥) while ﻭ ﺷﺮﺣﻪ ﺑﺼﻔﺔ ﻋﺎﻣﺔ ﻣﻮﺟﻮﺩ ﻋﻠﻰ ﺍﻟﺼﻮﺭﺓ ﺍﻟﺘﺎﻟﻴﺔ: } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 95 ﺍﻟﺸﻜﻞ :٢,٢,٦ﺷﺮﺡ ﻟﻌﻤﻠﻴﺔ ﺍﻟﺘﻜﺮﺍﺭ ﰲ while ﻫﺬﻩ ﺍﻟﺼﻮﺭﺓ ﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ،whileﻭ ﻫﺬﻩ ﺻﻮﺭﺓ ﺃﺧﺮﻯ ﻋﻦ ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ :do…while ﺍﻟﺸﻜﻞ :٢,٢,٧ﺷﺮﺡ ﻟﻌﻤﻠﻴﺔ ﺍﻟﺘﻜﺮﺍﺭ ﰲ do…while ﻭ ﺃﺧﲑﺍ ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ ﻟﻠﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ :for ﺍﻟﺸﻜﻞ :٢,٢,٨ﺷﺮﺡ ﻟﻌﻤﻠﻴﺔ ﺍﻟﺘﻜﺮﺍﺭ ﰲ for ﻭ ﺗﺒﻘﻰ ﻃﺮﻳﻘﺔ ﺍﻟﺘﻜﺮﺍﺭ ،gotoﺗﻠﻚ ﺍﻟﻄﺮﻳﻘﺔ ﳝﻜﻨﻨﺎ ﲡﺎﻫﻠﻬﺎ ﻷﺎ ﻃﺮﻳﻘﺔ ﺇﺿﺎﻓﻴﺔ ﻭ ﻫﻲ ﻏﺎﻟﺒﺎ ﻣﺎ ﺗﺴﺘﻌﻤﻞ ﰲ ﺍﻟﺘﻜﺮﺍﺭ .ﲨﻴـﻊ ﺍﻟﻄﺮﻕ ﺍﻟﺴﺎﺑﻘﺔ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﺑﻄﺮﻳﻘﺔ ﺃﺧﺮﻯ ،ﺣﻴﺚ ﳝﻜﻦ ﺃﻥ ﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﻛﻞ ﻣﻦ ﺑﺪﺍﻳﺔ ﺍﻟﻌﺪﺍﺩ ﻭ ﺍﻟﺸﺮﻁ ﻭ ﺍﳌﺆﺛﺮ ﺧﺎﺭﺝ ﻭﺳﺎﺋﻂ ﻛﻞ ﻣﻦ ،while, do...while, forﻭ ﻫﺬﺍ ﻣﺜﻞ ﻃﺒﻴﻌﻲ: 96 >#include<stdio.h 1 2 3 4 5 6 7 8 9 10 11 12 13 >#include<stdio.h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 )(main { ;int i )for(i=1;i<=3;i++ { ;)printf("\a%d ,", i } ;)"printf(" Go!\n } ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١٣ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻴﻄﺔ (٣) for ﻭ ﻫﻨﺎ ﻧﻔﺲ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﻭ ﻟﻜﻦ ﺑﻄﺮﻳﻘﺔ ﺃﺧﺮﻯ: )(main { ;int i ;i=1 );;(for { )if(i>3 ;break ;)printf("\a%d ,", i ;i++ } ;)"printf(" Go!\n ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١٤ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻴﻄﺔ (٤) for ﻭ ﻟﻜﻲ ﺗﻔﻬﻤﺎ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺇﻟﻴﻚ ﺻﻮﺭﺓ ﺗﻮﺿﺤﻪ: ﺍﻟﺸﻜﻞ :٢,٢,٩ for ﺑﻄﺮﻳﻘﺔ ﺃﺧﺮﻯ } 97 ﻭ ﻫﻨﺎ ﺳﺘﺠﺪ ﺃﻥ ﺍﻟﻨﺘﻴﺠﺔ ﺳﺘﻜﻮﻥ ﻧﻔﺴﻬﺎ ،ﻭ ﺍﳌﺜﺎﻝ ﻫﻨﺎ ﺑﺎﺳﺘﺨﺪﺍﻡ ،forﳝﻜﻦ ﺍﺳـﺘﻌﻤﺎﻝ whileﻭ ،do…whileﺑـﻨﻔﺲ ﺍﻟﻔﻜﺮﺓ. ٢,٢,٧ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ :continue ﺗﺴﺘﻌﻤﻞ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ continueﺩﺍﺧﻞ ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ ،ﺣﻴﺚ ﺗﻘﻮﻡ ﺑﺎﻟﺮﺟﻮﻉ ﺇﱃ ﺑﺪﺍﻳﺔ ﺍﳊﻠﻘﺔ ﺑـﺪﻭﻥ ﺇﻛﻤـﺎﻝ ﻣﺎﻫﻮ ﺑﻌﺪﻫﺎ ﻣﻦ ﺃﻭﺍﻣﺮ ،ﻭ ﻛﻲ ﺗﻌﺮﻑ ﺃﳘﻴﺘﻬﺎ ﺟﺮﺏ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: >#include<stdio.h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 >#include<stdio.h 1 2 3 4 5 6 7 8 9 10 11 12 13 )(main { ;int i ;i = 1 )while(1 { )if(i<=3 { ;)printf("\a%d ,", i ;++i } ;)"printf(" Go!\n ;break } } ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١٥ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻴﻄﺔ (٦) while ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﻟﻦ ﻳﻌﻤﻞ ﻛﻤﺎ ﻳﻨﺒﻐﻲ ،ﻧﺮﻳﺪ ﻣﻦ ﺍﻟﱪﻧﺎﻣﺞ ﺃﻥ ﻳﻘﻮﻡ ﺑﻌﺪ ﺗﺼﺎﻋﺪﻱ ﻣﻦ ١ﺇﱃ ٣ﺃﻣﺎ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﻟﻦ ﻳﻄﺒﻊ ﺇﱃ ﺍﻟﻌﺪﺩ ،١ﻭ ﻛﻲ ﻳﻌﻤﻞ ﺍﻟﱪﻧﺎﻣﺞ ﺑﻄﺮﻳﻘﺔ ﺻﺤﻴﺤﺔ ﻧﻈﻴﻒ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ continueﺇﱃ ﰲ ﺎﻳﺔ ﺍﳌﻘﺎﺭﻧﺔ ﻭ ﺳﻴـﺼﺒﺢ ﺍﳌﺜـﺎﻝ ﺍﻟﺴﺎﺑﻖ ﻛﻤﺎ ﻳﻠﻲ: )(main { ;int i ;i = 1 )while(1 { )if(i<=3 { ;)printf("\a%d ,", i ;++i 98 ;continue } ;)"printf(" Go!\n ;break } ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١٦ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ } 14 15 16 17 18 19 20 21 continue ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﻋﻠﻰ ﻛﻞ ﻣﻦ do…whileﻭ .for ٢,٢,٨ﺟﺪﻭﻝ :ASCII ﺑﺎﺳﺘﺨﺪﺍﻡ ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ ﳝﻜﻨﻨﺎ ﻣﻌﺮﻓﺔ ﻛﻞ ﺭﻣﺰ ﰲ ﺟﺪﻭﻝ ASCIIﻭ ﺭﻗﻤﻪ ،ﻭ ﺫﻟﻚ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: >#include<stdio.h )(main { ;int i )for(i=0;i<=255;i++ ;)printf("%d: %c\n", i, i ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١٧ﻃﺒﺎﻋﺔ ﺟﺪﻭﻝ ASCIIﺑﺈﺳﺘﺨﺪﺍﻡ ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ } 1 2 3 4 5 6 7 8 9 10 ﻭ ﺳﺘﺠﺪ ﻋﻨﺪ ﺗﺸﻐﻴﻞ ﺍﻟﱪﻧﺎﻣﺞ ﺃﻥ ﺑﻌﺾ ﺍﻟﺮﻣﻮﺯ ﱂ ﺗﻄﺒﻊ ﻣﻨﻬﺎ ﺍﻟﺮﻗﻢ ٠ﻭ ﺍﻟﺮﻗﻢ ١٣ ،٩ ،٨ ،٧ﻭ ﺃﺧﺮﻯ ،ﻭ ﺳﺒﺐ ﰲ ﺫﻟﻚ ﺃﺎ ﻻ ﺗﻘﻮﻡ ﺑﺄﻋﻤﺎﻝ ﻇﺎﻫﺮﺓ ﻓﻤﺜﻼ ﺍﻟﺮﻗﻢ ٠ﻫﻮ ﺍﻟﺮﻣﺰ \0ﻭ ﺍﻟﺮﻗﻢ ١٣ﻫﻮ ﺯﺭ ﺍﻟﺪﺧﻮﻝ ﰲ ﻟﻮﺣﺔ ﺍﳌﻔﺎﺗﻴﺢ)ﺃﻱ ﺳﻄﺮ ﺟﺪﻳﺪ(. ٢,٢,٩ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: .١ .٢ .٣ .٤ .٥ ﳚﺐ ﺩﺍﺋﻤﺎ ﺍﻻﻧﺘﺒﺎﻩ ﺇﱃ ﺍﻟﺸﺮﻁ ﻭ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ. ﺗﺬﻛﺮ ﺩﺍﺋﻤﺎ ﺃﻥ ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ do…whileﻳﺘﻢ ﺗﻨﻔﻴﺬ ﺃﻭﺍﻣﺮﻩ ﻣﺮﺓ ﻭﺍﺣﺪﺓ ﻋﻠﻰ ﺍﻷﻗﻞ ،ﺣﱴ ﻭ ﺇﻥ ﻛﺎﻥ ﺍﻟـﺸﺮﻁ ﺧﺎﻃﺊ. ﺍﺳﺘﻌﻤﺎﻝ ﺣﻠﻘﺔ ﺍﻟﺘﻜﺮﺍﺭ forﻓﺎﺭﻏﺔ ﺍﻟﻮﺳﺎﺋﻂ ﺗﻨﺘﺞ ﺣﻠﻘﺔ ﻏﲑ ﻣﻨﺘﻬﻴﺔ ،ﺣﻴﺚ ﺳﺘﻜﻮﻥ ﻋﻠﻰ ﺍﻟﺸﻜﻞ );;(.for ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﻄﺮﻳﻘﺔ ) while(1ﻳﻌﲏ ﺣﻠﻘﺔ ﺑﻼ ﺎﻳﺔ. ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ continueﺑﺪﻭﻥ ﺷﺮﻁ)ﺃﻭ ﺗﻜﺮﺍﺭ ﺑﺪﻭﻥ ﺷﺮﻁ( ﻳﻌﲏ ﺣﻠﻘﺔ ﺑﻼ ﺎﻳﺔ. ٢,٢,١٠ﲤﺎﺭﻳﻦ: 99 .١ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﺎﻟﻌﺪ ﺍﻟﺘﻨﺎﺯﱄ ﻣﻦ ١٠٠ﺇﱃ ،٠ﺑﺎﻟﻄﺮﻕ ﺍﻟﺜﻼﺛﺔ. .٢ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﻷﻋﺪﺍﺩ ﺍﻟﺜﻨﺎﺋﻴﺔ ﻣﻦ ٠ﺇﱃ ،١٠٠ﺑﺎﻟﻄﺮﻕ ﺍﻟﺜﻼﺛﺔ. 100 ﺗﺴﺘﻌﻤﻞ ﺍﳌﺼﻔﻮﻓﺎﺕ ﻹﺩﺍﺭﺓ ﳎﻤﻮﻋﺔ ﻛﺒﲑﺓ ﻣﻦ ﺍﻟﺒﻴﺎﻧﺎﺕ ﳍﺎ ﻧﻔﺲ ﺍﻟﻨﻮﻉ ،ﻭ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﺳﻢ ﻭﺍﺣﺪ ،ﻭ ﳝﻜﻦ ﺃﻥ ﺗﻜﻮﻥ ﺍﳌﺼﻔﻮﻓﺔ ﻣﻦ ﺃﻱ ﻧﻮﻉ ﻣﻦ ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ ،ﻭ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻣﻌﺎ ﺍﻟﺪﻭﺍﻝ .ﻓﺎﺋﺪﺓ ﺍﳌﺼﻔﻮﻓﺎﺕ ﻛﺒﲑﺓ ،ﻭ ﻃﺮﻕ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻛﺜﲑﺓ ﻭ ﻣﺘﻨﻮﻋﺔ ،ﻭ ﻟﻜﻲ ﺗﺮﻯ ﻓﺎﺋﺪﺎ ﺑﺸﻜﻞ ﻛﺒﲑ ﻓﺘﺨﻴﻞ ﺃﻧﻪ ﻃﻠﺐ ﻣﻨﻚ ﺑﻨﺎﺀ ﺑﺮﻧﺎﻣﺞ ﺑﻪ ﺃﻛﺜﺮ ﻣﻦ ٢٠ﻣﺘﻐﲑ ﻭ ﻛﻞ ﻣﺘﻐﲑ ﺑﻪ ﻗﻴﻤﺔ ﺭﲟﺎ ﻧﻘﻮﻡ ﺑﺘﺤﺪﻳﺪﻫﺎ ﳓﻦ ﺃﻭ ﻳﻘﻮﻡ ﺑﺘﺤﺪﻳﺪﻫﺎ ﺍﳌﺴﺘﺨﺪﻡ ،ﻭ ﺇﻟﻴﻚ ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;int arr1, arr2, arr3, arr4, arr5, ...,arr25 ;)" printf("Arr1: ;)scanf("%d", arr1 ;)" printf("Arr2: ;)scanf("%d", arr2 ;)" printf("Arr3: ;)scanf("%d", arr3 ;)" printf("Arr4: ;)scanf("%d", arr4 ;)" printf("Arr5: ;)scanf("%d", arr5 ... ;)" printf("Arr25: ;)scanf("%d", arr25 ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١ﺑﺮﻧﺎﻣﺞ ﺑﻪ ﺃﻛﺜﺮ ﻣﻦ ٢٠ﻣﺘﻐﲑ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 .. .. .. .. .. .. .. ﲣﻴﻞ...ﻛﻢ ﺳﻴﻜﻮﻥ ﻋﺪﺩ ﺃﺳﻄﺮ ﺍﻟﱪﻧﺎﻣﺞ ﺇﻥ ﻗﻤﻨﺎ ﺑﻜﺘﺎﺑﺔ ﲨﻴﻊ ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺗﺮﻙ ﺍﳌﺴﺘﺨﺪﻡ ﻳﻌﻄﻲ ﳍﺎ ﻗﻴﻢ ،ﰒ ﻣﺎﺫﺍ ﻟﻮ ﺃﺭﺩﻧـﺎ ﻃﺒﻊ ﺍﻟﻨﺘﺎﺋﺞ ،ﺳﻴﻜﻮﻥ ﻋﺪﺩ ﺃﺳﻄﺮ ﺍﻟﱪﻧﺎﻣﺞ ﺃﻛﺜﺮ ﻣﻦ ٢٠٠ﺳﻄﺮ ﻭ ﺳﻴﻜﻮﻥ ﺍﻟﱪﻧﺎﻣﺞ ﺟﺎﻣﺪ ،ﻏﲑ ﻣﺮﻥ ﻭ ﻏﲑ ﻣﻔﻬﻮﻡ .ﻫﻨـﺎ ﺗﻜﻤﻦ ﻓﺎﺋﺪﺓ ﺍﳌﺼﻔﻮﻓﺎﺕ ،ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﻠﻬﺎ ﻭ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻬﺎ ﻣﺸﺎﺑﻪ ﻟﻄﺮﻳﻘﺔ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺘﻐﲑﺍﺕ ،ﻛﻞ ﻣﺎ ﺳﺘﻔﻌﻠﻪ ﻫﻮ ﻛﺘﺎﺑـﺔ ﻧﻮﻉ ﺍﳌﺼﻔﻮﻓﺔ ﰒ ﺍﲰﻬﺎ ﰒ ﻳﺄﰐ ﺣﺠﻤﻬﺎ ﻭ ﻫﺬﻩ ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ: 101 ﺍﻟﺸﻜﻞ :٢,٣,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺔ ﻭ ﺍﻵﻥ ﺳﺄﻛﺘﺐ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﳌﺼﻔﻮﻓﺎﺕ: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 >#include<stdio.h )(main { ;]int arr[24 ;int i )for(i=0;i<25;i++ { ;)printf("Arr%d: ", i ;)]scanf("%d", &arr[i } ;)"printf("***********- LIST -***********\n )for(i=0;i<25;i++ { ;)]printf("Arr%d: %d\n", i, arr[i } ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٢ﺑﺮﻧﺎﻣﺞ ﺑﻪ ﺃﻛﺜﺮ ﻣﻦ ٢٠ﻣﺘﻐﲑ ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﳌﺼﻔﻮﻓﺎﺕ } ﺍﻵﻥ ﺃﺻﺒﺢ ﺍﻟﱪﻧﺎﻣﺞ ﺃﻛﺜﺮ ﻣﺮﻭﻧﺔ ﻭ ﻣﻔﻬﻮﻡ ﻣﻊ ﻗﻠﺔ ﻋﺪﺩ ﺍﻷﺳﻄﺮ ،ﺇﻥ ﻛﺎﻥ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺻﻌﺐ ﻓﻴﻤﻜﻦ ﺍﻟﺮﺟﻮﻉ ﺇﻟﻴﻪ ﺑﻌﺪﻣﺎ ﺗﻘﺮﺃ ﻫﺬﺍ ﺍﻟﺪﺭﺱ ﺟﻴﺪﺍ. ٢,٣,١ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﺍﳌﺼﻔﻮﻓﺎﺕ: ﺇﺫﺍ ﻛﺎﻧﺖ ﻟﺪﻳﻦ ﻣﺼﻔﻮﻑ ﺎ ﺍﻟﻌﺪﺩ ٤ﺃﻱ ] int arr[4ﻓﻬﺬﺍ ﻳﻌﲏ ﺃﻧﻨﺎ ﻗﻤﻨﺎ ﺑﺄﺧﺬ ﺃﺭﺑﻌﺔ ﺃﻣﺎﻛﻦ ﰲ ﺍﻟﺬﺍﻛﺮ ﻛﻞ ﻭﺍﺣﺪﺓ ﻣﻬﻨﺎ ﲝﺠﻢ ﺍﳌﺘﻐﲑ ،intﺗﻮﺟﺪ ﻃﺮﻳﻘﺘﲔ ﻹﻋﻄﺎﺀ ﻗﻴﻤﺔ ﻟﻠﻤﺼﻔﻮﻓﺎﺕ ،ﺍﻟﻄﺮﻳﻘﺔ ﺍﻷﻭﱃ ﻫﻲ ﻛﺘﺎﺑﺔ ﺍﳌﺼﻔﻮﻓﺔ ﰒ ﺑﻌﺪﻫﺎ ﻣﺒﺎﺷـﺮﺓ ﺍﻟﻘﻴﻢ ﺍﻟﱵ ﺎ ،ﻣﺜﺎﻝ ﺗﻮﺿﻴﺤﻲ: >#include<stdio.h )(main { ;}int arr[4] = {10, 12, 13, 15 ;)]printf("[%d][%d][%d][%d]\n", arr[0], arr[1], arr[2], arr[3 ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٣ﻃﺮﻳﻘﺔ ﺇﻋﻄﺎﺀ ﻗﻴﻢ ﳌﺼﻔﻮﻓﺔ } 1 2 3 4 5 6 7 8 102 ﺣﻴﺚ ﺳﺘﻜﻮﻥ ﻃﺮﻳﻘﺔ ﻭﺿﻊ ﺍﻟﻘﻴﻢ ﻣﻨﻈﻤﺔ ،ﻣﺜﻼ ﺇﻥ ﻭﺿﻌﻨﺎ ﺛﻼﺛﺔ ﻗﻴﻢ ﳌﺼﻔﻮﻓﺔ ﺫﺍﺕ ﺃﺭﺑﻌﺔ ﺃﻣﺎﻛﻦ ﻓﺈﻥ ﺍﳌﻜﺎﻥ ﺍﻟﺮﺍﺑﻊ ﺳـﻴﺒﻘﻰ ﺑﺪﻭﻥ ﻗﻴﻤﺔ ،ﻭ ﺗﺮﻯ ﺃﻧﻪ ﻋﻨﺪﻣﺎ ﻃﺒﻌﻨﺎ ﺍﻟﻨﺘﺎﺋﺞ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺑﺪﺃﻧﺎ ﺑﺎﳌﺼﻔﻮﻑ ٠ﺣﻴﺚ ﲨﻴﻊ ﺍﳌﺼﻔﻮﻓﺎﺕ ﺗﺒﺪﺃ ﻣﻦ ،٠ﻷﻥ ٠ﻳﻌﺘﱪ ﻗﻴﻤﺔ .ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ: 1 2 3 4 5 6 7 8 9 >#include<stdio.h )(main { ;]int arr[4 ;}arr[4] = {10, 12, 13, 15 ;)]printf("[%d][%d][%d][%d]\n", arr[0], arr[1], arr[2], arr[3 } ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٤ﻃﺮﻳﻘﺔ ﺇﻋﻄﺎﺀ ﻗﻴﻢ ﳌﺼﻔﻮﻓﺔ )(٢ ﺃﻱ ﺃﻧﻪ ﳚﺐ ﺇﻋﻄﺎﺀ ﺍﻟﻘﻴﻢ ﻣﺒﺎﺷﺮﺓ ﺑﻌﺪ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﳌﺼﻔﻮﻓﺔ ،ﺗﻮﺟﺪ ﻃﺮﻳﻘﺔ ﺃﺧﺮﻯ ﻭ ﻫﻲ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﳌﺼﻔﻮﻓﺔ ﰒ ﺇﻋﻄـﺎﺀ ﻛﻞ ﺻﻒ ﻗﻴﻤﺘﻪ ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻋﻦ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ: >#include<stdio.h )(main { ;]int arr[4 ;arr[0] = 10 ;arr[1] = 12 ;arr[2] = 13 ;arr[3] = 15 ;)]printf("[%d][%d][%d][%d]\n", arr[0], arr[1], arr[2], arr[3 ﻭ ﻫﻲ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﱵ ﺗﺴﺘﻌﻤﻞ ﺑﻜﺜﺮﺓ. ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٥ﻃﺮﻳﻘﺔ ﺇﻋﻄﺎﺀ ﻗﻴﻢ ﳌﺼﻔﻮﻓﺔ )(٣ } 1 2 3 4 5 6 7 8 9 10 11 12 ٢,٣,٢ﺍﳌﺼﻔﻮﻓﺎﺕ ﺍﻟﺜﻨﺎﺋﻴﺔ ﺍﻷﺑﻌﺎﺩ: ﺍﳌﺼﻔﻮﻓﺎﺕ ﺍﻟﱵ ﺩﺭﺳﻨﻬﺎ ﺳﺎﺑﻘﺎ ﻫﻲ ﻣﺼﻔﻮﻓﺎﺕ ﺫﺍﺕ ﺑﻌﺪ ﻭﺍﺣﺪ ،ﺍﻵﻥ ﺳﻨﺪﺭﺱ ﻣﺼﻔﻮﻓﺎﺕ ﺫﺍﺕ ﺑﻮﻋﺪﻳﻦ ﺣﻴﺚ ﺳﺘﻜﻮﻥ ﻃﺮﻳﻘﺔ ﺍﻻﺳﺘﻌﻤﺎﻝ ﺑﺴﻴﻄﺔ ﻭ ﻣﺸﺎﺑﻪ ﻟﻠﻤﺼﻔﻮﻓﺎﺕ ﺫﺍﺕ ﺑﻮﻋﺪ ﻭﺍﺣﺪ .ﻟﻜﺘﺎﺑﺔ ﻣﺼﻔﻮﻓﺔ ﺫﺍﺕ ﺑﻮﻋﺪﻳﻦ ،ﺳـﻨﻜﺘﺐ ﻣـﺼﻔﻮﻓﺔ ﻃﺒﻴﻌﻴﺔ ﰒ ﻧﻈﻴﻒ ﺇﻟﻴﻬﺎ ﺻﻒ ﺁﺧﺮ ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﺳﺄﻗﻮﻡ ﺑﺸﺮﺣﻪ: >#include<stdio.h )(main 1 2 3 103 { ;]int arr2d[2][2 ;int i,j ;arr2d[0][0] = 10 ;arr2d[0][1] = 20 ;arr2d[1][0] = 30 ;arr2d[1][1] = 40 )for(i=0;i<=1;i++ { )for(j=0;j<=1;j++ { ;)]printf("arr2d[%d][%d] = %d\n", i, j, arr2d[i][j } } ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٦ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺎﺕ ﺛﻨﺎﺋﻴﺔ ﺍﻷﺑﻌﺎﺩ } 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻗﻤﻨﺎ ﺑﺈﻧﺸﺎﺀ ﺍﳌﺼﻔﻮﻓﺔ ﺍﻟﺜﻨﺎﺋﻴﺔ ،ﺃﻋﻄﲔ ﻗﻴﻢ ﻟﻜﻞ ﺻﻒ ﻣﻦ ﺻﻔﻮﻑ ﺍﳌﺼﻔﻮﻓﺎﺕ ﰲ ﻛﻞ ﻣﻦ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﻭ ﺍﻟﺘﺎﺳﻊ ﻟﻠﻤﺼﻔﻮﻓﺔ ﺍﻷﻭﱃ ] ،[0ﻭ ﺍﻟﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ﻭ ﺍﻟﺜﺎﱐ ﻋﺸﺮ ﻟﻠﻤﺼﻔﻮﻓﺔ ﺍﻟﺜﺎﻧﻴﺔ ] .[1ﻣﺼﻔﻮﻓﺎﺕ ﺛﻨﺎﺋﻴﺔ ﺍﻷﺑﻌـﺎﺩ ﻫﻲ ﺍﳌﺼﻔﻮﻓﺎﺕ ﺎ ﻣﺼﻔﻮﻓﺎﺕ ،ﺃﻱ ﻣﺼﻔﻮﻓﺔ ﺭﺋﻴﺴﻴﺔ ﻭ ﻣﺼﻔﻮﻓﺔ ﺛﺎﻧﻮﻳﺔ ،ﻓﺈﺫﺍ ﻛﺎﻧﺖ ﻟﺪﻳﻨﺎ ﻣﺼﻔﻮﻓﺔ ﺭﺋﻴﺴﻴﺔ ﲝﺠـﻢ ٢ﻣـﻦ ﻧﻮﻉ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ﻭ ﻣﺼﻔﻮﻓﺔ ﺛﺎﻧﻮﻳﺔ ﲝﺠﻢ ٢ﻓﻬﺬﺍ ﻳﻌﲏ ﺃﻥ ﺍﳌﺼﻔﻮﻓﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﺍﻷﻭﱃ ﺗﻨﻘﺼﻢ ﺇﱃ ﻣﺼﻔﻮﻓﺘﲔ ﺛﺎﻧﻮﻳﺘﲔ ،ﻭ ﺍﳌﺼﻔﻮﻓﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﺍﻟﺜﺎﻧﻴﺔ ﺃﻳﻀﺎ ﺗﻨﻘﺴﻢ ﺇﱃ ﻣﺼﻔﻮﻓﺘﲔ ﺛﺎﻧﻮﻳﺘﲔ .ﰲ ﺍﳌﺼﻔﻮﻓﺎﺕ ﺍﻟﺜﻨﺎﺋﻴﺔ ﺍﻷﺑﻌﺎﺩ ﺗﻮﺟﺪ ﻃﺮﻳﻘﺘﲔ ﺃﻳﻀﺎ ﻹﻋﻄﺎﺋﻬﺎ ﻗﻴﻢ ﺳﺎﺑﻘﺔ ،ﺍﻟﻄﺮﻳﻘﺔ ﺍﻷﻭﱃ ﻭﺿﻌﻨﻬﺎ ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ،ﺃﻣﺎ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﺜﺎﻧﻴﺔ ﻓﻬﻲ: >#include<stdio.h )(main { ;}}int arr2d[2][2] = {{10, 20}, {30, 40 ;int i,j )for(i=0;i<=1;i++ { )for(j=0;j<=1;j++ { ;)]printf("arr2d[%d][%d] = %d\n", i, j, arr2d[i][j } } ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٧ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺎﺕ ﺛﻨﺎﺋﻴﺔ ﺍﻷﺑﻌﺎﺩ )(٢ ﻭ ﻫﻲ ﻣﺸﺎﺎ ﻟﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ ﰲ ﺍﳌﺼﻔﻮﻓﺎﺕ ﺫﺍﺕ ﺑﻮﻋﺪ ﻭﺍﺣﺪ. } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 104 ٢,٣,٢ﺍﳌﺼﻔﻮﻓﺎﺕ ﺍﻟﺜﻼﺛﻴﺔ ﺍﻷﺑﻌﺎﺩ: ﺍﻵﻥ ﳝﻜﻦ ﺣﱴ ﻋﻤﻞ ﻣﺼﻔﻮﻓﺎﺕ ﺫﺍﺕ ﺃﺭﺑﻌﺔ ﺃﻭ ﲬﺴﺔ ﺃﺑﻌﺎﺩ ،ﺑﻨﻔﺲ ﺍﻟﻄﺮﻕ ﺍﻟﺴﺎﺑﻘﺔ ،ﻓﻤﺜﻼ ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﻭﺿـﻊ ﻣـﺼﻔﻮﻓﺔ ﺛﻼﺛﻴﺔ ﺍﻷﺑﻌﺎﺩ ﻭ ﺇﻋﻄﺎﺀ ﳍﺎ ﻗﻴﻢ ﺳﺎﺑﻘﺔ ﺃﻭ ﺗﺮﻙ ﺍﳌﺴﺘﺨﺪﻡ ﻳﻀﻊ ﳍﺎ ﻗﻴﻢ ﻓﺴﻨﻜﺘﺐ ﺍﻵﰐ: ﰲ ﺣﺎﻟﺔ ﺇﻋﻄﺎﺀ ﻗﻴﻢ ﺳﺎﺑﻘﺔ ﻟﻠﻤﺼﻔﻮﻓﺎﺕ ﻧﻜﺘﺐ: >#include<stdio.h )(main { ;}}}int arr3d[2][2][2] = {{{10, 20},{30, 40}}, {{50, 60},{70, 80 ;int i, j, k )for(i=0;i<=1;i++ { )for(j=0;j<=1;j++ { )for(k=0;k<=1;k++ { printf("arr3d[%d][%d][%d] = %d\n", i, j, k, ;)]arr3d[i][j][k } } } ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٨ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺎﺕ ﺛﻼﺛﻴﺔ ﺍﻷﺑﻌﺎﺩ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ﻭ ﰲ ﺣﺎﻟﺔ ﺗﺮﻙ ﺍﳌﺴﺘﺨﺪﻡ ﻳﻘﻮﻡ ﺑﺈﺩﺧﺎﻝ ﺍﻟﻘﻴﻢ ﻧﻜﺘﺐ: >#include<stdio.h )(main { ;]int arr3d[2][2][2 ;int i, j, k )for(i=0;i<=1;i++ { )for(j=0;j<=1;j++ { )for(k=0;k<=1;k++ { ;)printf("arr3d[%d][%d][%d] : ", i, j, k ;)]scanf("%d", &arr3d[i][j][k } } } )for(i=0;i<=1;i++ { 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 105 )for(j=0;j<=1;j++ { )for(k=0;k<=1;k++ { printf("arr3d[%d][%d][%d] = %d\n", i, j, k, ;)]arr3d[i][j][k } } } ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٩ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺎﺕ ﺛﻼﺛﻴﺔ ﺍﻷﺑﻌﺎﺩ )(٢ } 22 23 24 25 26 27 28 29 30 31 ٢,٣,٣ﻣﺼﻔﻮﻓﺔ ﺫﺍﺕ ﺣﺠﻢ ﻏﲑ ﻣﻌﺮﻭﻑ: ﳝﻜﻨﻨﺎ ﺇﻧﺸﺎﺀ ﻣﺼﻔﻮﻓﺔ ﺫﺍﺕ ﺣﺠﻢ ﻏﲑ ﻣﻌﺮﻭﻑ ،ﺣﻴﺚ ﺳﺘﻜﻮﻥ ﺍﳌﺼﻔﻮﻓﺔ ﺩﻳﻨﺎﻣﻴﻜﻴﺔ ﺍﳊﺠﻢ ﺃﻱ ﺃﻥ ﺣﺠـﻢ ﺍﳌـﺼﻔﻮﻓﺔ ﺳﻴﺰﻳﺪ ﺣﺴﺐ ﺍﻟﻄﻠﺐ ،ﻭ ﻟﻜﻦ ﻣﻦ ﺷﺮﻭﻁ ﺍﳌﺼﻔﻮﻓﺎﺕ ﺍﻟﺪﻳﻨﺎﻣﻴﻜﻴﺔ ﳚﺐ ﺃﻥ ﺗﻜﻮﻥ ﺍﻟﻘﻴﻢ ﻣﻌﻄـﺎﺓ ﺳـﺎﺑﻘﺎ ﺃﻱ ﻻ ﳝﻜـﻦ ﻟﻠﻤﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﻗﻴﻢ ﰲ ﻣﺼﻔﻮﻓﺔ ﳎﻬﻮﻟﺔ ﺍﳊﺠﻢ .ﺳﺄﻋﻄﻲ ﺃﻣﺜﻠﺔ ﺣﻮﻝ ﺍﳌﺼﻔﻮﻓﺎﺕ ﺫﺍﺕ ﺣﺠﻢ ﻏﲑ ﻣﻌﺮﻭﻑ ،ﰒ ﻧﻨﺎﻗﺸﻬﺎ: >#include<stdio.h )(main { ;}int arr[] = {10, 20, 30 ;)]printf("%d\n", arr[0 ;)]printf("%d\n", arr[1 ;)]printf("%d\n", arr[2 ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ: ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٠ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺔ ﺫﺍﺕ ﺣﺠﻢ ﻏﲑ ﻣﻌﺮﻭﻑ } ;}int arr[] = {10, 20, 30 1 2 3 4 5 6 7 8 9 10 5 ﻫﻲ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﻮﺣﻴﺪﺓ ﺍﻟﱵ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﺣﺎﻟﻴﺎ ،ﻭ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﰲ ﻣﺼﻔﻮﻓﺎﺕ ﺛﺎﻧﻮﻳﺔ ،ﺃﻱ ﻣﺜﻼ ﰲ ﺍﳌﺼﻔﻮﻓﺎﺕ ﺍﻟﺜﻼﺛﻴﺔ ﺍﻷﺑﻌﺎﺩ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺜﻞ ﺍﻵﰐ: ;}}}int arr3d[][][] = {{{10, 20},{30, 40}}, {{50, 60},{70, 80 ﺍﻹﻣﻜﺎﻧﻴﺎﺕ ﺍﻟﻮﺣﻴﺪﺓ ﰲ ﺍﳌﺼﻔﻮﻓﺎﺕ ﺍﻟﺜﻨﺎﺋﻴﺔ ﻭ ﺍﻟﺜﻼﺛﻴﺔ ﺍﻷﺑﻌﺎﺩ ﺃﻭ ﺃﻛﺜﺮ ﻫﻲ ﻭﺿﻊ ﺍﳌﺼﻔﻮﻓﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﺑﺪﻭﻥ ﺣﺠﻢ ،ﻭ ﻛـﻲ ﻳﺼﺒﺢ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺻﺤﻴﺢ ﻧﻜﺘﺐ: 106 ;}}}int arr3d[][2][2] = {{{10, 20},{30, 40}}, {{50, 60},{70, 80 ٢,٣,٤ﺍﻟﺴﻼﺳﻞ ﺍﳊﺮﻓﻴﺔ )ﺍﻟﻨﺼﻮﺹ(: ﺍﻵﻥ ﺳﻨﻌﺮﻑ ﻃﺮﻳﻘﺔ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ،ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﳌﺼﻔﻮﻓﺎﺕ ،ﻭ ﺗﺴﻤﻰ ﺑﺴﻼﺳﻞ ﻣﻦ ﺣﺮﻭﻑ .ﻭ ﺗﺴﻤﻰ ﺑﺴﻼﺳﻞ ﺣﺮﻓﻴﺔ ﻷﺎ ﰲ ﺍﳊﻘﻴﻘﺔ ﻫﻲ ﻋﺒﺎﺭﺓ ﻋﻦ ﺳﻼﺳﻞ ﺎ ﺃﻣﺎﻛﻦ ﻭ ﻛﻞ ﻣﻜﺎﻥ ﺑﻪ ﺣﺮﻑ ،ﺭﻣﺰ ،ﺃﻭ ﺭﻗﻢ ،ﺗﻮﺟﺪ ﻃﺮﻕ ﻛﺜﲑﺓ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﺴﻼﺳﻞ ﺍﳊﺮﻓﻴﺔ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﳌﺼﻔﻮﻓﺎﺕ ﻣﻨﻬﺎ: ﺇﻋﻄﺎﺀ ﺣﺠﻢ ﳌﺼﻔﻮﻓﺔ ﻣﻦ ﻧﻮﻉ charﺣﻴﺚ ﻳﻜﻮﻥ ﺣﺠﻤﻬﺎ ﻫﻮ ﺍﳊﺪ ﺍﻷﻗﺼﻰ ﻟﻌﺪﺩ ﺍﳊﺮﻭﻑ ﺍﻟﱵ ﳝﻜﻦ ﺇﺩﺧﺎﳍـﺎ ،ﻣﺜـﺎﻝ ﺗﻮﺿﻴﺤﻲ: >#include<stdio.h )(main { ;"!char text[14] = "Hello, World ;)printf("%s\n", text ﺃﻭ ﳝﻜﻦ ﲡﺰﺋﺔ ﺍﻟﻨﺺ ﻛﻤﺎ ﻳﻠﻲ: ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ } >#include<stdio.h )(main { ;]char text[14 ;'text[0] = 'H ;'text[1] = 'e ;'text[2] = 'l ;'text[3] = 'l ;'text[4] = 'o ;'text[5] = ', ;' ' = ]text[6 ;'text[7] = 'w ;'text[8] = 'o ;'text[9] = 'r ;'text[10] = 'l ;'text[11] = 'd ;'!' = ]text[12 ;'text[13] = '\0 ;)printf("%s\n", text } 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 107 ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٢ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ )(٢ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺸﺮﻳﻦ ﻗﻤﻨﺎ ﺑﺈﺿﺎﻓﺔ ﺍﻟﺮﻣﺰ \0ﻭ ﺍﻟﺬﻱ ﻳﻌﲏ ﺎﻳﺔ ﺍﻟﺴﻠﺴﻠﺔ ،ﻭ ﻋﺪﻡ ﻭﺟﻮﺩﻩ ﺳﻴﻌﻄﻲ ﻧﺘﺎﺋﺞ ﻏﲑ ﻣﺮﻏﻮﺏ ﻓﻴﻬﺎ ،ﺃﻣﺎ ﰲ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻷﻭﱃ ﻓﻴﻜﻔﻲ ﺃﻥ ﻧﻌﻄﻴﻪ ﻣﻜﺎﻥ ﺇﺿﺎﰲ ﻭ ﺳﻴﺘﻢ ﺇﺿﺎﻓﺘﻪ ﺗﻠﻘﺎﺋﻴﺎ ،ﻭ ﺇﺫﺍ ﺍﻧﺘﺒﻬﺖ ﺇﱃ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﰲ: ;"!char text[14] = "Hello, World 5 ﻓﺴﺘﻼﺣﻆ ﺃﻥ ﻋﺪﺩ ﺍﻷﺣﺮﻑ ﻫﻮ ) ١٣ﺍﻟﻔﺮﺍﻍ ﻳﻌﺘﱪ ﺣﺮﻑ( ﻭ ﳓﻦ ﻗﻤﻨﺎ ﲝﺠﺰ ١٤ﻣﻜﺎﻥ ،ﺍﳌﻜﺎﻥ ﺍﻟﺮﺍﺑﻊ ﻋﺸﺮ ﺳﻴﻜﻮﻥ ﻟﺮﻣﺰ \0ﺣﻴﺚ ﺳﻴﺘﻢ ﺇﺿﺎﻓﺘﻪ ﺗﻠﻘﺎﺋﻴﺎ .ﺍﻵﻥ ﺳﻨﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺑﺮﻧﺎﻣﺞ ﻳﻄﻠﺐ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﺍﲰﻪ ،ﰒ ﻳﻄﺒﻊ ﻟﻪ ﺍﻟﱪﻧـﺎﻣﺞ ﻋـﺪﺩ ﺃﺣﺮﻑ ﺍﲰﻪ: >#include<stdio.h )(main { ;]char usr_name[255 ;int i ;i = 0 ;)" printf("Your name: ;)scanf("%s", &usr_name )'while(usr_name[i] != '\0 { ;++i } ;)printf("%s = %d characters\n", usr_name, i ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٣ﺣﺴﺎﺏ ﻋﺪﺩ ﺃﺣﺮﻑ ﺇﺳﻢ ﻣﺴﺘﺨﺪﻡ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻗﻤﻦ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﺑﺎﺳﻢ ،usr_nameﲝﺠﻢ ٢٥٥ﻣﻜﺎﻥ ﻭ ﻫﻮ ﺃﻗﺼﻰ ﺍﺣﺘﻤﺎﻝ ﳝﻜـﻦ ﺍﻟﻮﺻﻮﻝ ﺇﻟﻴﻪ ،ﺣﻴﺚ ﺳﺘﻜﻮﻥ ﺗﻠﻚ ﺍﻟﺴﻠﺴﻠﺔ ﻫﻲ ﺍﳌﻜﺎﻥ ﺍﻟﺬﻱ ﺳﻨﻀﻊ ﻓﻴﻪ ﺍﺳﻢ ﺍﳌﺴﺘﺨﺪﻡ ،ﻭ ﰲ ﺍﻟـﺴﻄﺮ ﺍﻟـﺴﺎﺩﺱ ﻗﻤـﻦ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻭ ﺍﻟﺬﻱ ﺳﻴﻜﻮﻥ ﺍﻟﻌﺪﺍﺩ ﻻﺳﻢ ﺍﳌﺴﺘﺨﺪﻡ ،ﰒ ﺃﻋﻄﻴﻨﺎﻩ ﺍﻟﻘﻴﻤﺔ ﺻﻔﺮ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟـﺴﺎﺑﻊ ،ﰒ ﻃﻠﺒﻨـﺎ ﻣـﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﺍﲰﻪ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ،ﻭ ﺧﺬﻧﺎ ﺍﺳﻢ ﺍﳌﺴﺘﺨﺪﻡ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﺣﻴﺚ ﺳﺘﺠﺪ ﺍﻟﺮﻣﺰ %sﻭ ﺍﳊـﺮﻑ s ﳐﺘﺼﺮ ﻣﻦ stringﻭ ﻫﻮ ﺍﻟﺮﻣﺰ ﺍﳋﺎﺹ ﺑﺎﻟﺴﻼﺳﻞ ﺍﳊﺮﻓﻴﺔ ،ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﱐ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﺈﻧﺸﺎﺀ ﺣﻠﻘﺔ ﻻ ﺗﻨﺘﻬﻲ ﺇﻻ ﺑﺎﻧﺘـﻬﺎﺀ ﺍﺳﻢ ﺍﳌﺴﺘﺨﺪﻡ ،ﻭ ﻛﻲ ﺗﻔﻬﻢ ﻫﺬﻩ ﺍﻷﺧﲑﺓ ﺇﻟﻴﻚ ﺍﻟﺼﻮﺭﺓ ﺍﻟﺘﺎﻟﻴﺔ: 108 ﺍﻟﺸﻜﻞ :٢,٣,٢ﻃﺮﻳﻘﺔ ﻭﺿﻊ ﺍﻟﺒﻴﺎﻧﺎﺕ ﰲ ﺍﳌﺼﻔﻮﻓﺎﺕ ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﻋﺸﺮ ﻳﻘﻮﻡ ﺍﻟﱪﻧﺎﻣﺞ ﺑﻄﺒﺎﻋﺔ ﺍﺳﻢ ﺍﳌﺴﺘﺨﺪﻡ ﻭ ﻋﺪﺩ ﺃﺣﺮﻓﻪ .ﻭ ﺇﺫﺍ ﺃﺭﺩﺕ ﺟﻌﻞ ﺍﻟﱪﻧﺎﻣﺞ ﺃﻛﺜﺮ ﻣﺮﻭﻧـﺔ ﻭ ﺃﻛﺜﺮ ﺗﻌﻤﻖ ﺟﺮﺏ ﻫﺬﺍ ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;]char usr_name[255 ;int i ;i = 0 ;)" printf("Your Fullname: ;)scanf("%s", &usr_name )'while(usr_name[i]!='\0 { ;)]printf("%i: %c\n", i+1, usr_name[i ;++i } ;)printf("%s = %d characters\n", usr_name, i ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٤ﺣﺴﺎﺏ ﻋﺪﺩ ﺃﺣﺮﻑ ﺇﺳﻢ ﻣﺴﺘﺨﺪﻡ )(٢ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 109 ٢,٣,٤,١ﺍﻟﺪﺍﻟﺔ :gets ﲢﺪﺛﻨﺎ ﻋﻦ ﺍﻟﺪﺍﻟﺔ getsﰲ ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ ،ﻭ ﻟﻜﻨﻨﺎ ﱂ ﻧﺘﺤﺪﺙ ﻋﻦ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ .ﻫﻲ ﺧﺎﺹ ﺑﺈﺩﺧـﺎﻝ ﺍﻟﻨـﺼﻮﺹ ﺣﻴﺚ ﺑﺪﻝ ﺍﺳﺘﻌﻤﺎﻝ ) scanf("%s", &string_nameﻧﺴﺘﻌﻤﻞ ) gets(string_nameﺃﻓﻀﻞ ،ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;]char usr_name[255 ;)"puts("Your name: ;)gets(usr_name ;)"puts("nice to meet you ;)puts(usr_name ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٥ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 12 gets ﻭ ﺍﻟﻔﺮﻕ ﺑﲔ ﺍﻟﺪﺍﻟﺔ scanfﻭ ﺍﻟﺪﺍﻟﺔ getsﻫﻮ ﻋﻨﺪ ﺇﺩﺧﺎﻝ ﺍﻷﲰﺎﺀ ،ﰲ ﺍﻟﺪﺍﻟﺔ getsﺇﻥ ﻛﺘﺒﺖ ﺍﲰﲔ ﻭ ﻓـﺼﻠﺖ ﺑﻴﻨـﻬﻤﺎ ﺑﻔﺮﺍﻍ ﻓﺴﻴﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﻛﻼﳘﺎ ،ﺃﻣﺎ ﰲ ﺍﻟﺪﺍﻟﺔ scanfﻓﺈﻧﻪ ﺳﺘﺘﻮﻗﻒ ﻋﻨﺪ ﺍﻟﻔﺮﺍﻍ ﺍﻷﻭﻝ ﻭ ﺗﻘﻮﻡ ﺑﻄﺒﻊ ﻣﺎ ﻫﻮ ﻗﺒﻞ ﺍﻟﻔـﺮﺍﻍ ﻻ ﺃﻛﺜﺮ. ٢,٣,٤,٢ﺍﻟﺪﺍﻟﺔ strcpyﻭ ﺍﻟﺪﺍﻟﺔ :strncpy ﺍﻟﺪﺍﻟﺔ strcpyﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ string.hﺣﻴﺚ ﺑﻪ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻟﺪﻭﺍﻝ ﺍﳋﺎﺻﺔ ﺑﺎﻟﺘﻌﺎﻣـﻞ ﻣـﻊ ﺍﻟـﺴﻼﺳﻞ ﺍﳊﺮﻓﻴﺔ ،ﻭ ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ﳐﺘﺼﺮ ﻣﻦ ،string copyﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﻨﺴﺦ ﻭ ﻟﺼﻖ ﺍﳊﺮﻭﻑ ﻣﻦ ﺳﻠﺴﻠﺔ ﺇﱃ ﺃﺧﺮﻯ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<string.h )(main { ;"!char String[] = "String ;]char Empty_String[20 ;)strcpy(Empty_String, String ;)printf("Empty_String = %s\n", Empty_String ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٦ﺍﻟﺪﺍﻟﺔ strcpy } 1 2 3 4 5 6 7 8 9 10 11 12 110 ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻣﻦ ﺍﻟﺪﺍﻟﺔ ﻧﻘﻮﻡ ﺑﺎﻟﻜﺘﺎﺑﺔ ﻓﻴﻪ ﺍﺳﻢ ﺍﻟﺴﻠﺴﻠﺔ ﺍﳊﺮﻓﻴﺔ ﺍﻟﱵ ﻧﺮﻳﺪ ﺃﻥ ﻧﻨﺴﺦ ﺎ ﺍﻟﻨﺺ ،ﻭ ﰲ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻧﻜﺘﺐ ﺍﻟﺴﻠﺴﻠﺔ ﺍﻟﱵ ﻧﺮﻳﺪ ﻧﺴﺨﻬﺎ .ﺃﻳﻀﺎ ﺍﻟﺪﺍﻟﺔ strncpyﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،string.hﻭ ﻫﻲ ﻣﺜـﻞ ﺍﻟﺪﺍﻟـﺔ ﺍﻟـﺴﺎﺑﻘﺔ strcpyﻣﻊ ﺇﺿﺎﻓﺔ ﺑﺴﻴﻄﺔ ﻭ ﻫﻲ ﲢﺪﻳﺪ ﻋﺪﺩ ﺍﻷﺣﺮﻑ ﺍﻟﱵ ﻧﺮﻳﺪ ﻧﺴﺨﻬﺎ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<string.h )(main { ;"!char String[] = "String ;]char Empty_String[20 ;)strncpy(Empty_String, String, 3 ;)printf("Empty_String = %s\n", Empty_String ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٧ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 12 strncpy ﰲ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﻟﺚ ﻣﻦ ﺍﻟﺪﺍﻟﺔ strncpyﻧﻘﻮﻡ ﺑﺘﺤﺪﻳﺪ ﻋﺪﺩ ﺍﻷﺣﺮﻑ ﺍﻟﱵ ﻧﺮﻳﺪ ﻧﺴﺨﻬﺎ. ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻛﺘﺎﺑﺔ ﺍﻟﺘﺎﱄ: >#include<stdio.h >#include<string.h )(main { ;]char Empty_String[20 ;)"!strcpy(Empty_String, "String ;)printf("Empty_String = %s\n", Empty_String ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٨ﺍﻟﺪﺍﻟﺔ (٢) strcpy } 1 2 3 4 5 6 7 8 9 10 11 ٢,٣,٤,٣ﺍﻟﺪﺍﻟﺔ strcatﻭ ﺍﻟﺪﺍﻟﺔ :strncat ﺍﻟﺪﺍﻟﺔ strcatﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،string.hﻭ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣﻦ ﻭ ﺇﺿﺎﻓﺘﻪ ﰲ ﺎﻳﺔ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ،ﻣﺜﺎﻝ: concatenate ،stringﻭ ﻫﻲ ﺗﻘﻮﻡ ﻧﺴﺦ ﻧﺺ >#include<stdio.h >#include<string.h )(main { ;"!char String[20] = "String ;)"strcat(String, ", String2 1 2 3 4 5 6 7 8 111 ;)printf("String = %s\n", String ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٩ﺍﻟﺪﺍﻟﺔ } 9 10 11 strcat ﰲ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻣﻦ ﺍﻟﺪﺍﻟﺔ strcatﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺍﺳﻢ ﺍﻟﺴﻠﺴﻠﺔ ﺍﻟﱵ ﺳﻨﻀﻴﻒ ﺇﻟﻴﻬﺎ ﺍﻟﻨﺺ ،ﻭ ﰲ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜـﺎﱐ ﻧﻘـﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺍﻟﻨﺺ .ﺍﻟﺪﺍﻟﺔ strncatﻣﺜﻞ ﺍﻟﺪﺍﻟﺔ strcatﻣﻊ ﺇﺿﺎﻓﺔ ﺑﺴﻴﻄﺔ ﻭ ﻫﻲ ﲢﺪﻳﺪ ﻋﺪﺩ ﺍﻷﺣﺮﻑ ﺍﻟﱵ ﻧﺮﻳـﺪ ﻧـﺴﺨﻬﺎ، ﻣﺜﺎﻝ: >#include<stdio.h >#include<string.h )(main { ;"!char String[20] = "String ;)strncat(String, ", String2", 3 ;)printf("String = %s\n", String ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٢٠ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 strncat ﰲ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﻟﺚ ﻧﻘﻮﻡ ﺑﺘﺤﺪﻳﺪ ﻋﺪﺩ ﺍﻷﺣﺮﻑ ﺍﻟﱵ ﻧﺮﻳﺪ ﻧﺴﺨﻬﺎ. ٢,٣,٥ﻃﺮﻕ ﺃﺧﺮﻯ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺼﻔﻮﻓﺎﺕ: ﳝﻜﻨﻨﺎ ﻛﺘﺎﺑﺔ = 10 ) *(arr+0ﰲ ﻣﻜﺎﻥ = 10 ] ،arr[0ﺣﻴﺚ ﺃﺎ ﻣﻜﺎﻓﺌﺔ ﻟﻠﺴﺎﺑﻘﺔ ،ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻃﺒﻴﻌﻲ: >#include<stdio.h )(main { ;]int arr[1 ;arr[0] = 10 ;)]printf("%d\n", arr[0 ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٢١ﻃﺮﻕ ﺃﺧﺮﻯ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺼﻔﻮﻓﺎﺕ } 1 2 3 4 5 6 7 8 9 ﻭ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﺜﺎﻧﻴﺔ: >#include<stdio.h )(main { ;]int arr[1 1 2 3 4 5 112 ;*(arr+0) = 10 ;))printf("%d\n", *(arr+0 } 6 7 8 9 ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٢٢ﻃﺮﻕ ﺃﺧﺮﻯ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺼﻔﻮﻓﺎﺕ )(٢ ﺍﻟﺸﻔﺮﺓ ] arr[0ﻫﻲ ﻧﻔﺴﻬﺎ ﺍﻟﺸﻔﺮﺓ ) .*(arr+0ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮﺍﺕ ﻣﺜﻞ ﺍﳉﻤﻊ ،ﺍﻟﻄﺮﺡ ،ﺍﻟﻘـﺴﻤﺔ ﻭ ﺍﻟـﻀﺮﺏ ﻟﻺﺷﺎﺭﺓ ﺇﱃ ﻋﻨﺼﺮ ﻣﻦ ﻣﺼﻔﻮﻓﺔ ﻣﺜﻞ: >#include<stdio.h )(main { ;]int arr[2 ;arr[0+0] = 10 printf("%d\n", arr[0+0]); /* or printf("%d\n", arr[0]); */ ;arr[0-0] = 20 printf("%d\n", arr[0-0]); /* or printf("%d\n", arr[0]); */ ;arr[1*1] = 30 printf("%d\n", arr[1*1]); /* or printf("%d\n", arr[1]); */ ;arr[1/1] = 40 printf("%d\n", arr[1/1]); /* or printf("%d\n", arr[1]); */ ٢,٣,٦ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٢٣ﻃﺮﻕ ﺃﺧﺮﻯ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺼﻔﻮﻓﺎﺕ )(٣ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 .١ﻧﻔﺮﺽ ﺃﻧﻪ ﻟﺪﻳﻚ ﻣﺼﻔﻮﻓﺔ ﲝﺠﻢ ٢ﻭ ﺍﲰﻬﺎ ،arrﰒ ﺃﺭﺩﺕ ﻭﺿﻊ ﻗﻴﻢ ﻟﻠﻤﺼﻔﻮﻓﺔ ﻭ ﻗﻤﺖ ﺑﻜﺘﺎﺑﺔ ﺍﻟﺘﺎﱄ: ; ]int arr[2 ; arr[0] = 10 ; arr[8] = 20 ﻓﻬﻨﺎ ﺳﻴﺤﺪﺙ ﺍﻧﺘﻬﺎﻙ ﰲ ﺍﻟﺬﺍﻛﺮﺓ ،ﻭ ﺭﲟﺎ ﻳﺆﺩﻱ ﺇﱃ ﺗﻮﻗﻒ ﺍﻟﱪﻧﺎﻣﺞ ﻋﻦ ﺍﻟﻌﻤﻞ .ﻭ ﺍﻟﻄﺮﻗﺔ ﺍﻟﺼﺤﻴﺤﺔ ﻟﻠﻤﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﻫﻲ: ; ]int arr[2 ; arr[0] = 10 ; arr[1] = 20 113 .٢ﰲ ﺍﻟﺴﻼﺳﻞ ﺍﳊﺮﻓﻴﺔ ﻋﻨﺪ ﻛﺘﺎﺑﺔ ﻧﺺ ﻣﺒﺎﺷﺮﺓ ﺑﻌﺪ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ ﻓﻴﺠﺐ ﻋﻠﻴﻚ ﺩﺍﺋﻤﺎ ﻭﺿﻊ ﻣﻜﺎﻥ ﺇﺿﺎﰲ ﻟﺮﻣﺰ ﻭ ﺇﻻ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﺎﺋﺞ ﻏﲑ ﺻﺤﻴﺤﺔ. \0 .٣ﺍﻟﺪﺍﻟﺔ getsﻻ ﺗﺴﺘﻌﻤﻞ ﺇﻻ ﰲ ﺇﺩﺧﺎﻝ ﺍﻟﻨﺼﻮﺹ. ٢,٣,٧ﲤﺎﺭﻳﻦ: .١ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻄﻠﺐ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﺍﲰﻪ ،ﰒ ﻳﻄﺒﻊ ﻟﻪ ﺍﻟﱪﻧﺎﻣﺞ ﻋﺪﺩ ﺃﺣﺮﻑ ﺍﲰﻪ )ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﺍﻟﺘﲔ ﻭ .(gets .٢ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻄﻠﺐ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﺃﻋﺪﺍﺩ ﺣﻘﻴﻘﻴﺔ ،ﰒ ﻳﻘـﻮﻡ ﺍﻟﱪﻧـﺎﻣﺞ ﺑﺈﻋـﺎﺩﺓ ﻃﺒﻌﻬـﺎ )ﺑﺎﺳـﺘﺨﺪﺍﻡ ﺍﳌﺼﻔﻮﻓﺎﺕ(. .٣ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﺑﻪ ﻣﺼﻔﻮﻓﺔ ﺎ ﺍﻟﻨﺺ ! Hello, Worldﰒ ﻗﻢ ﺑﻌﻤﻞ ﺣﻠﻘﺔ ﺗﻘﻮﻡ ﺑﻌﺪ ﻋﺪﺩ ﺭﻣﻮﺯ ﺃﻭ ﺃﺣـﺮﻑ ﺗﻠـﻚ ﺍﳉﻤﻠﺔ)ﺇﺫﺍ ﻭﺟﺪﺕ ١٣ﺣﺮﻓﺎ ﻓﺈﻥ ﺍﻟﻨﺘﻴﺠﺔ ﺧﺎﻃﺌﺔ( ﳚﺐ ﺃﻥ ﺗﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ١٢ﻣﻊ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺳﻠﻴﻤﺔ ﻳﻌـﲏ ﺑﺪﻭﻥ ﺍﺳﺘﻌﻤﺎﻝ .١- puts 114 ﻛﻠﻤﺔ ﻣﺆﺷﺮ ﺗﻌﲏ ﺍﻹﺷﺎﺭﺓ ﺇﱃ ﺷﻲﺀ ،ﻭ ﰲ ﻟﻐﺔ Cﺍﳌﺆﺷﺮﺍﺕ ﺗﺸﲑ ﺇﱃ ﻋﻨﺎﻭﻳﻦ ﰲ ﺍﻟﺬﺍﻛﺮﺓ .ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺆﺷﺮ ﳑﺎﺛﻠﺔ ﻟﻄﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﳌﺘﻐﲑﺍﺕ ،ﻭ ﺍﻹﺧﺘﻼﻑ ﺑﲔ ﺍﳌﺆﺷﺮ ﻭ ﺍﳌﺘﻐﲑ ﻫﻮ ﺃﻥ ﺍﳌﺆﺷﺮ ﻳﺸﲑ ﺇﱃ ﻋﻨﻮﺍﻥ ﻣـﺘﻐﲑ ﺃﻭ ﻋﻨـﻮﺍﻥ ﻋﺸﻮﺍﺋﻲ ﰲ ﺍﻟﺬﺍﻛﺮﺓ .ﻭ ﺗﻮﺟﺪ ﻣﻼﺣﻈﺔ ﻫﻨﺎ ﻭ ﻫﻲ ﺃﻥ ﺍﳌﺆﺷﺮﺍﺕ ﰲ ﺍﻷﻧﻈﻤﺔ ﺍﳊﺪﻳﺚ ﻻ ﳝﻜﻦ ﺇﻋﻄﺎﺋﻬﺎ ﻋﻨﺎﻭﻳﻦ ﻋﺸﻮﺍﺋﻴﺔ )ﺇﻻ ﰲ ﺣﺎﻻﺕ ﺧﺎﺻﺔ( ﻭ ﺫﻟﻚ ﻟﺘﺸﺪﺩ ﺍﳊﻤﺎﻳﺔ ﻓﻴﻬﺎ .ﻟﺬﺍ ﻫﻨﺎ ﺳﻨﺮﻯ ﻓﻘﻂ ﻃﺮﻳﻘﺔ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺆﺷﺮﺍﺕ ﻭ ﺍﳌـﺘﻐﲑﺍﺕ ،ﻭ ﻫـﺬﻩ ﺻﻮﺭﺓ ﺗﻮﺿﺢ ﻟﻄﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺆﺷﺮ: ﺍﻟﺸﻜﻞ :٢,٤,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺆﺷﺮ ﺍﻟﻔﺮﻕ ﺍﻟﻮﺣﻴﺪ ﺑﲔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻭ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺆﺷﺮ ﻫﻮ ﻣﺆﺛﺮ ﺍﻟﻀﺮﺏ ﰲ ﺍﳌﺆﺷﺮﺍﺕ ﻭ ﺍﻟﺬﻱ ﻳﻜﻮﻥ ﻗﺒﻞ ﺍﺳﻢ ﺍﳌﺆﺷﺮ. ٢,٤,١ﻧﻮﻉ ﺍﳌﺆﺷﺮ :Pointer Type ﻧﻮﻉ ﺍﳌﺆﺷﺮ ﻳﻜﻮﻥ ﺣﺴﺐ ﺭﻏﺒﻨﺎ ،ﻣﺜﻼ ﻟﻮ ﺃﺭﺩﻧﺎ ﺍﻹﺷﺎﺭﺓ ﺇﱃ ﻣﺘﻐﲑ ﺣﺠﻤﻪ ٢ﺑﺎﻳﺖ ﻓﻴﺠﺐ ﻋﻠﻴﻨﺎ ﺍﻹﻋﻼﻥ ﻋـﻦ ﻣﺆﺷـﺮ ﳝﻜﻨﻪ ﺍﻟﻮﺻﻮﻝ ﺇﱃ ٢ﺑﺎﻳﺖ ﻣﻦ ﺍﻟﺬﺍﻛﺮﺓ .ﻟﻠﻤﺆﺷﺮﺍﺕ ﺃﻧﻮﺍﻉ ﻫﻲ ﻧﻔﺴﻬﺎ ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ،ﻭ ﻫﻲ int, float, double, .long, short, unsigned, signed, char, ٢,٤,٢ﺍﺳﻢ ﺍﳌﺆﺷﺮ :Pointer Name ﻻﺳﻢ ﺍﳌﺆﺷﺮ ﺷﺮﻭﻁ ﻫﻲ ﻧﻔﺴﻬﺎ ﺷﺮﻭﻁ ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﻫﻲ: § ﺃﻥ ﻻ ﻳﺘﺠﺎﻭﺯ ﺍﺳﻢ ﺍﳌﺆﺷﺮ ﺃﻛﺜﺮ ﻣﻦ ٣١ﺣﺮﻑ. § ﺃﻥ ﻻ ﻳﺒﺪﺃ ﺍﺳﻢ ﺍﳌﺆﺷﺮ ﺑﺄﺭﻗﺎﻡ. § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳌﺆﺷﺮ ﳛﺘﻮﻱ ﻋﻠﻰ ﻣﺆﺛﺮﺍﺕ ﻣﺜﻞ ﺍﳉﻤﻊ ﻭ ﺍﻟﻄﺮﺡ ﻭ.... § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳌﺆﺷﺮ ﳛﺘﻮﻱ ﻋﻠﻰ ﺭﻣﻮﺯ ﻣﺜﻞ %ﻭ #ﻭ { ﻭ)...ﺑﺎﺳﺘﺜﻨﺎﺀ ﺍﻟﺮﻣﺰ _(. 115 § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳌﺆﺷﺮ ﻣﺴﺘﻌﻤﻞ ﺳﺎﺑﻘﺎ ﰲ ﺩﺍﻟﺔ ﺃﻭ ﻣﺘﻐﲑ ﺃﻭ ﻣﺆﺷﺮ ﺁﺧﺮ. § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳌﺆﺷﺮ ﻣﻦ ﺃﲰﺎﺀ ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ. ﺍﳌﺆﺷﺮﺍﺕ ﲢﻤﻞ ﻋﻨﺎﻭﻳﻦ ﳌﻮﺍﻗﻊ ﰲ ﺍﻟﺬﺍﻛﺮﺓ ﻭ ﻻ ﳝﻜﻦ ﺃﻥ ﻧﻌﻄﻴﻬﺎ ﻗﻴﻢ ﻣﺒﺎﺷﺮﺓ ﺇﻻ ﰲ ﺣﺎﻻﺕ ،ﻭ ﰲ ﺍﻟﻌﻨﺎﻭﻳﻦ ﳒﺪ ﻗﻴﻢ ﻭ ﻟﻜﻞ ﻋﻨﻮﺍﻥ ﻗﻴﻤﺘﻪ ،ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;int *ptr, i ;i = 10 ;ptr = &i ;)printf("*ptr = %d\n", *ptr } ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺆﺷﺮ 1 2 3 4 5 6 7 8 9 10 ﺍﳌﺆﺷﺮ ﻣﻮﺟﻮﺩ ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻣﻊ ﻣﺘﻐﲑ ،ﺍﺳﻢ ﺍﳌﺆﺷﺮ ﻫﻮ ptrﻭ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﻫﻮ ،iﺃﻋﻄﻴﻨﺎ ﻟﻠﻤﺘﻐﲑ iﺍﻟﻘﻴﻤـﺔ ١٠ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ،ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺃﻋﻄﻴﻨﺎ ﻟﻠﻤﺆﺷﺮ ptrﻋﻨﻮﺍﻥ ﺍﳌﺘﻐﲑ iﺃﻱ ﺃﻧﻪ ﻋﻨﺪ ﻛﺘﺎﺑﺔ &Variable_Nameﻓﻬـﺬﺍ ﻳﻌﲏ ﻋﻨﻮﺍﻥ ﻣﺘﻐﲑ ،ﻭ ﺃﺧﲑﺍ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ﺣﻴﺚ ﻛﺘﺒﺘﺎ *ptrﻭ ﺍﻟﺬﻱ ﻳﻌﲏ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻮﺟﻮﺩ ﰲ ﻋﻨﻮﺍﻥ ﺍﳌﺆﺷـﺮ ،ptrﻭ ﰲ ﺣﺎﻟﺔ ﺃﻧﻨﺎ ﻛﺘﺒﻨﺎ ﺍﺳﻢ ﺍﳌﺆﺷﺮ ﺑﺪﻭﻥ ﻣﺆﺛﺮ ﺍﻟﻀﺮﺏ ﻓﺴﻴﺘﻢ ﻃﺒﺎﻋﺔ ﻋﻨﻮﺍﻥ ﺍﳌﺆﺷﺮ .ptrﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺇﻥ ﻗﻤﻨﺎ ﺑﺘﻐﲑ ﺍﻟﻘﻴﻤـﺔ ﺍﳌﻮﺟﻮﺩﺓ ﰲ ﻋﻨﻮﺍﻥ ﺍﳌﺆﺷﺮ ptrﻓﺴﺘﺘﻐﲑ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻮﺟﻮﺩ ﰲ ﺍﳌﺘﻐﲑ ،iﻷﻧﻨﺎ ﺃﺧﺬﻧﺎ ﻋﻨﻮﺍﻥ ﺍﳌﺘﻐﲑ iﻭ ﺍﻟﺬﻱ ﻫﻮ ﻧﻔﺴﻪ ﻋﻨﻮﺍﻥ ﺍﳌﺆﺷﺮ ،ptrﺟﺮﺏ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ: >#include<stdio.h )(main { ;int *ptr, i ;i = 10 ;ptr = &i ;*ptr = 100 ;)printf("*ptr = %d\n", *ptr ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺷﺮ } 1 2 3 4 5 6 7 8 9 10 11 ﻫﻨﺎ ﳝﻜﻨﻨﺎ ﺇﻋﻄﺎﺀ ﻗﻴﻤﺔ ﻟﻠﻤﺆﺷﺮ ptrﻷﻧﻪ ﻟﺪﻳﻪ ﻋﻨﻮﺍﻥ ﻭ ﻫﻮ ﻋﻨﻮﺍﻥ ﺍﳌﺘﻐﲑ ،iﻭ ﺳﻴﻘﻮﻡ ﲝﺬﻑ ﺍﻟﻘﻴﻤﺔ ﺍﻟﺴﺎﺑﻘﺔ ﺍﳌﻮﺟـﻮﺩ ﰲ ﻋﻨﻮﺍﻥ iﻭ ﻳﻘﻮﻡ ﺑﺘﺤﺪﻳﺜﻬﺎ ﺇﱃ ﺍﻟﻌﺪﺩ .١٠٠ﻭ ﻟﻜﻲ ﺗﻔﻬﻢ ﺍﳌﺆﺷﺮﺍﺕ ﺟﻴﺪﺍ ﺟﺮﺏ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: 116 >#include<stdio.h )(main { ;int *ptr, i ;i = 10 ;ptr = &i ;)printf("i = %d\n", i ;)printf("*ptr = %d\n", *ptr ;)printf("&i = %p\n", &i ;)printf("ptr = %p\n", ptr } 1 2 3 4 5 6 7 8 9 10 11 12 13 ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺷﺮ )(٢ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ﻭ ﺍﻟﻌﺎﺷﺮ ﻗﻤﻨﺎ ﺑﻄﺒﺎﻋﺔ ﻛﻞ ﻣﻦ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻮﺟﻮﺩﺓ ﰲ ﺍﳌﺘﻐﲑ iﻭ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻮﺟﻮﺩ ﰲ ﻋﻨﻮﺍﻥ ﺍﳌﺆﺷـﺮ ptrﻭ ﻟﻜﻲ ﻧﺮﻯ ﻗﻴﻤﺔ ﻣﻮﺟﻮﺩﺓ ﺩﺍﺧﻞ ﻣﺆﺷﺮ ﻧﻜﺘﺐ ﻣﺆﺛﺮ ﺍﻟﻀﺮﺏ ﻗﺒﻞ ﺍﲰﻪ ﻭ ﺃﻳﻀﺎ ﳝﻜﻨﻨﺎ ﻭﺿﻊ ﻗﻴﻤﺔ ﻟﻪ ﺑﻨﻔﺲ ﺍﻟﻄﺮﻳﻘﺔ )ﳚﺐ ﺃﻥ ﻳﻜﻮﻥ ﻟﺪﻳﻪ ﻋﻨﻮﺍﻥ ﻛﻲ ﻧﺴﺘﻄﻴﻊ ﻭﺿﻊ ﻟﻪ ﻗﻴﻤﺔ( ،ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ﻭ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﱐ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﻄﺒﺎﻋﺔ ﻛـﻞ ﻣـﻦ ﻋﻨﻮﺍﻥ ﺍﳌﺘﻐﲑ iﻭ ﻋﻨﻮﺍﻥ ﺍﳌﺆﺷﺮ ،ptrﻭ ﺗﻼﺣﻆ ﺃﻧﻪ ﻭﺿﻌﻨﺎ ﺍﻟﺮﻣﺰ %pﻭ ﻫﻮ ﳐﺘﺼﺮ ﻣﻦ pointerﻭ ﳝﻜﻦ ﺍﺳـﺘﻌﻤﺎﻟﻪ ﻣـﻊ ﺍﳌﺆﺷﺮﺍﺕ ﺃﻭ ﻋﻨﻮﺍﻥ ﳌﺘﻐﲑ ﺣﻴﺚ ﻗﻤﻨﺎ ﺑﺎﺳﺘﻌﻤﺎﻟﻪ ﻛﻲ ﻳﺘﻢ ﻃﺒﺎﻋﺔ ﺍﻟﻌﻨﺎﻭﻳﻦ ﺑﺸﻜﻞ ﺻﺤﻴﺢ .ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ ﻟﻠﻤﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ: ٢,٤,٣ﺍﳌﺆﺷﺮﺍﺕ ﻭ ﺍﳌﺼﻔﻮﻓﺎﺕ: ﺍﻟﺸﻜﻞ :٢,٤,٢ﺍﻟﺬﺍﻛﺮﺓ ﻭ ﺍﻟﻌﻨﺎﻭﻳﻦ ﺍﳌﺆﺷﺮﺍﺕ ﺷﺒﻴﻬﺎ ﺑﺎﳌﺼﻔﻮﻓﺎﺕ ،ﻷﻧﻨﺎ ﻧﺸﲑ ﺇﱃ ﻋﻨﻮﺍﻥ ﳝﻜﻨﻨﺎ ﺍﻟﺘﻘﺪﻡ ﺑﻪ )ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺛﺮ ++ﻣﺜﻼ( ﳑـﺎ ﳚﻌﻠﻨـﺎ ﻧـﺼﻞ ﺇﱃ ﳎﻤﻮﻋﺔ ﻣﻦ ﺑﻴﺘﺎﺕ ﻣﺘﺴﻠﺴﻠﺔ .ﻭ ﻫﻨﺎ ﻣﺜﺎﻝ ﻳﻮﺿﺢ ﺍﻟﺸﺒﻪ ﺑﲔ ﺍﳌﺆﺷﺮﺍﺕ ﻭ ﺍﳌﺼﻔﻮﻓﺎﺕ: 117 >#include<stdio.h )(main { ;]int arr[2 ;int *ptr ;arr[0] = 10 ;arr[1] = 20 ;]ptr = &arr[0 ;)]printf("%d\n", ptr[0 ;)]printf("%d\n", ptr[1 ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٤ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺷﺮ ﻋﻠﻰ ﻃﺮﻳﻘﺔ ﺍﳌﺼﻔﻮﻓﺎﺕ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺔ ﲝﺠﻢ ،٢ﰒ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺆﺷﺮ ،ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﻭ ﺍﻟﺘﺎﺳﻊ ﺃﻋﻄﻴﻨﺎ ﻗﻴﻢ ﻟﻠﻤﺼﻔﻮﻓﺔ ،ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ﺃﻋﻄﻴﻨﺎ ﻟﻠﻤﺆﺷﺮ ptrﻋﻨﻮﺍﻥ ﺑﺪﺍﻳﺔ ﺍﳌﺼﻔﻮﻓﺔ ،ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﻋﺸﺮ ﻭ ﺍﻟﺮﺍﺑﻊ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﻄﺒﺎﻋـﺔ ﻣﺎ ﻫﻮ ﻣﻮﺟﻮﺩ ﰲ ﻋﻨﻮﺍﻥ ﺍﳌﺆﺷﺮ .ptrﻭ ﳝﻜﻨﻨﺎ ﻛﺘﺎﺑﺔ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺒﺎﻕ ﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ: >#include<stdio.h )(main { ;]int arr[2 ;int *ptr ;*(arr+0) = 10 ;*(arr+1) = 20 ;)ptr = &*(arr+0 ;))printf("%d\n", *(ptr+0 ;))printf("%d\n", *(ptr+1 ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٥ﻃﺮﻳﻘﺔ ﺃﺧﺮﻯ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺆﺷﺮﺍﺕ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻛﺘﺎﺑﺘﻪ ﺑﺎﻟﻄﺮﻳﻘﺔ ﺍﻟﺘﺎﻟﻴﺔ: >#include<stdio.h )(main { ;]int arr[2 ;int *ptr ;arr[0] = 10 ;arr[1] = 20 1 2 3 4 5 6 7 8 9 118 ;]ptr = &arr[0 ;)printf("%d\n", *ptr ;)printf("%d\n", *++ptr } ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٦ﻃﺮﻳﻘﺔ ﺃﺧﺮﻯ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺆﺷﺮﺍﺕ )(٢ ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻻ ﳝﻜﻦ ﺗﻄﺒﻴﻘﻪ ﻋﻠﻰ ﺍﳌﺼﻔﻮﻓﺎﺕ: >#include<stdio.h )(main { ;]int arr[2 ;int *ptr ;arr[0] = 10 ;arr[1] = 20 ;]ptr = &arr[0 ;)printf("%d\n", arr ;)printf("%d\n", ++arr ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٧ﺇﻣﻜﺎﻧﻴﺎﺕ ﺍﳌﺆﺷﺮ ﻣﻘﺎﺭﻧﺔ ﻣﻊ ﺍﳌﺼﻮﻓﺎﺕ } 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ٢,٤,٤ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ: ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ ﻣﺸﺎﺑﻪ ﻟﻠﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﳌﺼﻔﻮﻓﺎﺕ،ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;"!char *str = "Hello, World ;)printf("%s\n", str ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٨ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ } 1 2 3 4 5 6 7 8 ﺃﻣﺎ ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﺍﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ ﰲ ﺍﻹﺩﺧﺎﻝ ﻓﻴﻮﺟﺪ ﺷﺮﻭﻁ ﳚﺐ ﺍﻟﺘﻘﻴﺪ ﺎ ﻭ ﺇﻻ ﺳﺘﺤﺪﺙ ﺃﺧﻄﺎﺀ ﺭﲟﺎ ﰲ ﺍﳌﺼﺪﺭ ﺍﻟﱪﻧﺎﻣﺞ ﺃﻭ ﺃﺛﻨﺎﺀ ﺗﺸﻐﻴﻞ ﺍﻟﱪﻧﺎﻣﺞ ،ﻓﻤﺜﻼ ﻻ ﳝﻜﻨﻨﺎ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺜﻞ ﻣﺎ ﻫﻮ ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: >#include<stdio.h )(main { ;char *str 1 2 3 4 5 119 ;)" printf("Enter a string: ;)scanf("%s", str ;)printf("%s\n", str } 6 7 8 9 10 ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٩ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ )(٢ ﰲ ﺍﳌﺘﺮﲨﺎﺕ ﺍﳉﺪﻳﺪ ﺭﲟﺎ ﻟﻦ ﻳﺴﻤﺢ ﻟﻚ ﺍﳌﺘﺮﺟﻢ ﺑﺎﺳﺘﻌﻤﺎﻝ ﻫﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ،ﻭ ﺍﻟﺴﺒﺐ ﰲ ﺫﻟﻚ ﻫﻮ ﻋﺪﻡ ﲢﺪﻳﺪ ﻟﻠﻤﺆﺷﺮ str ﻋﻨﻮﺍﻧﺎ ،ﺃﻱ ﺃﻧﻪ ﺑﻼ ﻋﻨﻮﺍﻥ ،ﻭ ﻟﻜﻲ ﺗﺼﺒﺢ ﻃﺮﻳﺘﻨﺎ ﺻﺤﻴﺢ ﻓﻴﺠﺐ ﻋﻠﻰ ﺍﻷﻗﻞ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﺣﺮﰲ ﻭ ﻧﻌﻄﻲ ﻟﻠﻤﺆﺷﺮ str ﻋﻨﻮﺍﻥ ﺫﻟﻚ ﺍﳌﺘﻐﲑ ﻭ ﺍﻟﺬﻱ ﺳﻴﻜﻮﻥ ﺑﺪﺍﻳﺔ ﺍﳌﺆﺷﺮ strﻭ ﺳﻴﺼﺒﺢ ﺍﳌﺜﺎﻝ ﻋﻠﻰ ﺍﻟﺸﻜﻞ ﺍﻟﺘﺎﱄ: >#include<stdio.h )(main { ;char *str ;char adr_str ;str = &adr_str ;)" printf("Enter a string: ;)scanf("%s", str ;)printf("%s\n", str ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٠ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ )(٣ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ﻭ ﺳﺘﻼﺣﻆ ﰲ ﺍﻟﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﻜﺘﺎﺑﺔ strﺑﺪﻭﻥ ﺍﻟﺮﻣﺰ & ،ﺫﻟﻚ ﻷﻧﻨﺎ ﺍﺳﺘﻌﻤﻠﻨﺎ ﻣﺆﺷﺮ ﻭ ﺍﻟﻮﺿـﻊ ﺍﻻﻓﺘﺮﺍﺿـﻲ ﻟﻠﻤﺆﺷﺮﺍﺕ ﻫﻲ ﻋﻨﻮﺍﺎ .ﻭ ﳝﻜﻨﻨﺎ ﺃﻳﻀﺎ ﻛﺘﺎﺑﺔ ﺍﺳﻢ ﻣﺼﻔﻮﻓﺔ ﺑﺪﻭﻥ ﺭﻣﺰ ﺍﻟﻌﻨﻮﺍﻥ & ﰲ ﺍﻟﺪﺍﻟﺔ ،scanfﻣﺜﺎﻝ ﺗﻮﺿﻴﺤﻲ: >#include<stdio.h 1 2 3 4 5 6 7 8 9 10 11 >#include<stdio.h 1 2 )(main { ;]char arr[255 ;)" printf("Enter a string: ;)scanf("%s", arr ;)printf("%s\n", arr ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١١ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ )(٤ ﻭ ﻣﻦ ﺇﻣﻜﺎﻧﻴﺎﺕ ﺍﳌﺆﺷﺮﺍﺕ ﺃﻧﻪ ﳝﻜﻦ ﺃﻥ ﻧﻌﻄﻴﻪ ﻗﻴﻢ ﻣﺼﻔﻮﻓﺔ ﺑﺎﺳﺘﺨﺪﺍﻡ: } 120 )(main { ;}int arr[3] = {10, 20, 30 ;int *ptr ;int i ;ptr = arr )for(i=0;i<=2;i++ ;)]printf("ptr[%d] = %d\n", i, ptr[i } ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٢ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ )(٥ ﻭ ﻻ ﳝﻜﻨﻨﺎ ﻛﺘﺎﺑﺔ ﺍﻟﻌﻜﺲ.arr = ptr ، 3 4 5 6 7 8 9 10 11 12 13 ٢,٤,٥ﺍﳌﺮﺟﻊ :reference ﺍﳌﺮﺟﻊ ﻫﻮ ﺃﺧﺬ ﻋﻨﻮﺍﻥ ﻣﺘﻐﲑ ،ﻋﻨﺪ ﻛﺘﺎﺑﺔ: >#include<stdio.h ;ref ;*ptr ;= 10 ;= &ref ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٣ﺍﳌﺮﺟﻊ {)(main int int ref ptr } 1 2 3 4 5 6 7 8 ﻫﻨﺎ ﺍﻟـ ptrﻫﻮ ﺍﳌﺆﺷﺮ ،ﻭ ﺍﻟـ &refﻫﻮ ﺍﳌﺮﺟﻊ .ﻛﺘﺎﺑﺔ ﺍﳌﺆﺛﺮ & ﰒ ﺍﺳﻢ ﻣﺘﻐﲑ ﻳﻌﲏ ﺃﺧﺬ ﻋﻨﻮﺍﻥ ﺫﻟﻚ ﺍﳌﺘﻐﲑ ،ﻭ ﺗـﺴﻤﻰ ﻫﺬﻩ ﺍﻟﻌﻤﻠﻴﺔ ﺑﺎﳌﺮﺟﻊ .reference ٢,٤,٦ﻣﺆﺷﺮ ﻟـ :void ﻻ ﳝﻜﻨﻨﺎ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ،voidﻭﺳﺒﺐ ﰲ ﺫﻟﻚ ﺃﻧﻪ ﻟﻴﺲ ﳍﺎ ﺣﺠﻢ ﻛﻲ ﻳﺘﻢ ﺍﳊﻔﻆ ﻓﻴﻪ ﺍﻟﻘﻴﻢ ﺍﳌﺮﺍﺩﺓ ،ﻭ ﻟﻜﻨﻨﺎ ﳝﻜﻦ ﺃﻥ ﻧﻘﻮﻡ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺆﺷﺮ ﻟـ voidﺣﻴﺚ ﻳﻌﺘﱪ ﺍﻷﻛﺜﺮ ﻣﺮﻭﻧﺔ ﻣﻊ ﺍﳌﺆﺷﺮﺍﺕ ،ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;void *p_void /* can't use void v_void; */ ;(int)p_void = 10 ;)printf("(int)p_void = %d\n", p_void 1 2 3 4 5 6 7 8 9 10 121 ;'(char)p_void = 'H ;)printf("(char)p_void = %c\n", p_void ;"(char *)p_void = "Hello ;)printf("(char *)p_void = %s\n", p_void ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٤ﻣﺆﺷﺮ ﻟـ } 11 12 13 14 15 16 void ﻋﻨﺪﻣﺎ ﻧﺮﻳﺪ ﻭﺿﻊ ﻗﻴﻢ ﳌﺆﺷﺮ voidﻧﻜﺘﺐ ،(Type)Pointer_Nameﰲ ﻣﻜﺎﻥ Typeﻧﻜﺘﺐ ﻧﻮﻉ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﺳـﻨﻘﻮﻡ ﺑﺈﺩﺧﺎﳍﺎ ،ﰒ ﺍﺳﻢ ﺍﳌﺆﺷﺮ ﰒ ﻧﻌﻄﻴﻪ ﺍﻟﻘﻴﻤﺔ. ٢,٤,٧ﻣﺆﺷﺮ ﳌﺼﻔﻮﻓﺔ: ﻋﻨﺪﻣﺎ ﻧﻌﻠﻦ ﻋﻦ ﻣﺆﺛﺮ ﳌﺼﻮﻓﺔ ﻓﻬﺬﺍ ﻳﻌﲏ ﺃﻥ ﻛﻞ ﻋﻨﺼﺮ ﻣﻦ ﺗﻠﻚ ﺍﳌﺼﻔﻮﻓﺔ ﳝﻜﻦ ﺃﻱ ﳛﻤﻞ ﻋﻨﻮﺍﻧﺎ ،ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;]int *arr[2 ;int a = 10, b = 20 ;)printf("A = %d, ", a ;)printf("B = %d\n", b ;arr[0] = &a ;*arr[0] = 5 ;arr[1] = &b ;*arr[1] = 10 ;)printf("A = %d, ", a ;)printf("B = %d\n", b } ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٥ﻣﺆﺷﺮ ﳌﺼﻔﻮﻓﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺆﺷﺮ ﳌﺼﻔﻮﻓﺔ ﺛﻨﺎﺋﻴﺔ ﺃﻭ ﺛﻼﺛﻴﺔ ﺍﻷﺑﻌﺎﺩ .ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺆﺷﺮ ﻟﺴﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﺣﻴﺚ ﻛﻞ ﻋﻨـﺼﺮ ﻣﻦ ﺗﻠﻚ ﺍﻟﺴﻠﺴﻠﺔ ﳝﻜﻦ ﺃﻥ ﳛﻤﻞ ﻧﺺ ﻣﺜﻞ: >#include<stdio.h {)(main ;}"char *arr[] = {"Text 1", "Text 2", "Text 3 ;)]printf("arr[0] = %s\n", arr[0 ;)]printf("arr[1] = %s\n", arr[1 ;)]printf("arr[2] = %s\n", arr[2 } 1 2 3 4 5 6 7 8 9 122 ٢,٤,٨ﻣﺆﺷﺮ ﳌﺆﺷﺮ: ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٦ﻣﺆﺷﺮ ﳌﺼﻔﻮﻓﺔ )(٢ ﻣﺆﺷﺮ ﳌﺆﺷﺮ ﻗﻠﻴﻠﺔ ﺍﻻﺳﺘﻌﻤﺎﻝ .ﻣﺆﺷﺮ ﳌﺘﻐﲑ ﻳﻌﲏ ﺃﻥ ﻧﺸﲑ ﺇﱃ ﻋﻨﻮﺍﻥ ﺍﳌﺘﻐﲑ ،ﻭ ﻣﺆﺷﺮ ﳌﺆﺷﺮ ﻳﻌﲏ ﺃﻥ ﻧﺸﲑ ﺇﱃ ﻋﻨـﻮﺍﻥ ﻣﺆﺷﺮ ،ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;int p ;int *pt ;int **ptr ;p = 10 ;)printf("p = %d\n", p ;pt = &p ;ptr = &pt ;**ptr = 5 ;)printf("p = %d\n", p } ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٧ﻣﺆﺷﺮ ﳌﺆﺷﺮ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ﰎ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺆﺷﺮ ﳌﺆﺷﺮ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ .ﻭ ﳝﻜﻦ ﺃﻥ ﻧﻘﻮﻡ ﺑﺈﻋﻼﻥ ﻋﻦ ﻣﺆﺷﺮ ﳌﺆﺷﺮ ﻣﻦ ﻧﻮﻉ ﺍﳊﺮﰲ ﺣﻴـﺚ ﻛـﻞ ﻣﺆﺷﺮ ﳝﻜﻦ ﺃﻥ ﳛﻤﻞ ﺳﻠﺴﻠﺔ ﻣﻦ ﺣﺮﻭﻑ ﻣﺜﻞ: >#include<stdio.h {)(main ;char *AdrPtr ;char **ptr = &AdrPtr ;"ptr[0] = "Text 1 ;"ptr[1] = "Text 2 ;"ptr[2] = "Text 3 ;)]printf("ptr[0] = %s\n", ptr[0 ;)]printf("ptr[1] = %s\n", ptr[1 ;)]printf("ptr[2] = %s\n", ptr[2 ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٨ﻣﺆﺷﺮ ﳌﺆﺷﺮ )(٢ ﻭ ﳝﻜﻦ ﻋﻤﻞ ﺃﻛﺜﺮ ﻣﻦ ﻣﺆﺷﺮ ﳌﺆﺷﺮ ،ﺃﻱ ﳝﻜﻦ ﺍﻹﻋﻼﻥ ﻋﻦ ،int *****ptrﺃﻭ ﺃﻛﺜﺮ. } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 123 ٢,٤,٩ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: .١ﰲ ﺍﳌﺘﺮﲨﺎﺕ ﺍﳉﺪﻳﺪ ﻻ ﻳﺴﻤﺢ ﺑﺈﻋﻄﺎﺀ ﻗﻴﻤﺔ ﳌﺆﺷﺮ ﺑﺪﻭﻥ ﻋﻨﻮﺍﻥ ،ﺃﻱ ﻻ ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﻛﻤﺎ ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: >#include<stdio.h )(main { ;int *ptr ;*ptr = 10 ;)printf("%d\n", *ptr ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٩ﺍﳋﻄﺄ ١ } 1 2 3 4 5 6 7 8 9 ﻭ ﺃﻳﻀﺎ ﻻ ﳝﻜﻦ ﻛﺘﺎﺑﺔ: >#include<stdio.h )(main { ;int *ptr ;int i ;*ptr = i ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٢٠ﺍﳋﻄﺄ ٢ } 1 2 3 4 5 6 7 8 9 .٢ﻻ ﳝﻜﻦ ﺇﻋﻄﺎﺀ ﻋﻨﻮﺍﻥ ﳌﺘﻐﲑ ﻃﺒﻴﻌﻲ: >#include<stdio.h )(main { ;int *ptr ;int i ;i = ptr ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٢١ﺍﳋﻄﺄ ٣ } 1 2 3 4 5 6 7 8 9 ٢,٤,١٠ﲤﺎﺭﻳﻦ: .١ﺃﻛﺘﺐ ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺘﺎﱄ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ: >#include<stdio.h )(main 1 2 3 124 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 { char usr_name[255]; int i; i = 0; printf("Your Fullname: "); scanf("%s", &usr_name); while(usr_name[i]!='\0') { printf("%i: %c\n", i+1, usr_name[i]); ++i; } } printf("%s = %d characters\n", usr_name, i); ١ ﺍﻟﺘﻤﺮﻳﻦ:٢,٤,٢٢ ﺍﻟﱪﻧﺎﻣﺞ 125 ﺍﻟﺪﻭﺍﻝ ﻫﻲ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻷﻭﺍﻣﺮ ﻭ ﺍﻟﺒﻴﺎﻧﺎﺕ ﲢﺖ ﺍﺳﻢ ﻭﺍﺣﺪ ﺣﻴﺚ ﳝﻜﻦ ﺍﺳﺘﺪﻋﺎﺀﻫﺎ ﻣﻦ ﺃﻣﺎﻛﻦ ﳐﺘﻠﻔﺔ ﰲ ﺍﻟﱪﻧﺎﻣﺞ. ﻭ ﻫﻲ ﲟﺎ ﺗﻌﺮﻑ ﺑـﺎﻟﺮﻭﺗﲔ ﺍﻟﺜﺎﻧﻮﻱ ،subroutineﻭ ﻣﻦ ﻓﻮﺍﺋﺪﻫﺎ ﺍﻟﺘﻘﻠﻴﻞ ﰲ ﺷﻔﺮﺓ ﺍﻟﱪﻧﺎﻣﺞ ﻭ ﺣﺠﻢ ﺍﻟﱪﻧﺎﻣﺞ ،ﳑﺎ ﳚﻠﻪ ﺃﻛﺜﺮﺍ ﺗﻨﻈﻴﻤﺎ .ﺍﻟﺼﻮﺭﺓ ﺍﻟﺘﺎﻟﻴﺔ ﺗﻮﺿﺢ ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ: ﺍﻟﺸﻜﻞ :٢,٥,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﻭ ﳝﻜﻦ ﺃﻥ ﻻ ﲢﺘﻮﻱ ﺍﻟﺪﺍﻟﺔ ﻋﻠﻰ ﻭﺳﺎﺋﻂ .ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﻋﻤﻞ ﺩﺍﻟﺔ ﺗﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﳉﻤﻠـﺔ ﻛﺎﻟﺘﺎﱄ: ! World Hello,ﻓـﺴﻴﻜﻮﻥ ﺑﺮﻧﺎﳎﻨـﺎ >#include<stdio.h )(void Func_HelloWorld { ;)"printf("Hello, World!\n } )(main { ;)(Func_HelloWorld } ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ 1 2 3 4 5 6 7 8 9 10 11 ﻫﺬﻩ ﻃﺮﻳﻘﺔ ،ﺃﻣﺎ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﺜﺎﻧﻴﺔ ﻓﻬﻲ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﻟﺪﺍﻟﺔ )ﻳﺴﻤﻰ ﺑﺎﻟﻨﻤﻮﺫﺝ (prototypeﰒ ﻧﻘﻮﻡ ﺑﺈﻋﻄﺎﺋﻬﺎ ﺍﻷﻭﺍﻣﺮ ﺑﻌﺪ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﻭ ﺳﻴﺼﺒﺢ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﻛﺎﻟﺘﺎﱄ: >#include<stdio.h ;)(void Func_HelloWorld 1 2 3 126 )(main { ;)(Func_HelloWorld } )(void Func_HelloWorld { ;)"printf("Hello, World!\n } 4 5 6 7 8 9 10 11 12 13 ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٢ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ )(٢ ﻭ ﻫﻲ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻷﻓﻀﻞ ﻣﻦ ﺣﻴﺚ ﺍﻟﺘﻨﻈﻴﻢ .ﻭ ﺗﻮﺟﺪ ﻃﺮﻳﻘﺔ ﺃﺧﺮﻯ ﻭ ﻟﻜﻦ ﻻ ﻳﻔﻀﻞ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻣﻦ ﻧﺎﺣﻴﺔ ﺍﻟﺘﻨﻈﻴﻒ ﻭ ﺃﻳـﻀﺎ ﺑﻌﺾ ﺍﳌﺘﺮﲨﺎﺕ ﻻ ﺗﻘﺒﻠﻬﺎ ﻭ ﻫﻲ: >#include<stdio.h 1 2 3 4 5 6 7 8 9 10 11 >#include<stdio.h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 )(main { ;)(Func_HelloWorld } )(void Func_HelloWorld { ;)"printf("Hello, World!\n } ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٣ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ )(٣ ﻭ ﺇﻥ ﻛﺎﻥ ﻣﺘﺮﲨﻚ ﻗﺪ ﻧﺒﻬﻚ ﻋﻦ ﻭﺟﻮﺩ ﺧﻄﺄ ﻓﺴﻴﻜﻮﻥ ﻋﻦ ﺍﳋﻄﺄ ﻋﻦ ﳕﻮﺫﺝ prototypeﺍﻟﺪﺍﻟﺔ ،Func_HelloWorldﻭ ﺫﻟﻚ ﰲ ﺍﻷﺻﻞ ﻫﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ﻫﻲ ﻣﻦ ﻃﺮﻕ ﻟﻐﺔ ،Cﻳﻌﲏ ﺃﺎ ﻃﺮﻳﻘﺔ ﺻﺤﻴﺤﺔ ﻓﻘﻂ ﺑﻌﺾ ﺍﳌﺘﺮﲨﺎﺕ ﻻ ﺗـﺪﻋﻤﻬﺎ .ﺍﻟﻜﻠﻤـﺔ ﺍﶈﺠﻮﺯﺓ voidﺗﺴﺘﻌﻤﻞ ﻣﻊ ﺍﻟﺪﻭﺍﻝ ﺣﻴﺚ ﺣﺠﻤﻬﺎ ٠ﺑﺎﻳﺖ ،ﻭ ﻫﻲ ﻻ ﺗﻘﻮﻡ ﺑﺈﺭﺟﺎﻉ ﺃﻱ ﻗﻴﻢ .ﺳﻨﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺩﺍﻟﺔ ﺎ ﻭﺳﻴﻂ ﻋﺒﺎﺭﺓ ﻋﻦ ﺳﻠﺴﻠﺔ ﺣﺮﻭﻑ ﺛﺎﺑﺘﺔ ،ﺣﻴﺚ ﺳﺘﻘﻮﻡ ﺗﻠﻚ ﺍﻟﺪﺍﻟﺔ ﺑﻄﺒﺎﻋﺔ ﻣﺎ ﻫﻮ ﺩﺍﺧﻞ ﺍﻟﻮﺳﻴﻂ ﺍﳋﺎﺹ ﺎ: ;)void Func_Print(const char *str )(main { ;)"Func_Print("Func_Print:\n ;)"Func_Print("Hello, World!\n } )void Func_Print(const char *str { ;)printf("%s", str } ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٤ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﺫﺍﺕ ﻭﺳﻴﻂ 127 ﺍﻟﻘـﺴﻤﺔ ﻭ، ﺍﻟﻄـﺮﺡ، ﳝﻜﻦ ﺃﻥ ﻧﻘﻮﻡ ﺑﻌﻤﻞ ﺩﺍﻟﺔ ﺗﻘﻮﻡ ﺑـﺎﳉﻤﻊ،ﻫﺬﻩ ﻟﻴﺴﺖ ﺇﻻ ﺃﻣﺜﻠﺔ ﺑﺴﻴﻄﺔ ﺣﻮﻝ ﻃﺮﻳﻘﺔ ﻋﻤﻞ ﺍﻟﺪﻭﺍﻝ : ﺳﻴﻜﻮﻥ ﺍﳌﺜﺎﻝ ﻋﻠﻰ ﺍﻟﺸﻜﻞ ﺍﻟﺘﺎﱄ،ﺍﻟﻀﺮﺏ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 #include<stdio.h> void void void void Func_Add(const Func_Sub(const Func_Mul(const Func_Div(const main() { Func_Add(30, Func_Sub(30, Func_Mul(30, Func_Div(30, } int int int int num1, num1, num1, num1, const const const const int int int int num2); num2); num2); num2); 10); 10); 10); 10); void Func_Add(const int num1, const int num2) { printf("%d + %d = %d\n", num1, num2, num1+num2); } void Func_Sub(const int num1, const int num2) { printf("%d - %d = %d\n", num1, num2, num1-num2); } void Func_Mul(const int num1, const int num2) { printf("%d * %d = %d\n", num1, num2, num1*num2); } void Func_Div(const int num1, const int num2) { printf("%d / %d = %d\n", num1, num2, num1/num2); } ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﺫﺍﺕ ﻭﺳﻴﻄﲔ:٢,٥,٥ ﺍﻟﱪﻧﺎﻣﺞ :ﻭ ﳝﻜﻦ ﺃﻥ ﳒﻌﻞ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﺃﻛﺜﺮ ﻣﺮﻭﻧﺔ ﺑﺎﻟﻄﺮﻳﻘﺔ ﺍﻟﺘﺎﻟﻴﺔ 1 2 3 4 5 6 7 8 9 #include<stdio.h> void Func_(const int num1, const char sign, const int num2); main() { Func_(30, '+', 10); Func_(30, '-', 10); Func_(30, '*', 10); 128 ;)Func_(30, '/', 10 } )sign, const int num2 ;)num1, sign, num2, num1+num2 ;)num1, sign, num2, num1-num2 ;)num1, sign, num2, num1*num2 ;)num1, sign, num2, num1/num2 void Func_(const int num1, const char { )switch(sign { case '+': printf("%d %c %d = %d\n", ;break case '-': printf("%d %c %d = %d\n", ;break case '*': printf("%d %c %d = %d\n", ;break case '/': printf("%d %c %d = %d\n", ;break default: ;)"printf("ERROR!\n ;break } ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٦ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﺫﺍﺕ ﺃﻛﺜﺮ ﻣﻦ ﻭﺳﻴﻄﲔ } 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ٢,٥,١ﻧﻮﻉ ﺍﻟﺪﺍﻟﺔ :Function Type ﻟـ ﺍﻟﺪﻭﺍﻝ ﺃﻧﻮﺍﻉ ﻭ ﻫﻲ ﻧﻔﺴﻬﺎ ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑ ،ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺩﺍﻟﺔ ﻣﻦ ﻧﻮﻉ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ intﺃﻭ ﺃﻋـﺪﺍﺩ ﺣﻘﻴﻘﻴـﺔ .floatﺑﺎﻟﻨﺴﺒﺔ ﻟﺪﻭﺍﻝ ﻣﻦ ﻧﻮﻉ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ﻓﻬﻲ ﳍﺎ ﻗﻴﻤﺔ ﺗﻘﻮﻡ ﺑﺈﺭﺟﺎﻋﻬﺎ ،ﺃﻱ ﰲ ﺎﻳﺔ ﺍﻟﺪﺍﻟﺔ ﻧﻘﻮﻡ ﺑﺈﺭﺟـﺎﻉ ﻗﻴﻤـﺔ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ returnﻛﻤﺎ ﰲ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: >#include<stdio.h ;)int Int_Func(const int num )(main { ;))printf("%d\n", Int_Func(5 } )int Int_Func(const int num { ;return num } ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٧ﺇﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ ﻫﻨﺎ ﻗﻤﻨﺎ ﺑﺈﺭﺟﺎﻉ ﻗﻴﻤﺔ ﺍﻟﻮﺳﻴﻂ num 1 2 3 4 5 6 7 8 9 10 11 12 13 intﺇﱃ ﺍﻟﺪﺍﻟﺔ ،Int_Funcﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ،ﰲ ﺍﻟﺪﺍﻟﺔ printfﳝﻜﻨﻨﺎ ﻛﺘﺎﺑـﺔ ﺩﻭﺍﻝ ﺍﻟﱵ ﺗﻘﻮﻡ ﺑﺈﺭﺟﺎﻉ ﻗﻴﻢ ﻛﻤﺎ ﰲ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ،ﻭ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻫﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ﻣﻊ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ voidﻷﺎ ﺑﺪﻭﻥ 129 ﺣﺠﻢ ﻭ ﻻ ﳝﻜﻨﻬﺎ ﲪﻞ ﻗﻴﻢ .ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺍﻟﺪﺍﻟﺔ ﺑﺪﻭﻥ ﻧﻮﻉ ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﻤﺜﺎﻝ ﺍﻟﺴﺎﺑﻘﺔ ،ﻷﻥ ﺩﺍﻟﺘﻨﺎ ﻣﻦ ﻧﻮﻉ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ،ﻭ ﰲ ﻟﻐﺔ Cﺍﻟﻮﺿﻊ ﺍﻻﻓﺘﺮﺍﺿﻲ ﻟﺪﻭﺍﻝ ﺑﺪﻭﻥ ﻧﻮﻉ ﻫﻮ intﻭ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺳﻴﺼﺒﺢ ﻋﻠﻰ ﺍﻟﺸﻜﻞ ﺍﻟﺘﺎﱄ: >#include<stdio.h ;)Int_Func(const int num )(main { ;))printf("%d\n", Int_Func(5 } )Int_Func(const int num { ;return num } ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٨ﺍﻟﻮﺿﻊ ﺍﻹﻓﺘﺮﺍﺿﻲ ﻟﺪﺍﻟﺔ ﺑﺪﻭﻥ ﲢﺪﻳﺪ ﻧﻮﻋﻬﺎ 1 2 3 4 5 6 7 8 9 10 11 12 13 ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻛﺘﺎﺑﺔ ﺍﺳﻢ ﻣﺘﻐﲑ ﺑﺪﻭﻥ ﻧﻮﻉ ،ﰒ ﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﻧﻮﻋﻪ ﺃﺳﻔﻞ ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ﺍﻟﱵ ﻫﻲ ﺑﻌﺪ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ،ﻣﺜﺎﻝ: >#include<stdio.h ;)Int_Func(const int num )(main { ;))printf("%d\n", Int_Func(5 } )Int_Func(num ;const int num { ;return num } ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٩ﻃﺮﻳﻘﺔ ﺃﺧﺮﻯ ﻟﻺﻋﻼﻥ ﻋﻦ ﻭﺳﻴﻂ ﻟﺪﺍﻟﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ﻭ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﳌﺜﺎﻝ: >#include<stdio.h ;)int Int_Func(const int num )(main { ;))printf("%d\n", Int_Func(5 } )int Int_Func(const int num { ;return num 1 2 3 4 5 6 7 8 9 10 11 12 130 13 1 2 3 4 5 6 7 8 9 10 11 12 13 } ﺍﻟﻄﺮﻳﻘﺔ ﺍﻹﻓﺘﺮﺍﺿﻴﺔ ﻟﻺﻋﻼﻥ ﻋﻦ ﻭﺳﻴﻂ ﻟﺪﺍﻟﺔ:٢,٥,١٠ ﺍﻟﱪﻧﺎﻣﺞ :short ﺑﺎﺳﺘﺨﺪﺍﻡ #include<stdio.h> short Short_Func(const short num); main() { printf("%d\n", Short _Func(5)); } short Short _Func(const short num) { return num; } short ﺇﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﻣﻦ ﻧﻮﻉ:٢,٥,١١ ﺍﻟﱪﻧﺎﻣﺞ ﻓﻬﺬﺍ ﻣﺜـﺎﻝ ﻟﻄﺮﻳﻘـﺔchar ﺃﻣﺎ، ﺑﻨﻔﺲ ﺍﻟﻄﺮﻳﻘﺔunsigned ،signed ،double ،float ،long ﻭ ﺑﺎﺳﺘﺨﺪﺍﻡ ﻛﻞ ﻣﻦ :ﺍﺳﺘﻌﻤﺎﳍﺎ 1 2 3 4 5 6 7 8 9 10 11 12 13 #include<stdio.h> char Char_Func(const char ch); main() { printf("%c\n", Char_Func('C')); } char Char_Func(const char ch) { return ch; } char ﺇﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﻣﻦ ﻧﻮﻉ:٢,٥,١٢ ﺍﻟﱪﻧﺎﻣﺞ :ﻭ ﺍﻟﺪﻭﺍﻝ ﺍﻟﱵ ﺗﺮﺟﻊ ﻗﻴﻢ ﳝﻜﻦ ﺇﻋﻄﺎﺀﻫﺎ ﳌﺘﻐﲑ ﻃﺒﻴﻌﻲ ﻣﺒﺎﺷﺮﺓ ﻣﺜﻞ 1 2 3 4 5 6 7 8 9 10 #include<stdio.h> int Int_Func(const int num); main() { int i = Int_Func(5); printf("i = %d\n", i); } 131 )int Int_Func(const int num { ;return num*2 } ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١٣ﺇﻋﻄﺎﺀ ﳌﺘﻐﲑ ﻗﻴﻤﺔ ﺗﺮﺟﻌﻬﺎ ﺩﺍﻟﺔ 11 12 13 14 15 ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻋﻤﻞ ﺩﺍﻟﺔ ﺗﻘﻮﻡ ﺑﺈﺭﺟﺎﻉ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ ،ﻣﺜﺎﻝ: >#include<stdio.h {)char *string(char *str ;return str } )(main { ;))"!printf("%s\n", string("Hello, World } ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١٤ﺇﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﻣﻦ ﻧﻮﻉ 1 2 3 4 5 6 7 8 9 10 *char ٢,٥,٢ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ :Function Name ﻻﺳﻢ ﺍﻟﺪﺍﻟﺔ ﺣﺪﻭﺩ ﻭ ﻫﻲ ﻣﺜﻞ ﺍﺳﻢ ﺍﳌﺘﻐﲑ: § ﺃﻥ ﻻ ﻳﺘﺠﺎﻭﺯ ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ٣١ﺣﺮﻑ. § ﺃﻥ ﻻ ﻳﺒﺪﺃ ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ﺑﺄﺭﻗﺎﻡ. § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ﳛﺘﻮﻱ ﻋﻠﻰ ﻣﺆﺛﺮﺍﺕ ﻣﺜﻞ ﺍﳉﻤﻊ ﻭ ﺍﻟﻄﺮﺡ ﻭ.... § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ﳛﺘﻮﻱ ﻋﻠﻰ ﺭﻣﻮﺯ ﻣﺜﻞ %ﻭ #ﻭ { ﻭ)...ﺑﺎﺳﺘﺜﻨﺎﺀ ﺍﻟﺮﻣﺰ _(. § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ﻣﺴﺘﻌﻤﻞ ﺳﺎﺑﻘﺎ ﰲ ﻣﺘﻐﲑ ﺃﻭ ﺩﺍﻟﺔ ﺃﺧﺮﻯ. § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ﻣﻦ ﺃﺣﺪ ﺃﲰﺎﺀ ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ. ٢,٥,٣ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ :Function Parameters ﺍﻟﻮﺳﺎﺋﻂ ﻫﻲ ﻣﺘﻐﲑﺍﺕ ﻧﻘﻮﻡ ﺑﻮﺿﻌﻬﺎ ﻋﻠﻰ ﺣﺴﺐ ﻣﺘﻄﻠﺒﺎﺗﻨﺎ ﺣﻴﺚ ﺗﻜﻮﻥ ﻣﻦ ﺍﻷﻧﻮﺍﻉ ][ .long, int, float, double, char, char*, charﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﺃﻥ ﺗﻜﻮﻥ ﺍﻟﻮﺳﺎﺋﻂ ﻋﺒﺎﺭﺓ ﻋﻦ ﻣـﺼﻔﻮﻓﺎﺕ ﺃﻭ ﻣﺆﺷﺮﺍﺕ ﻣﻦ ﻛﻞ ﺍﻷﻧﻮﺍﻉ. , signed, short, ٢,٥,٤ﺍﻷﻭﺍﻣﺮ: ﺍﻷﻭﺍﻣﺮ ﳝﻜﻦ ﻛﺘﺎﺑﺘﻬﺎ ﲝﺮﻳﺔ ﻣﺜﻞ ﻣﺎ ﻧﻜﺘﺒﻬﺎ ﻋﻠﻰ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ .main unsigned 132 ٢,٥,٥ﺍﳌﺨﺘﺼﺮﺍﺕ :macros ﻻ ﺗﺴﻤﻰ ﺑﺪﻭﺍﻝ ﻭ ﻟﻜﻨﻬﺎ ﺷﺒﻴﻬﺎ ﳍﺎ ،ﺗﺴﻤﻰ ﺑﺎﻟـ macrosﺃﻱ ﺍﳌﺨﺘﺼﺮﺍﺕ ،ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻟﻄﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ: >#include<stdio.h )#define Add(a, b) (a+b )(main { ;int a, b ;a = 50 ;b = 100 ;))printf("%d + %d = %d\n", a, b, Add(a, b ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١٥ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﳐﺘﺼﺮ } 1 2 3 4 5 6 7 8 9 10 11 12 ﻭ ﻫﻨﺎ ﻋﻨﺪ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺘﻐﲑﺍﺕ ﻻ ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺃﻭ ﲢﺪﻳﺪ ﻧﻮﻋﻬﺎ ،ﺳﻴﺘﻢ ﲢﺪﻳﺪ ﻧﻮﻉ ﺍﳌﺘﻐﲑ ﺗﻠﻘﺎﺋﻴﺎ ﻣﻦ ﺍﳌﻮﺟﻪ .#defineﻣﺜﺎﻝ ﺁﺧﺮ: >#include<stdio.h )#define PrintF_(String) printf("%s", String )(main { ;)"PrintF_("Macro...\n } ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١٦ﺇﺳﺘﺪﻋﺎﺀ ﺩﺍﻟﺔ ﻣﻦ ﳐﺘﺼﺮ 1 2 3 4 5 6 7 8 ٢,٥,٦ﺍﻟﻔﺮﻕ ﺑﲔ ﺍﻹﺟﺮﺍﺀ ﻭ ﺍﻟﺪﺍﻟﺔ: ﰲ ﻟﻐﺔ Cﺍﻹﺟﺮﺍﺀﺍﺕ ﳝﻜﻦ ﺍﻟﻘﻮﻝ ﻋﻠﻴﻬﺎ ﻫﻲ ﻧﻔﺴﻬﺎ ﺍﻟﺪﻭﺍﻝ ﻷﺎ ﻣﺪﻣﺞ ﻣﻌﻬﺎ ،ﻭ ﺍﻹﺟﺮﺍﺀ Procedureﻫﻮ ﺩﺍﻟﺔ ﻻ ﺗﻘـﻮﻡ ﺑﺈﺭﺟﺎﻉ ﻗﻴﻤﺔ ﻭ ﳝﻜﻦ ﺍﻟﻘﻮﻝ ﺃﻥ ﺩﻭﺍﻝ ﻣﻦ ﻧﻮﻉ voidﺗﺴﻤﻰ ﺇﺟﺮﺍﺀ ﻷﺎ ﻻ ﺗﺮﺟﻊ ﻗﻴﻢ ﻣﺜﻞ ﺍﻟـﺪﻭﺍﻝ ﻣـﻦ ﻧـﻮﻉ intﺃﻭ floatﺃﻭ ﻏﲑﻫﺎ ،ﺣﻴﺚ ﺗﻘﻮﻡ ﺍﻹﺟﺮﺍﺀﺍﺕ ﺑﺘﻨﻔﻴﺬ ﺃﻭﺍﻣﺮ ﺃﻣﺎ ﺍﻟﺪﻭﺍﻝ ﻓﻬﻲ ﺗﻘﻮﻡ ﺑﻌﻤﻠﻴﺎﺕ ﻭ ﺗﻌﻄﻲ ﻧﺘﻴﺠﺔ. ٢,٥,٧ﺩﻭﺍﻝ ﳍﺎ ﻭﺳﺎﺋﻂ ﻣﻦ ﻧﻮﻉ ﺩﻭﺍﻝ: ﳝﻜﻨﻨﺎ ﻋﻤﻞ ﺩﻭﺍﻝ ﺎ ﺩﻭﺍﻝ ﺃﺧﺮﻯ ،ﻭ ﺫﻟﻚ ﻛﺘﺎﱄ: >#include<stdio.h ;))void CallFunc(void Func_Name(void 1 2 3 133 4 5 6 7 8 9 10 11 12 13 14 15 16 17 void Function(); main(){ CallFunc(Function); } void CallFunc(void Func_Name(void)){ printf("Call Function:\n"); Func_Name(); } void Function(){ printf("This is a function!\n"); } ﺩﺍﻟﺔ ﺫﺍﺕ ﻭﺳﻴﻂ ﻟﺪﺍﻟﺔ ﺃﺧﺮﻯ:٢,٥,١٧ ﺍﻟﱪﻧﺎﻣﺞ ﺃﻭ ﺍﺳﺘﺪﻋﺎﺀ ﺩﻭﺍﻝ ﺃﺧﺮﻯ ﰲ ﻭﺳـﺎﺋﻂ،ﺎ ﻭﺳﺎﺋﻂ ﺃﺧﺮﻯ ﺃﻭ ﺩﻭﺍﻝ،ﻭ ﳝﻜﻦ ﺃﻥ ﺗﻜﻮﻥ ﺍﻟﻮﺳﺎﺋﻂ ﻋﺒﺎﺭﺓ ﻋﻦ ﺩﻭﺍﻝ ﺗﺮﺟﻊ ﻗﻴﻢ : ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻟﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺑﺎﺭﺍﻣﺎﺭﺕ ﺩﻭﺍﻝ ﳍﺎ ﻭﺳﺎﺋﻂ ﺃﺧﺮﻯ. ﻭ ﺃﻛﺜﺮ ﻣﻦ ﺫﻟﻚ،ﺍﻟﺪﻭﺍﻝ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include<stdio.h> void CallFunc(void Func_Name(int a, int b)); void Function(int a, int b); main(){ CallFunc(Function); } void CallFunc(void Func_Name(int a, int b)){ printf("Call Function:\n"); Func_Name(10, 20); } void Function(int a, int b){ printf("%d + %d = %d\n", a, b, a+b); } ﺩﺍﻟﺔ ﺫﺍﺕ ﻭﺳﻴﻂ ﻟﺪﺍﻟﺔ ﺃﺧﺮﻯ ﺫﺍﺕ ﻭﺳﺎﺋﻂ:٢,٥,١٨ ﺍﻟﱪﻧﺎﻣﺞ : ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ٢,٥,٨ : ﻣﺜﺎﻝ،ﺎﻳﺔ ﺩﻭﺍﻝ ﻧﻘﻮﻡ ﺑﺈﻋﻄﺎﺋﻬﺎ ﺃﻭﺍﻣﺮ ﻻ ﻧﻀﻊ ﺍﻟﻔﻮﺍﺻﻞ ﺍﳌﻨﻘﻮﻃﺔ ﰲ.١ 1 2 3 4 5 6 7 8 9 10 #include<stdio.h> void Function(); main() { } Function(); void Function(); 134 { /*Empty Funtion;*/ ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١٩ﺍﳋﻄﺄ ١ } 11 12 13 ﻭ ﺍﳋﻄﺄ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ،ﻋﻨﺪ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﺑﺪﻭﻥ ﺃﻭﺍﻣﺮ ﳚﺐ ﻛﺘﺎﺑﺔ ﺍﻟﻔﺎﺻﻠﺔ ﺍﳌﻨﻘﻮﻃﺔ ﰲ ﺎﻳﺔ ﺍﻟﺪﺍﻟﺔ ،ﺃﻣﺎ ﻋﻨﺪ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﻭﺍﻝ ﻟﻜﻲ ﻧﻌﻄﻲ ﳍﺎ ﺃﻭﺍﻣﺮ ﻓﻼ ﳚﺐ ﺃﻥ ﻧﻜﺘﺐ ﻓﺎﺻﻠﺔ ﻣﻨﻘﻮﻃﺔ ﰲ ﺎﻳﺔ ﺍﻟﺪﺍﻟﺔ. .٢ﻻ ﳝﻜﻦ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺘﲔ ﺑﻨﻔﺲ ﺍﻻﺳﻢ. ٢,٥,٩ﲤﺎﺭﻳﻦ: .١ﺃﻛﺘﺐ ﺩﺍﻟﺔ ﺗﻘﻮﻡ ﺑـ ﻋﺪ ﻋﺪﺩ ﺃﺣﺮﻑ ﻧﺺ ،ﺣﻴﺚ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ StrLenﻭ ﺎ ﺍﻟﻮﺳـﻴﻂ .*str .٢ﺃﻛﺘﺐ ﺩﺍﻟﺔ ﺗﻘﻮﻡ ﺑﺈﺧﺮﺍﺝ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻄﻠﻘﺔ ﻟﻠﻌﺪﺩ ﺍﻟﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ ،ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ﻫﻮ absﻣﻊ ﺍﻟﻮﺳـﻴﻂ .value char const int 135 ﻛﻞ ﻣﻦ stdio.hﻭ conio.hﻋﺒﺎﺭﺓ ﻋﻦ ﻣﻠﻔﺎﺕ ﺭﺃﺳﻴﺔ ،ﺣﻴﺚ ﺗﻮﺟﺪ ﺎ ﺛﻮﺍﺑﺖ ،ﳕﺎﺫﺝ ﺩﻭﺍﻝ ﻭ ﺑﻨﻴﺎﺕ ﺗﺴﺎﻋﺪﻧﺎ ﰲ ﺑﺮﺍﳎﻨﺎ ،ﺳﻨﺘﺤﺪﺙ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ ﻋﻦ ﻃﺮﻳﻘﺔ ﺇﻧﺸﺎﺀ ﻣﻠﻔﺎﺕ ﺭﺃﺳﻴﺔ ﻭ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ .ﺳﻨﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﻣﻠﻒ ﺭﺃﺳﻲ ﺑـﻪ ﺩﻭﺍﻝ ﻟﻜﻞ ﻣﻦ ﺍﳉﻤﻊ ،ﺍﻟﻄﺮﺡ ،ﺍﻟﻘﻴﻤﺔ ﻭ ﺍﻟﻀﺮﺏ ،ﺃﻭﻻ ﻧﻘﻮﻡ ﺑﺈﻧﺸﺎﺀ ﻣﻠﻒ ﻧﺼﻲ ﻭ ﺣﻔﻈﻪ ﻋﻠﻰ ﺻﻴﻐﺔ ،.hﻭ ﻳﻜﻮﻥ ﺍﺳـﻢ ﻣﻠﻔﻨﺎ ﺍﻟﺮﺃﺳﻲ functions.hﻣﺜﻼ ،ﻭ ﻧﻜﺘﺐ ﻓﻴﻪ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: /*Functions Header file*/ )int Add(int num1, int num2 { ;return num1+num2 } )int Sub(int num1, int num2 { ;return num1-num2 } )int Mul(int num1, int num2 { ;return num1*num2 } )int Div(int num1, int num2 { ;return num1/num2 } ﺍﻟﱪﻧﺎﻣﺞ :٢,٦,١ﺇﻧﺸﺎﺀ ﻣﻠﻒ ﺭﺃﺳﻲ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ﰒ ﻗﻢ ﺑﺈﻧﺸﺎﺀ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﻟﻠﻤﺸﺮﻭﻉ ﰲ ﻧﻔﺲ ﺍﳌﻜﺎﻥ ﺍﻟﺬﻱ ﻗﻤﺖ ﺑﺈﻧﺸﺎﺀ ﻓﻴﻪ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳـﻲ ،functions.hﻭ ﻗـﻢ ﺑﺎﻟﻜﺘﺎﺑﺔ ﻓﻴﻪ ﻣﺎ ﻳﻠﻲ: >#include<stdio.h "#include"functions.h )(main { ;int num1 = 30, num2 = 10 ;))num2 ;))num2 ;))num2 ;))num2 Add(num1, Sub(num1, Mul(num1, Div(num1, num2, num2, num2, num2, num1, num1, num1, num1, %d\n", %d\n", %d\n", %d\n", ﺍﻟﱪﻧﺎﻣﺞ :٢,٦,٢ﺿﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ = = = = %d %d %d %d + * / printf("%d printf("%d printf("%d printf("%d } 1 2 3 4 5 6 7 8 9 10 11 12 136 ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﱐ ﻗﻤﻨﺎ ﺑﺈﺿﺎﻓﺔ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ functions.hﻭ ﻟﻜﻦ ﺑﻄﺮﻳﻘﺔ ﳐﺘﻠﻔﺔ ﻭ ﻫﻲ ﻭﺿﻊ ﺍﺳﻢ ﺍﳌﻠﻒ ﺑﲔ ﺇﻗﺘﺒﺎﺳﲔ ﻭ ﺫﻟﻚ ﻷﻥ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ functions.hﻣﻮﺟﻮﺩ ﰲ ﻧﻔﺲ ﺍﳌﻜﺎﻥ ﺍﻟﺬﻱ ﻣﻮﺟﻮﺩ ﺑﻪ ﺍﳌﻠﻒ ﺍﻟﻨﺼﻲ ﺍﻟﺮﺋﻴﺴﻲ ،main.cﺃﻣﺎ ﺇﺫﺍ ﺃﺭﺩﺕ ﻛﺘﺎﺑﺔ: >#include<stdio.h >#include<functions.h )(main { ;int num1 = 30, num2 = 10 ;))num2 ;))num2 ;))num2 ;))num2 Add(num1, Sub(num1, Mul(num1, Div(num1, num2, num2, num2, num2, num1, num1, num1, num1, %d\n", %d\n", %d\n", %d\n", ﺍﻟﱪﻧﺎﻣﺞ :٢,٦,٣ﺿﻢ ﻣﻠﻒ ﺭﺃﺳﻲ ﻣﻮﺟﻮﺩ ﺑﺎﻠﺪ = = = = %d %d %d %d + * / printf("%d printf("%d printf("%d printf("%d } 1 2 3 4 5 6 7 8 9 10 11 12 include ﻓﻴﺠﺐ ﻋﻠﻴﻚ ﻭﺿﻊ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ functions.hﰲ ﻧﻔﺲ ﺍﳌﻜﺎﻥ ﺍﻟﺬﻱ ﻣﻮﺟﻮﺩ ﺑﻪ ﺍﳌﻠـﻒ ﺍﻟﺮﺃﺳـﻲ )stdio.hﺃﻱ ﰲ ﺍﻠﺪ includeﺍﳌﻮﺟﻮﺩ ﰲ ﳎﻠﺪ ﺍﳌﺘﺮﺟﻢ(. ٢,٦,١ﺍﺳﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ: ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺃﺭﻗﺎﻡ ﰲ ﺑﺪﺍﻳﺔ ﺍﺳﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﻭ ﺃﻳﻀﺎ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮﺍﺕ ﺍﳉﻤﻊ ﻭ ﺍﻟﻄﺮﺡ ،ﻭ ﺍﻟﺮﻣﻮﺯ ﺍﻟﱵ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﰲ ﺍﺳﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﻫﻲ ،/ ? : & \ * " < > | # % :ﻭ ﺃﻗﺼﻰ ﺣﺪ ﳝﻜﻦ ﺇﻋﻄﺎﺀﻩ ﻻﺳﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﻫﻮ ٢٥٦ ﺭﻣﺰ. ٢,٦,٢ﻣﱴ ﻧﺴﺘﻌﻤﻞ ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ: ﺗﺴﺘﻌﻤﻞ ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ﻋﻨﺪ ﻛﺘﺎﺑﺔ ﺑﺮﺍﻣﺞ ﻛﺒﲑﺓ ،ﻣﺜﻼ ﺇﺫﺍ ﻛﻨﺖ ﺗﺴﺘﻌﻤﻞ ﻛﺜﲑ ﺩﻭﺍﻝ ﺍﻟﺮﻳﺎﺿﻴﺎﺕ ﰲ ﺑﺮﺍﻣﺞ ﻓﻴﺴﺘﺤﺴﻦ ﺃﻥ ﺗﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﻣﻠﻒ ﺭﺃﺳﻲ ﺑﺎﺳﻢ math.hﺣﻴﺚ ﺗﻀﻊ ﺑﻪ ﲨﻴﻊ ﺍﻟﺪﻭﺍﻝ ﺍﻟﱵ ﺗﺮﻳﺪ ﺍﺳﺘﻌﻤﺎﳍﺎ ﰲ ﺍﳌـﺴﺘﻘﺒﻞ ،ﻭ ﺇﺫﺍ ﻛﻨـﺖ ﺗﺴﺘﻌﻤﻞ ﺩﻭﺍﻝ ﺍﻟﺮﺳﻢ ﺃﻳﻀﺎ ﻗﻢ ﺑﺈﻧﺸﺎﺀ ﻣﻠﻒ ﺭﺃﺳﻲ ﳍﺎ ﺑﺎﺳﻢ design.hﺃﻭ graphics.hﺣﻴﺚ ﺗﻜﻮﻥ ﺑﻪ ﺃﻏﻠـﺐ ﺩﻭﺍﻝ ﺍﻟﺮﺳﻢ ،ﻭ ﻫﻜﺬﺍ ﺣﱴ ﺗﻜﻮﻥ ﻟﺪﻳﻚ ﻣﻜﺘﺒﺔ ﻛﺒﲑﺓ ﺧﺎﺻﺔ ﺑﻚ. ٢,٦,٣ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: .١ﻋﻨﺪ ﺇﺿﺎﻓﺔ ﻣﻠﻒ ﺭﺃﺳﻲ ﳚﺐ ﺍﻟﺘﺄﻛﺪ ﺃﻧﻪ ﻣﻮﺟﻮﺩ ﰲ ﻧﻔﺲ ﻣﻜﺎﻥ ﺍﳌﺸﺮﻭﻉ. 137 ٢,٦,٤ﲤﺎﺭﻳﻦ: .١ﺃﻛﺘﺐ ﻣﻠﻒ ﺭﺃﺳﻲ ﺑﺎﺳﻢ math.hﺣﻴﺚ ﺑﻪ ﺍﻟﺪﺍﻟﺔ absﻭ ﺍﻟﱵ ﺗﻘﻮﻡ ﺑﺈﺧﺮﺍﺝ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻄﻠﻘﺔ ﻟﻠﻌﺪﺩ ﺍﳌﺪﺧﻞ ،ﰒ ﻗﻢ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ absﰲ ﺑﺮﻧﺎﳎﻚ. 138 ﺳﻨﻌﺮﻑ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ ﻃﺮﻳﻘﺔ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﻠﻔﺎﺕ ﰲ ﻛﻞ ﻣﻦ ﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ )ﻗﺮﺍﺀﺓ ﺍﳌﻠﻔﺎﺕ ،ﻭ ﺇﻧﺸﺎﺀ ﺍﳌﻠﻔﺎﺕ ﻭ ﻛﺘﺎﺑﺔ ﻋﻠﻴﻬﺎ(. ٢,٧,١ﺍﻹﺧﺮﺍﺝ ﰲ ﺍﳌﻠﻔﺎﺕ: ﺍﻹﺧﺮﺍﺝ ﻳﻌﲏ ﺑﻨﺎﺀ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﺈﺧﺮﺍﺝ )ﺇﻧﺸﺎﺀ( ﻣﻠﻔﺎﺕ ﺫﺍﺕ ﺍﻣﺘﺪﺍﺩ ﻳﻘﻮﻡ ﺑﺘﺤﺪﻳﺪﻩ ﺍﳌﱪﻣﺞ ،ﺣﻴﺚ ﲢﺘﻮﻱ ﺗﻠﻚ ﺍﳌﻠﻔﺎﺕ ﻋﻠﻰ ﺑﻴﺎﻧﺎﺕ .ﺍﳌﺜﺎﻝ ﺍﻷﻭﻝ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ ﺳﻴﻜﻮﻥ ﻋﺒﺎﺭﺓ ﻋﻦ ﺑﺮﻧﺎﻣﺞ ﻳﻄﻠﺐ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﻛﺘﺎﺑﺔ ﺍﺳﻢ ﺍﳌﻠﻒ ﺍﻟـﺬﻱ ﻳﺮﻳـﺪ ﺇﻧﺸﺎﺀﻩ ﻣﻊ ﺍﻣﺘﺪﺍﺩﻩ ،ﻭ ﻳﻄﻠﺐ ﻣﻨﻪ ﺃﻳﻀﺎ ﺇﺩﺧﺎﻝ ﺍﻟﻨﺺ ﺍﻟﺬﻱ ﻳﺮﻳﺪ ﺣﻔﻈﻪ ﰲ ﺍﳌﻠﻒ ،ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;FILE *File ;]char FileName[255 ;]char String[255 ;)" printf("Enter the name of file(with type)\n[MAX Character 255]: ;)gets(FileName ;)"printf("Creating File...\n ;)"File = fopen(FileName, "w ;)"printf("File Created.\n ;)"printf("TEXT:\n ;)gets(String ;)printf("Save Text to the file %s...\n", FileName ;)fprintf(File, "%s", String ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,١ﻃﺮﻳﻘﺔ ﻓﺘﺢ ﻣﻠﻒ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻗﻤﻨﺎ ﺑﺈﻧﺸﺎﺀ ﻣﺆﺷﺮ ﻟﻠﺒﻨﻴﺔ FILEﻭ ﺫﻟﻚ ﻷﻥ ﺍﻟﺪﻭﺍﻝ ﺍﳋﺎﺻﺔ ﺑﺎﳌﻠﻔﺎﺕ ﲨﻴﻊ ﺗﺘﻄﻠﺐ ﻣﺆﺷﺮ ﻟﻠﺒﻨﻴﺔ .FILE ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﻭ ﺍﻟﱵ ﺳﺘﻜﻮﻥ ﺍﺳﻢ ﺍﳌﻠﻒ .ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴـﺔ ﻭ ﺍﻟـﱵ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺺ ﺍﻟﺬﻱ ﺳﻨﻀﻌﻪ ﰲ ﺍﳌﻠﻒ .ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﻃﻠﺒﻨﺎ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﺍﺳﻢ ﺍﳌﻠﻒ ﻣﻊ ﺍﻣﺘﺪﺍﺩﻩ ﻭ ﺃﻧﻪ ﺃﻗﺼﻰ ﻋﺪﺩ ﺍﻷﺣﺮﻑ ﺍﻟﱵ ﳝﻜﻦ ﺇﺩﺧﺎﳍﺎ ﻫﻮ .٢٥٥ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﻗﻤﻨﺎ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ getsﺑﺪﻝ ﺍﻟﺪﺍﻟﺔ scanfﻷﺧـﺬ ﺍﺳﻢ ﺍﳌﻠﻒ ،ﻭ ﺳﺒﺐ ﺫﻟﻚ ﻫﻮ: 139 ﺇﻥ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﺪﺍﻟﺔ scanfﻹﺩﺧﺎﻝ ﺍﺳﻢ ﺍﳌﻠﻒ ﻓﺮﲟﺎ ﻳﻘﻮﻡ ﺍﳌﺴﺘﺨﺪﻡ ﺑﺈﺩﺧﺎﻝ ﺍﺳﻢ ﻣﻜﻮﻥ ﻣﻦ ﻛﻠﻤﺘﲔ ﻣﻨﻔﺼﻠﺘﲔ ﻣﺜﻞ test.txtﻓﻬﻨﺎ ﺍﻟﺪﺍﻟﺔ scanfﺳﺘﺘﻮﻗﻒ ﻋﻦ ﺍﻟﻔﺮﺍﻍ ﺃﻱ ﺃﻥ ﺍﺳﻢ ﺍﳌﻠﻒ ﺳﻴﻜﻮﻥ testﻭ ﺑﺪﻭﻥ ﺍﻣﺘﺪﺍﺩ ،ﻭ ﻫـﺬﺍ ﻫـﻮ ﺳـﺒﺐ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ getsﻷﺎ ﺗﺄﺧﺬ ﺍﻻﺳﻢ ﻛﺎﻣﻞ ﺣﱴ ﻭ ﺇﻥ ﻛﺎﻧﺖ ﻓﺮﺍﻏﺎﺕ .ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﺈﻋﻄﺎﺀ ﺍﳌﺆﺷـﺮ Fileﻋﻨﻮﺍﻥ ﺍﻟﺪﺍﻟﺔ fopenﻭ ﺍﻟﱵ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣﻦ ،file openﺍﻟﺪﺍﻟﺔ ﳍﺎ ﻭﺳﻴﻄﲔ ،ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﺧﺎﺹ ﺑﺎﺳﻢ ﺍﳌﻠـﻒ ﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻓﻬﻮ ﺍﻟﻨﻤﻂ ﺃﻱ ﻧﻮﻉ ﺍﺳﺘﺨﺪﺍﻡ ﺍﳌﻠﻒ ،ﻭ ﻫﻨﺎ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﻜﺘﺎﺑﺔ ﻟﺬﺍ ﻛﺘﺒﻨﺎ ﺍﻟﺮﻣﺰ wﻭ ﺍﻟﺬﻱ ﻳﻌﲏ ،writeﻭ ﺗﻮﺟﺪ ﺃﺣﺮﻑ ﺃﺧﺮﻯ ﺳﻨﻌﺮﻓﻬﺎ ﻓﻴﻤﺎ ﺑﻌﺪ .ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﻋﺸﺮ ﻳﻨﺘﻈﺮ ﺍﻟﱪﻧﺎﻣﺞ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ﻟﻜﻲ ﻳﻘﻮﻡ ﺑﺈﺩﺧـﺎﻝ ﻧـﺺ ﻭ ﺍﺳﺘﻌﻤﺎﻟﻨﺎ ﻫﻮ ﺍﻟﺪﺍﻟﺔ getsﻟﻨﻔﺲ ﺍﻟﺴﺒﺐ ﺍﻟﺴﺎﺑﻖ .ﻭ ﺃﺧﲑﺍ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺸﺮﻳﻦ ﺣﻴﺚ ﺗﻮﺟﺪ ﺍﻟﺪﺍﻟﺔ ﺍﻟﱵ ﺗﻘﻮﻡ ﺑﺈﺩﺧﺎﻝ ﺍﻟﻨﺺ ﺇﱃ ﺍﳌﻠﻒ ،ﻭ ﺍﻟﺪﺍﻟﺔ ﻫﻲ fprintfﻭ ﻫﻲ ﻣﺜﻞ ﺍﻟﺪﺍﻟﺔ printfﻭ ﻟﻜﻨﻬﺎ ﺗﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﻠﻔﺎﺕ ﺃﻣﺎ printfﻓﻬﻲ ﺗﺘﻌﺎﻣـﻞ ﻣـﻊ ﺍﻟﺸﺎﺷﺔ ،ﺍﻟﺪﺍﻟﺔ fprintfﳐﺘﺼﺮﺓ ﻣﻦ file print formatﻭ ﳍﺎ ﻭﺳﻴﻂ ﺇﺿﺎﰲ ﻋﻠﻰ ﺍﻟﺪﺍﻟﺔ printfﻭ ﻫﻮ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻭ ﻫﻮ ﻣﺆﺷﺮ ﺍﳌﻠﻒ ﺍﻟﺬﻱ ﻧﺮﻳﺪ ﺍﻟﻜﺘﺎﺑﺔ ﻓﻴﻪ ﺃﻣﺎ ﺑﺎﻗﻲ ﺍﻟﻮﺳﺎﺋﻂ ﻓﻬﻲ ﻧﻔﺴﻬﺎ ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ printfﻭ ﺃﻳـﻀﺎ ﻧﻔـﺲ ﻃﺮﻳﻘـﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ .ﺳﻨﻘﻮﻡ ﺍﻵﻥ ﺑﻜﺘﺎﺑﺔ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ ﻭ ﺍﻟﺪﻭﺍﻝ ﻭ ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ )ﻣﻊ ﺟﻌﻞ ﺍﻟﱪﻧـﺎﻣﺞ ﺃﻛﺜـﺮ ﻣﺮﻭﻧﺔ( ﻛﻲ ﻧﻌﺘﺎﺩ ﻋﻠﻲ ﺍﺳﺘﻌﻤﺎﳍﺎ .ﺃﻭﻻ ﻧﻘﻮﻡ ﺑﺈﻧﺸﺎﺀ ﻣﻠﻒ ﺭﺃﺳﻲ ﺑﺎﺳﻢ fileio.hﻭ ﻧﻘﻮﻡ ﺑﺎﻟﻜﺘﺎﺑﺔ ﻋﻠﻴﻪ ﺍﻟﺘﺎﱄ: test /*fileio.h header file for files functions*/ #include<stdlib.h> /*for exit() fonction*/ void CreateFile(const char *FileName, /*for the name of file*/ )const char *String /*for text of file*/ { ;FILE *FileOut )'if(*FileName == '\0 { ;)"printf("Error in the name of file!\n ;)exit(1 } {)if((FileOut = fopen(FileName, "w"))==NULL ;)"printf("Can't create file!\n ;)exit(1 {}else ;)fprintf(FileOut, "%s", String } ;)fclose(FileOut ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,٢ﻃﺮﻳﻘﺔ ﺇﻧﺸﺎﺀ ﻣﻠﻒ ﻫﺬﺍ ﺍﳌﻠﻒ ﻫﻮ ﺍﳌﺮﺣﻠﺔ ﺍﻷﻭﱃ ﻣﻦ ﺍﻟﱪﻧﺎﻣﺞ ،ﻭ ﺷﺮﺣﻪ ﻫﻮ: } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 140 ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﺃﺿﻔﻨﺎ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ stdlib.hﻭ ﻫﻮ ﳐﺘﺼﺮ ﻣﻦ ،standard libraryﻭ ﺃﺿـﻔﻨﺎﻩ ﻻﺳـﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟـﺔ )…( exitﻭ ﺍﻟﱵ ﺗﻘﻮﻡ ﺑﺎﳋﺮﻭﺝ ﻣﻦ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺪﻭﻥ ﺗﻨﻔﻴﺬ ﺑﺎﻗﻲ ﺍﻷﻭﺍﻣﺮ .ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﺍﻟﺪﺍﻟﺔ CreateFileﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻣﻊ ﻭﺳﻴﻄﲔ ﺍﻷﻭﻝ ﻻﺳﻢ ﺍﳌﻠﻒ ﻭ ﺍﻟﺜﺎﱐ ﻟﻨﺺ ﺍﳌﻠﻒ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﻗﻤﻨﺎ ﺑﻮﺿﻊ ﻣﻘﺎﺭﻧﺔ ﺑﲔ ﺍﺳﻢ ﺍﳌﻠﻒ ﺍﻟـﺬﻱ ﺃﺩﺧﻠﻪ ﺍﳌﺴﺘﺨﺪﻡ ﻭ ﺍﻟﺼﻔﺮ ،ﻭ ﻫﻮ ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﳌﺴﺘﺨﺪﻡ ﱂ ﻳﺪﺧﻞ ﺃﻱ ﺣﺮﻑ ﺃﻭ ﺍﺳﻢ ﻟﻠﻤﻠﻒ ﻓﺴﻴﺘﻢ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﻟﱪﻧـﺎﻣﺞ ﻟﺘﺠﻨﺐ ﺍﻷﺧﻄﺎﺀ ﻭ ﺗﻨﺒﻴﻪ ﺍﳌﺴﺘﺨﺪﻡ ﻋﻦ ﻭﺟﻮﺩ ﺧﻄﺄ ﰲ ﺍﺳﻢ ﺍﳌﻠﻒ .ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ﻋﺸﺮ ﻗﻤﻨﺎ ﲟﻘﺎﺭﻧﺔ ﺃﺧﺮﻯ ﻭ ﻫـﻲ ﺑﲔ ﺍﳌﺆﺷﺮ FileOutﻭ NULLﺣﻴﺚ NULLﻫﻲ: #define NULL 0 ﻭ ﻳﻔﻀﻞ ﻛﺘﺎﺑﺔ NULLﺃﺣﺴﻦ ﻣﻦ ﺍﻟﺼﻔﺮ ،ﺍﳌﻘﺎﺭﻧﺔ ﻫﻲ ﺇﻥ ﻛﺎﻧﺖ ﺃﺧﻄﺎﺀ ﻣﺜﻞ ﺇﺩﺧﺎﻝ ﺃﺣﺮﻑ ﻏﲑ ﻣﺘﻔﻖ ﻋﻠﻴﻬﺎ ﻣﺜـﻞ >< ﰲ ﺍﺳﻢ ﺍﳌﻠﻒ ﻓﻬﻨﺎ ﺃﻳﻀﺎ ﺳﻴﺘﻢ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺪﻭﻥ ﺇﻛﻤﺎﻝ ﺗﻨﻔﻴﺬ ﺑﺎﻗﻲ ﺍﻷﻭﺍﻣﺮ ،ﻭﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﳌﻘﺎﺭﻧﺔ ﺧﺎﻃﺌـﺔ ﻓـﺴﻴﺘﻢ ﻛﺘﺎﺑﺔ ﺍﻟﻨﺺ ﺇﱃ ﺍﳌﻠﻒ .ﻭ ﺍﺳﺘﻌﻤﻠﻨﺎ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﻋﺸﺮ ﻭ ﺍﻟﺜﺎﻣﻦ ﻋﺸﺮ ﺍﻟﺪﺍﻟﺔ exitﺣﻴﺚ ﳍﺎ ﻭﺳـﻴﻂ ﻭﺍﺣـﺪ ﻭ ﻫـﻮ ﺍﻟﻮﺿﻊ ﺃﻣﺎ ١ﻭ ﺗﻌﲏ ﺻﺤﻴﺢ trueﻫﻨﺎ ﺳﻴﺘﻢ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﻟﱪﻧﺎﻣﺞ ،ﺃﻭ ٠ﻭ ﺗﻌﲏ ﺧﻄﺄ falseﻭ ﻫﻨﺎ ﻟﻦ ﻳﺘﻢ ﺍﳋـﺮﻭﺝ ﻣـﻦ ﺍﻟﱪﻧﺎﻣﺞ .ﻭ ﺃﺧﲑﺍ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﱐ ﻭ ﺍﻟﻌﺸﺮﻳﻦ ﻭ ﻫﻲ ﺍﻟﺪﺍﻟﺔ fcloseﻭ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣﻦ file closeﻭ ﺍﻟﱵ ﺗﻘﻮﻡ ﺑﺈﻏﻼﻕ ﺍﳌﻠﻒ ﻋﻨﺪ ﺍﻻﻧﺘﻬﺎﺀ ﻣﻨﻪ ﺣﱴ ﳝﻜﻨﻨﺎ ﺍﺳﺘﻌﻤﺎﻟﻪ ﻣﺮﺓ ﺃﺧﺮﻯ ﺳﺘﻼﺣﻆ ﺫﻟﻚ ﻓﻴﻤﺎ ﺑﻌﺪ .ﻫﺬﺍ ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﻤﻠﻒ ﺍﻟﺮﺃﺳﻲ ،fileio.hﺍﻵﻥ ﻧﻘﻮﻡ ﺑﺈﻧﺸﺎﺀ ﺍﳌﻠﻒ ﺍﻟﺮﺋﻴﺴﻲ ﳌﺸﺮﻭﻋﻨﺎ ﺑﺎﺳﻢ :main.c >#include<stdio.h "#include"fileio.h )(main { ;]char FileName[255 ;]char String[255 ;)"printf("Enter the name of file(with type)\n ;)" printf("[MAX Character 255]: ;)gets(FileName ;)"printf("TEXT:\n ;)gets(String ;)"printf("Creating File and save text...\n ;)CreateFile(FileName, String ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,٣ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ CreateFileﻣﻦ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢,٧,١,١ﺍﻟﺪﺍﻟﺔ :fopen } fileio.h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 141 ﻫﻲ ﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،stdio.hﻭ ﻫﻲ ﺧﺎﺻﺔ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﻠﻔﺎﺕ ﻭ ﳍﺎ ﻭﺳﻴﻄﲔ ،ﺍﻷﻭﻝ ﺑﻪ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﻭ ﻫﻲ ﺍﺳﻢ ﺍﳌﻠﻒ ،ﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻫﻮ ﺍﻟﻨﻤﻂ ﺃﻭ ﺍﻟﻮﺿﻊ ﺍﻟﺬﻱ ﺗﺮﻳﺪ ﺍﺳﺘﻌﻤﺎﳍﺎ )ﺍﻟﻘﺮﺍﺀﺓ ﺃﻭ ﺍﻟﻜﺘﺎﺑﺔ( ،ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ: ٢,٧,١,٢ﺍﻟﺪﺍﻟﺔ :fclose ﺍﻟﺸﻜﻞ :٢,٧,١ﻃﺮﻳﻘﺔ ﻓﺘﺢ ﻣﻠﻒ ﻭ ﻫﻲ ﺃﻳﻀﺎ ﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،stdio.hﻭ ﻫﻲ ﺃﻳﻀﺎ ﺧﺎﺻﺔ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﻠﻔﺎﺕ ﻭ ﳍﺎ ﻭﺳﻴﻂ ﻭﺍﺣـﺪ ﻭ ﻫـﻮ ﻣﺆﺷﺮ ﻟـ * ،FILEﻧﻜﺘﺐ ﻓﻴﻪ ﺍﺳﻢ ﻣﺆﺷﺮ ﺍﻟﺒﻨﻴﺔ ﻟﻜﻲ ﻳﺘﻢ ﺇﻏﻼﻗﻬﺎ ،ﻭ ﻓﺎﺋﺪﺓ ﺇﻏﻼﻗﻬﺎ ﻫﻲ ﻛﻲ ﻧﺴﺘﻄﻴﻊ ﻗﺮﺍﺀﺎ ﻣﺮﺓ ﺃﺧﺮﻯ ﰲ ﺍﻟﱪﻧﺎﻣﺞ. ٢,٧,١,٣ﺍﻟﺪﺍﻟﺔ :exit ﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،stdlib.hﳍﺎ ﻭﺳﻴﻂ ﻭﺍﺣﺪ ﺣﻴﺚ ﳝﻜﻦ ﺃﻥ ﳛﻤﻞ ﺍﻟﻘﻴﻤﺔ ١ﺃﻭ ﺍﻟﻘﻴﻤﺔ ،٠ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﻟﻘﻴﻤﺔ ﺗﻌﲏ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﻟﱪﻧﺎﻣﺞ ﻣﺒﺎﺷﺮﺓ ﺑﺪﻭﻥ ﺗﻨﻔﻴﺬ ﺑﺎﻗﻲ ﺍﻷﻭﺍﻣﺮ ،ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻧﺖ ٠ﻓﺴﻴﺘﻢ ﲡﺎﻫﻠﻬﺎ. ٢,٧,٢ﺇﺿﺎﻓﺔ ﻧﺺ ﰲ ﺎﻳﺔ ﺍﳌﻠﻒ: ١ ﺍﻷﻣﺜﻞ ﺍﻟﺴﺎﺑﻘﺔ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ ﻋﻨﺪﻣﺎ ﺗﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺍﺳﻢ ﻣﻠﻒ ﻣﻮﺟﻮﺩ ﺳﺎﺑﻘﺎ ﻓﺴﻴﺘﻢ ﻓﻘﺪﻩ ،ﻭ ﻫﻨﺎ ﺳﻨﻌﺮﻑ ﻛﻴﻔﻴﺔ ﻧﻘـﻮﻡ ﺑﺈﺿﺎﻓﺔ ﻧﺺ ﰲ ﺃﺧﺮ ﺍﳌﻠﻒ ﺑﺪﻭﻥ ﻓﻘﺪ ﺍﻟﺒﻴﺎﻧﺎﺕ ﺍﻟﺴﺎﺑﻘﺔ .ﻧﻔﺲ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﺴﺎﺑﻘﺔ ﲤﺎﻡ ﻓﻘﻂ ﺑﺪﻝ ﺍﳊﺮﻑ wﰲ ﺍﻟﺪﺍﻟـﺔ fopen ﻧﻜﺘﺐ ﺍﳊﺮﻑ ،aﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ﻋﺸﺮ: {)if((FileOut = fopen(FileName, "w"))==NULL 16 ﻭ ﻳﺼﺒﺢ ﻋﻠﻰ ﺍﻟﺸﻜﻞ ﺍﻟﺘﺎﱄ: {)if((FileOut = fopen(FileName, "a"))==NULL 16 142 ﻭ ﺍﳊﺮﻑ aﻳﻌﲏ .appending ٢,٧,٣ﺍﻹﺩﺧﺎﻝ ﰲ ﺍﳌﻠﻔﺎﺕ: ﺍﻹﺩﺧﺎﻝ ﺗﻌﲏ ﺍﻟﻘﺮﺍﺀﺓ ،ﻭ ﰲ ﺍﳌﻠﻔﺎﺕ ﻫﻲ ﻗﺮﺍﺀﺓ ﳏﺘﻮﻯ ﻣﻠﻒ ﻭ ﺍﺳﺘﻌﻤﺎﻟﻪ ﰲ ﺍﻟﱪﻧﺎﻣﺞ .ﰲ ﻧﻔﺲ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﺍﻟـﺴﺎﺑﻖ fileio.hﻗﻢ ﺑﺈﺿﺎﻓﺔ ﺍﻟﺘﺎﱄ: )void DisplayFile(const char *FileName { ;FILE *FileIn ;]char String[1024 )'if(*FileName == '\0 { ;)"printf("Error in name of file!\n ;)exit(1 } {)if((FileIn = fopen(FileName, "r"))==NULL ;)"printf("Can't Open file!\n ;)exit(1 {}else ;)fgets(String, 1024, FileIn ;)printf("%s", String } ;)fclose(FileIn ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,٤ﺇﻧﺸﺎﺀ ﺩﺍﻟﺔ ﺗﻘﻮﻡ ﺑﻌﺮﺽ ﳏﺘﻮﻯ ﻣﻠﻒ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ﻫﻨﺎ ﻧﻜﻮﻥ ﻗﺪ ﺃﻋﻠﻨﺎ ﻋﻦ ﺍﻟﺪﺍﻟﺔ ﺍﻟﱵ ﺳﺘﻘﻮﻡ ﺑﻘﺮﺍﺀﺓ ﺍﳌﻠﻔﺎﺕ ،ﻭ ﻫﻲ ﻣﺸﺎﺑﻪ ﺑﺪﺍﻟﺔ ﺇﻧﺸﺎﺀ ﺍﳌﻠﻔﺎﺕ .ﺍﻟﺪﺍﻟﺔ ﲢﺘﻮﻱ ﻋﻠـﻰ ﻭﺳـﻴﻂ ﻭﺍﺣﺪ ﻭ ﻫﻮ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﻻﺳﻢ ﺍﳌﻠﻒ ﺍﳌﺮﺍﺩ ﻗﺮﺍﺀﺗﻪ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺮﺍﺑﻊ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺔ ﻭ ﻫﻨﺎﻙ ﻧﻘﻮﻡ ﺑﻮﺿﻊ ﻧﺺ ﺍﳌﻠﻒ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﱐ ﻋﺸﺮ ،ﰲ ﺍﻟﺪﺍﻟﺔ fopenﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﻨﻤﻂ rﺑﺪﻝ ،wﺍﳊﺮﻑ rﻳﻌﲏ .readﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ﻋﺸﺮ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﺪﺍﻟﺔ ،fgetsﻭ ﻫﻲ ﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ stdio.hﻭ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣﻦ ،file get stringﳍﺎ ﺛﻼﺛﺔ ﻭﺳـﺎﺋﻂ، ﺍﻷﻭﻝ ﻻﺳﻢ ﺍﻟﺴﻠﺴﻠﺔ ﺍﳊﺮﻓﻴﺔ ،ﺍﻟﺜﺎﱐ ﳊﺠﻢ ﺍﻟﺴﻠﺴﻠﺔ ﻭ ﺍﻟﺜﺎﻟﺚ ﳌﺆﺷﺮ ﻣﻠﻒ ﺍﻹﺩﺧﺎﻝ .FILE *FileInﺗﻘﻮﻡ ﺍﻟﺪﺍﻟﺔ fgets ﺑﻮﺿﻊ ﺳﻠﺴﻠﺔ ﺣﺮﻭﻑ ﺍﳌﻠﻒ )ﲝﺠﻢ ﺍﻟﻮﺳﺎﺋﻂ ﺍﻟﺜﺎﱐ( ﰲ ﺍﻟﻮﺳﺎﺋﻂ ﺍﻷﻭﻝ ﻭ ﺍﻟﺬﻱ ﻫﻮ ﻋﺒﺎﺭﺓ ﻋﻦ ﺳﻠﺴﻠﺔ ﺣﺮﻭﻑ ،ﰒ ﻃﺒـﻊ ﺳﻠﺴﻠﺔ ﺣﺮﻭﻑ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﻋﺸﺮ. ﻭ ﺍﻵﻥ ﻗﻢ ﺑﺈﺿﺎﻓﺔ ﺍﻷﻭﺍﻣﺮ ﺍﻟﺘﺎﻟﻴﺔ ﰲ ﺎﻳﺔ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ )( mainﰲ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﺍﻟﺮﺋﻴﺴﻲ :main.c ;)"printf("/////////Reading\\\\\\\\\n ;)DisplayFile(FileName 1 2 143 ﻭ ﻫﻨﺎ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﺪﺍﻟﺔ ﻻﺳﺘﻌﺮﺍﺽ ﳏﺘﻮﻯ ﺍﳌﻠﻒ. ٢,٧,٤ﺍﻟﻨﻤﻂ w+ﻭ a+ ﻭ :r+ ﺩﺭﺳﻨﺎ ﺳﺎﺑﻘﺎ ﻛﻞ ﻣﻦ ﺍﻷﳕﺎﻁ ) wﻟﻠﻜﺘﺎﺑﺔ( ﻭ ) aﻹﺿﺎﻓﺔ ﻧﺺ ﰲ ﺎﻳﺔ ﻣﻠﻒ( ﻭ ) rﻟﻘﺮﺍﺀﺓ ﻣﻠﻒ( ،ﻭ ﺍﻵﻥ ﺳﻨﺮﻯ ﻧﻔـﺲ ﺍﻷﳕﺎﻁ ﺍﻟﺴﺎﺑﻘﺔ ﻣﻊ ﺇﺿﺎﻓﺎﺕ ﻭ ﻫﻲ: ٢,٧,٤,١ﺍﻟﻨﻤﻂ :w+ ﻫﻨﺎ ﻳﺘﻢ ﺇﻧﺸﺎﺀ ﻣﻠﻒ ﻓﺎﺭﻍ ﻟﻠﻘﺮﺍﺀﺓ ﻭ ﺍﻟﻜﺘﺎﺑﺔ ﻣﻌﺎ ،ﻭ ﺇﺫﺍ ﻛﺎﻥ ﺍﳌﻠﻒ ﻣﻮﺟﻮﺩ ﺳﺎﺑﻘﺎ ﻓﺴﻴﺘﻢ ﻓﻘﺪ ﲨﻴﻊ ﳏﺘﻮﻳﺎﺗﻪ. ٢,٧,٤,٢ﺍﻟﻨﻤﻂ :a+ ﻫﻨﺎ ﻳﺘﻢ ﺇﺿﺎﻓﺔ ﻧﺺ ﰲ ﺎﻳﺔ ﺍﳌﻠﻒ ﺇﺫﺍ ﻛﺎﻥ ﻣﻮﺟﻮﺩ ﻭ ﺇﻥ ﱂ ﻳﻜﻮﻥ ﻣﻮﺟﻮﺩ ﻳﺘﻢ ﺇﻧﺸﺎﺀﻩ ،ﻭ ﺃﻳﻀﺎ ﻳﺴﺘﻌﻤﻞ ﻫﺬﺍ ﺍﻟـﻨﻤﻂ ﻟﻠﻘﺮﺍﺀﺓ. ٢,٧,٤,٣ﺍﻟﻨﻤﻂ :r+ ﻫﺬﺍ ﺍﻟﻨﻤﻂ ﻟﻠﻘﺮﺍﺀﺓ ﻭ ﺍﻟﻜﺘﺎﺏ ﻭ ﻟﻜﻦ ﳚﺐ ﺃﻥ ﻳﻜﻮﻥ ﺍﳌﻠﻒ ﻣﻮﺟﻮﺩ. ﻭ ﺗﻮﺟﺪ ﺃﳕﻂ ﺃﺧﺮﻯ ﻭ ﻫﻲ t ،r ،s ،bﻭ ،dﻭ ﻟﻜﻬﺎﻥ ﻏﲑ ﻣﻬﻤﺔ ،ﺍﻷﳕﺎﻁ ﺍﻟﺴﺎﺑﻘﺔ ﻫﻲ ﺍﳌﻬﻤﺔ ﻭ ﺍﻟﱵ ﺗﺴﺘﻌﻤﻞ ﺑﻜﺜﺮﺓ. ٢,٧,٥ﺩﻭﺍﻝ ﺃﺧﺮﻯ ﺧﺎﺻﺔ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﻠﻔﺎﺕ: ﺗﻮﺟﺪ ﺩﻭﺍﻝ ﻋﺪﻳﺪﺓ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﻠﻔﺎﺕ ﻭ ﻛﻠﻬﺎ ﺷﺒﻴﻪ ﺑﺎﻟﱵ ﻗﺮﺃﺎ ﺳﺎﺑﻘﺎ ،ﻭ ﲨﻴﻌﻬﺎ ﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،stdio.h ﺍﻟﺪﻭﺍﻝ ﻫﻲ: ٢,٧,٥,١ﺍﻟﺪﺍﻟﺔ fprintfﻭ ﺍﻟﺪﺍﻟﺔ :fscanf ﺍﻟﺪﺍﻟﺔ fprintfﺩﺭﺳﻨﻬﺎ ﺳﺎﺑﻘﺎ ،ﺃﻣﺎ ﺍﻟﺪﺍﻟﺔ fscanfﻓﻬﻲ ﻣﻜﺎﻓﺌﺔ ﻟﻠﺪﺍﻟﺔ scanfﻭ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣـﻦ ،file scan fileﻭ ﻟﻜﻨﻬﺎ ﻫﻨﺎ ﻻ ﺗﺄﺧﺬ ﻗﻴﻢ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ ،ﺑﻞ ﺗﺄﺧﺬﻫﺎ ﻣﻦ ﻗﻴﻢ ﻣﻦ ﻣﻠﻒ ،ﺃﻱ ﺃﺎ ﺧﺎﺻﺔ ﺑﺎﻹﺩﺧﺎﻝ ﻟﻠﻤﻠﻔﺎﺕ ،ﻣﺜﺎﻝ ﺳﺮﻳﻊ: >#include<stdio.h )(main { ;FILE *FileOut 1 2 3 4 5 144 ;]char Str[100 ;int Var ;)"FileOut = fopen("fscanf.txt", "w+ ;)fprintf(FileOut, "%s %d", "Hello", 255 ;)fseek(FileOut, 0, SEEK_SET ;)fscanf(FileOut, "%s", Str ;)fscanf(FileOut, "%d", &Var ;)printf("%s\n", Str ;)printf("%d\n", Var ;)fclose(FileOut ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,٥ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ fprintfﻭ ﺍﻟﺪﺍﻟﺔ } 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 fscanf ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺆﺷﺮ ﻟﻠﺒﻨﻴﺔ FILEﺑﺎﺳﻢ .FileOutﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﲝﺠﻢ ،١٠٠ ﻭ ﻫﻲ ﺍﻟﱵ ﺳﺘﺤﻤﻞ ﻧﺺ ﺍﳌﻠﻒ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﻣﺘﻐﲑ ﻭ ﻫﻮ ﺍﻟﺬﻱ ﺳﻴﺤﻤﻞ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻮﺟﻮﺩﺓ ﰲ ﺍﳌﻠﻒ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ﻗﻤﻨﺎ ﺑﻮﺿﻊ ﺍﺳﻢ ﺍﳌﻠﻒ ﺍﻟﺬﻱ ﺳﻨﻔﺘﺤﻪ ﻭ ﻧﻘﺮﺃ ﻣﻨﻪ ﺍﻟﺒﻴﺎﻧﺎﺕ ﺍﳌﻮﺟﻮﺩﺓ .ﰲ ﺍﻟﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ﻭﺿﻌﻨﺎ ﰲ ﺍﳌﻠـﻒ ﺳﻠـﺴﻠﺔ ﺣﺮﻓﻴﺔ ﻭ ﻫﻲ Helloﻭ ﺍﻟﻘﻴﻤﺔ .٢٥٥ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﻋﺸﺮ ﺗﻮﺟﺪ ﺩﺍﻟﺔ ﻭ ﻫﻲ fseekﻭ ﻫﻲ ﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠـﻒ ﺍﻟﺮﺃﺳـﻲ stdio.hﻭ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣﻦ ،file seekﻭ ﻫﻲ ﲢﺮﻙ ﻣﺆﺷﺮ ﺍﳌﻠﻒ ﺇﱃ ﻣﻜﺎﻥ ﻳﻘﻮﻡ ﺑﺘﺤﺪﻳﺪﻩ ﺍﳌﱪﻣﺞ ،ﳍﺎ ﺛﻼﺛـﺔ ﻭﺳـﺎﺋﻂ ﺍﻷﻭﻝ ﻫﻮ ﺍﺳﻢ ﳌﺆﺷﺮ ﺍﻟﺒﻨﻴﺔ FILEﻭ ﺍﻟﺜﺎﱐ ﻫﻮ ﻋﺪﺩ ﺍﻟﺒﺎﻳﺘﺎﺕ ﺍﻟﱵ ﻳﺒﺪﺃ ﻣﻨﻬﺎ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﻟﺚ ﻭ ﻏﺎﻟﺒﺎ ﻣﺎ ﺗﻜﻮﻥ ٠ﻟﻜﻲ ﻳـﺘﻢ ﻗﺮﺍﺀﺓ ﲨﻴﻊ ﺍﻟﺒﻴﺎﻧﺎﺕ ،ﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﻟﺚ ﻫﻮ ﻭﺿﻊ ﺍﳌﺆﺷﺮ ﻭ ﻟﻪ ﺛﻼﺛﺔ ﺛﻮﺍﺑﺖ ﻭ ﻫﻲ: SEEK_SET .١ﻭ ﻫﻮ ﻭﺿﻊ ﻣﺆﺷﺮ ﺍﳌﻠﻒ ﰲ ﺍﻟﺒﺪﺍﻳﺔ. SEEK_CUR .٢ﻭ ﻫﻮ ﺍﳌﻮﻗﻊ ﺍﳊﺎﱄ ﳌﺆﺷﺮ ﺍﳌﻠﻒ. SEEK_END .٣ﻭ ﻫﻮ ﻭﺿﻊ ﻣﺆﺷﺮ ﺍﳌﻠﻒ ﰲ ﺎﻳﺘﻪ. ﻭ ﰲ ﻣﺜﺎﻟﻨﺎ ﺍﻟﺴﺎﺑﻖ ﺍﺳﺘﻌﻤﺎﻟﻨﺎ SEEK_SETﻛﻲ ﻧﺒﺪﺃ ﺑﻘﺮﺍﺀﺓ ﺑﻴﺎﻧﺎﺕ ﺍﳌﻠﻒ ﻣﻦ ﺍﻟﺒﺪﺍﻳﺔ ﻭ ﻭﺿﻌﻨﺎ ﺍﻟﻘﻴﻤﺔ ٠ﰲ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜـﺎﱐ ﻛﻲ ﻧﻘﺮﺃ ﻧﻔﺤﺺ ﲨﻴﻊ ﺍﻟﺒﻴﺎﻧﺎﺕ .ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺮﺍﺑﻊ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﻔﺤﺺ ﺳﻠﺴﻠﺔ ﺍﳊﺮﻭﻑ ﺍﳌﻮﺟﻮﺩ ﰲ ﺍﳌﻠﻒ ﻭ ﻧـﺴﺨﻪ ﰲ ﺍﻟﺴﻠﺴﻠﺔ ﺍﳊﺮﻓﻴﺔ ،Strﻭ ﻫﻮ ﺍﻟﻨﺺ .Helloﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﻔﺤﺺ ﺍﻟﻌﺪﺩ ﺍﻟﺼﺤﻴﺢ ٢٥٥ﻭ ﻧﺴﺨﻪ ﰲ ﺍﳌﺘﻐﲑ .Varﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﻋﺸﺮ ﻭ ﺍﻟﺘﺎﺳﻊ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﻄﺒﺎﻋﺔ ﺍﻟﻨﺘﺎﺋﺞ. ٢,٧,٥,٢ﺍﻟﺪﺍﻟﺔ fgetsﻭ :fputs 145 ﺍﻟﺪﺍﻟﺔ fgetsﺩﺭﺳﻨﻬﺎ ﺳﺎﺑﻘﺎ ،ﻭ ﺍﻟﺪﺍﻟﺔ fputsﻫﻲ ﻣﻜﺎﻓﺌﺔ ﻟﻠﺪﺍﻟﺔ putsﻭ ﻟﻜﻨﻬﺎ ﺧﺎﺻﺔ ﺑﺎﳌﻠﻔﺎﺕ ﻭ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣـﻦ ،file put stringﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﻟﻨﺼﻮﺹ ﰲ ﺍﳌﻠﻔﺎﺕ ﻭ ﻟﻴﺴﺖ ﻣﺜﻞ ﺍﻟﺪﺍﻟﺔ putsﺣﻴﺚ ﺗﻘﻮﻡ ﺑﻄﺒﺎﻋـﺔ ﻧـﺺ ﻋﻠـﻰ ﺍﻟﺸﺎﺷﺔ ،ﻣﺜﻞ ﺳﺮﻳﻊ ﺣﻮﻝ ﺍﻟﺪﺍﻟﺔ :fputs >#include<stdio.h )(main { ;FILE *FileOut ;)"FileOut = fopen("fputs.txt", "w ;)fputs("Hello, World!\n", FileOut ;)fclose(FileOut ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,٦ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 fputs ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﺪﺍﻟﺔ fputsﺣﻴﺚ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻫﻮ ﺍﻟﻨﺺ ﺍﳌﺮﺍﺩ ﻃﺒﻌﻪ ،ﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻫﻮ ﺍﺳـﻢ ﺍﳌﺆﺷـﺮ FileOutﺣﻴﺚ ﻓﻴﻪ ﺳﻴﺘﻢ ﻃﺒﺎﻋﺔ ﺍﻟﻨﺺ. ٢,٧,٥,٣ﺍﻟﺪﺍﻟﺔ fgetcﻭ ﺍﻟﺪﺍﻟﺔ :fputc ﺍﻟﺪﺍﻟﺔ fgetcﺗﺄﺧﺬ ﺣﺮﻑ ﻭﺍﺣﺪ ﻣﻦ ﻣﻠﻒ ،ﻭ ﺍﻟﺪﺍﻟﺔ fputcﺗﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺣﺮﻑ ﻭﺍﺣﺪ ﺇﱃ ﻣﻠﻒ ﻣﻌﲔ ،ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;FILE *FileOut ;FILE *FileIn ;char ch ;)"FileOut = fopen("fputc.txt", "w ;)"FileIn = fopen("fputc.txt", "r ;)fputc('A', FileOut ;)fclose(FileOut ;)ch = fgetc(FileIn ;)fclose(FileIn ;)printf("%c\n", ch ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,٧ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ fgetcﻭ ﺍﻟﺪﺍﻟﺔ } fputc 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 146 ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﻋﺸﺮ ﺇﻥ ﱂ ﺗﺴﺘﻌﻤﻞ ﺍﻟﺪﺍﻟﺔ fcloseﻓﺴﺘﺮﻯ ﻧﺘﺎﺋﺞ ﻏﲑ ﻣﺮﻏﻮﺏ ﺎ ،ﻭ ﻫﻨﺎ ﺳﺘﻌﺮﻑ ﺃﳘﻴﺘـﻬﺎ .ﻭ ﳝﻜـﻦ ﻛﺘﺎﺑﺔ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﻋﻠﻰ ﻫﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ: >#include<stdio.h )(main { ;FILE *FileInOut ;char ch ;)"FileInOut = fopen("fputc.txt", "w ;)fputc('A', FileInOut ;)fclose(FileInOut ;)"FileInOut = fopen("fputc.txt", "r ;)ch = fgetc(FileInOut ;)fclose(FileInOut ;)printf("%c\n", ch } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,٨ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ fgetcﻭ ﺍﻟﺪﺍﻟﺔ (٢) fputc ﻫﺬﻩ ﻫﻲ ﺍﻟﺪﻭﺍﻝ ﺍﳌﻬﻤﺔ ﺣﺎﻟﻴﺎ ﰲ ﺍﻟﻌﺎﻣﻞ ﻣﻊ ﺍﳌﻠﻔﺎﺕ ،ﺗﻮﺟﺪ ﺩﻭﺍﻝ ﺃﺧﺮﻯ ﻛﺜﲑﺓ ﺣﻮﻝ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﻠﻔﺎﺕ ﻭ ﺳﻨﺪﺭﺳـﻬﺎ ﰲ ﺩﺭﺱ ﺍﳌﻜﺘﺒﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ﻟﻠﻐﺔ .C ٢,٧,٦ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: ﻻ ﺗﻮﺟﺪ ﺃﺧﻄﺎﺀ ﳏﺘﻤﻠﺔ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ. ٢,٧,٧ﲤﺎﺭﻳﻦ: .١ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﻌﻤﻠﻴﺎﺕ ﺍﳉﻤﻊ ﻭ ﺍﻟﻄﺮﺡ ﺍﻟﻀﺮﺏ ﻭ ﺍﻟﻘﺴﻤﺔ ،ﻭ ﻳﺘﻢ ﺣﻔﻆ ﺍﻟﻨﺘـﺎﺋﺞ ﰲ ﻣﻠـﻒ results.dat ﺗﻠﻘﺎﺋﻴﺎ. 147 ﺍﻟﺘﺮﺍﻛﻴﺐ )ﺍﻟﺒﻨﻴﺎﺕ( ﻫﻲ ﳎﻤﻮﻋﺔ ﻣﻦ ﻣﺘﻐﲑ ﻭﺍﺣﺪ ﺃﻭ ﺃﻛﺜﺮ ﲡﻤﻊ ﲢﺖ ﺍﺳﻢ ﻭﺍﺣﺪ ﻳﺴﻬﻞ ﺍﺳﺘﻌﻤﺎﳍﺎ ،ﻭ ﺍﳌـﺘﻐﲑﺍﺕ ﰲ ﺍﻟﺘﺮﺍﻛﻴﺐ ﻟﻴﺲ ﻣﺜﻞ ﺍﳌﺘﻐﲑﺍﺕ ﰲ ﺍﳌﺼﻔﻮﻓﺎﺕ ،ﳝﻜﻦ ﺃﻥ ﺗﻜﻮﻥ ﺑﻪ ﻣﺘﻐﲑﺍﺕ ﳐﺘﻠﻔﺔ ﺍﻷﻧﻮﺍﻉ ،ﻭ ﺍﻟﺘﺮﺍﻛﻴﺐ ﳝﻜﻦ ﺃﻥ ﲢﻤﻞ ﺃﻱ ﻧﻮﻉ ﻣﻦ ﻣﺘﻐﲑﺍﺕ ﻟﻐﺔ Cﺣﱴ ﻣﺼﻔﻮﻓﺎﺕ ﺃﻭ ﻣﺆﺷﺮﺍﺕ ﺃﻭ ﺗﺮﺍﻛﻴﺐ ﺩﺍﺧﻞ ﺗﺮﺍﻛﻴﺐ ﺃﺧﺮﻯ ،ﻭ ﲨﻴﻊ ﺍﳌﺘﻐﲑﺍﺕ ﺍﳌﻮﺟﻮﺩ ﺩﺍﺧﻞ ﺍﻟﺘﺮﺍﻛﻴﺐ ﺗﺴﻤﻰ ﺑﺄﻋﻀﺎﺀ ﻟﺘﺮﺍﻛﻴﺐ. ﻟﻺﻋﻼﻥ ﻋﻦ ﺑﻨﻴﺔ ﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ structﰒ ﺍﺳﻢ ﺍﻟﺒﻨﻴﺔ ﻭ ﻧﻘﻮﻡ ﺑﻔﺘﺢ ﺣﺎﺿﻨﺔ ﻭ ﻧﻜﺘﺐ ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﱵ ﻧﺮﻳﺪﻫﺎ )ﺍﻷﻋﻀﺎﺀ( ﰒ ﻧﻐﻠﻖ ﺍﳊﺎﺿﻨﺔ ﻣﻊ ﻭﺿﻊ ﻓﺎﺻﻠﺔ ﻣﻨﻘﻮﻃﺔ ،ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ: ﺍﻟﺸﻜﻞ :٢,٨,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺑﻨﻴﺔ ٢,٨,١ﺍﺳﻢ ﺍﻟﺒﻨﻴﺔ :Struct Name ﺍﺳﻢ ﺍﻟﺒﻨﻴﺔ ﻟﻪ ﺷﺮﻭﻁ ﻣﺜﻞ ﺷﺮﻭﻁ ﺍﺳﻢ ﺍﳌﺘﻐﲑ ﻭ ﻫﻲ: § ﺃﻥ ﻻ ﻳﺘﺠﺎﻭﺯ ﺍﺳﻢ ﺍﻟﺒﻨﻴﺔ ﺃﻛﺜﺮ ﻣﻦ ٣١ﺣﺮﻑ. § ﺃﻥ ﻻ ﻳﺒﺪﺃ ﺍﺳﻢ ﺍﻟﺒﻨﻴﺔ ﺑﺄﺭﻗﺎﻡ. § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﻟﺒﻨﻴﺔ ﳛﺘﻮﻱ ﻋﻠﻰ ﻣﺆﺛﺮﺍﺕ ﻣﺜﻞ ﺍﳉﻤﻊ ﻭ ﺍﻟﻄﺮﺡ ﻭ.... § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﻟﺒﻨﻴﺔ ﳛﺘﻮﻱ ﻋﻠﻰ ﺭﻣﻮﺯ ﻣﺜﻞ %ﻭ #ﻭ { ﻭ)...ﺑﺎﺳﺘﺜﻨﺎﺀ ﺍﻟﺮﻣﺰ _(. § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﻟﺒﻨﻴﺔ ﻣﺴﺘﻌﻤﻞ ﺳﺎﺑﻘﺎ ﻻﺳﻢ ﺩﺍﻟﺔ ﺃﻭ ﻣﺘﻐﲑ ﺃﻭ ﺑﻨﻴﺔ ﺃﺧﺮﻯ. § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﻟﺒﻨﻴﺔ ﻣﻦ ﺃﺣﺪ ﺃﻣﺴﺎﺀ ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ. ﻭ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﻟﺒﻨﻴﺎﺕ ﻳﺴﺘﺤﺴﻦ ﺃﻥ ﻳﻜﻮﻥ ﺩﺍﺋﻤﺎ ﺧﺎﺭﺝ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﻭ ﻗﺒﻠﻬﺎ ،ﻣﺜﺎﻝ: 148 >#include<stdio.h struct _2D { ;int x ;int y ;} )(main { ;struct _2D Struct_2D ;int x, y ;)" printf("Enter X: ;)scanf("%d", &Struct_2D.x ;)" printf("Enter Y: ;)scanf("%d", &Struct_2D.y )for(x=0;x<=Struct_2D.x;x++ { ;)printf("%c", 219 )for(y=0;y<Struct_2D.y;y++ ;)printf("%c", 219 ;)"printf("\n } ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻭ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺒﻨﻴﺎﺕ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﺮﺳﻢ ﺍﳌﺮﺑﻌﺎﺕ ﺣﺴﺐ ﺍﻟﻘﻴﻢ ﺍﻟﱵ ﻳﻘﻮﻡ ﺑﺈﺩﺧﺎﳍﺎ ﺍﳌﺴﺘﺨﺪﻡ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﺍﻟﺒﻨﻴـﺔ ._2Dﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻭ ﺍﻟﺴﺎﺩﺱ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑﻳﻦ xﻭ ،yﺣﻴﺚ ﻳﻌﺘﱪﺍﻥ ﻋﻀﻮﻳﻦ ﻟﻠﺒﻴﻨﺔ ._2Dﰲ ﺍﻟـﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﻜﺘﺎﺑﺔ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ structﻣﻊ ﺍﺳﻢ ﺍﻟﺒﻨﻴﺔ ﺍﻟﺴﺎﺑﻘﺔ _2Dﻭ ﺍﻻﺳﻢ Struct_2Dﻭ ﺍﻟـﺬﻱ ﺳـﻴﺘﻢ ﺍﻟﻌﻤﻞ ﻋﻠﻴﻪ ﰲ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ،ﻭ ﻻ ﳝﻜﻦ ﻛﺘﺎﺑﺔ _2D Struct_2Dﺑﺪﻭﻥ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ،structﻭ ﻻ ﳝﻜﻦ ﺍﺳـﺘﻌﻤﺎﻝ ﺍﻟﺒﻨﻴﺔ _2Dﻣﺒﺎﺷﺮﺓ ﻟﺬﺍ ﳚﺐ ﺃﻥ ﻧﻘﻮﻡ ﺑﺈﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻟﻠﺒﻨﻴﺔ _2Dﻭ ﺍﻟﱵ ﻫﻲ Struct_2Dﰲ ﺑﺮﻧﺎﳎﻨﺎ ﻫﺬﺍ .ﺃﻣـﺎ ﺑـﺎﻗﻲ ﺍﻟﺴﻄﻮﺭ ﻓﻬﻲ ﻣﻔﻬﻮﻣﺔ .ﻭ ﳝﻜﻦ ﺍﻹﻋﻼﻥ ﻋﻦ ﺃﻛﺜﺮ ﻣﻦ ﺑﻨﻴﺔ ،ﻓﻤﺜﻼ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﰲ ﺍﻟﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ﳝﻜﻨﻨﺎ ﻛﺘﺎﺑﺔ: ;struct _2D Struct_2D_1, Struct_2D_2 ﻭ ﻫﻨﺎ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻛﻞ ﻣﻦ ﺍﻟﺒﻨﻴﺘﲔ Struct_2D_1ﻭ ﺍﻟﺒﻨﻴﺔ .Struct_2D_2ﺃﻣﺎ ﺇﺫﺍ ﺃﺭﺩﺕ ﲡﺎﻫـﻞ ﻛﺘﺎﺑـﺔ ﺍﻟـﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ،ﻓﻴﻤﻜﻦ ﺫﻟﻚ ﻭ ﻟﻜﻦ ﳚﺐ ﺃﻥ ﻧﻌﻄﻲ ﻟﺒﻨﻴﺘﻨﺎ ﻣﻌﺮﻑ ﻭ ﺳﻨﻜﺘﺒﻪ ﻗﺒﻞ ﺍﻟﻔﺎﺻﻠﺔ ﺍﳌﻨﻘﻄﺔ: struct _2D 1 149 2 3 4 5 { int x; int y; }Struct_2D; :ﻭ ﰲ ﺣﺎﻟﺔ ﻧﺮﻳﺪ ﺍﻟﺘﻌﺮﻳﻒ ﻋﻦ ﺃﻛﺜﺮ ﻣﻦ ﺍﺳﻢ ﺍﻟﺒﻨﻴﺔ ﻓﻨﻔﺼﻞ ﺑﲔ ﺍﺳﻢ ﻭ ﺍﺳﻢ ﺑﻔﺎﺻﻠﺔ ﻣﺜﻞ 1 2 3 4 5 struct _2D { int x; int y; }Struct_2D_1, Struct2D_2; :ﻭ ﻳﺼﺒﺢ ﺍﳌﺜﺎﻝ ﻋﻠﻰ ﺍﻟﺸﻜﻞ ﺍﻟﺘﺎﱄ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 #include<stdio.h> 1 2 3 #include<stdio.h> struct _2D { int x; int y; }Struct_2D; main() { int x, y; printf("Enter the position X: "); scanf("%d", &Struct_2D.x); printf("Enter the position Y: "); scanf("%d", &Struct_2D.y); for(x=0;x<=Struct_2D.x;x++) { printf("%c", 219); for(y=0;y<Struct_2D.y;y++) printf("%c", 219); printf("\n"); } } (٢) ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻭ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺒﻨﻴﺎﺕ:٢,٨,٢ ﺍﻟﱪﻧﺎﻣﺞ : ﻣﺜﺎﻝ، ﻣﺜﻼ ﳝﻜﻦ ﺇﻋﻄﺎﺀ ﻗﻴﻤﺔ ﺳﺎﺑﻘﺔ ﳌﺘﻐﲑ ﰲ ﺑﻨﻴﺔ ﻭ ﺍﺳﺘﻌﻤﺎﻟﻪ ﰲ ﺍﻟﱪﻧﺎﻣﺞ،ﻭ ﺗﻮﺟﺪ ﻃﺮﻕ ﺃﺧﺮﻯ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﺒﻨﻴﺎﺕ struct _Value 150 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 { 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include<stdio.h> int x; float y; char *Str; }Value; main() { Value.x = 10; Value.y = 10.00; Value.Str = "Hello, World"; } printf("%d\n", Value.x); printf("%f\n", Value.y); printf("%s\n", Value.Str); (٣) ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻭ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺒﻨﻴﺎﺕ:٢,٨,٣ ﺍﻟﱪﻧﺎﻣﺞ :ﺃﻭ ﳝﻜﻦ ﺇﻋﻄﺎﺀ ﺍﻟﻘﻴﻢ ﻣﺒﺎﺷﺮﺓ ﺑﻌﺪ ﺍﻟﺘﻌﺮﻑ ﻋﻦ ﺍﺳﻢ ﻟﻠﺒﻨﻴﺔ ﻣﺜﻞ struct _Value { int x; float y; char *Str; }Value = {10, 10.00, "Hello, World"}; main() { printf("%d\n", Value.x); printf("%f\n", Value.y); printf("%s\n", Value.Str); } ﺇﻋﻄﺎﺀ ﻗﻴﻢ ﻷﻋﻀﺎﺀ ﺑﻨﻴﺔ ﻣﺒﺎﺷﺮﺓ ﺑﻌﺪ ﺍﻟﺘﻌﲑ ﻋﻦ ﺇﺳﻢ ﺍﳌﺒﻨﻴﺔ:٢,٨,٤ ﺍﻟﱪﻧﺎﻣﺞ :ﻭ ﻻ ﳝﻜﻦ ﺇﻋﻄﺎﺀ ﻗﻴﻤﺔ ﻋﻨﺪ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﻟﺒﻨﻴﺔ ﻣﺜﻞ 1 2 3 4 5 6 struct _Value { int x = 10; float y = 10.00; char *Str = "Hello World"; }; :_ ﻭ ﻻ ﻣﻌﲎ ﻻﺳﺘﻌﻤﺎﻝ ﺍﻟﺒﻨﻴﺔ ﺃﺻﻼ ﻷﻧﻪ ﳝﻜﻦ ﻛﺘﺎﺑﺔValue ﻷﻥ ﰲ ﻫﺬﻩ ﺍﳊﺎﻟﺔ ﻻ ﻣﻌﲎ ﻟﻠﺒﻨﻴﺔ 1 2 #include<stdio.h> 151 ;int x = 10 ;float y = 10.00 ;"char *Str = "Hello World )(main { ;)printf("%d\n", x ;)printf("%f\n", y ;)printf("%s\n", Str } ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,٥ﺃﻓﻀﻞ ﻣﻦ ﺇﺳﺘﻌﻤﺎﻝ ﺃﻋﻀﺎﺀ ﺍﻟﺒﻨﻴﺔ 3 4 5 6 7 8 9 10 11 12 ٢,٨,٢ﺍﻟﺒﻨﻴﺎﺕ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ :union ﳝﻜﻨﻨﻨﺎ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﻟﺒﻨﻴﺎﺕ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ unionﺑﻨﻔﺲ ﺍﻟﻄﺮﻕ ﺍﻟﺴﺎﺑﻘﺔ ،ﻭ ﺍﻟﻔﺮﻕ ﺍﻟﻮﺣﻴﺪ ﺑﲔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺒﻨﻴﺔ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ structﻭ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ unionﻫﻮ ﻋﻨﺪ ﺍﺳـﺘﻌﻤﺎﻝ ﺍﻟﺒﻨﻴـﺎﺕ ﺑﺎﺳـﺘﺨﺪﺍﻡ union ﻓﺎﻟﻨﺘﺎﺋﺞ ﻟﻦ ﺗﻜﻮﻥ ﻣﺜﻞ ﺍﻟﺒﻨﻴﺎﺕ ﺍﻟﱵ ﺑـ structﻣﺜﻼ ﺃﻧﻈﺮ ﺇﱃ ﺍﳌﺜﺎﻝ ﺍﻟﺘﺎﱄ: >#include<stdio.h union _Union { ;int x ;int y ;}Union )(main { ;Union.x = 10 ;Union.y = 15 ;)printf("Union.x = %d\n", Union.x ;)printf("Union.z = %d\n", Union.y ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,٦ﻃﺮﻳﻘﺔ ﺇﺳﺘﺨﺪﺍﻡ ﺑﻨﻴﺔ ﻣﻌﺮﻓﺔ ﺑـ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 union ﰲ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺪﻝ ﺃﻥ ﺗﻜﻮﻥ ﺍﻟﻨﺘﺎﺋﺞ ١٥ ١٠ﻓﺴﻴﺘﻜﻮﻥ ،١٥ ١٥ﻭ ﺃﻳﻀﺎ ﺳﺘﺨﺘﻠﻒ ﺍﻟﻨﺘﺎﺋﺞ ﺇﻥ ﺍﺳﺘﻌﻤﻠﺖ ﺍﻟﺘﺎﱄ: >#include<stdio.h union _Union { ;int x ;int y ;}Union )(main { ;Union.y = 15 ;Union.x = 10 1 2 3 4 5 6 7 8 9 10 11 12 13 152 14 15 16 } printf("Union.x = %d\n", Union.x); printf("Union.z = %d\n", Union.y); (٢) union ﻃﺮﻳﻘﺔ ﺇﺳﺘﺨﺪﺍﻡ ﺑﻨﻴﺔ ﻣﻌﺮﻓﺔ ﺑـ:٢,٨,٧ ﺍﻟﱪﻧﺎﻣﺞ ﻭ ﺍﻟﺒﻨﻴﺎﺕ ﺑﺎﺳـﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤـﺔ ﺍﶈﺠـﻮﺯﺓstruct ﳝﻜﻨﻚ ﺍﻵﻥ ﺍﺳﺘﻨﺘﺎﺝ ﺍﻟﻔﺮﻕ ﺑﲔ ﺍﻟﺒﻨﻴﺎﺕ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ﻭ ﺇﻥ ﻏﲑﻧﺎ ﻗﻴﻤﺔ ﻣﺘﻐﲑ ﻭﺍﺣﺪﺓ ﻓﺴﺘﻜﻮﻥ ﺗﻠﻚ ﺍﻟﻘﻴﻤﺔ ﳉﻤﻴﻊ، ﻭ ﺍﻟﺬﻱ ﻫﻮ ﺇﺷﺘﺮﺍﻙ ﲨﻴﻊ ﺍﳌﺘﻐﲑﺍﺕ ﰲ ﻋﻨﻮﺍﻥ ﻭﺍﺣﺪ،union : ﻣﺜﺎﻝ،ﻣﺘﻐﲑﺍﺕ ﺍﻟﺒﻨﻴﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #include<stdio.h> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> union _Union { int x1, x2; int y1, y2; }Union; main() { Union.x1 = 10; printf("Value printf("Value printf("Value printf("Value } of of of of printf("Address printf("Address printf("Address printf("Address Union.x1 Union.x2 Union.y1 Union.y2 of of of of = = = = Union.x1 Union.x2 Union.y1 Union.y2 %d\n", %d\n", %d\n", %d\n", = = = = Union.x1); Union.x2); Union.y1); Union.y2); %p\n", %p\n", %p\n", %p\n", &Union.x1); &Union.x2); &Union.y1); &Union.y2); (٣) union ﻃﺮﻳﻘﺔ ﺇﺳﺘﺨﺪﺍﻡ ﺑﻨﻴﺔ ﻣﻌﺮﻓﺔ ﺑـ:٢,٨,٨ ﺍﻟﱪﻧﺎﻣﺞ : ﻣﺜﺎﻝ،ﺎ ﻣﺘﻐﲑﺍﺕ ﳐﺘﻠﻔﺔ ﺍﻷﻧﻮﺍﻉ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﺎﺋﺞ ﻏﲑ ﻣﻮﺛﻮﻗﺔ union ﻭ ﻋﻨﺪ ﺍﺳﺘﻌﻤﺎﻝ ﺑﻨﻴﺎﺕ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ union _Union { int x; float y; }Union; main() { Union.x = 10; Union.y = 15.00; } printf("Union.x = %d\n", Union.x); printf("Union.z = %f\n", Union.y); 153 ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,٩ﻃﺮﻳﻘﺔ ﺇﺳﺘﺨﺪﺍﻡ ﺑﻨﻴﺔ ﻣﻌﺮﻓﺔ ﺑـ (٤) union ﺑﺎﻟﻨﺴﺒﺔ ﻟﻨﺘﻴﺠﺔ ﻣﺘﻐﲑ ﺍﻟﻌﺪﺩ ﺍﳊﻘﻴﻘﻲ yﺳﺘﻜﻮﻥ ﺻﺤﻴﺤﺔ ،ﺃﻣﺎ ﺍﳌﺘﻐﲑ xﻓﺴﺘﻜﻮﻥ ﻧﺘﻴﺠﺘﻬﺎ ﻏﲑ ﻣﺮﻏﻮﺑﺔ ،ﻭ ﳝﻜﻨﻚ ﺍﺳـﺘﻨﺘﺎﺝ ﺍﻟﺴﺒﺐ. ٢,٨,٣ﺍﳌﺼﻔﻮﻓﺎﺕ ﻭ ﺍﳌﺆﺷﺮﺍﺕ ﻋﻠﻰ ﺍﻟﺒﻨﻴﺎﺕ: ﻻ ﺃﻗﺼﺪ ﺑﻨﻴﺔ ﺎ ﺃﻋﻀﺎﺀ ﻣﻦ ﻧﻮﻉ ﻣﺼﻔﻮﻓﺎﺕ ﺃﻭ ﻣﺆﺷﺮﺍﺕ ،ﺑﻞ ﺃﻗﺼﺪ ﺍﻟﺒﻨﻴﺔ ﻧﻔﺴﻬﺎ ،ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﻤﺼﻔﻮﻓﺎﺕ ﻣﻊ ﺍﻟﺒﻨﻴﺔ ﻓﻬﻲ ﺷﺒﻴﻪ ﺑﻄﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺎﺕ ﻃﺒﻴﻌﻴﺔ ،ﻣﺜﺎﻝ: >#include<stdio.h struct _Arr { ;int x ;]}Arr[2 )(main { ;Arr[0].x = 10 ;Arr[1].x = 20 ;)printf("Arr[0].x = %d\n", Arr[0].x ;)printf("Arr[1].x = %d\n", Arr[1].x ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,١١ﺍﳌﺼﻔﻮﻓﺎﺕ ﻋﻠﻰ ﺍﻟﺒﻨﻴﺎﺕ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ﻭ ﺃﻳﻀﺎ ﳝﻜﻦ ﻛﺘﺎﺑﺔ: struct _Arr { ;int x ;}}Arr[2] = {10, 20 1 2 3 4 ﺑﺪﻝ: ;Arr[0].x = 10 ;Arr[1].x = 20 1 2 ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻛﺘﺎﺑﺔ ﻣﺼﻔﻮﻓﺔ ﻟﺒﻨﻴﺔ ﺛﻨﺎﺋﻴﺔ ﺃﻭ ﺛﻼﺛﻴﺔ ﺍﻷﺑﻌﺎﺩ ﺃﻭ ﺃﻛﺜﺮ ﺑﻨﻔﺲ ﺍﻟﻄﺮﻕ ﺍﻟﺴﺎﺑﻘﺔ ﺍﻟﱵ ﺩﺭﺳﻨﻬﺎ ﰲ ﺩﺭﺱ ﺍﳌﺼﻔﻮﻓﺎﺕ، ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻛﺘﺎﺑﺔ ﻣﺼﻔﻮﻓﺔ ﻟﺒﻨﻴﺔ ﲢﺘﻮﻱ ﻋﻠﻰ ﻣﺘﻐﲑﺍﺕ ﻷﻧﻮﺍﻉ ﻋﺪﻳﺪﺓ ﻣﺜﻞ: 154 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include<stdio.h> struct _Arr { int x; float y; char *Str; }Arr[2] = { {10, 10.00, "Str1"}, {20, 20.00, "Str2"} }; main() { /*Arr[0] :*/ printf("Arr[0].x = %d\n", Arr[0].x); printf("Arr[0].y = %f\n", Arr[0].y); printf("Arr[0].Str = %s\n", Arr[0].Str); } /*Arr[1] :*/ printf("Arr[1].x = %d\n", Arr[1].x); printf("Arr[1].y = %f\n", Arr[1].y); printf("Arr[1].Str = %s\n", Arr[1].Str); (٢) ﺍﳌﺼﻔﻮﻓﺎﺕ ﻋﻠﻰ ﺍﻟﺒﻨﻴﺎﺕ:٢,٨,١٢ ﺍﻟﱪﻧﺎﻣﺞ #include<stdio.h> struct _ptr { int x; }Addr_ptr, *ptr; main() { ptr = &Addr_ptr; ptr->x = 10; printf("ptr->x = %d\n", ptr->x); } /*Or*/ (*ptr).x = 20; printf("(*ptr).x = %d\n", (*ptr).x); ﺍﳌﺆﺷﺮﺍﺕ ﻋﻠﻰ ﺍﻟﺒﻨﻴﺎﺕ:٢,٨,١٣ ﺍﻟﱪﻧﺎﻣﺞ :ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻟﻠﻤﺆﺷﺮﺍﺕ 155 ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺆﺷﺮ ﻟﺒﻨﻴﺔ ﲣﺘﻠﻒ ﻗﻠﻴﻼ ﻋﻦ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺆﺷﺮﺍﺕ ﻃﺒﻴﻌﻴﺔ ،ﺑﺎﻟﻨﺴﺒﺔ ﻟﻺﻋﻼﻥ ﻓﻬﻲ ﻧﻔﺴﻬﺎ ،ﺃﻣﺎ ﺇﻋﻄﺎﺀ ﺍﻟﻌﻨﻮﺍﻥ ﻭ ﺍﻟﻘﻴﻤﺔ ﲣﺘﻠﻒ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﺃﻋﻄﻴﻨﺎ ﻟﻠﻤﺆﺷﺮ ptrﻋﻨﻮﺍﻧﺎ ﻭ ﻫﻮ ﻋﻨﻮﺍﻥ ﺍﻟﺒﻨﻴﺔ .Adrr_ptrﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﳊﺎﺩﻱ ﻋﺸﺮ ﺃﻋﻄﻴﻨﺎ ﻟﻠﻌﻀﻮ xﺍﻟﻘﻴﻤﺔ ،١٠ﻭ ﻳﺘﻢ ﺇﻋﻄﺎﺀ ﻗﻴﻢ ﻷﻋﻀﺎﺀ ﻣﺆﺷﺮ ﺑﻨﻴﺔ ﻋﱪ ﺍﻟﺮﻣﺰﻳﻦ > -ﰒ ﺍﺳﻢ ﺍﻟﻌﻀﻮ ،ﰒ ﻗﻴﻤﺘﻪ. ٢,٨,٤ﺇﻋﻼﻥ ﺑﻨﻴﺔ ﺩﺍﺧﻞ ﺑﻨﻴﺔ: ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺑﻨﻴﺔ ﺩﺍﺧﻞ ﺑﻨﻴﺔ ،ﻣﺜﻼ ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﺃﻥ ﻧﺮﺳﻢ ﺧﻂ ﻣﺴﺘﻘﻴﻢ ،ﻫﺬﺍ ﳛﺘﺎﺝ ﺇﱃ ﻧﻘﺘﻄﲔ ،ﺍﻷﻭﱃ ﻫﻲ ﺑﺪﺍﻳﺔ ﺍﳌﺴﺘﻘﻴﻢ ﻭ ﺍﻟﺜﺎﻧﻴﺔ ﻫﻲ ﺎﻳﺔ ﺍﳌﺴﺘﻘﻴﻢ ،ﻭ ﳚﺐ ﺃﻥ ﻳﻜﻮﻥ ﻟﻜﻞ ﻧﻘﻄﺔ ﻣﻜﺎﺎ ﻋﻠﻰ ﺷﺎﺷﺔ ﺍﳊﺎﺳﻮﺏ ﰲ ﻛﻞ ﻣﻦ xﻭ ،yﻣﺜﺎﻝ: >#include<stdio.h struct _line { struct _point { ;int x ;int y ;}point_1, point_2 ;}line ;= 10 ;= 10 ;= 100 ;= 10 ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,١٤ﺇﻋﻼﻥ ﺑﻨﻴﺔ ﺩﺍﺧﻞ ﺑﻨﻴﺔ )(main { /*point 1:*/ line.point_1.x line.point_1.y /*point 2:*/ line.point_2.x line.point_2.y } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ﻭ ﻫﻨﺎ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﺒﻨﻴﺔ _pointﺩﺍﺧﻞ ﺍﻟﺒﻨﻴﺔ ،_lineﻭ ﳚﺐ ﺃﻥ ﻧﻘﻮﻡ ﺑﺎﻟﺘﻌﺮﻑ ﻷﲰﺎﺀ _pointﻣﺒﺎﺷﺮﺓ ﻋﻨﺪ ﻛﺘﺎﺑﺘﻬﺎ ﻛـﻲ ﻧﺴﺘﻄﻴﻊ ﺍﺳﺘﻌﻤﺎﻝ ﺍﳌﺘﻐﲑﻳﻦ xﻭ .y ٢,٨,٥ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: .١ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺑﻨﻴﺔ ﻣﺒﺎﺷﺮﺓ ﻣﺜﻞ: >#include<stdio.h struct Struct { ;int x, y ;} 1 2 3 4 5 6 7 156 ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,١٥ﺍﳋﻄﺄ ١ )(main { ;Struct.x = 10 ;Struct.y = 20 } 8 9 10 11 12 .٢ﻻ ﳝﻜﻦ ﺍﻹﻋﻼﻥ ﻋﻦ ﺑﻨﻴﺘﲔ ﻣﻦ ﻧﻔﺲ ﺍﻻﺳﻢ. ٢,٨,٦ﲤﺎﺭﻳﻦ: .١ﺃﻛﺘﺐ ﺑﻨﻴﺔ ﺑﺴﻢ timeﺎ ﺛﻼﺛﺔ ﺃﻋﻀﺎﺀ ﻭ ﻫﻲ hh, mm, ssﻭ ﻛﻠﻬﺎ ﻣﻦ ﺍﻟﻨﻮﻉ ،intﻭ ﻧﻄﻠﺐ ﻣﻦ ﺍﳌـﺴﺘﺨﺪﻡ ﺇﺩﺧﺎﻝ ﺍﻟﺴﺎﻋﺔ ﻭ ﺍﻟﺪﻗﻴﻘﺔ ﻭ ﺍﻟﺜﺎﻧﻴﺔ ﺍﳊﺎﻟﻴﺔ ﻭ ﻧﻌﻄﻲ ﺗﻠﻚ ﺍﻟﻘﻴﻢ ﻟﻠﺒﻨﻴﺔ timeﰒ ﻧﻄﺒـﻊ ﺍﻟـﺴﺎﻋﺔ ﻋﻠـﻰ ﺍﻟﻄﺮﻳﻘـﺔ .HH :MM :SS 157 ﺩﺭﺳﻨﺎ ﺳﺎﺑﻘﺎ ﺩﺍﻟﺔ ﺍﻹﺩﺧﺎﻝ ،scanfﻭ ﻗﻠﻨﺎ ﺃﻧﻪ ﳚﺐ ﺃﻥ ﻧﻌﻄﻴﻪ ﺍﺳﻢ ﻣﺘﻐﲑ ﻣﻊ ﻣﺆﺛﺮ ﺍﻟﻌﻨﻮﺍﻥ & ،ﻭ ﺫﻟﻚ ﻳﻌﲏ ﺃﻧﻪ ﻋﻨﺪ ﻛﺘﺎﺑﺔ: >#include<stdio.h )(main { ;int i ;)scanf("%d", &i ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 scanf ﻓﻬﻨﺎ ﺳﻴﺘﻢ ﻭﺿﻊ ﺍﻟﻘﻴﻤﺔ ﺍﳌﺪﺧﻠﺔ ﰲ ﻋﻨﻮﺍﻥ ﺍﳌﺘﻐﲑ ،iﻷﻥ ﺍﻟﺪﺍﻟﺔ scanfﺗﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺆﺷﺮﺍﺕ ،ﻭ ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺍﳌﺘﻐﲑ ﺑـﺪﻭﻥ ﻣﺆﺛﺮ ،ﻭ ﻟﻜﻦ ﺍﻟﻨﺘﺎﺋﺞ ﻟﻦ ﺗﻜﻮﻥ ﺻﺤﻴﺤﺔ. ٢,٩,١ﻣﻌﲎ ﺩﺍﻟﺔ ﺎ ﻭﺳﻴﻂ :void ﺃﺣﻴﺎﻧﺎ ﻣﺎ ﲡﺪ ﰲ ﺑﻌﺾ ﺍﻷﻣﺜﻞ ﺩﻭﺍﻝ ﺎ ﻭﺳﻴﻂ voidﻣﺜﻞ: >#include<stdio.h ;)Function(void )(main { } )Function(void { ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢ﻣﻌﲎ ﺩﺍﻟﺔ ﺎ ﻭﺳﻴﻂ } 1 2 3 4 5 6 7 8 9 10 11 12 13 void ﺃﻭ ﲡﺪ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﻧﻔﺴﻬﺎ ﺎ ﻫﺬﺍ ﺍﻟﻮﺳﻴﻂ ،ﻣﺜﺎﻝ: )main(void { ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٣ﻣﻌﲎ ﺩﺍﻟﺔ ﺎ ﻭﺳﻴﻂ (٢) void } 1 2 3 4 158 ﻣﺜﻞ ﻫﺬﻩ ﺍﻟﺪﻭﺍﻝ ﺍﻟﻮﺳﻴﻂ ﺍﳋﺎﺹ ﺎ ﻻ ﻳﻌﲏ ﺷﻲﺀ ،ﻭ ﻛﻠﻤﺔ voidﺇﳒﻠﻴﺰﻳﺔ ﻭ ﻫﻲ ﺗﻌﲏ ﻓﺮﺍﻍ ،ﻭ ﻫﺬﺍ ﻫﻮ ﻣﻌﲎ ﻛﺘﺎﺑﺔ ﺩﻭﺍﻝ ﺎ ﻭﺳﻴﻂ ﻣﻦ ﻫﺬﺍ ﺍﻟﻨﻮﻉ ،ﻳﻌﲏ ﺍﻟﺘﺄﻛﻴﺪ ﻋﻠﻰ ﺃﻥ ﺍﻟﺪﺍﻟﺔ ﻓﺎﺭﻏﺔ ﺍﻟﻮﺳﺎﺋﻂ ،ﻭ ﻣﺜﻞ ﺗﻠﻚ ﺍﻟﺪﻭﺍﻝ ﳝﻜﻦ ﲡﺎﻫﻞ ﻛﺘﺎﺑـﺔ ﺍﻟﻜﻠﻤـﺔ ﺍﶈﺠﻮﺯﺓ ،voidﺣﻴﺚ ﺃﻥ ﻛﻼ ﻣﻦ ﻫﺬﻩ ﺍﻷﻣﺜﻠﺔ: >#include<stdio.h ;)(Function )(main { } )(Function { ﻭ ﺍﳌﺜﺎﻝ: } ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٤ﻣﻌﲎ ﺩﺍﻟﺔ ﺎ ﻭﺳﻴﻂ (٣) void )(main { ﻣﻜﺎﻓﺌﺔ ﻟﻸﻣﺜﻠﺔ ﺍﻟﺴﺎﺑﻘﺔ. } ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٥ﻣﻌﲎ ﺩﺍﻟﺔ ﺎ ﻭﺳﻴﻂ (٣) void 1 2 3 4 5 6 7 8 9 10 11 12 13 1 2 3 4 ٢,٩,٢ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ :static ﻛﻠﻤﺔ staticﺗﻌﲏ ﺳﺎﻛﻦ ﻭ ﻫﻲ ﺗﺴﺘﻌﻤﻞ ﻣﻊ ﺍﳌﺘﻐﲑﺍﺕ ﺣﻴﺚ ﲡﻌﻠﻬﺎ ﺛﺎﺑﺖ ﺑﻄﺮﻗﺔ ﺳﺘﻔﻬﻤﻬﺎ ﻣﻦ ﻫﺬﺍ ﺍﳌﺜﺎﻝ: >#include<stdio.h )(main { ;int x )for(x=0; x<10; x++ { ;static int Static = 0 ;Static++ ;)printf("%d\n", Static } 1 2 3 4 5 6 7 8 9 10 11 12 13 159 ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٦ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ } 14 static ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ staticﻣﻊ ﺍﳌﺘﻐﲑ Staticﺩﺍﺧﻞ ﺣﻠﻘﺔ ﻭ ﺃﻋﻄﻴﻨﺎﻩ ﺍﻟﻘﻴﻤﺔ ،٠ﻭ ﺍﺳـﺘﻌﻤﻠﻨﺎ ﻣﺆﺷﺮ ﺍﻟﺰﻳﺎﺩﺓ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﻌﺎﺷﺮ ﻣﻊ ﻧﻔﺲ ﺍﳌﺘﻐﲑ ،Staticﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﱐ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﻄﺒﺎﻋﺔ ﺍﻟﻨﺘﺎﺋﺞ .ﺇﺫﺍ ﻗﻤﻨـﺎ ﺑﺈﺯﺍﻟـﺔ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ staticﻣﻦ ﺍﳌﺘﻐﲑ Staticﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﺎﺋﺞ ﺛﺎﺑﺘﺔ ﻭ ﻫﻲ ١ﻋﺸﺮﺓ ﻣﺮﺍﺕ ،ﺃﻣﺎ ﻋﻨﺪ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻓﺴﺘﺮﻯ ﺃﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺛﺎﺑﺘﺔ ﻭ ﺗﻌﻤﻞ ﺑﺘﺰﺍﻳﺪ .ﻭ ﺗﺴﺘﻌﻤﻞ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ staticﺑﻜﺜﺮﺓ ﰲ ﺍﻟﺪﻭﺍﻝ ،ﻣﺜﺎﻝ: >#include<stdio.h ;)int Test_static(int a )(main { ;int i )for(i=0;i<=10;i++ ;))printf("%d * %d = %d\n", i, i, Test_static(i } )int Test_static(int a { ;static int c = 0 ;int a_c = a*c ;c++ ;return a_c } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٧ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ (٢) static ﻭ ﰲ ﺣﺎﻟﺔ ﺇﺯﺍﻟﺔ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ staticﻓﺴﺘﻜﻮﻥ ﲨﻴﻊ ﺍﻟﻨﺘﺎﺋﺞ .٠ﺇﻥ ﱂ ﻧﻘﻢ ﺑﺘﺤﺪﻳﺪ ﻗﻴﻤﺔ ﳌﺘﻐﲑ staticﻓـﺴﺘﻜﻮﻥ ﻗﻴﻤﺘﻪ ٠ﺗﻠﻘﺎﺋﻴﺎ ،ﻭ ﻟﻴﺲ ﻣﺜﻞ ﺍﳌﺘﻐﲑﺍﺕ ﺍﻟﻄﺒﻴﻌﻴﺔ ﺍﻟﱵ ﺗﻨﺘﺞ ﻗﻴﻢ ﻋﺸﻮﺍﺋﻴﺔ. ٢,٩,٣ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ :typedef ﺗﺴﺘﻌﻤﻞ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ typedefﻣﻊ ﻛﻞ ﻣﻦ ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺒﻨﻴﺎﺕ ،ﻭ ﻫﻲ ﺗﻌﻄﻲ ﺇﻣﻜﺎﻧﻴﺎﺕ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ ﻣﺜﻞ ﺍﻟﺒﻨﻴﺔ، ﻣﺜﺎﻝ: >#include<stdio.h ;typedef int Decimal )(main { /* or typedef int Decimal; here */ 1 2 3 4 5 6 7 160 ;Decimal Var_1, Var_2 ;Decimal Var_3 ;Var_1 = 10 ;Var_2 = 20 ;Var_3 = Var_1 + Var_2 ;)printf("%d\n", Var_3 ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٨ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ } 8 9 10 11 12 13 14 15 16 typedef ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ intﻣﻊ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ typedefﺑﺎﺳـﻢ .Decimalﰲ ﺍﻟـﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﻭ ﺍﻟﺘﺎﺳﻊ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﳌﺘﻐﲑ Decimalﻟﻺﻋﻼﻥ ﻋﻦ ﺍﳌﺘﻐﲑﺍﺕ Var_1ﻭ Var_2ﻭ Var_3ﻭ ﺗﻌﺎﻣﻠﻨـﺎ ﻣﻌـﺎ ﺗﻠـﻚ ﺍﳌﺘﻐﲑﺍﺕ ﻛﺄﻱ ﻛﺘﻐﲑﺍﺕ ﺃﺧﺮﻯ .ﻭ ﰲ ﻣﺜﺎﻟﻨﺎ ﻫﺬﺍ ﺍﺳﺘﺒﺪﻟﻨﺎ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ intﺑـ Decimalﺣﻴﺚ ﺣﺠﻤﻬﺎ ﺳـﻴﻜﻮﻥ ﺣﺠﻢ ﺍﻟﻨﻮﻉ ﺍﻟﺬﻱ ﰎ ﺍﻹﻋﻼﻥ ﺑﻪ ،ﻭ ﻻ ﳝﻜﻦ ﺇﻋﻄﺎﺀﻫﺎ ﻗﻴﻢ .ﺃﻣﺎ ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﻤﺒﻨﻴﺔ ﻓﻬﻲ ﻧﻔﺴﻬﺎ ﻣﺸﺎﺑﻪ ﻣﺜﻼ: >#include<stdio.h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 >#include<stdio.h 1 2 3 4 5 6 7 8 9 10 11 12 struct _2D { ;int x, y ;} )(main { ;struct _2D A ;struct _2D B ;A.x = 10 ;B.y = 20 ;)printf("%d\n", A.x ;)printf("%d\n", B.y ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٩ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ (٢) typedef ﻭ ﻟﻜﻨﻬﺎ ﲡﻌﻠﻬﺎ ﺃﻛﺜﺮ ﻣﺮﻭﻧﺔ ﻣﻦ ﺍﻟﺴﺎﺑﻘﺔ ،ﻣﺜﺎﻝ: } typedef struct _2D { ;int x, y ;}Struct1, Struct2 )(main { ;Struct1 S1_1, S1_2 ;Struct2 S2_1, S2_2 161 ;S1_1.x = 10, S1_2.x = 20 ;S2_1.y = 30, S2_2.y = 40 } ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١٠ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ (٣) typedef ﻣﻼﺣﻈﺔ :ﻋﻨﺪ ﺍﺳﺘﻌﻤﺎﻝ ﻣﺘﻐﲑﺍﺕ ﺃﻭ ﺩﻭﺍﻝ ﺃﻭ ﺑﻨﻴﺎﺕ ﻣﻊ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ typdefﻓﻼ ﳝﻜﻦ ﺇﻋﻄﺎﺀﻫﺎ ﻗﻴﻢ ﺳﺎﺑﻘﺔ ﻣﺜﻞ: >#include<stdio.h )(main { ;typedef float PI ;PI = 10.00 ;)printf("%f\n", PI } ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ (٤) typedef 13 14 15 1 2 3 4 5 6 7 8 ٢,٩,٤ﺑﺮﺍﻣﺞ ﺗﺪﺭﻳﺒﻴﺔ: ﰲ ﻫﺬﺍ ﺍﳉﺰﺀ ﻣﻦ ﺍﻟﺪﺭﺱ ﺳﻨﺮﻯ ﺑﻌﺾ ﺍﻟﱪﺍﻣﺞ ﺍﻟﱵ ﺳﺘﺴﺎﻋﺪﻙ ﻋﻠﻰ ﻓﻬﻢ ﻟﻐﺔ Cﺑﺸﻜﻞ ﻣﺒﺴﻂ ،ﻣﻊ ﺷﺮﺡ ﺳﺮﻳﻊ ﻟﻜـﻞ ﺑﺮﻧﺎﻣﺞ: ٢,٩,٤,١ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ،ﺍﻟﻨﺴﺦ: ﰲ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺩﺍﻟﺔ ﺗﻘﻮﻡ ﺑﻨﺴﺦ ﺳﻠﺴﻠﺔ ﺣﺮﻭﻑ ﺇﱃ ﺳﻠﺴﻠﺔ ﺣﺮﻭﻑ ﺃﺧﺮﻯ ﻓﺎﺭﻏﺔ ،ﺍﳌﺜﺎﻝ: ﺍﳌﻠﻒ :str.h /*string.h )strcopy(pointers */ {)void strcopy(char *From, char *To )'while((*To++ = *From++)!='\0 ; } ;)/*strcopy(arrays {)][void strcopy(char From[], char To ;int i ;i = 0 )'while((To[i] = From[i])!='\0 ;++i ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١٢ﺍﻟﻨﺴﺦ ،ﺍﳌﻠﻒ }*/ str.h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 162 ﺍﳌﻠﻒ ﺍﻟﺮﺋﻴﺴﻲ: /*main.c*/ >#include<stdio.h "#include"str.h )(main { ;"char *From = "STRING ;]char Empty[6 ;)strcopy(From, Empty ;)printf(Empty } ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١٣ﺍﻟﻨﺴﺦ ،ﺍﳌﻠﻒ ﺍﻟﺮﺋﻴﺴﻲ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ﻫﻨﺎ ﺍﻟﺪﺍﻟﺔ ﺳﺘﻘﻮﻡ ﺑﻨﺴﺦ ﻣﺎ ﻫﻮ ﻣﻮﺟﻮﺩ ﰲ ﺍﻟﺴﻠﺴﻠﺔ Fromﺇﱃ ﺍﻟﺴﻠﺴﻠﺔ ،Emptyﰒ ﻧﻄﺒﻊ ﳏﺘﻮﻯ ﺍﻟﺴﻠـﺴﻠﺔ Emptyﻛـﻲ ﻧﺘﺄﻛﺪ ﻣﻦ ﺍﻟﻨﺘﺎﺋﺞ. ٢,٩,٤,٢ﺗﺒﺎﺩﻝ ﻗﻴﻢ ﺑﲔ ﻭﺳﻴﻄﲔ: ﰲ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﻧﻘﻮﻡ ﺑﺈﻧﺸﺎﺀ ﺩﺍﻟﺔ ﺗﻘﻮﻡ ﺑﻮﺿﻊ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﰲ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻭ ﻗﻴﻤﺔ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜـﺎﱐ ﰲ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ،ﺍﳌﺜﺎﻝ: >#include<stdio.h )void Change(int *a, int *b { ;int c ;c = *a ;*a = *b ;*b = c } )(main { ;int a, b ;a = 5 ;b = 10 ;)printf("a = %d, b = %d\n", a, b ;)Change(&a, &b ;)printf("a = %d, b = %d\n", a, b } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 163 ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١٤ﺗﺒﺎﺩﻝ ﻗﻴﻢ ﺑﲔ ﻭﺳﻴﻄﲔ ﺇﺫﺍ ﺍﺳﺘﻌﻤﻠﻨﺎ ﻣﺘﻐﲑﺍﺕ ﰲ ﻣﻜﺎﻥ ﺍﳌﺆﺷﺮﻳﻦ ﻋﻨﺎﻭﻳﻦ ﺍﻟﺬﺍﻛﺮﺓ. *b *a,ﻓﺈﻥ ﺍﻟﻨﺘﺎﺋﺞ ﺍﻟﱪﻧﺎﻣﺞ ﺳﺘﻜﻮﻥ ﺧﺎﻃﺌﺔ ،ﻭ ﻫﻨﺎ ﻧﺮﻯ ﻓﺎﺋﺪﺓ ﺍﻟﺘﻌﺎﻣـﻞ ﻣـﻊ ٢,٩,٤,٣ﺍﻟﺘﻐﲑ ﰲ ﻗﻴﻢ ﺛﻮﺍﺑﺖ: ﻗﻠﻨﺎ ﺳﺎﺑﻘﺎ ﺃﻧﻪ ﻻ ﳝﻜﻦ ﺍﻟﺘﻐﲑ ﰲ ﻗﻴﻢ ﺛﻮﺍﺑﺖ ،ﻭ ﻟﻜﻦ ﻋﱪ ﺍﳌﺆﺷﺮﺍﺕ ﳝﻜﻨﻨﺎ ﺫﻟﻚ ،ﻣﺜﺎﻝ: >#include<stdio.h )(main { ;const int Const = 10 ;int *ptr = &Const ;)printf("Const = %d\n", Const ;*ptr = 5 ;)printf("Const = %d\n", Const } ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١٥ﺗﻐﲑ ﻗﻴﻤﺔ ﺛﺎﺑﺖ 1 2 3 4 5 6 7 8 9 10 11 12 ٢,٩,٤,٤ﻋﻜﺲ ﺳﻠﺴﻠﺔ ﻧﺼﻴﺔ: ﰲ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﻧﻘﻮﻡ ﺑﺈﻧﺸﺎﺀ ﺩﺍﻟﺔ ﺎ ﻭﺳﻴﻂ ﻟﺴﻠﺴﻠﺔ ﻣﻦ ﺣﺮﻭﻑ ،ﺣﻴﺚ ﺗﻘﻮﻡ ﺗﻠﻚ ﺍﻟﺪﺍﻟﺔ ﺑﻌﻜﺲ ﺗﻠـﻚ ﺍﻟﺴﻠـﺴﻠﺔ ﰲ ﻧﻔﺴﻬﺎ ،ﺍﳌﺜﺎﻝ: >#include<stdio.h >#include<string.h ;)* void Reverse_Str(char )(main { ;"!char *str = "Hello, World ;)printf("%s\n", str ;)Reverse_Str(str ;)printf("%s\n", str } {)void Reverse_Str(char *String ;int i = strlen(String)-1, j = 0 ;char ch {)while(j<i ;]ch = String[j 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 164 21 22 23 24 25 String[j] = String[i]; String[i] = ch; j++, i--; } } ﻋﻜﺲ ﺳﻠﺴﻠﺔ ﻧﺼﻴﺔ:٢,٩,١٦ ﺍﻟﱪﻧﺎﻣﺞ : ﺍﻟﺘﺤﻮﻳﻞ ﻣﻦ ﺍﻟﻨﻈﺎﻡ ﺍﻟﻌﺸﺮﻱ ﺇﱃ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺜﻨﺎﺋﻲ٢,٩,٤,٥ : ﺍﳌﺜﺎﻝ،ﻣﻦ ﺧﻼﻝ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﳝﻜﻨﻚ ﺍﺳﺘﻨﺘﺎﺝ ﻛﻴﻔﻴﺔ ﺍﻟﺘﺤﻮﻳﻞ ﺇﱃ ﺑﺎﻗﻲ ﺍﻷﻧﻈﻤﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 #include<stdio.h> void ConvertToBinary(int); main() { int Decimal; printf("Decimal Number: "); scanf("%d", &Decimal); printf("%d in Binary = ", Decimal); ConvertToBinary(Decimal); } void ConvertToBinary(int num){ int i = 0, Binary[32]; while(num>0){ if((num%2)==0){ Binary[i] num /= 2, } else { Binary[i] num /= 2, } } = 0; ++i; = 1; ++i; --i; while(i>=0) { printf("%d", Binary[i]), --i; } printf("\n"); } ﺍﻟﺘﺤﻮﻳﻞ ﻣﻦ ﺍﻟﻨﻈﺎﻡ ﺍﻟﻌﺸﺮﻱ ﺇﱃ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺜﻨﺎﺋﻲ:٢,٩,١٧ ﺍﻟﱪﻧﺎﻣﺞ : ﺍﻟﺘﺤﻮﻳﻞ ﻣﻦ ﺍﳊﺮﻭﻑ ﺍﻟﺼﻐﲑﺓ ﺇﱃ ﺍﳊﺮﻭﻑ ﺍﻟﻜﺒﲑﺓ٢,٩,٤,٦ 165 : ﺍﳌﺜﺎﻝ،ﰲ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﻧﻘﻮﻡ ﺑﺈﻧﺸﺎﺀ ﺩﺍﻟﺔ ﺗﻘﻮﻡ ﺑﺘﺤﻮﻳﻞ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﻣﻦ ﺍﳊﺮﻭﻑ ﺍﻟﺼﻐﲑﺓ ﺇﱃ ﺍﳊﺮﻭﻑ ﺍﻟﻜﺒﲑﺓ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #include<stdio.h> void To_Capital_letter(char ch[]); main() { char *ch = "hello"; printf("Small Letters: %s\n", ch); To_Capital_letter(ch); printf("Capital Letters: %s\n", ch); } void To_Capital_letter(char ch[]) { int i=0; while(ch[i]!='\0'){ if(ch[i]>=97 && ch[i]<=122) ch[i] = ch[i]-32; ++i; } } ﺍﻟﺘﺤﻮﻳﻞ ﻣﻦ ﺍﳊﺮﻭﻑ ﺍﻟﺼﻐﲑﺓ ﺇﱃ ﺍﳊﺮﻭﻑ ﺍﻟﻜﺒﲑﺓ:٢,٩,١٨ ﺍﻟﱪﻧﺎﻣﺞ . ﺍﺳﺘﻨﺘﺞ ﺫﻟﻚ، ﻣﻦ ﺍﻷﺣﺮﻑ ﺍﻟﻜﺒﲑﺓ ﺇﱃ ﺍﻷﺣﺮﻑ ﺍﻟﺼﻐﲑﺓ،ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﻌﻜﺲ :wcsncpy ﻭ ﺍﻟﺪﺍﻟﺔwcscpy ﺍﻟﺪﺍﻟﺔ٢,٩,٥ wide character 1 2 3 4 5 6 8 9 10 11 12 13 ﻭ ﺍﲰﻬﺎ ﳐﺘﺼﺮ ﻣﻦstring.h ﻭ ﻫﻲ ﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲstrcpy ﻣﻜﺎﻓﺌﺔ ﻟﻠﺪﺍﻟﺔwcscpy ﺍﻟﺪﺍﻟﺔ : ﻣﺜﺎﻝ، ﻓﻘﻂ ﻫﻲ ﻟﻸﺣﺮﻑ ﺍﻟﻌﺮﻳﻀﺔstrcpy ﺗﻘﻮﻡ ﺑﻨﻔﺲ ﻋﻤﻞ ﺍﻟﺪﺍﻟﺔ،string copy #include<stdio.h> #include<string.h> main() { wchar_t *wStr = L"Hello"; wchar_t Empty[20]; wcscpy(Empty, wStr); wprintf(L"%s\n", Empty); } wcscpy ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ:٢,٩,١٩ ﺍﻟﱪﻧﺎﻣﺞ : ﻣﺜﺎﻝ،string.h ﻭ ﻫﻲ ﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲstrncpy ﻣﻜﺎﻓﺌﺔ ﻟﻠﺪﺍﻟﺔwcsncpy ﻭ ﺃﻳﻀﺎ ﺍﻟﺪﺍﻟﺔ 166 1 2 3 4 5 6 7 8 9 10 11 12 #include<stdio.h> #include<string.h> main() { wchar_t *wStr = L"Hello"; wchar_t Empty[20]; wcsncpy(Empty, wStr, 4); wprintf(L"%s\n", Empty); } wcsncpy ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ:٢,٩,٢٠ ﺍﻟﱪﻧﺎﻣﺞ :wcsncat ﻭ ﺍﻟﺪﺍﻟﺔwcscat ﺍﻟﺪﺍﻟﺔ٢,٩,٦ : ﻣﺜﺎﻝ،strncat ﻭstrcat ﻣﻜﺎﻓﺌﺔ ﻟﻠﺪﺍﻟﺘﲔwcsncat ﻭwcscat ﻭ ﻛﻼ ﻣﻦ ﺍﻟﺪﺍﻟﺘﲔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include<stdio.h> #include<string.h> main() { wchar_t *wStr = L"Hello"; wchar_t *wStr2 = L", World!"; wcscat(wStr, wStr2); wprintf(L"%s\n", wStr); /* wcsncat(wStr, wStr2, 4); } wprintf(L"%s\n", wStr); */ wcsncat ﻭ ﺍﻟﺪﺍﻟﺔwcscat ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ:٢,٩,٢١ ﺍﻟﱪﻧﺎﻣﺞ :putwchar ﻭgetwchar ﺍﻟﺪﺍﻟﺔ٢,٩,٧ get wide 1 2 3 4 5 6 7 ﻭﺍﲰﻬﺎ ﳐﺘﺼﺮ ﻣـﻦ،stdio.h ﻭ ﻫﻲ ﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ،getchar ﻣﻜﺎﻓﺌﺔ ﻟﺪﺍﻟﺔgetwchar ﺍﻟﺪﺍﻟﺔ : ﻣﺜﺎﻝ،put wide character ﻭ ﳐﺘﺼﺮﺓ ﻣﻦ،putchar ﻣﻜﺎﻓﺌﺔ ﻟﺪﺍﻟﺔputwchar ﻭ ﺃﻳﻀﺎ ﺍﻟﺪﺍﻟﺔ،character #include<stdio.h> main() { wchar_t wch; wch = getwchar(); 167 ;)putwchar(wch ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ getwcharﻭ ﺍﻟﺪﺍﻟﺔ } 8 9 putwchar ٢,٩,٨ﺍﻟﺪﺍﻟﺔ _getwsﻭ :_putws ﺍﻟﺪﺍﻟﺔ _getwsﻣﻜﺎﻓﺌﺔ ﻟﺪﺍﻟﺔ ،getsﻭ ﺍﻟﺪﺍﻟﺔ _putwsﻣﻜﺎﻓﺌﺔ ﻟﺪﺍﻟﺔ ،putsﻭ ﳘﺎ ﻣﻦ ﺩﻭﺍﻝ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،stdio.h ﻭ ﻛﻞ ﻣﻦ ﺍﳊﺮﻓﲔ ﺍﻹﺿﺎﻓﻴﲔ wsﳐﺘﺼﺮﻳﻦ ﻣﻦ ،wide stringﻣﺜﺎﻝ: >#include<stdio.h )(main { ;]wchar_t wch[255 ;)_getws(wch ;)_putws(wch ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ _getwsﻭ ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 _putws ٢,٩,٩ﺟﺪﻭﻝ ) ASCIIﺻﻮﺭﺓ(: ﻛﻠﻤﺔ ASCIIﳐﺘﺼﺮﺓ ﻣﻦ ،American Standard Code for Information Interchangeﻫﻮ ﺟﺪﻭﻝ ﻤﻮﻋﺔ ﻣﻦ ﺍﻟﺮﻣـﻮﺯ ﻣﺴﺘﻨﺪﺓ ﻋﻠﻰ ﺍﻷﲜﺪﻳﺔ ﺍﻟﺮﻭﻣﺎﻧﻴﺔ ﲤﺜﻞ ﺭﻣﻮﺯ ﰲ ﺍﳊﺎﺳﺒﺎﺕ ،ﺍﻟﺮﻣﻮﺯ ﻋﻠﻰ ﺍﳉﺪﻭﻝ ﺍﻟﺘﺎﱄ: ﺇﺫﺍ ﺃﺭﺩﺕ ﺍﺳﺘﻌﻤﻞ ﺃﻱ ﺭﻣﺰ ﻣﻦ ﺍﻟﺮﻣﻮﺯ ﺍﻟﺴﺎﺑﻘﺔ ﻗﻢ ﺑﻜﺘﺎﺑﺔ ﺍﻟﺘﺎﱄ: >#include<stdio.h )(main { ;)printf("The number %d is the character %c in ASCII code.\n", 210, 210 } ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٤ﻃﺒﺎﻋﺔ ﺣﺮﻑ ﻋﱪ ﺭﻗﻤﻪ ﰲ ﺟﺪﻭﻝ ﺃﺳﻜﻲ 1 2 3 4 5 6 ﻭ ﻫﻨﺎ ﺳﻴﺘﻢ ﻃﺒﻊ ﺍﻟﺮﻣﺰ ﺭﻗﻢ ٢١٠ﻣﻦ ﺟﺪﻭﻝ ASCIIﻭ ﻫﻮ ﺍﻟﺮﻣﺰ ╥ ،ﻭ ﳝﻜﻦ ﺍﺧﺘﻴﺎﺭ ﺃﻱ ﺭﻣﺰ ﻣﻦ ﺍﻟﺮﻣﻮﺯ ﺍﻟـﺴﺎﺑﻘﺔ ﻓﻘـﻂ ﻧﻜﺘﺐ ﺍﻟﺮﻗﻢ ﻭ ﻧﻄﺒﻌﻪ ﻋﻠﻰ ﺷﻜﻞ ﺣﺮﻑ )ﺭﻣﺰ(. 168 ٢,٩,١٠ﻣﻌﻠﻮﻣﺎﺕ ﺃﻛﺜﺮ ﺣﻮﻝ ﺍﳌﺘﻐﲑﺍﺕ: ﺍﻟﺸﻜﻞ :٢,٩,١ﺟﺪﻭﻝ ﺃﺳﻜﻲ ﺗﻮﺟﺪ ﻣﺘﻐﲑﺍﺕ ﺧﺎﺭﺟﻴﺔ ﻭ ﻣﺘﻐﲑﺍﺕ ﳏﻠﻴﺔ ،ﺍﻷﻭﱃ ﻫﻲ ﻣﺘﻐﲑﺍﺕ ﻋﺎﻣﺔ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﺑﺼﻔﺔ ﻋﺎﻣﺔ ،ﺃﻣﺎ ﺍﳌﺘﻐﲑﺍﺕ ﺍﶈﻠﻴـﺔ ﻓﻬﻲ ﻣﺘﻐﲑﺍﺕ ﳍﺎ ﺣﺪﻭﺩﻫﺎ. ٢,٩,١٠,١ﺍﳌﺘﻐﲑﺍﺕ ﺍﶈﻠﻴﺔ: ﻫﻲ ﻣﺘﻐﲑﺍﺕ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﰲ ﺍﻟﺪﺍﻟﺔ ﺍﻟﱵ ﰎ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ ،ﻣﺜﺎﻝ: >#include<stdio.h /*Local Variable*/ /*Local Variable*/ ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٥ﺍﳌﺘﻐﲑﺍﺕ ﺍﶈﻠﻴﺔ )(void Func { ;int a } )(main { ;int b } 1 2 3 4 5 6 7 8 9 10 11 169 ﻫﻨﺎ ﻛﻞ ﻣﻦ ﺍﳌﺘﻐﲑ aﰲ ﺍﻟﺪﺍﻟﺔ Funcﻭ ﺍﳌﺘﻐﲑ bﰲ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﻳﻌﺘﱪﺍ ﻣﺘﻐﲑﺍﺕ ﳏﻠﻴﺔ ﺣﻴﺚ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﳌـﺘﻐﲑ ﰲ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﻷﻧﻪ ﺧﺎﺹ ﺑﺎﻟﺪﺍﻟﺔ ،Funcﻭ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﳌﺘﻐﲑ bﰲ ﺍﻟﺪﺍﻟﺔ Funcﻷﻧﻪ ﻣﻌﺮﻑ ﰲ ﺍﻟﺪﺍﻟﺔ ،mainﻭ ﻫﺬﺍ ﻫﻮ ﻣﻔﻬﻮﻡ ﺍﳌﺘﻐﲑﺍﺕ ﺍﶈﻠﻴﺔ. a ٢,٩,١٠,٢ﺍﳌﺘﻐﲑﺍﺕ ﺍﳋﺎﺭﺟﻴﺔ )ﺍﻟﻌﺎﻣﺔ(: ﻫﻲ ﻣﺘﻐﲑﺍﺕ ﳝﻜﻦ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ ﰲ ﲨﻴﻊ ﺍﻟﺪﻭﺍﻝ ،ﺃﻱ ﰲ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺄﻛﻤﻠﻪ ،ﻭ ﻳﺘﻢ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ ﺧﺎﺭﺝ ﲨﻴﻊ ﺍﻟـﺪﻭﺍﻝ، ﻣﺜﺎﻝ: >#include<stdio.h /*External Variable*/ /*Use The External Variable ab*/ ;int ab )(void Func { ;ab = 10 } )(main { ;)(Func printf("%d\n", ab); /*print The External Variable ab*/ } ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٦ﺍﳌﺘﻐﲑﺍﺕ ﺍﳋﺎﺭﺟﻴﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ﺍﳌﺘﻐﲑ abﻫﻮ ﺍﳌﺘﻐﲑ ﺍﻟﻌﺎﻡ ﻟﻠﱪﻧﺎﻣﺞ ،ﺣﻴﺚ ﳝﻜﻦ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻪ ﰲ ﲨﻴﻊ ﺍﻟﺪﻭﺍﻝ ،ﺃﻋﻄﲔ ﻟﻠﻤﺘﻐﲑ abﻗﻴﻤﺔ ﰲ ﺍﻟﺪﺍﻟـﺔ Funcﰒ ﻗﻨﺎ ﺑﺘﻨﻔﻴﺬ ﺍﻟﺪﺍﻟﺔ Funcﰲ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﰒ ﻃﺒﻊ ﳏﺘﻮﻯ ﺍﳌﺘﻐﲑ ﺍﳋﺎﺭﺟﻲ abﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﻋﺸﺮ .ﺇﺫﺍ ﱂ ﺗﻜﻦ ﻟﻠﻤﺘﻐﲑﺍﺕ ﺍﻟﻌﺎﻣﺔ ﻗﻴﻢ ﺳﺎﺑﻘﺔ ﻓﺴﺘﻜﻮﻥ ﻗﻴﻤﻬﺎ ٠ﺗﻠﻘﺎﺋﻴﺎ. ٢,٩,١٠,٣ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ :extern ﺗﺴﺘﻌﻤﻞ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ externﻣﻊ ﺍﳌﺘﻐﲑﺍﺕ ﺩﺍﺧﻞ ﺩﻭﺍﻝ ،ﻭ ﺗﺴﺘﻌﻤﻞ ﳉﻌﻞ ﻣﺘﻐﲑ ﳏﻠﻲ ﻣﺸﺘﺮﻙ ﻣﻊ ﻣﺘﻐﲑ ﺧﺎﺭﺟﻲ، ﻣﺜﻼ ﳝﻜﻨﻨﺎ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﳏﻠﻲ ﻭ ﻣﺘﻐﲑ ﺧﺎﺭﺟﻲ ﺑﻨﻔﺲ ﺍﻻﺳﻢ ﻭ ﻟﻜﻦ ﺑﻘﻴﻢ ﳐﺘﻠﻔﺔ ،ﻣﺜﺎﻝ: >#include<stdio.h ;int ab )(void Func { ;int ab ;ab = 10 1 2 3 4 5 6 7 8 170 ;)printf("%d\n", ab } ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٧ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ )(main { ;ab = 5 ;)(Func ;)printf("%d\n", ab } ﺍﶈﺠﻮﺯﺓ extern 9 10 11 12 13 14 15 16 17 ﰲ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﺍﳌﺘﻐﲑ ﺍﶈﻠﻲ abﺍﳌﻮﺟﻮﺩ ﺩﺍﺧﻞ ﺍﻟﺪﺍﻟﺔ Funcﻻ ﻋﻼﻗﺔ ﻟﻪ ﻣﻊ ﺍﳌﺘﻐﲑ ﺍﳋﺎﺭﺟﻲ ،abﺃﻣﺎ ﺇﺫﺍ ﺃﺭﺩﻧـﺎ ﺃﻥ ﳒﻌـﻞ ﻗﻴﻤﺘﻬﻤﺎ ﻣﺸﺘﺮﻙ ﻧﻀﻴﻒ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ externﺇﱃ ﺍﳌﺘﻐﲑ ﺍﶈﻠﻲ ،ﻣﺜﺎﻝ: >#include<stdio.h ;int ab )(void Func { ;extern int ab ;ab = 10 ;)printf("%d\n", ab } )(main { ;ab = 5 ;)(Func ;)printf("%d\n", ab } ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٨ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ (٢) extern ﻫﻨﺎ ﺳﺘﻜﻮﻥ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ﺍﳋﺎﺭﺟﻲ abﻫﻲ ﻧﻔﺲ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ ﺍﻟﺪﺍﺧﻠﻲ .ab 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ٢,٩,١٠,٤ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ :auto ﺗﺴﺘﻌﻤﻞ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ autoﻣﻊ ﺍﳌﺘﻐﲑﺍﺕ ،ﻭ ﻫﻲ ﺗﻌﲏ automaticﺃﻱ ﺁﱄ ،ﻭ ﺗﺴﺘﻌﻤﻞ ﻣﻊ ﺍﳌﺘﻐﲑﺍﺕ ﻟﺘﺒﲔ ﺃﻥ ﺗﻠﻚ ﺍﳌﺘﻐﲑﺍﺕ ﺍﻓﺘﺮﺍﺿﻴﺔ ﺃﻱ ﻃﺒﻴﻌﻴﺔ ﻭ ﻟﻴﺴﺖ ﺳﺎﻛﻨﺔ ،staticﻣﺜﺎﻝ: >#include<stdio.h )(void Func { ;static int Static = 0 ;auto int Auto = 0 ;)printf("Static = %d\n", Static++ printf("Auto ;)= %d\n", Auto++ 1 2 3 4 5 6 7 8 9 171 } )(main { ;int i = 0 {)while(i<=3 ;)(Func ;i++ } ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٩ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ auto } 10 11 12 13 14 15 16 17 18 19 20 ﻭ ﳝﻜﻦ ﻛﺘﺎﺑﺔ ﺍﳌﺘﻐﲑ Autoﺑﺪﻭﻥ ﺍﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ .auto ٢,٩,١٠,٥ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ :register ﺃﻳﻀﺎ ﺗﺴﺘﻌﻤﻞ ﻣﻊ ﺍﳌﺘﻐﲑﺍﺕ ﺍﻟﻌﺪﺩﻳﺔ ،ﻭ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻣﻊ ﻣﺼﻔﻮﻓﺎﺕ ﺃﻭ ﺑﻨﻴﺎﺕ ﺃﻭ ﻣﺘﻐﲑﺍﺕ ﺧﺎﺭﺟﻴﺔ ﺃﻭ ﻣـﺘﻐﲑﺍﺕ ﺳﺎﻛﻨﺔ ،ﺍﺳﺘﻌﻤﺎﻝ ﻣﺘﻐﲑﺍﺕ ﺎ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ registerﺗﻌﲏ ﻭﺿﻊ ﺗﻠﻚ ﺍﳌﺘﻐﲑﺍﺕ ﰲ ﺳﺠﻞ ﺍﳊﺎﺳـﻮﺏ ،ﻭ ﺳـﺠﻞ ﺍﳊﺎﺳﻮﺏ ﻣﻮﺟﻮﺩ ﰲ ﻭﺣﺪﺓ ﺍﳌﻌﺎﳉﺔ ﺍﳌﺮﻛﺰﻳﺔ ،(Central Processing Unit) CPUﻣﺜﺎﻝ: >#include<stdio.h )(main { ;register Reg_Var = 4 ;)printf("Reg_Var = %d\n", Reg_Var ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٣٠ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ } 1 2 3 4 5 6 7 8 register ﻭ ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻹﺩﺧﺎﻝ ﳌﺘﻐﲑﺍﺕ ﺍﻟﺴﺠﻞ. ٢,٩,١١ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ :sizeof ﺗﺴﺘﻌﻤﻞ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ sizeofﳌﻌﺮﻓﺔ ﺃﺣﺠﺎﻡ ﺍﻟﺒﻴﺎﻧﺎﺕ ،ﻭ ﻣﻨﻬﺎ ﳝﻜﻦ ﻣﻌﺮﻓﺔ ﺍﳊﺠﻢ ﺍﻟﻜﺎﻣﻞ ﺍﳌﺴﺘﻌﻤﻞ ﻟﱪﺍﻣﺞ ،ﺗﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﺑﺎﻟﺒﺎﻳﺖ ،bytesﻣﺜﺎﻝ ﳌﻌﺮﻓﺔ ﺃﺣﺠﺎﻡ ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ: >#include<stdio.h )(main { ;]int SizeOfArray[800 1 2 3 4 5 6 7 172 printf("short ;))= %d Byte(s)\n", sizeof(short printf("int ;))= %d Byte(s)\n", sizeof(int printf("unsigned ;))= %d Byte(s)\n", sizeof(unsigned printf("signed ;))= %d Byte(s)\n", sizeof(signed printf("long ;))= %d Byte(s)\n", sizeof(long printf("float ;))= %d Byte(s)\n", sizeof(float printf("double ;))= %d Byte(s)\n", sizeof(double ;))printf("SizeOfArray = %d Byte(s)\n", sizeof(SizeOfArray ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٣١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ } 8 9 10 11 12 13 14 15 16 sizeof ﻭﻫﻨﺎ ﺳﺘﺘﻌﺮﻑ ﻋﻠﻰ ﺃﺣﺠﺎﻡ ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ ﺍﻟﱵ ﺗﺮﻳﺪﻫﺎ ،ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻣﻌﺮﻓﺔ ﺣﺠﻢ ﻣﺼﻔﻮﻓﺔ ﻛﻤﺎ ﰲ ﺍﳌﺜﺎﻝ. ٢,٩,١٢ﺍﺳﺘﺪﻋﺎﺀ ﺩﺍﻟﺔ ﻟﻨﻔﺴﻬﺎ: ﳝﻜﻨﻨﺎ ﺇﺿﺎﻓﺔ ﻫﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ﺇﱃ ﺍﻟﺘﻜﺮﺍﺭ ،ﺣﻴﺚ ﻧﺴﺘﺪﻋﻲ ﺩﺍﻟﺔ ﻣﻦ ﻧﻔﺴﻬﺎ ،ﺇﻥ ﱂ ﺗﻜﻮﻥ ﺷﺮﻭﻁ ﰲ ﺍﻟﺪﺍﻟﺔ ﻓﺴﺘﻜﻮﻥ ﺍﻟﺪﺍﻟـﺔ ﺑﻼ ﺎﻳﺔ ،ﻣﺜﺎﻝ: >#include <stdio.h )void Func(int num { ;)printf("%d\n", num ;)Func(num+1 } ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٣٢ﺍﺳﺘﺪﻋﺎﺀ ﺩﺍﻟﺔ ﻟﻨﻔﺴﻬﺎ )(main { ;)Func(5 } 1 2 3 4 5 6 7 8 9 10 11 12 ﻫﻨﺎ ﺍﺳﺘﺪﻋﻴﻨﺎ ﺍﻟﺪﺍﻟﺔ ﻟﻨﻔﺴﻬﺎ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ،ﻭ ﰲ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﺳﻴﺘﻢ ﺍﻟﺘﻜﺮﺍﺭ ﺇﱃ ﺃﻥ ﻳﺼﻞ ﺇﱃ ﺍﳊﺪ ﺍﻷﻗﺼﻰ ﻣﻦ ﺍﻟﻘـﻴﻢ ﺍﻟﱵ ﳝﻜﻦ ﺃﻥ ﳛﻤﻠﻬﺎ ﻧﻮﻉ ﺍﳌﺘﻐﲑ ،ﻭ ﻫﺎ ﺳﻴﺘﻮﻗﻒ ﺍﻟﱪﻧﺎﻣﺞ ﻋﻨﺪ ﺍﻟﺮﻗﻢ ٦٥٥٣٥ﻷﻧﻪ ﺍﻟﻌﺪﺩ ﺍﻷﻗﺼﻰ ﺍﻟﺬﻱ ﳝﻜﻦ ﺃﻥ ﳛﻤﻠـﻪ ﺍﳌﺘﻐﲑ ،int numﻟﻨﺠﻌﻞ ﺍﻟﺪﺍﻟﺔ ﺗﻘﻮﻡ ﺑﺘﻜﺮﺍﺭ ﳏﺪﻭﺩ ﻧﺴﺘﻌﻤﻞ ﺷﺮﻁ ﻣﺜﻞ ﺍﻟﺘﺎﱄ: >#include <stdio.h )void Func(int num { )if(num <= 10 { ;)printf("%d\n", num ;)Func(num+1 } } 1 2 3 4 5 6 7 8 9 10 11 173 )(main { ;)Func(5 } ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٣٣ﺍﺳﺘﺪﻋﺎﺀ ﺩﺍﻟﺔ ﻟﻨﻔﺴﻬﺎ )(٢ ﻫﻨﺎ ﺳﻴﻘﻮﻡ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺎﻟﺘﻜﺮﺍﺭ ﻣﻦ ﺍﻟﻌﺪﺩ ٥ﺇﱃ ﺍﻟﻌﺪﺩ .١٠ 12 13 14 15 ٢,٩,١٣ﺍﻟﺘﺤﻜﻢ ﰲ ﻃﺒﺎﻋﺔ ﺍﻟﻨﺘﺎﺋﺞ: ﰲ ﺍﻟﺪﺍﻟﺔ ،printfﳝﻜﻨﻨﺎ ﺍﻟﺘﺤﻜﻢ ﰲ ﻃﺮﻳﻘﺔ ﻃﺒﻊ ﺍﻟﻨﺘﺎﺋﺞ ،ﺳﻮﺍﺀ ﻛﺎﻧﺖ ﺍﻟﻨﺘﺎﺋﺞ ﻋﺒﺎﺭﺓ ﻋﻦ ﺃﺭﻗﺎﻡ ﺃﻭ ﺣﺮﻭﻑ ،ﻓﻤﺜﻼ ﺇﺫﺍ ﻛﺎﻥ ﻟﺪﻳﻨﺎ ﻋﺪﺩ ﺣﻘﻴﻘﻲ ﻟﻪ ﺃﺭﺑﻌﺔ ﺃﺭﻗﺎﻡ ﻭﺭﺍﺀ ﺍﻟﻔﺎﺻﻠﺔ ﻭ ﻻ ﻧﺮﻳﺪ ﻃﺒﺎﻋﺔ ﺇﻻ ﺇﺛﻨﲔ ﻣﻨﻬﺎ ﻧﺴﺘﻌﻤﻞ ﺍﻟﻄﺮﻕ ﺍﻟﺘﺎﻟﻴﺔ: >#include<stdio.h {)][main(int argc, char *argv ;"!char str[] = "Hello, World ;float flt = 3.1415F /*String*/ ;)printf("%s\n", str ;)printf("%5s\n", str ;)printf("%-5s\n", str ;)printf("%5.5s\n", str ;)printf("%-5.5s\n", str ;)"printf("\n /*Float number*/ ;)printf("%10.0f\n", flt ;)printf("%.1f\n", flt ;)printf("%.2f\n", flt ;)printf("%.3f\n", flt ;)printf("%.4f\n", flt ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٣٤ﻃﺮﻳﻘﺔ ﺍﻟﺘﺤﻜﻢ ﰲ ﻃﺒﺎﻋﺔ ﺍﻟﻨﺘﺎﺋﺞ ﺟﺮﺏ ﻛﻞ ﻭﺍﺣﺪﺓ ﻣﻦ ﺍﻟﻄﺮﻕ ﺍﻟﺴﺎﺑﻘﺔ ﺣﱴ ﺗﺴﺘﻨﺘﺞ ﻛﻞ ﻃﺮﻳﻘﺔ ﻭ ﻓﺎﺋﺪﺎ. ٢,٩,١٤ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: ﻻ ﺗﻮﺟﺪ ﺃﺧﻄﺎﺀ ﳏﺘﻤﻠﺔ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ. ٢,٩,١٥ﲤﺎﺭﻳﻦ: } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 174 .١ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﻳﻘﻮﻡ ﺑﺎﻟﺘﺤﻮﻳﻞ ﻣﻦ ﺍﻟﻨﻈﺎﻡ ﺍﻟﻌﺸﺮﻱ ﺇﱃ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺴﺪﺍﺳﻲ ﻋﺸﺮ. ٣,١ﺍﳊﺴﺎﺏ .............................................................................. Enumeration ٣,٢ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ .................................................... Command-line Arguments ٣,٣ﺍﻟﺘﻮﺟﻴﻬﺎﺕ )............................................................... Directives(Preprocessor ٣,٤ﺩﻭﺍﻝ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ ........................................................................ ٣,٥ﺍﳌﻜﺘﺒﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ................................................................... Standard Library ﻣﻘﺪﻣﺔ :ﺎﻳﺔ ﺍﳌﻄﺎﻑ ،ﻫﻨﺎ ﺳﻨﻨﻬﻲ ﻃﺮﻳﻘﻨﺎ ﰲ ﻟﻐﺔ ،Cﱂ ﻳﺒﻘﻰ ﺇﱃ ﺃﺷﻴﺎﺀ ﺻﻐﲑﺓ )ﻭ ﻻ ﺃﻗﻮﻝ ﺑﺴﻴﻄﺔ( ﳍﺎ ﺍﻟﻔﺼﻞ ،ﻭ ﻣـﺎ ﺟﻌﻠﻪ ﻳﻜﻮﻥ ﻃﻮﻳﻼ ﻫﻮ ﺍﳌﻜﺘﺒﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ﻟﻜﺜﺮﺓ ﺩﻭﺍﳍﺎ. ﺑﺎﻟﺘﻮﻓﻴﻖ ﺇﻥ ﺷﺎﺀ ﺍﷲ ﻗﺎﻝ ﺍﷲ ﺗﻌﺎﱃ: ﴿ ﻗﻞ ﻫﻞ ﻳﺴﺘﻮﻱ ﺍﻟﺬﻳﻦ ﻳﻌﻠﻤﻮﻥ ﻭ ﺍﻟﺬﻳﻦ ﻻ ﻳﻌﻠﻤﻮﻥ ﴾ ﺻﺪﻕ ﺍﷲ ﺗﻌﺎﱃ 176 ﺍﳊﺴﺎﺏ ) (Enumerationﻫﻮ ﳎﻤﻮﻋﺔ ﻣﻦ ﺛﻮﺍﺑﺖ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ،intﻭ ﻳﺘﻢ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ enumﻭ ﺍﻟﱵ ﻫﻲ ﳐﺘﺼﺮﺓ ﻣﻦ ،enumerationﻭ ﻫﻲ ﻣﺸﺎﺎ ﻟﻠﺒﻨﻴﺔ ﰲ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ ﻭ ﻃﺮﻳﻘﺔ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻬﺎ .ﻭ ﻫﺬﻩ ﺻﻮﺭﺓ ﺗﻮﺿﻴﺤﻴﺔ ﻟﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﳊﺴﺎﺑﺎﺕ: ﺍﻟﺸﻜﻞ :٣,١,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﳊﺴﺎﺏ ٣,١,١ﺍﺳﻢ ﺍﳊﺴﺎﺏ :Enumeration Name ﻻﺳﻢ ﺍﳊﺴﺎﺏ ﺷﺮﻭﻁ ﻫﻲ ﻧﻔﺴﻬﺎ ﺍﻟﺸﺮﻭﻁ ﺍﻟﺴﺎﺑﻘﺔ ﻟﻠﻤﺘﻐﲑﺍﺕ ،ﺍﻟﺒﻨﻴﺎﺕ ﻭ ﺍﻟﺪﻭﺍﻝ ،ﻭ ﺍﻟﺸﺮﻭﻁ ﻫﻲ: § ﺃﻥ ﻻ ﻳﺘﺠﺎﻭﺯ ﺍﺳﻢ ﺍﳊﺴﺎﺏ ﺃﻛﺜﺮ ﻣﻦ ٣١ﺣﺮﻑ. § ﺃﻥ ﻻ ﻳﺒﺪﺃ ﺍﺳﻢ ﺍﳊﺴﺎﺏ ﺑﺄﺭﻗﺎﻡ. § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳊﺴﺎﺏ ﳛﺘﻮﻱ ﻋﻠﻰ ﻣﺆﺛﺮﺍﺕ ﻣﺜﻞ ﺍﳉﻤﻊ ﻭ ﺍﻟﻄﺮﺡ ﻭ.... § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳊﺴﺎﺏ ﳛﺘﻮﻱ ﻋﻠﻰ ﺭﻣﻮﺯ ﻣﺜﻞ %ﻭ #ﻭ { ﻭ)...ﺑﺎﺳﺘﺜﻨﺎﺀ ﺍﻟﺮﻣﺰ _(. § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳊﺴﺎﺏ ﻣﺴﺘﻌﻤﻞ ﺳﺎﺑﻘﺎ ﻻﺳﻢ ﺩﺍﻟﺔ ،ﻣﺘﻐﲑ ،ﺑﻨﻴﺔ ﺃﻭ ﺣﺴﺎﺏ ﺁﺧﺮ. § ﺃﻥ ﻻ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳊﺴﺎﺏ ﻣﻦ ﺃﺣﺪ ﺃﲰﺎﺀ ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ. ٣,١,٢ﺛﻮﺍﺑﺖ ﺍﳊﺴﺎﺏ: 177 ﺇﺫﺍ ﱂ. ﻭ ﻳﺘﻢ ﺍﻟﻔﺼﻞ ﺑﲔ ﺛﻮﺍﺑﺖ ﻭ ﺁﺧﺮ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﻟﻔﺎﺻﻠﺔ،ﺛﻮﺍﺑﺖ ﺍﳊﺴﺎﺏ ﳝﻜﻦ ﺃﻥ ﲢﻤﻴﻞ ﻗﻴﻢ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ﻓﻘﻂ ﳓﺪﺩ ﻟﺘﻠﻚ ﺍﻟﺜﻮﺍﺑﺖ ﻗﻴﻢ ﻓﺴﻴﺘﻢ ﺇﻋﻄﺎﺀﻫﺎ ﻗﻴﻢ ﺇﻓﺘﺮﺍﺿﻴﺔ ﻣﺘﺴﻠﺴﻠﺔ ﺗﺒﺪﺃ ﻣﻦ ﺍﻟﺼﻔﺮ ﻟﻠﺜﺎﺑﺖ ﺍﻷﻭﻝ ﰒ ﺗﺘﺰﺍﻳـﺪ ﺣـﺴﺐ ﻋـﺪﺩ : ﻭ ﻫﻮenum ﺳﻨﻘﻮﻡ ﺍﻵﻥ ﺑﻜﺘﺎﺑﺔ ﺃﺑﺴﻂ ﻣﺜﺎﻝ ﻟﻜﻴﻔﻴﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ.ﺍﻟﺜﻮﺍﺑﺖ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #include<stdio.h> enum _COLOR { RED = 0, BLUE, GREEN }; main() { enum _COLOR Color; /*Color = RED;*/ Color = BLUE; /*Color = GREEN;*/ if(Color == RED){ printf("Color = %d\n", Color); }else if(Color == BLUE){ printf("Color = %d\n", Color); }else if(Color == GREEN){ printf("Color = %d\n", Color); }else printf("Error!\n"); } enum ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ:٣,١,١ ﺍﻟﱪﻧﺎﻣﺞ :ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻛﺘﺎﺑﺔ ﺍﳌﺜﺎﻝ ﺑﺎﻟﻄﺮﻳﻘﺔ ﺍﻟﺘﺎﻟﻴﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include<stdio.h> enum _COLOR { RED = 0, BLUE, GREEN }Color; main() { /*Color = RED;*/ Color = BLUE; /*Color = GREEN;*/ if(Color == RED){ printf("Color = %d\n", Color); }else if(Color == BLUE){ 178 ;)printf("Color = %d\n", Color {)}else if(Color == GREEN ;)printf("Color = %d\n", Color }else ;)"printf("Error!\n } ﺍﻟﱪﻧﺎﻣﺞ :٣,١,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ (٢) enum 19 20 21 22 23 24 ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﺇﻋﻄﺎﺀ ﺍﻟﻘﻴﻤﺔ ﺍﳌﺨﺘﺎﺭ ﻣﺒﺎﺷﺮﺓ ﻋﻨﺪ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﻌﺮﻑ ﻟﻠﺤﺴﺎﺏ _COLORﻣﺜﻞ ﻛﺘﺎﺑﺔ: ;enum _COLOR Color = BLUE ﺃﻭ ﻛﺘﺎﺑﺔ: enum _COLOR { RED = 0, BLUE, GREEN ;}Color = BLUE ﺳﻨﺸﺮﺡ ﺍﻵﻥ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﻣﻊ ﺍﻟﻘﻠﻴﻞ ﻣﻦ ﺍﻟﺘﻔﺎﺻﻴﻞ .ﻗﻠﻨﺎ ﺳﺎﺑﻘﺎ ﺃﻧﻪ ﻋﻨﺪ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ enumﺎ ﻗﻴﻢ ﻓﻬﺬﺍ ﻳﻌﲏ ﺃﻥ ﺗﻠﻚ ﺍﻟﻘﻴﻢ ﺛﺎﺑﺘﺔ ﻭ ﻻ ﳝﻜﻦ ﺍﻟﺘﻐﲑ ﻓﻴﻬﺎ ،ﻭ ﳝﻜﻦ ﺗﺴﻤﻴﺔ ﺃﻋﻀﺎﺀ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ enumﺑﺜﻮﺍﺑـﺖ .ﻭ ﺛﻮﺍﺑـﺖ ﺍﻟﻜﻠﻤـﺔ ﺍﶈﺠﻮﺯﺓ enumﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺃﲰﺎﺀﻫﺎ ﺑﺪﻭﻥ ﻛﺘﺎﺑﺔ ﻧﻮﻋﻬﺎ ،ﺣﻴﺚ ﻗﻠﻨﺎ ﺳﺎﺑﻘﺎ ﺃﻥ ﻧﻮﻋﻬﺎ ﻫﻮ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ .int ﺃﻋﻄﻴﻨﺎ ﻟﺜﺎﺑﺖ REDﺍﻟﻘﻴﻤﺔ 0ﻭ ﻫﺬﺍ ﻳﻌﲏ ﺃﻥ ﺍﻟﺜﺎﺑﺖ BLUEﻳﺴﺎﻭﻱ ١ﻭ ﺍﻟﺜﺎﺑﺖ GREENﻳﺴﺎﻭﻱ .٢ﻭ ﳝﻜﻦ ﺃﻥ ﻻ ﻧﻌﻄـﻲ ﻟﻠﺜﺎﺑﺖ REDﺍﻟﻘﻴﻤﺔ ،٠ﻷﻧﻪ ﻳﺘﻢ ﺇﻋﻄﺎﺀﻩ ﺍﻟﻘﻴﻤﺔ ٠ﺗﻠﻘﺎﺋﻴﺎ ﺇﻥ ﱂ ﺗﻜﻦ ﻟﺪﻳﻪ ﻗﻴﻤﺔ ﺳﺎﺑﻘﺔ. ﺃﻣﺎ ﺇﺫﺍ ﺃﻋﻄﻴﻨﺎ ﻟﺜﺎﺑﺖ BLUEﺍﻟﻘﻴﻤﺔ ٠ﻓﻬﻨﺎ ﺳﺘﺼﺒﺢ ﲨﻴﻊ ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﺴﺎﺑﻘﺔ ﲢﻤﻞ ﺍﻟﻘﻴﻤﺔ ٠ﺇﻥ ﱂ ﺗﻜﻦ ﻟﺪﻳﻬﺎ ﻗﻴﻢ ،ﻭ ﻫﺬﺍ ﻳﻌﲏ ﺃﻥ ﺍﻟﺜﺎﺑﺖ REDﺳﻴﺤﻤﻞ ﺍﻟﻘﻴﻤﺔ ٠ﻭ ﺍﻟﺜﺎﺑﺖ BLUEﺃﻳﻀﺎ ﳛﻤﻞ ﺍﻟﻘﻴﻤﺔ ٠ﺃﻣﺎ ﺍﻟﺜﺎﺑﺖ GREENﻓﺴﻴﺤﻤﻞ ﺍﻟﻘﻴﻤﺔ .١ﻭ ﳝﻜﻦ ﺃﻥ ﻧﻌﻄﻲ ﺃﻛﺜﺮ ﻣﻦ ﻣﻌﺮﻑ ﻟﻠﺤﺴﺎﺑﺎﺕ ﻣﺜﻞ ﺍﻟﺒﻨﻴﺎﺕ ،ﻣﺜﺎﻝ: >#include<stdio.h enum _COLOR { RED = 0, BLUE, GREEN ;} )(main { 1 2 3 4 5 6 7 8 9 10 11 179 12 13 14 15 enum _COLOR cRed = RED, cBlue = BLUE, cGreen = GREEN; } (٣) enum ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ:٣,١,٣ ﺍﻟﱪﻧﺎﻣﺞ :ﺃﻭ ﺍﻹﻋﻼﻥ ﻋﻨﻬﺎ ﻣﺒﺎﺷﺮﺓ ﺑﻌﺪ ﺍﳊﺴﺎﺏ ﻣﺜﻞ 1 2 3 4 5 6 7 8 9 10 11 12 13 #include<stdio.h> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include<stdio.h> 1 2 3 #include<stdio.h> enum _COLOR { RED = 0, BLUE, GREEN }cRed = RED, cBlue = BLUE, cGreen = GREEN; main() { } (٤) enum ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ:٣,١,٤ ﺍﻟﱪﻧﺎﻣﺞ :ﻭ ﺗﻮﺟﺪ ﻃﺮﻕ ﺃﺧﺮﻯ ﻛﺜﲑﺓ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻣﻊ ﺍﳊﺴﺎﺑﺎﺕ ﻣﻨﻬﺎ ﺇﻋﻄﺎﺀ ﳌﺘﻐﲑ ﻗﻴﻤﺔ ﺣﺴﺎﺏ ﻣﺜﻞ enum _NUMBER { Num = 10, Num2 = 20 }; main() { enum _NUMBER Number = Num; int i = 0; printf("i i = Number; = %d\n", i); printf("Number = %d\n", Number); printf("i = %d\n", i); } enum _COLOR (٥) enum ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ:٣,١,٥ ﺍﻟﱪﻧﺎﻣﺞ :ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻹﺩﺧﺎﻝ ﻋﻠﻰ ﺍﳊﺴﺎﺏ ﻣﺜﻞ 180 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 { }; BLACK, WHITE, RED, GREEN, BLUE main() { enum _COLOR Color; printf("colors:\n"); printf("0)BLACK\n1)WHITE\n2)RED\n3)GREEN\n4)BLUE\n"); printf("choose a color:"); scanf("%d", &Color); if(Color == BLACK){ printf("Your choice }else if(Color == WHITE){ printf("Your choice }else if(Color == RED){ printf("Your choice }else if(Color == GREEN){ printf("Your choice }else if(Color == BLUE){ printf("Your choice } } are Black\n"); are White\n"); are Red\n"); are Green\n"); are Blue\n"); (٦) enum ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ:٣,١,٦ ﺍﻟﱪﻧﺎﻣﺞ : ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ٣,١,٣ : ﻻ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻝ ﺍﺳﻢ ﺍﳊﺴﺎﺏ ﻣﺒﺎﺷﺮﺓ ﻣﺜﻞ.١ 1 2 3 4 5 6 7 8 9 10 11 12 #include<stdio.h> enum _NUMBER { Zero, One }; main() { enum _NUMBER = ZERO; } ١ ﺍﳋﻄﺄ:٣,١,٧ ﺍﻟﱪﻧﺎﻣﺞ . ﻻ ﳝﻜﻦ ﺍﻹﻋﻼﻥ ﻋﻦ ﺣﺴﺎﺑﲔ ﻣﻦ ﻧﻔﺲ ﺍﻻﺳﻢ.٢ : ﲤﺎﺭﻳﻦ٣,١,٤ 181 .١ﺃﻛﺘﺐ ﺑﺮﻧﺎﻣﺞ ﺑﻪ ﺣﺴﺎﺏ ﺑﺎﺳﻢ _POWERﺑﻪ ﺛﺎﺑﺘﲔ ،ﺍﻷﻭﻝ ﺑﺎﺳﻢ Offﻭ ﺍﻟﺜﺎﱐ ﺑﺎﺳﻢ ،Onﰒ ﻗﻢ ﺑﺎﺳﺘﺨﺪﺍﻡ ﻣﻌﺮﻓﺔ ﻟﻠﺤﺴﺎﺏ _POWERﺑﺎﺳﻢ Powerﻭ ﺍﺳﺘﻌﻤﻠﻬﺎ ﻟﻺﺩﺧﺎﻝ ﻣﺒﺎﺷﺮﺓ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﺍﻟﺔ ،scanfﻓﺈﺫﺍ ﻛﺎﻧﺖ ﺍﻟﻨﺘﻴﺠـﺔ ﺍﳌﺪﺧﻞ ٠ﺃﻱ Offﻓﺴﻴﺘﻢ ﺍﳋﺮﻭﺝ ﻣﻦ ﺍﻟﱪﻧﺎﻣﺞ ،ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﻟﻌﻜﺲ ﺃﻱ (On) ١ﻓﺴﻴﺒﻘﻰ ﺍﻟﱪﻧﺎﻣﺞ ﻳﺴﺘﻤﺮ ﺣﱴ ﺗﺼﺒﺢ ﺍﻟﻘﻴﻤﺔ ﺍﳌﺪﺧﻠﺔ ﻟﻠﺤﺴﺎﺏ Powerﻫﻲ .٠ 182 ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﳐﺘﻠﻔﺔ ﻋﻦ ﻏﲑﻫﺎ ﻣﻦ ﺍﻟﻮﺳﺎﺋﻂ ،ﺣﻴﺚ ﳝﻜﻦ ﺇﻋﺘﺒﺎﺭﻫﺎ ﻛﻮﺳﺎﺋﻂ ﻟﻠﱪﻧﺎﻣﺞ .ﻭ ﻣﺜﺎﻝ ﻋﻠﻰ ﺫﻟﻚ ﺍﻷﻭﺍﻣﺮ ﺍﻟﱵ ﻳﺘﻢ ﺇﺳﺘﺪﻋﺎﺀﻫﺎ ﰲ ﻧﻈﺎﻡ DOSﻣﺜﻼ ،ﺑﻌﺾ ﻣﻦ ﻫﺬﻩ ﺍﻷﻭﺍﻣﺮ ﲢﺘﺎﺝ ﺇﱃ ﻭﺳﺎﺋﻂ ﻣﺜﻞ ﺍﻷﻣﺮ delﻭ ﺍﻟـﺬﻱ ﻳﻘـﻮﻡ ﲝﺬﻑ ﻣﻠﻒ ،ﻭ ﻣﻦ ﻭﺳﺎﺋﻄﻪ ﻫﻲ ﺇﺳﻢ ﺍﳌﻠﻒ ﺍﻟﺬﻱ ﺳﻴﺘﻢ ﺣﺬﻓﻪ ،ﻭ ﺑﻌﺾ ﺍﻟﻮﺳﺎﺋﻂ ﺧﻴﺎﺭﺍﻳﺔ ﻣﺜﻞ ﺍﳋﻴﺎﺭ /pﻭ /sﻣﺜﻼ. ٣,٢,١ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ: ﺃﻭ ﲟﺎ ﻳﻌﺮﻑ ﺑـ argcﺇﺧﺘﺼﺎﺭ ﻟـ argument countﺃﻱ ﻋﺪﺍﺩ ،ﻭ ﻫﻮ ﻣﻌﺮﻑ ﻋﻠﻰ ﺷﻜﻞ ﻣﺘﻐﲑ ﻣﻦ ﻧـﻮﻉ ﺍﻷﻋـﺪﺍﺩ ﺍﻟﺼﺤﻴﺤﺔ ،ﻭ ﰲ ﻫﺬﺍ ﺍﻟﻮﺳﻴﻂ ﻳﻜﻮﻥ ﺑﻪ ﻋﺪﺩ ﻭﺳﺎﺋﻂ ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﱵ ﰎ ﺇﺩﺧﺎﳍﺎ ،ﻭ ﺗﻜﻮﻥ ﻗﻴﻤﺔ ﻫﺬﺍ ﺍﳌﺘﻐﲑ ١ﻭ ﻫﻲ ﻹﺳـﻢ ﺍﻟﱪﻧﺎﻣﺞ .ﻭ ﻣﺜﺎﻝ ﻋﻠﻰ ﺫﻟﻚ ﻧﺄﺧﺬ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ﻭ ﺍﻟﺬﻱ ﻫﻮ ﺍﻷﻣﺮ ،delﻭ ﻧﻜﺘﺐ ﻣﺜﻼ ،del filename.ext /pﻫﻨﺎ ﺳﺘﻜﻮﻥ ﻗﻴﻤﺔ ﺍﳌﺘﻐﲑ argcﻫﻲ ﺛﻼﺛﺔ ،ﺍﻷﻭﱃ ﻫﻲ ﺇﺳﻢ ﻭ ﻣﺴﺎﺭ ﺍﻟﱪﻧﺎﻣﺞ ،delﻭ ﺍﻟﺜﺎﻧﻴﺔ ﻫﻲ ﺍﺳﻢ ﺍﳌﻠﻒ ،filename.extﻭ ﺍﻟﻘﻴﻤﺔ ﺍﻟﺜﺎﻟﺜﺔ ﻟﻠﺨﻴﺎﺭ ،/pﻭ ﻣﻦ ﻫﺬﺍ ﺍﳌﺜﺎﻝ ﻧﺴﺘﻨﺘﺞ ﺃﻥ ﺍﳌﺘﻐﲑ argcﻳﻘﻮﻡ ﲝﺴﺎﺏ ﻭﺳﺎﺋﻂ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺎﻹﻋﺘﻤﺎﺩ ﻋﻠﻰ ﺍﻟﻔﺮﺍﻏﺎﺕ )ﺃﻱ ﺍﻟﻔـﺼﻞ ﺑﲔ ﺧﻴﺎﺭ ﻭ ﺁﺧﺮ ﲟﺴﺎﺣﺔ( .ﻣﺜﺎﻝ ﺗﻄﺒﻴﻘﻲ: >#include<stdio.h )main(int argc { ;)printf("Program have %d argument(s).\n", argc } ﺍﻟﱪﻧﺎﻣﺞ :٣,٢,١ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﱃ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ 1 2 3 4 5 6 ﻭ ﻫﻨﺎ ﻗﻢ ﲝﻔﻆ ﺍﻟﱪﻧﺎﻣﺞ ﺑﺎﺳﻢ test.cﰒ ﻗﻢ ﺑﺈﻧﺸﺎﺀ ﺍﳌﻠﻒ ﺍﻟﺘﻨﻔﻴﺬﻱ ﻟﻪ ﻭ ﻣﻦ ﻣﻨﻔﺬ ﺍﻷﻭﺍﻣﺮ ﻗﻢ ﺑﺘﻨﻔﻴﺬ ﺍﻟﱪﻧﺎﻣﺞ ﻋﻠﻰ ﺍﻟﺸﻜﻞ: test this_is_the_first_argument and_this_is_the_second_argument ﻭ ﻧﺎﺗﺞ ﻫﺬﻩ ﺍﻟﱪﻧﺎﻣﺞ ﻳﻜﻮﻥ ﻋﻠﻰ ﺍﻟﺸﻜﻞ: Program have 3 argument(s). ﺛﻼﺛﺔ ﻭﺳﺎﺋﻂ ،ﻷﻧﻪ ﻭ ﻛﻤﺎ ﻗﻠﻨﺎ ﺃﻥ ﺍﺳﻢ ﻭ ﻣﺴﺎﺭ ﺍﻟﱪﻧﺎﻣﺞ ﺃﻳﻀﺎ ﻳﺘﻢ ﺇﺿﺎﻓﺘﻪ ،ﻭ ﺇﺫﺍ ﻛﻨﺖ ﺗﺮﻳﺪ ﻋﺪﺩ ﺍﻟﻮﺳﺎﺋﻂ ﻓﻘﻂ ﻓﻴﻤﻜﻨﻚ ﻛﺘﺎﺑﺔ .argc-1ﻭ ﻫﻨﺎ ﺍﳌﺘﻐﲑ argcﳝﻜﻦ ﺇﻋﻄﺎﺀﻩ ﺇﺳﻢ ﺁﺧﺮ ،ﻷﻥ ﺍﳌﺘﺮﺟﻢ ﻳﺄﺧﺬﻫﺎ ﻋﻠﻰ ﺷﻜﻞ ﻭﺳﺎﺋﻂ ﻭ ﻟﻴﺲ ﺃﲰـﺎﺀ ،ﻭ ﻟﻜﻦ ﺑﻌﺾ ﺍﳌﺘﺮﲨﺎﺕ ﺗﺄﺧﺬ ﻫﺬﻩ ﺍﻟﻮﺳﺎﺋﻂ ﻋﻠﻰ ﺷﻜﻞ ﺃﲰﺎﺀ ،ﺃﻱ ﺃﳕﻪ ﻻ ﳝﻜﻦ ﺍﻟﺘﻐﲑ ﰲ ﺍﻹﺳﻢ .argc 183 ٣,٢,٢ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ: ﺇﱃ ﺍﻵﻥ ﻋﺮﻓﻨﺎ ﻋﺪﺩ ﺍﻟﻮﺳﺎﺋﻂ ﺍﳌﺪﺧﻞ ﻟﱪﻧﺎﳎﻨﺎ ،ﻭ ﻟﻜﻦ ﻛﻴﻒ ﳝﻜﻨﻨﺎ ﺃﻥ ﻧﺮﻯ ﺗﻠﻚ ﺍﻟﻮﺳﺎﺋﻂ ،ﺃﻱ ﺍﻟﻘﻴﻢ ﺍﻟﱵ ﺎ ،ﺫﻟـﻚ ﻳﻜﻮﻥ ﻋﱪ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ﺃﻱ ﲟﺎ ﻳﻌﺮﻑ ﺑـ argvﺇﺧﺘﺼﺎﺭ ﻟـ ،argument vectorﺣﻴﺚ ﻳﻜﻮﻥ ﻋﺒﺎﺭﺓ ﻋﻦ ﻣﺼﻔﻮﻓﺎﺕ ،ﻛﻞ ﻣﺼﻔﻮﻓﺔ ﺗﺄﺧﺬ ﻭﺳﻴﻂ ،ﻣﺜﺎﻝ: >#include<stdio.h )][main(int argc, char *argv { ;int i ;)printf("Program have %d argument(s).\n", argc )for(i=0;i<argc;i++ ;)]printf("argv[%d]= %s\n", i, argv[i } ﺍﻟﱪﻧﺎﻣﺞ :٣,٢,٢ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ 1 2 3 4 5 6 7 8 9 10 11 12 ﻣﺜﻞ ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻖ ،ﻧﻘﻮﻡ ﺑﺘﻨﻔﻴﺬ ﺍﻟﱪﻧﺎﻣﺞ ﻋﻠﻰ ﺍﻟﺸﻜﻞ: test this_is_the_first_argument and_this_is_the_second_argument ﻭ ﻧﺎﺗﺞ ﺍﻟﱪﻧﺎﻣﺞ ﻳﻜﻮﻥ ﻋﻠﻰ ﺍﻟﺸﻜﻞ ﺍﻟﺘﺎﱄ: have 3 argument(s): = C:\...\...\TEST.EXE = this_is_the_first_argument = this_is_the_second_argument Program ]argv[0 ]argv[1 ]argv[2 ﻫﺬﻩ ﳎﺮﺩ ﺃﻣﺜﻠﺔ ﻟﺘﺒﲔ ﻃﺮﻳﻘﺔ ﻋﻤﻞ ﻫﺬﻩ ﺍﻟﻮﺳﺎﺋﻂ ﻻ ﺃﻛﺜﺮ ،ﺃﻡ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻭ ﺍﻹﻋﺘﻤﺎﺩ ﻋﻠﻴﻬﺎ ﻓﻬﺬﺍ ﻣﺜﺎﻝ ﺷﺒﻪ ﻛﺎﻣﻞ: >#include<stdio.h >#include<conio.h )][main(int argc, char *argv { ;char ch {)if(argc<2 ;)"printf("Delete one or more files.\n\n ;)"printf("Usage: DEL FILENAME\n } {else 1 2 3 4 5 6 7 8 9 10 11 184 ;)]printf("Delete %s file, are you sure? (Y/N): ", argv[1 {)'if((ch=getche())=='y' || ch=='Y ;)]printf("\nDeleting %s...\n", argv[1 ;)]remove(argv[1 ;)]printf("%s deleted.\n", argv[1 } ﺍﻟﱪﻧﺎﻣﺞ :٣,٢,٣ﺑﺮﻧﺎﻣﺞ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ﻳﻘﻮﻡ ﲝﺬﻑ ﻣﻠﻔﺎﺕ } } 12 13 14 15 16 17 18 19 ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﻗﻤﻨﺎ ﺑﻌﻤﻞ ﺷﺮﻁ ﻭ ﻫﻮ ﺇﻥ ﻛﺎﻥ ﻋﺪﺩ ﻭﺳﺎﺋﻂ ﺍﻟﱪﻧﺎﻣﺞ ﺃﻗﻞ ﻣﻦ ،٢ﺃﻱ ﺃﻥ ﺍﻟﻮﺳﺎﺋﻂ ﺍﳌﻄﻠﻮﺑﺔ ﻏﲑ ﻣﺘﻮﻓﺮﺓ، ﰒ ﻧﻈﻬﺮ ﻟﻠﻤﺴﺘﺨﺪﻡ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﱪﻧﺎﻣﺞ .ﺇﺫﺍ ﻛﺎﻥ ﻋﺪﺩ ﻭﺳﺎﺋﻂ ﺍﻟﱪﻧﺎﻣﺞ ﺃﻛﺜﺮ ﻣﻦ ﺇﺛﻨﲔ ﻓﺈﻧﻨﺎ ﻧﻘﻮﻡ ﺑﻌﻤﻠﻴـﺔ ﺍﳊـﺬﻑ ﺣﻴﺚ ﻳﻜﻮﻥ ﺍﺳﻢ ﺍﳌﻠﻒ ﺍﳌﺮﺍﺩ ﺣﺬﻓﻪ ﰲ ﺍﻟﺴﻠﺴﻠﺔ ] argv[1ﺃﻱ ﺑﻌﺪ ﺳﻠﺴﻠﺔ ﺍﺳﻢ ﻭ ﻣﺴﺎﺭ ﺍﻟﱪﻧﺎﻣﺞ )].(argv[0 ٣,٢,٣ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: .١ﺗﺄﻛﺪ ﺩﺍﺋﻤﺎ ﺃﻥ ﺍﳌﺘﻐﲑ argcﲢﻤﻞ ﺍﻟﻘﻴﻤﺔ ١ﻋﻠﻰ ﺍﻷﻗﻞ ،ﻭ ﻫﻲ ﻹﺳﻢ ﻭ ﻣﺴﺎﺭ ﺍﻟﱪﻧﺎﻣﺞ. ٣,٢,٤ﲤﺎﺭﻳﻦ: ﻻ ﺗﻮﺟﺪ ﲤﺎﺭﻳﻦ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ. 185 ﺍﻟﺘﻮﺟﻴﻬﺎﺕ ﻫﻲ ﻋﺒﺎﺭﺓ ﻋﻦ ﺗﻌﻠﻴﻤﺎﺕ ﺧﺎﺹ ﺑﺎﳌﺘﺮﺟﻢ ﻳﺘﻢ ﺗﻨﻔﻴﺬﻫﺎ ﻗﺒﻞ ﺍﻟﺒﺪﺃ ﰲ ﺍﻟﺘﺮﲨﺔ ،ﻭ ﳝﻜﻦ ﲤﻴﺰﻫﺎ ﺩﺍﺋﻤﺎ ﺑﺎﻟﺮﻣﺰ ﰲ ﺑﺪﺍﻳﺔ ﺍﺳﻢ ﻛﻞ ﺗﻌﻠﻴﻤﺔ ،ﻭ ﻫﻲ ﻛﺜﲑﺓ ﻭ ﺳﻨﺘﺤﺪﺙ ﻋﻦ ﻛﻞ ﻣﻨﻬﺎ ﻣﻊ ﺍﻟﺒﻌﺾ ﻣﻦ ﺍﻟﺘﻔﺎﺻﻴﻞ. # ٣,٣,١ﺍﻟﺘﻮﺟﻴﻪ :#include ﻳﻌﺘﱪ ﻫﺬﺍ ﺍﻟﺘﻮﺟﻴﻪ ﻣﻦ ﺃﻫﻢ ﺍﻟﺘﻮﺟﻬﺎﺕ ،ﻭ ﻗﺪ ﻗﻤﻨﺎ ﺑﺎﺳﺘﻌﻤﻠﻪ ﻭ ﺩﺭﺍﺳﺘﻪ ﺳﺎﺑﻘﺎ ،ﻭ ﻫﻮ ﻳﻄﻠﺐ ﻣﻦ ﺍﳌﺘﺮﺟﻢ ﺑﻀﻢ ﳏﺘﻮﻳـﺎﺕ ﻣﻠﻔﺎﺕ ﺭﺃﺳﻴﺔ ﺇﱃ ﻣﺸﺮﻭﻋﻨﺎ ،ﺣﻴﺚ ﳝﻜﻦ ﺍﺳﺘﻌﻤﻞ ﺩﻭﺍﻝ ﻭ ﺛﻮﺍﺑﺖ ﺗﻠﻚ ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ﻣﻨﻬﺎ ﻣﺒﺎﺷﺮﺓ ﺑﺪﻭﻥ ﺇﻋﺎﺩﺓ ﻛﺘﺎﺑﺘﻬﺎ. ﻭ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﻠﻬﺎ ﻃﺮﻳﻘﺘﲔ ﳘﺎ: ﺍﻟﻄﺮﻳﻘﺔ ﺍﻷﻭﱃ ﻫﻲ ﺿﻢ ﻣﻠﻔﺎﺕ ﺭﺃﺳﻴﺔ ﺧﺎﺻﺔ ﺑﺎﳌﺘﺮﺟﻢ ،ﻭ ﻏﺎﻟﺒﺎ ﻣﺎ ﺗﻜﻮﻥ ﰲ ﳎﻠﺪ ﺑﺎﺳـﻢ ،includeﰲ ﻫـﺬﻩ ﺍﳊﺎﻟـﺔ ﻧﻜﺘﺐ: >#include<FileName.h ﻭ ﻫﻨﺎ ﻧﻜﺘﺐ ﺍﺳﻢ ﺍﳌﻠﻒ ﺍﻟﺬﻱ ﻧﺮﻳﺪ ﺿﻤﻪ ﺇﱃ ﻣﺸﺮﻭﻋﻨﺎ ﰲ ﻣﻜﺎﻥ .FileNameﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﺜﺎﻧﻴﺔ ﻫﻲ ﺿـﻢ ﻣﻠـﻒ ﺭﺃﺳـﻲ ﻣﻮﺟﻮﺩ ﰲ ﻧﻔﺲ ﺍﻠﺪ ﺍﳌﻮﺟﻮﺩ ﺑﻪ ﻣﺸﺮﻭﻋﻨﺎ ،ﻭ ﻃﺮﻳﻘﺔ ﺿﻢ ﺍﳌﻠﻔﺎﺕ ﰲ ﻫﺬﻩ ﺍﳊﺎﻟﺔ ﺗﻜﻮﻥ ﻛﺎﻟﺘﺎﱄ: "#include"FileName.h ﻭ ﺍﻟﻔﺮﻕ ﺍﻟﻮﺣﻴﺪ ﺑﲔ ﺍﻟﻄﺮﻳﻘﺘﲔ ﻫﻮ ﻛﺘﺎﺑﺔ ﺍﻟﺮﻣﺰﻳﻦ >< ﻋﻨﺪﻣﺎ ﻧﺮﻳﺪ ﺇﺿﺎﻓﺔ ﻣﻠﻒ ﺭﺃﺳﻲ ﻣﻦ ﺍﻠـﺪ ﺍﳌﺘـﺮﺟﻢ ) ،(includeﻭ ﻛﺘﺎﺑﺔ ﺍﻹﻗﺘﺒﺎﺳﲔ " " ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﻣﻮﺟﻮﺩ ﰲ ﻧﻔﺲ ﺍﻠﺪ ﺍﳌﺸﺮﻭﻉ .ﻭ ﳝﻜﻦ ﺃﻥ ﻧﻘﻮﻝ ﺃﻥ ﺍﻟﺘﻮﺟﻴﻪ #include ﺧﺎﺹ ﺑﺮﺑﻂ ﺍﳌﻠﻔﺎﺕ ﺑﺒﻌﻀﻬﺎ ﺍﻟﺒﻌﺾ. ٣,٣,٢ﺍﻟﺘﻮﺟﻴﻪ :#define ﻳﺴﺘﻌﻤﻞ ﺍﻟﺘﻮﺟﻴﻪ #defineﰲ ﺍﻹﻋﻼﻥ ﺍﻟﺜﻮﺍﺑﺖ ﻭ ﺍﻟﱵ ﲢﺪﺛﻨﺎ ﻋﻨﻬﺎ ﺳﺎﺑﻘﺎ ،ﻭ ﺃﻳـﻀﺎ ﻳـﺴﺘﻌﻤﻞ ﰲ ﺍﻹﻋـﻼﻥ ﻋـﻦ ﺍﳌﺨﺘﺼﺮﺍﺕ ،Macrosﺑﺎﻟﻨﺴﺒﺔ ﻟﻺﻋﻼﻥ ﻋﻦ ﺍﻟﺜﻮﺍﺑﺖ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺘﻮﺟﻴﻪ #defineﻓﻬﻲ ﻛﺘﺎﱄ: #define Constant_Name Constant_Value 186 ﰲ ﻣﻜﺎﻥ Constant_Nameﻧﻘﻮﻡ ﺑﻜﺘﺎﺑﺔ ﺍﺳﻢ ﺍﻟﺜﺎﺑﺖ ،ﻭ ﰲ ﻣﻜﺎﻥ Constant_Valueﻧﻜﺘﺐ ﻗﻴﻤﺔ ﺍﻟﺜﺎﺑﺖ .ﻭ ﺃﻣﺎ ﻋـﻦ ﻧﻮﻉ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﻟﻠﺜﺎﺑﺖ ﻓﺈﻥ ﺍﻟﺘﻮﺟﻴﻪ #defineﻳﻘﻮﻡ ﻳﻘﻮﻡ ﺑﺘﺤﺪﻳﺪﻫﺎ ﺗﻠﻘﺎﺋﻴﺎ ﺣﻴﺚ ﳝﻜﻦ ﺍﺳﺘﻌﻤﻞ ﺃﻱ ﻧﻮﻉ ﻣﻦ ﺍﻷﻧﻮﺍﻉ، ﻣﺜﺎﻝ: ""Hello ''H 3.14 10 String Character fNumber iNumber #define #define #define #define 1 2 3 4 ﺃﻣﺎ ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﻤﺨﺘﺼﺮﺍﺕ Macrosﻓﻬﻲ ﻣﺸﺎﺑﻪ ﻟﻠﺪﻭﺍﻝ ،ﻭ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﻠﻬﺎ ﻛﺘﺎﱄ: #define Macro_Add(i, j) i+j ﻫﻨﺎ ﻗﻤﻨﺎ ﺑﺈﻧﺸﺎﺀ ﳐﺘﺼﺮ ﺑﻪ ﻭﺳﻴﻄﲔ) ،ﻭ ﺃﻳﻀﺎ ﻫﻨﺎ ﻻ ﻧﻘﻮﻡ ﺑﺘﺤﺪﻳﺪ ﻧﻮﻉ ﺗﻠﻚ ﺍﻟﺜﻮﺍﺑﺖ( ﻭ ﻗﻴﻤﺘﻪ ﻫﻲ ﺍﳉﻤﻊ ﺑﲔ ﺍﻟﺜﺎﺑﺖ iﻭ ﺍﻟﺜﺎﺑﺖ ،jﻣﺜﺎﻝ ﻛﺎﻣﻞ: >#include<stdio.h #define Macro_Add(i, j) i+j {)(main ;int l ;)l = Macro_Add(10, 20 ;)printf("%d\n", l /*or*/ ;))printf("%d\n", Macro_Add(10, 20 ﺍﻟﱪﻧﺎﻣﺞ :٣,٣,١ﳐﺘﺼﺮ ﻳﻘﻮﻡ ﺑﻌﻤﻠﻴﺔ ﲨﻊ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ٣,٣,٣ﺍﻟﺘﻮﺟﻴﻪ :#undef ﺍﻟﺘﻮﺟﻴﻪ #undefﻫﻮ ﻣﻌﺎﻛﺲ ﻟﺘﻮﺟﻴﻪ ،#defineﺣﻴﺚ ﺗﻘﻮﻡ ﺑﺈﻟﻐﺎﺀ ﺍﻟﺜﻮﺍﺑﺖ ﻭ ﺍﳌﺨﺘﺼﺮﺍﺕ ﺍﻟﱵ ﻧﺮﻳﺪ ﺃﻥ ﻧﻘﻮﻡ ﺑﺈﻟﻐﺎﺀﻫﺎ ﻭ ﺇﻋﺎﺩﺓ ﺗﻌﺮﻓﻴﻬﺎ ،ﻭ ﻟﻜﻦ ﰲ ﺣﺎﻟﺔ ﺍﻟﺜﻮﺍﺑﺖ ﻓﻴﺠﺐ ﺃﻥ ﺗﻠﻚ ﺍﻟﺜﻮﺍﺑﺖ ﻣﻌﻠﻨﺔ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺘﻮﺟﻴﻪ ،#defineﻣﺜﺎﻝ: >#include<stdio.h #define Constant 5 #define Macro_Add(i, j) i+j 1 2 3 4 187 #undef Constant #undef Macro_Add {)(main printf("%d\n", Constant); /*Error: 'Constant': undeclared identifier*/ ;)Macro_Add(5, 10 /*Errors*/ ﺍﻟﱪﻧﺎﻣﺞ :٣,٣,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻮﺟﻴﻪ } 5 6 7 8 9 10 11 12 13 14 #undef ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻟﺚ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﺍﻟﺜﺎﺑﺖ Constantﻭ ﺃﻋﻄﻴﻨﺎﻩ ﺍﻟﻘﻴﻤﺔ ،٥ﻭ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺮﺍﺑﻊ ﻗﻤﻨـﺎ ﺑـﺎﻹﻋﻼﻥ ﻋـﻦ ﺍﳌﺨﺘﺼﺮ ،Macro_Addﰒ ﻗﻤﻨﺎ ﺑﺈﻟﻐﺎﺀ ﻛﻞ ﻣﻦ ﺍﻟﺜﺎﺑﺖ ﻭ ﺍﳌﺨﺘﺼﺮ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ﻭ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ،ﻭ ﻋﻨﺪ ﺍﺳـﺘﻌﻤﺎﻝ ﺍﻟﺜﺎﺑﺖ Constantﺃﻭ ﺍﳌﺨﺘﺼﺮ Macro_Addﺑﻌﺪ ﺇﻟﻐﺎﺀﳘﺎ ﻓﺴﻴﻨﺒﻬﻚ ﺍﳌﺘﺮﺟﻢ ﻋﻦ ﻭﺟﻮﺩ ﺃﺧﻄﺎﺀ. ٣,٣,٤ﺍﻟﺘﻮﺟﻴﻬﺎﺕ #else ،#elif ،#ifﻭ :#endif ﻫﻲ ﺗﻮﺟﻴﻬﺎﺕ ﺗﺴﺘﻌﻤﻞ ﻟﻌﻤﻠﻴﺎﺕ ﺷﺮﻃﻴﺔ ﻗﺒﻞ ﺍﻟﺘﺮﲨﺔ ،ﻭ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﻠﻬﺎ ﻫﻲ ﻧﻔﺲ ﺍﻟﻄﺮﻳﻘﺔ ﻣﻌﺎ ﻛﻞ ﻣﻦ ifﻭ ،else ﻓﻬﻨﺎ ﺍﻟﺘﻮﺟﻴﻪ #ifﻣﺸﺎﺑﻪ ﻟﺸﺮﻁ ،ifﻭ ﺍﻟﺘﻮﺟﻴﻪ #elifﻣﺸﺎﺑﻪ ﻻﺳﺘﻌﻤﺎﻝ else ifﻣﻌﺎ ،ﻭ ﺃﺧﲑ ﺍﻟﺘﻮﺟﻴﻪ #elseﻭ ﻫـﻮ ﺃﻳﻀﺎ ﻣﺸﺎﺑﻪ ﻟﺸﺮﻁ .elseﻭ ﺍﻟﺘﻮﺟﻴﻪ #endifﻳﻌﲏ ﺎﻳﺔ ﺍﻟﺸﺮﻭﻁ ،ﻣﺜﺎﻝ: >#include<stdio.h #define dNum 20 #if dNum == 10 "#define Result "dNum = 10 #elif dNum == 20 "#define Result "dNum = 20 #else "?? = #define Result "dNum #endif {)(main ;)printf("%s\n", Result } ﺍﻟﱪﻧﺎﻣﺞ :٣,٣,٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻮﺟﻴﻬﺎﺕ #else ،#elif ،#ifﻭ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #endif ٣,٣,٥ﺍﻟﺘﻮﺟﻴﻪ #ifdefﻭ ﺍﻟﺘﻮﺟﻴﻪ :#ifndef ﻳﺴﺘﻌﻤﻞ ﺍﻟﺘﻮﺟﻴﻪ #ifdefﰲ ﺣﺎﻟﺔ ﺃﻧﻨﺎ ﺃﺭﺩﻧﺎ ﺃﻧﺮﻯ ﻧﺮﻯ ﺇﻥ ﻛﺎﻥ ﻫﻨﺎﻙ ﺛﺎﺑﺖ ﺃﻭ ﳐﺘﺼﺮ ﻣﻌﺮﻑ ﺳﺎﺑﻖ ،ﻣﺜﺎﻝ: >#include<stdio.h #define dNum 1 2 3 188 4 5 6 7 8 9 10 11 12 13 #ifdef dNum #define Result "dNum Defined" #else #define Result "dNum Undefined" #endif main(){ printf("%s\n", Result); } ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻮﺟﻴﻪ:٣,٣,٤ ﺍﻟﱪﻧﺎﻣﺞ #ifdef ﻭ ﳝﻜﻦ ﻛﺘﺎﺑـﺔ ﺍﳌﺜـﺎﻝ، ﺳﺎﺑﻘﺎdNum ﻷﻧﻨﺎ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﺍﻟﺜﺎﺑﺖ،dNum 1 2 3 4 5 6 7 8 9 10 11 12 13 Defined ﻫﻨﺎ ﺳﺘﻜﻮﻥ ﻧﺘﻴﺠﺔ ﺍﻟﱪﻧﺎﻣﺞ ﻫﻲ #include<stdio.h> #define dNum #if defined dNum #define Result "dNum Defined" #else #define Result "dNum Undefined" #endif main(int argc, char *argv[]){ printf("%s\n", Result); } #ifdef ﻃﺮﻳﻘﺔ ﺃﺧﺮﻯ ﻣﻜﺎﻓﺌﺔ ﻟـ:٣,٣,٥ ﺍﻟﱪﻧﺎﻣﺞ : ﻣﺜﺎﻝ،#ifdef ﻣﻌﺎﻛﺲ ﻟﺘﻮﺟﻴﻪ 1 2 3 4 5 6 7 8 9 10 11 12 13 :ﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﺴﺎﺑﻖ #ifndef ﻭ ﺍﻟﺘﻮﺟﻴﻪ #include<stdio.h> #define dNum #ifndef dNum #define Result "dNum Undefined" #else #define Result "dNum Defined" #endif main(){ printf("%s\n", Result); } #ifndef ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻮﺟﻴﻪ:٣,٣,٦ ﺍﻟﱪﻧﺎﻣﺞ :ﻭ ﳝﻜﻦ ﺃﻳﻀﺎ ﻛﺘﺎﺑﺔ ﻫﺬﺍ ﻣﺜﺎﻝ ﺑﺎﻟﻄﺮﻳﻘﺔ ﺍﻟﺘﺎﱄ 189 >#include<stdio.h #define dNum #if !defined dNum "#define Result "dNum Undefined #else "#define Result "dNum Defined #endif {)(main ;)printf("%s\n", Result } ﺍﻟﱪﻧﺎﻣﺞ :٣,٣,٧ﻃﺮﻳﻘﺔ ﺃﺧﺮﻯ ﻣﻜﺎﻓﺌﺔ ﻟـ 1 2 3 4 5 6 7 8 9 10 11 12 13 #ifndef ٣,٣,٦ﺍﻟﺘﻮﺟﻴﻪ :#line ﻳﺴﺘﻌﻤﻞ ﺍﻟﺘﻮﺟﻴﻪ #lineﻟﺘﺤﺪﻳﺪ ﺳﻄﺮ ﻟﻠﻤﻠﻒ ﺍﳊﺎﱄ ﺃﻭ ﺳﻄﺮ ﳌﻠﻒ ﻏﲑ ﺍﳊﺎﱄ ،ﻭ ﺫﻟﻚ ﻏﲑ ﻣﻬﻢ ﺇﻻ ﰲ ﻋﻤﻠﻴﺔ ﺑﻨـﺎﺀ ﺍﳌﺘﺮﲨﺎﺕ ،ﻭ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﻠﻪ ﻛﺎﻟﺘﺎﱄ: #line LineNumber ﻫﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ﰲ ﺣﺎﻟﺔ ﺃﺭﺩﻧﺎ ﲢﺪﻳﺪ ﺭﻗﻢ ﺳﻄﺮ ﻟﻠﻤﻠﻒ ﺍﳊﺎﱄ ،ﺣﻴﺚ ﻧﻜﺘﺐ ﺭﻗﻢ ﺍﻟﺴﻄﺮ ﰲ ﻣﻜﺎﻥ ،LineNumberﻭ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻷﺧﺮﻯ ﻫﻲ: "#line LineNumber "FileName ﻭ ﻋﻨﺪ ﺍﺳﺘﻌﻤﺎﻝ ﻫﺬﻩ ﺍﻟﻄﺮﻳﻘﺔ ﳚﺐ ﺩﺍﺋﻤﺎ ﻛﺘﺎﺑﺔ ﺍﺳﻢ ﺍﳌﻠﻒ ﺩﺍﻟﺔ ﺍﻻﻗﺘﺒﺎﺳﲔ " " .ﺳﺘﻔﻬﻢ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﻫﺬﺍ ﺍﻟﺘﻮﺟﻴﻪ ﺃﻛﺜﺮ ﻋﻨﺪﻣﺎ ﺗﻌﺮﻑ ﺍﳌﺨﺘﺼﺮﺍﺕ ﺍﳌﻌﺮﻓﺔ )ﺳﻨﺪﺭﺳﻬﺎ ﻓﻴﻤﺎ ﺑﻌﺪ(. ٣,٣,٧ﺍﻟﺘﻮﺟﻴﻪ :#error ﻳﺴﺎﻋﺪ ﻫﺬﺍ ﺍﻟﺘﻮﺟﻴﻪ ﰲ ﺗﻨﺒﻴﻪ ﺍﳌﱪﻣﺞ ﰲ ﻣﺮﺣﻠﺔ ﺍﻟﺘﺮﲨﺔ ﻣﺒﺎﺷﺮﺓ ،ﻷﺧﻄﺎﺀ ﻳﻘﻮﻡ ﺑﺘﺠﻬﻴﺰﻫﺎ ﺍﳌﱪﻣﺞ ﰲ ﺣﺎﻟﺔ ﺍﻟﻮﻗﻮﻉ ﻓﻴﻬـﺎ، ﻣﺜﺎﻝ: #ifndef dNum !#error dNum are not declared #endif {)(main } 1 2 3 4 5 6 7 190 ﺍﻟﱪﻧﺎﻣﺞ :٣,٣,٨ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻮﺟﻴﻪ #error ﻫﻨﺎ ﺍﻟﱪﻧﺎﻣﺞ ﻟﻦ ﻳﻌﻤﻞ ﻭ ﺍﳋﻄﺄ ﻫﻮ ﺍﻟﺮﺳﺎﻟﺔ ﺍﳌﻜﺘﺒﺔ ﺑﻌﺪ ﺍﻟﺘﻮﺟﻴﻪ ،#errorﺃﻱ ﺃﻥ ﺍﻟﺜﺎﺑﺖ dNumﻏﲑ ﻣﻌﺮﻑ ﺳﺎﺑﻘﺎ. ٣,٣,٨ﺍﻟﺘﻮﺟﻴﻪ :#pragma ﻳﺴﺘﻌﻤﻞ ﺍﻟﺘﻮﺟﻴﻪ #pragmaﻟﺘﺤﻜﻢ ﰲ ﺍﳌﺘﺮﺟﻢ ﺣﺴﺐ ﺭﻏﺒﺔ ﺍﳌﱪﻣﺞ ،ﻭ ﻫﻲ ﲣﺘﻠﻒ ﻣﻦ ﻣﺘﺮﺟﻢ ﻵﺧـﺮ ،ﻳﺴﺘﺤـﺴﻦ ﻣﺮﺍﺟﻌﺔ ﺍﳌﺴﺎﻋﺪ ﺍﳋﺎﺹ ﺑﺎﳌﺘﺮﺟﻢ ﺍﻟﺬﻱ ﺗﺴﺘﻌﻤﻠﻪ. ٣,٣,٩ﺍﻷﲰﺎﺀ ﺍﳌﻌﺮﻓﺔ :Predefined Names ﻫﻲ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﳌﺨﺘﺼﺮﺍﺕ Macrosﺟﺎﻫﺰﺓ ،ﻭ ﳝﻜﻦ ﲤﻴﺰﻫﺎ ﺑﺎﻟﺮﻣﺰﻳﻦ Underscoreﰲ ﺑﺪﺍﻳﺔ ﻭ ﺎﻳﺔ ﺍﺳﻢ ﺍﳌﺨﺘـﺼﺮ ،ﻭ ﻫﺬﺍ ﺟﻮﻝ ﳉﻤﻴﻊ ﺍﻷﲰﺎﺀ ﺍﳌﻌﺮﻓﺔ: ﺍﻟﺸﺮﺡ ﺍﳌﺨﺘﺼﺮ ____LINE ﺛﺎﺑﺖ ﻋﺸﺮﻱ ﳛﻤﻞ ﺭﻗﻢ ﺳﻄﺮ ﺍﳌﺼﺪﺭ ﺍﳊﺎﱄ ____FILE ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﲢﻤﻞ ﺍﺳﻢ ﺍﳌﻠﻒ ﺍﳉﺎﺭﻱ ﺗﺮﲨﺘﻪ ____TIME ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﲢﻤﻴﻞ ﺍﻟﻮﻗﺖ ﺍﻟﺬﻱ ﰎ ﻓﻴﻪ ﺍﻟﺘﺮﺟﻢ ____DATE ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﲢﻤﻴﻞ ﺍﻟﺘﺎﺭﻳﺦ ﺍﻟﺬﻱ ____STDC ﺗﻜﻮﻥ ﻗﻴﻤﺔ ﻫﺬﺍ ﺍﻟﺜﺎﺑﺖ ١ﺇﺫﺍ ﻛﺎﻥ ﺍﳌﺘﺮﺟﻢ ﺍﳌﺴﺘﻌﻤﻞ ﻣﺘﺮﺟﻢ ﻗﻴﺎﺳﻲ ﻟﻠﻐﺔ .C ﺍﳉﺪﻭﻝ :٣,٣,١ﺍﻷﲰﺎﺀ ﺍﳌﻌﺮﻓﺔ ﻣﺜﺎﻝ ﺣﻮﻝ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺗﻠﻚ ﺍﻷﲰﺎﺀ: >#include<stdio.h {)(main ;)__printf("Line: %d\n", __LINE ;)__printf("File: %s\n", __FILE ;)__printf("Date Of Compilation: %s\n", __DATE ;)__printf("Time Of Compilation: %s\n", __TIME ;)__printf("ANSI C(0=false, 1=true): %d\n", __STDC } ﺍﻟﱪﻧﺎﻣﺞ :٣,٣,٩ﺇﺳﺘﻌﻤﺎﻝ ﺍﻷﲰﺎﺀ ﺍﳌﻌﺮﻓﺔ ٣,٣,١٠ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: ﻻ ﺗﻮﺟﺪ ﺃﺧﻄﺎﺀ ﳏﺘﻤﻠﺔ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ. 1 2 3 4 5 6 7 8 9 191 ٣,٣,١١ﲤﺎﺭﻳﻦ: ﻻ ﺗﻮﺟﺪ ﲤﺎﺭﻳﻦ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ. 192 ﺩﺭﺳﻨﺎ ﺳﺎﺑﻘﺎ ﺍﻟﺪﻭﺍﻝ ،ﻭ ﻗﻠﻨﺎ ﺃﻧﻪ ﳝﻜﻦ ﻋﻤﻞ ﳍﺎ ﻭﺳﺎﺋﻂ ،ﻭ ﻋﻨﺪ ﺍﺳﺘﻌﻤﺎﻝ ﺗﻠﻚ ﺍﻟﺪﻭﺍﻝ ﳚـﺐ ﺃﻭﻻ ﺃﻥ ﻧـﻮﻓﺮ ﳍـﺎ ﺍﻟﻮﺳﺎﺋﻂ ﺍﻟﱵ ﺗﺮﻳﺪﻫﺎ ،ﻓﻤﺜﻼ ﻻ ﳝﻜﻦ ﻋﻤﻞ ﻣﺜﻠﻤﺎ ﻫﻮ ﻣﻮﺿﺢ ﰲ ﻫﺬﺍ ﺍﳌﺜﺎﻝ: >#include<stdio.h ;)int Add(int a, int b {)(main ;int a = 10, b = 20, c = 30, d ;)d = Add(a, b, c ;)printf("%d\n", d } {)int Add(int a, int b ;return a+b } ﺍﻟﱪﻧﺎﻣﺞ :٣,٤,١ﺗﻮﻓﲑ ﺛﻼﺛﺔ ﻭﺳﺎﺋﻂ ﻟﺪﺍﻟﺔ ﺎ ﻭﺳﻴﻄﲔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ﻫﻨﺎ ﺍﻟﱪﻧﺎﻣﺞ ﻟﻦ ﻳﻌﻤﻞ ،ﻭ ﺍﳋﻄﺄ ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﻭ ﻫﻮ ﺃﻥ ﺍﻟﺪﺍﻟﺔ Addﲢﺘﻮﻱ ﻋﻠﻰ ﻭﺳﺎﺋﻂ ﻓﻘﻂ ،ﺃﻣﺎ ﳓﻦ ﻓﻘﺪ ﻣﺮﺭﻧﺎ ﳍـﺎ ﺛﻼﺛﺔ ﻭﺳﺎﺋﻂ .ﻭ ﺳﺘﺴﺘﻨﺘﺞ ﺃﻥ ﺍﻟﺪﺍﻟﺘﲔ printfﻭ ﺍﻟﺪﺍﻟﺔ scanfﳍﻤﺎ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ ﻭ ﳝﻜﻦ ﺃﻥ ﻧﺰﻳﺪ ﻋﻠﻴﻬﺎ ﻭﺳـﺎﺋﻂ ﺣﺴﺐ ﺭﻏﺒﺎﺗﻨﺎ ،ﻭ ﺳﻨﻘﻮﻡ ﺍﻵﻥ ﺑﻌﻤﻞ ﺍﺳﺘﻨﺴﺎﺥ ﺻﻐﲑ ﻟﺪﺍﻟﺔ printfﻭ ﺟﻌﻠﻬﺎ ﺃﻛﺜﺮ ﻣﺮﻭﻧﺔ ﻣﻦ ﺍﻟﺴﺎﺑﻘﺔ: >#include<stdio.h >#include<stdarg.h ;)void NewPrintf(char *, ... {)(main ;)NewPrintf("%d\a, %d\a, %d\a\n", 1, 2, 3 ;)"NewPrintf("Hello!\n } {)void NewPrintf(char *format, ... ;va_list Argument ;char *str ;int Decimal ;)va_start(Argument, format {)for(str=format;*str;str++ {)'if(*str != '% ;)putchar(*str ;continue } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 193 {)switch(*++str case 'd': case 'i': case 'D': case 'I': ;)Decimal = va_arg(Argument, int ;)printf("%d", Decimal ;break default: ;)putchar(*str ;break } } ;)va_end(Argument ﺍﻟﱪﻧﺎﻣﺞ :٣,٤,٢ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﺩﺍﻟﺔ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ } 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 ﺃﻭﻻ ﳚﺐ ﺿﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،stdarg.hﻭ ﺍﺳﻢ ﺍﳌﻠﻒ ﳐﺘﺼﺮ ﻣﻦ ،standard argumentﻭ ﻫﻮ ﺍﳌﻠﻒ ﺍﻟﺬﻱ ﺳـﻴﻌﻄﻴﻨﺎ ﺍﻹﻣﻜﺎﻧﻴﺎﺕ ﳉﻌﻞ ﺍﻟﺪﻭﺍﻝ ﳍﺎ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺮﺍﺑﻊ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋـﻦ ﺍﻟﺪﺍﻟـﺔ ﺍﳉﺪﻳـﺪ ﻟﻄﺒﻌـﺔ ﺑﺎﺳـﻢ ،NewPrintfﺣﻴﺚ ﳍﺎ ﻭﺳﻴﻂ ﻭﺍﺣﺪ ﻭ ﻫﻮ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺮﺋﻴﺴﻲ ،ﺃﻣﺎ ﺗﻠﻚ ﺍﻟﻨﻘﺎﻁ ...ﻓﻬﻲ ﺗﻌﲏ ﺃﻧﻪ ﺳﺘﺘﻢ ﲤﺮﻳﺮ ﻟﺪﺍﻟﺔ ﻋـﺪﺩ ﻣﻦ ﺍﻟﻮﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﱐ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﺎﻹﻋﻼﻥ ﻋﻦ ﻣﺆﺷﺮ ﻟـ ،va_listﻭ ﻫﻮ ﳐﺘﺼﺮﺓ ﻣﻦ ،variable list ﻭ ﻫﻮ ﻣﻦ ﻣﺆﺷﺮﺍﺕ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،stdarg.hﺣﻴﺚ ﺳﻴﺤﻤﻞ ﻫﺬﺍ ﺍﳌﺆﺷﺮ ﻋﺪﺩ ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ .NewPrintfﰲ ﺍﻟـﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ﻋﺸﺮ ﻗﻤﻨﺎ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﳌﺨﺘﺼﺮ ،va_startﺣﻴﺚ ﻟﻪ ﻭﺳﻴﻄﲔ ،ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻫﻮ ﻣﺆﺷـﺮ ﻟــ ،va_listﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﻧﻴﺔ ﻫﻮ ﲤﺮﻳﺮ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻟﺪﺍﻟﺔ ،NewPrintfﻭ ﻫﻨﺎ ﺳﻨﻘﻮﻡ ﺑﺘﻤﺮﻳﺮ ﺍﳌﺆﺷﺮ .formatﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳـﻊ ﻭ ﺍﻟﻌﺸﺮﻳﻦ ﻗﻤﻨﺎ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﳌﺨﺘﺼﺮ ،va_argﻭ ﻫﻮ ﳐﺘﺼﺮ ﻣﻦ ،variable argumentﻭ ﻟﻪ ﻭﺳﻴﻄﲔ ،ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻣﺆﺷﺮ ﻟـ ،va_listﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻫﻮ ﻧﻮﻉ ﺍﳌﺘﻐﲑ ﺍﻟﺬﻱ ﺳﻴﺘﻢ ﺃﺧﺬ ﻗﻴﻤﺘﻪ ﻣﻦ ﻣﻜﺎﻥ ﺍﻟﻮﺳﻴﻂ ﺍﻹﺿﺎﰲ ﰒ ﻧﻘﻠـﻪ ﺇﱃ ﺍﳌـﺘﻐﲑ ،Decimalﰒ ﻃﺒﻌﻪ ﻣﺒﺎﺷﺮﺓ .ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻟﻜﻴﻔﻴﺔ ﺟﻌﻞ ﺍﳌﺜﺎﻝ ﺍﻷﻭﻝ ﻳﻌﻤﻞ ﺑﺸﻜﻞ ﺻﺤﻴﺢ ،ﺍﳌﺜﺎﻝ: >#include<stdio.h >#include<stdarg.h ;)int Add(int NumOfArg, ... {)(main ;int a = 10, b = 20, c = 30, d ;)d = Add(3, a, b, c ;)printf("%d\n", d } {)int Add(int NumOfArg, ... ;va_list Arg ;int sum = 0, i 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 194 ;)va_start(Arg, NumOfArg )for(i=0;i<NumOfArg;i++ ;)sum += va_arg(Arg, int ;return sum ﺍﻟﱪﻧﺎﻣﺞ :٣,٤,٣ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﺩﺍﻟﺔ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ )(٢ ٣,٤,١ﺍﻷﺧﻄﺎﺀ ﺍﶈﺘﻤﻠﺔ: ﻻ ﺗﻮﺟﺪ ﺃﺧﻄﺎﺀ ﳏﺘﻤﻠﺔ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ. ٣,٤,٢ﲤﺎﺭﻳﻦ: ﻻ ﺗﻮﺟﺪ ﲤﺎﺭﻳﻦ ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ. } 17 18 19 20 21 22 23 24 195 ﰲ ﻫﺬﺍ ﺍﻟﺪﺭﺱ ﺳﻨﺘﻌﺮﻑ ﻋﻠﻰ ﺃﻫﻢ ﺛﻮﺍﺑﺖ ،ﳐﺘﺼﺮﺍﺕ ﻭ ﺩﻭﺍﻝ ﻟﻐﺔ Cﺍﻟﻘﻴﺎﺳﻴﺔ ،ﻭ ﻛﻞ ﳎﻤﻮﻋﺔ ﻣﻨـﻬﺎ ﻣﻮﺟـﻮﺩﺓ ﰲ ﻣﻠﻒ ﺭﺃﺳﻲ ﺫﺍﺕ ﺍﺳﻢ ﻳﺪﻝ ﻋﻠﻰ ﺩﻭﺭﻫﺎ. ٣,٥,١ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ :assert.h ﳛﺘﻮﻱ ﻫﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﻋﻠﻰ ﺩﺍﻟﺔ ﻭ ﻫﻲ ،assertﺎ ﻭﺳﻴﻂ ﻭﺍﺣﺪ ،ﻭ ﻫﻲ ﺩﺍﻟﺔ ﺗﻘﻮﻡ ﺑﺎﳌﻘﺎﺭﻧﺔ ﺑﲔ ﻗﻴﻤـﺘﲔ ﺣﻴـﺚ ﺗﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﺇﻣﺎ ﺻﻔﺮ ﺃﻱ ﺧﺎﻃﺌﺔ ،ﺃﻭ ﻏﲑ ﺍﻟﺼﻔﺮ ﺃﻱ ﺻﺤﻴﺤﺔ ،ﺇﻥ ﻛﺎﻧﺖ ﺍﻟﻨﺘﻴﺠﺔ ﺧﺎﻃﺌﺔ ﺃﻱ ٠ﻓﺴﻴﺘﻢ ﺍﺳﺘﻌﺪﺍﺀ ﺗﻠﻚ ﺍﻟﺪﺍﻟﺔ ﻛﻤﺨﺘﺼﺮ ،macroﺣﻴﺚ ﻳﻘﻮﻡ ﺫﻟﻚ ﺍﳌﺨﺘﺼﺮﺓ ﺑﻄﺒﺎﻋﺔ ﺍﳋﻄﺄ ﻣﻊ ﺍﺳﻢ ﺍﳌﻠﻒ ﺍﳌﻮﺟﻮﺩ ﺑﻪ ﺍﳋﻄﺄ ﻭ ﺭﻗﻢ ﺍﻟﺴﻄﺮ ﺃﺛﻨﺎﺀ ﺗـﺸﻐﻴﻞ ﺍﻟﱪﻧﺎﻣﺞ ،ﻭ ﻫﻨﺎ ﺳﻴﺘﻮﻗﻒ ﺍﻟﱪﻧﺎﻣﺞ ،ﺃﻣﺎ ﺇﻥ ﻛﺎﻧﺖ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﻓﺴﻴﺘﻢ ﲡﺎﻫﻞ ﺍﳌﺨﺘﺼﺮ ،assertﻭ ﻟﻦ ﺗﻘﻮﻡ ﺍﻟﺪﺍﻟـﺔ assertﺑﻌﻤﻞ ﺷﻲﺀ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<assert.h {)(main assert(10<20); /*true*/ assert(20<10); /*false*/ } ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١ﺍﻟﺪﺍﻟﺔ/ﺍﳌﺨﺘﺼﺮ 1 2 3 4 5 6 7 assert ﺃﻭﻻ ﻗﻤﻨﺎ ﺑﻀﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ assert.hﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﱐ ،ﻭ ﺍﺳﺘﻌﻤﻠﻨﺎ ﺍﻟﺪﺍﻟﺔ assertﰲ ﻛﻞ ﻣﻦ ﺍﻟـﺴﻄﺮ ﺍﳋـﺎﻣﺲ ﻭ ﺍﻟﺴﺎﺩﺱ .ﰲ ﺍﻟﺴﻄﺮ ﺍﳋﺎﻣﺲ ﻗﻤﻨﺎ ﺑﺈﻋﻄﺎﺀﻩ ﻟﺪﺍﻟﺔ assertﻣﻘﺎﺭﻧﺔ ﺻﺤﻴﺢ ،ﻭ ﰲ ﻫﺬﻩ ﺍﳊﺎﻟﺔ ﺳﻴﺘﻢ ﲡﺎﻫﻞ ﺍﻟﺪﺍﻟﺔ ،ﻭ ﻟﻦ ﻳﻘﻮﻡ ﺍﻟﱪﻧﺎﻣﺞ ﺑﻌﻤﻞ ﺃﻱ ﺷﻰﺀ ﻣﻦ ﻃﺮﻑ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺩﺱ ﺃﻋﻄﻴﻨﺎ ﻟﺪﺍﻟﺔ assertﻣﻘﺎﺭﻧﺔ ﺧﺎﻃﺌﺔ ،ﻭ ﻫﻨـﺎ ﺳـﻴﺘﻢ ﺍﻟﺘﺤﻮﻳﻞ ﺇﱃ ﺍﳌﺨﺘﺼﺮﺓ assertﻭ ﺍﻟﺬﻱ ﺳﻴﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺍﳋﻄﺄ ﺃﺛﻨﺎﺀ ﺗﺸﻐﻴﻞ ﺍﻟﱪﻧﺎﻣﺞ ،ﻭ ﺍﳋﻄﺄ ﻫﻮ 20<10ﰲ ﺍﳌﻠﻒ main.c ﰲ ﺍﻟﺴﻄﺮ .٦ ٣,٥,٢ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ :ctype.h ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ctype.hﳛﺘﻮﻱ ﻋﻠﻰ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻟﺪﻭﺍﻝ ﺍﳋﺎﺹ ﺃﻧﻮﺍﻉ ﺍﻟﺮﻣﻮﺯ ،ﻭ ﺍﲰﻪ ﳐﺘﺼﺮ ﻣﻦ ﲨﻴﻊ ﺩﻭﺍﻟﻪ ﺫﺍﺕ ﻭﺳﻴﻂ ﻭﺍﺣﺪ ﻭ ﻫﻮ ﳌﺘﻐﲑ ﳛﻤﻞ ﺭﻗﻢ ﺍﻟﺮﻣﺰ. ٣,٥,٢,١ﺍﻟﺪﺍﻟﺔ :isalnum type ،characterﻭ 196 ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ﳐﺘﺼﺮ ﻣﻦ ،is alphanumericﻭ ﺗﺴﺘﻌﻤﻞ ﻫﺬﺍ ﺍﻟﺪﺍﻟﺔ ﻹﺧﺘﺒﺎﺭ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﳍﺎ ،ﺇﺫﺍ ﻛﺎﻧﺖ ﻣﻦ ﺍﻟﻘﻴﻤﺔ ﻟﺮﻣـﺰ ﺣﺮﰲ ﺃﻭ ﺭﻗﻤﻲ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ،ﺃﻣﺎ ﰲ ﺣﺎﻟﺔ ﺍﻟﻌﻜﺲ ﻓﻨﺘﻴﺠﺔ ﺳﺘﻜﻮﻥ ،٠ﻣﺜﺎﻝ: >#include<stdio.h >#include<ctype.h {)(main ;int c = 1, c2 = 65 ;)printf("%d = %c\n", isalnum(c), c ;)printf("%d = %c\n", isalnum(c2), c2 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢ ﺍﻟﺪﺍﻟﺔ isalnum } 1 2 3 4 5 6 7 8 9 ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ١ﰲ ﺟﺪﻭﻝ ASCIIﻋﺒﺎﺭﺓ ﻋﻦ ﺃﻳﻘﻮﻧـﺔ .ﰲ ﺍﻟـﺴﻄﺮ ﺍﻟﺜـﺎﻣﻦ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ١ﺃﻱ ﺻﺤﻴﺤﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٦٥ﻫﻮ ﺍﳊﺮﻑ Aﰲ ﺟﺪﻭﻝ ،ASCIIﻭ ﻫﻮ ﻣﻦ ﺍﻟﺮﻣﻮﺯ ﺍﳊﺮﻓﻴﺔ. ٣,٥,٢,٢ﺍﻟﺪﺍﻟﺔ :isalpha ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ﳐﺘﺼﺮ ﻣﻦ ،is alphabeticﻭ ﺗﺴﺘﻌﻤﻞ ﻹﺧﺘﺒﺎﺭ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﳍﺎ ﺇﺫﺍ ﻛﺎﻧﺖ ﻣﻦ ﺣﺮﻭﻑ ﺍﻷﲜﺪﻳـﺔ ﺃﻡ ﻻ ،ﺇﺫﺍ ﻛﺎﻥ ﻣﻦ ﺍﳊﺮﻭﻑ ﺍﻷﲜﺪﻳﺔ ﻓﻨﺘﻴﺠﺔ ﺳﺘﻜﻮﻥ ،١ﻭ ﰲ ﺣﺎﻟﺔ ﺍﻟﻌﻜﺲ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ،٠ﻣﺜﺎﻝ: >#include<stdio.h >#include<ctype.h {)(main ;int c = 49, c2 = 65 ;)printf("%d = %c\n", isalpha(c), c ;)printf("%d = %c\n", isalpha(c2), c2 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 isalpha ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ،ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ،٠ﻷﻥ ﺍﻟﺮﻗﻢ ٤٩ﻫﻮ ﺍﻟﻌﺪﺩ ١ﰲ ﺟﺪﻭﻝ ،ASCIIﻭ ﻫﻮ ﻟﻴﺲ ﻣﻦ ﺍﳊﺮﻭﻑ ﺍﻷﲜﺪﻳـﺔ. ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ،١ﻷﻥ ﺍﻟﻌﺪﺩ ٦٥ﻫﻮ ﺍﳊﺮﻑ Aﰲ ﺟﺪﻭﻝ ،ASCIIﻭ ﺍﳊﺮﻑ Aﻣﻦ ﺍﳊﺮﻭﻑ ﺍﻷﲜﺪﻳﺔ. ٣,٥,٢,٣ﺍﻟﺪﺍﻟﺔ :iscntrl ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ﳐﺘﺼﺮ ﻣﻦ ،is controlﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﺈﺧﺘﺒﺎﺭ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﳍﺎ ﺇﺫﺍ ﻛﺎﻧﺖ ﻣﻦ ﺭﻣـﻮﺯ ﺍﻟـﺘﺤﻜﻢ ،ﻭ ﺭﻣـﻮﺯ ﺍﻟﺘﺤﻜﻢ ﺗﻜﻮﻥ ﺑﲔ ٠ﻭ ،٣١ﻭ ﺃﻳﻀﺎ ﻣﻦ ١٢٨ﺇﱃ ،٢٥٥ﻭ ﻫﻨﺎ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺃﻱ ﺻﺤﻴﺤﺔ ،ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﻟﻘﻴﻤﺔ ﺑﲔ ٣٢ﻭ ١٢٧ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﺧﺎﻃﺌﺔ ﻷﻥ ﻛﻞ ﻣﻦ ﺗﻠﻚ ﺍﻟﺮﻣﻮﺯ ﻋﺒﺎﺭﺓ ﻋﻦ ﺃﺭﻗﺎﻡ ﻭ ﺣﺮﻭﻑ ﻻ ﺃﻛﺜﺮ ،ﻣﺜﺎﻝ: 197 >#include<stdio.h >#include<ctype.h {)(main ;int c = 65, c2 = 0 ;)printf("%d = %c\n", iscntrl(c), c ;)printf("%d = %c\n", iscntrl(c2), c2 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٤ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 iscntrl ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺍﻟﻨﺘﻴﺠﺔ ﺳﺘﻜﻮﻥ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٦٥ﳛﻤﻞ ﺍﳊﺮﻑ Aﰲ ﺟﺪﻭﻝ ASCIIﻭ ﻫﻮ ﻟﻴﺲ ﻣﻦ ﺭﻣـﻮﺯ ﺍﻟﺘﺤﻜﻢ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺃﻱ ﺻﺤﻴﺤﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٠ﻣﻦ ﺭﻣﻮﺯ ﺍﻟﺘﺤﻜﻢ ﰲ ﺟﺪﻭﻝ .ASCII ٣,٥,٢,٤ﺍﻟﺪﺍﻟﺔ :isdigit ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺈﺧﺘﺒﺎﺭ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺀﺓ ﳍﺎ ﺇﺫﺍ ﻛﺎﻧﺖ ﻣﻦ ﺍﻷﺭﻗﺎﻡ ﺍﻟﻌﺸﺮﻳﺔ ﺣﻴﺚ ﺗﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺇﻥ ﻛﺎﻧـﺖ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﺑﲔ ﺍﻟﺮﻗﻢ ٤٨ﻭ ،٥٧ﻭ ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﻟﻨﺘﻴﺠﺔ ﱂ ﺗﻜﻦ ﺑﲔ ﺍﻟﺮﻗﻢ ٤٨ﻭ ٥٧ﻣﻦ ﺟـﺪﻭﻝ ASCIIﻓـﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<ctype.h {)(main ;int c = 65, c2 = 48 ;)printf("%d = %c\n", isdigit(c), c ;)printf("%d = %c\n", isdigit(c2), c2 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٥ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 isdigit ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٦٥ﻫﻮ ﺍﳊﺮﻑ Aﰲ ﺟﺪﻭﻝ ASCIIﻭ ﺍﳊﺮﻑ Aﻟﻴﺲ ﺭﻗﻤﺎ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٤٨ﰲ ﺟﺪﻭﻝ ASCIIﻫﻮ ﺍﻟﺮﻗﻢ .٠ ٣,٥,٢,٥ﺍﻟﺪﺍﻟﺔ :isgraph ﺗﻘﻮﻡ ﻫﺬﺍ ﺍﻟﺪﺍﻟﺔ ﺑﺈﺧﺘﺒﺎﺭ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﳍﺎ ﺇﺫﺍ ﻛﺎﻥ ﺭﻣﻮﺯ ﻏﲑ ﻣﺮﺋﻴﺔ ﺃﻭ ﻣﺮﺋﻴﺔ ،ﺇﺫﺍ ﻛﺎﻧﺖ ﻏﲑ ﻣﺮﺋﻴﺔ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺃﻱ ﺻﺤﻴﺤﺔ ،ﺃﻣﺎ ﰲ ﺣﺎﻟﺔ ﺍﻟﻌﻜﺲ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<ctype.h 1 2 3 198 {)(main ;int c = 0, c2 = 48 ;)printf("%d = %c\n", isgraph(c), c ;)printf("%d = %c\n", isgraph(c2), c2 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦ﺍﻟﺪﺍﻟﺔ } 4 5 6 7 8 9 isgraph ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٠ﰲ ﺟﺪﻭﻝ ASCIIﻋﺒﺎﺭﺓ ﻋﻦ ﺭﻣﺰ ﻣﺮﺋﻲ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜـﺎﻣﻦ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٤٨ﰲ ﺟﺪﻭﻝ ASCIIﻫﻮ ﺍﻟﺮﻗﻢ ٠ﻭ ﻫﻮ ﺭﻣﺰ ﻏﲑ ﻣﺮﺋﻲ. ٣,٥,٢,٦ﺍﻟﺪﺍﻟﺔ :islower ﺗﻘﻮﻡ ﻫﺬﺍ ﺍﻟﺪﺍﻟﺔ ﺑﺈﺧﺘﺒﺎﺭ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﳍﺎ ،ﺇﺫﺍ ﻛﺎﻧﺖ ﻣﻦ ﺍﻷﺣﺮﻑ ﺍﻟﺼﻐﲑﺓ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺃﻱ ﺻﺤﻴﺤﺔ، ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻧﺖ ﻏﲑ ﺫﻟﻚ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ،٠ﻣﺜﺎﻝ: >#include<stdio.h >#include<ctype.h {)(main ;int c = 65, c2 = 97 ;)printf("%d = %c\n", islower(c), c ;)printf("%d = %c\n", islower(c2), c2 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 islower ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٦٥ﻫﻮ ﺍﻟﺮﻣﺰ Aﰲ ﺟﺪﻭﻝ ،ASCIIﻭ ﺍﻟﺮﻣـﺰ Aﻟـﻴﺲ ﻣـﻦ ﺍﳊﺮﻭﻑ ﺍﻟﺼﻐﲑﺓ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺃﻱ ﺻﺤﻴﺤﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٩٧ﰲ ﺟﺪﻭﻝ ASCIIﻫﻮ ﺍﻟﺮﻣﺰ a ﻭ ﻫﻮ ﻣﻦ ﺍﻟﺮﻣﺰ ﺍﻟﺼﻐﲑﺓ. ٣,٥,٢,٧ﺍﻟﺪﺍﻟﺔ :isprint ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺈﺧﺘﺒﺎﺭ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﳍﺎ ،ﺇﺫﺍ ﱂ ﻛﺎﻧﺖ ﺍﻟﻘﻴﻤﺔ ﺑﲔ ٣٢ﻭ ١٢٦ﻣﻦ ﺟﺪﻭﻝ ASCIIﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠـﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ،ﻭ ﻫﻲ ﺍﻟﺮﻣﻮﺯ ﺍﳌﺴﺘﻌﻤﻠﺔ ﰲ ﺍﻟﻄﺒﺎﻋﺔ ﺍﻹﻓﺘﺮﺍﺿﻴﺔ )ﺍﻟﻔﺮﺍﻍ ﻳﻌﺘﱪ ﺭﻣﺰ ﺃﻳﻀﺎ( ،ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﻟﻘـﻴﻢ ﻏـﲑ ﺫﻟـﻚ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<ctype.h {)(main ;int c = 1, c2 = 65 1 2 3 4 5 199 ;)printf("%d = %c\n", isprint(c), c ;)printf("%d = %c\n", isprint(c2), c2 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٨ﺍﻟﺪﺍﻟﺔ } 6 7 8 9 isprint ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ،٠ﻷﻥ ﺍﻟﺮﻗﻢ ١ﰲ ﺟﺪﻭﻝ ASCIIﻋﺒﺎﺭﺓ ﻋﻦ ﺭﺳﻢ ﻹﺑﺘﺴﺎﻣﺔ ،ﻭ ﻻ ﺗﺴﺘﻌﻤﻞ ﺍﻹﺑﺘﺴﺎﻣﺎﺕ ﰲ ﺍﻟﻨﺼﻮﺹ ﺍﻹﻓﺘﺮﺍﺿﻴﺔ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٦٥ﻫﻮ ﺍﳊﺮﻑ Aﰲ ﺟـﺪﻭﻝ ASCIIﻭ ﻫﻮ ﺣﺮﻑ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻟﻪ ﰲ ﺍﻟﻨﺼﻮﺹ ﺍﻹﻓﺘﺮﺍﺿﻴﺔ. ٣,٥,٢,٨ﺍﻟﺪﺍﻟﺔ :ispunct ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ ﳐﺘﺼﺮ ﻣﻦ ،is punctuationﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﺈﺧﺘﺒﺎﺭ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﳍﺎ ،ﺇﺫﺍ ﻛﺎﻧﺖ ﻣﻦ ﺃﺣـﺪ ﺭﻣـﻮﺯ ﺍﻟﺘـﺮﻗﲔ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺃﻱ ﺻﺤﻴﺤﺔ ،ﺃﻣﺎ ﻏﲑ ﺭﻣﻮﺯ ﺍﻟﺘﺮﻗﲔ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<ctype.h {)(main ;int c = 44, c2 = 65 ;)printf("%d = %c\n", ispunct(c), c ;)printf("%d = %c\n", ispunct(c2), c2 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٩ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 ispunct ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺃﻱ ﺻﺤﻴﺤﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٤٤ﻫﻮ ﺍﻟﻔﺎﺻﻠﺔ ﰲ ﺟﺪﻭﻝ ،ASCIIﺍﻟﻔﺎﺻـﻠﺔ ﻣـﻦ ﺭﻣﻮﺯ ﺍﻟﺘﺮﻗﲔ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﺻﻔﺮ ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٦٥ﻫـﻮ ﺍﳊـﺮﻑ Aﰲ ﺟـﺪﻭﻝ ،ASCIIﻭ ﺍﳊﺮﻭﻑ ﻟﻴﺴﺖ ﺭﻣﻮﺯ ﺗﺮﻗﲔ. ٣,٥,٢,٩ﺍﻟﺪﺍﻟﺔ :isspace ﺗﻘﻮﻡ ﺍﻟﺪﺍﻟﺔ ﺑﺈﺧﺘﺒﺎﺭ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﳍﺎ ،ﺇﺫﺍ ﻛﺎﻧﺖ ﻣﻦ ﺭﻣﻮﺯ ﺍﻟﻔﻀﺎﺀ ﺍﻷﺑﻴﺾ ﺃﻣﺎ ﻻ ،ﻭ ﺭﻣﻮﺯ ﺍﻟﻔﻀﺎﺀ ﺍﻷﺑﻴﺾ ﺗﺒﺪﺃ ﻣﻦ ٩ ﺇﱃ ،١٣ﻭ ﰲ ﻫﺬﻩ ﺍﳊﺎﻟﺔ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺃﻱ ﺻﺤﻴﺢ ،ﺃﻣﺎ ﺇﻥ ﱂ ﺗﻜﻮﻥ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﻣﻦ ﺃﺣﺪ ﺍﻟﺮﻣﻮﺯ ﺍﻟﻔﻀﺎﺀ ﺍﻷﺑﻴﺾ ﻓﺈﻥ ﺍﻟﻨﺘﻴﺠﺔ ﺳﺘﻜﻮﻥ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<ctype.h {)(main ;int c = 9, c2 = 97 1 2 3 4 5 200 ;)printf("%d = %c\n", isspace(c), c ;)printf("%d = %c\n", isspace(c2), c2 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١٠ } ﺍﻟﺪﺍﻟﺔ isspace 6 7 8 9 ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺃﻱ ﺻﺤﻴﺤﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٩ﰲ ﺟﺪﻭﻝ ASCIIﻫﻮ ﻣﻦ ﺃﺣﺪ ﺭﻣـﻮﺯ ﺍﻟﻔـﻀﺎﺀ ﺍﻷﺑﻴﺾ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٩٧ﰲ ﺟﺪﻭﻝ ASCIIﻫﻮ ﺍﳊﺮﻑ ،aﻭ ﻫﻮ ﻟﻴﺲ ﻣـﻦ ﺭﻣﻮﺯ ﺍﻟﻔﻀﺎﺀ ﺍﻷﺑﻴﺾ. ٣,٥,٢,١٠ﺍﻟﺪﺍﻟﺔ :isupper ﺗﻘﻮﻡ ﻫﺬﺍ ﺍﻟﺪﺍﻟﺔ ﺑﺈﺧﺘﺒﺎﺭ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﳍﺎ ،ﺇﺫﺍ ﻛﺎﻧﺖ ﻣﻦ ﺍﻟﺮﻣﻮﺯ ﺍﻟﻜﺒﲑﺓ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺃﻱ ﺻﺤﻴﺤﺔ ،ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻧﺖ ﻗﻴﻢ ﻷﺣﺮﻑ ﺻﻐﲑﺓ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<ctype.h {)(main ;int c = 65, c2 = 97 ;)printf("%d = %c\n", isupper(c), c ;)printf("%d = %c\n", isupper(c2), c2 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١١ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 isupper ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺃﻱ ﺻﺤﻴﺤﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٦٥ﰲ ﺟﺪﻭﻝ ASCIIﻫﻮ ﺍﳊﺮﻑ Aﻭ ﻫـﻮ ﻣـﻦ ﺍﻷﺣﺮﻑ ﺍﻟﻜﺒﲑﺓ .ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٩٧ﰲ ﺟﺪﻭﻝ ASCIIﻫﻮ ﺍﳊﺮﻑ aﻭ ﻫـﻮ ﻟﻴﺲ ﺣﺮﻑ ﻛﺒﲑ. ٣,٥,٢,١١ﺍﻟﺪﺍﻟﺔ :isxdigit ﺍﺳﻢ ﻫﺬﺍ ﺍﻟﺪﺍﻟﺔ ﳐﺘﺼﺮ ﻣﻦ ،is hexadecimal digitalﻭ ﺗﻘﻮﻡ ﻫﺬﺍ ﺍﻟﺪﺍﻟﺔ ﺑﺈﺧﺘﺒﺎﺭ ﺍﻟﺪﺍﻟﺔ ﺍﳌﻌﻄﺎﺓ ﳍﺎ ،ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﻟﻘﻴﻤﺔ ﻣﻦ ﺃﻋﺪﺍﺩ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺴﺪﺍﺳﻲ ﻋﺸﺮ ﺃﻱ ﻣﻦ A-Fﻭ ﻣﻦ ٩ – ٠ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺃﻱ ﺻﺤﻴﺤﺔ ،ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻧﺖ ﻏﲑ ﺗﻠﻚ ﺍﻟﻘﻴﻢ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ٠ﺃﻱ ﺧﺎﻃﺌﺔ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<ctype.h {)(main ;int c = 70, c2 = 71 1 2 3 4 5 201 ;)printf("%d = %c\n", isxdigit(c), c ;)printf("%d = %c\n", isxdigit(c2), c2 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١٢ﺍﻟﺪﺍﻟﺔ } 6 7 8 9 isxdigit ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺃﻱ ﺻﺤﻴﺤﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٧٠ﻫﻮ ﺍﳊﺮﻑ Fﰲ ﺟﺪﻭﻝ ،ASCIIﻭ ﺍﳊـﺮﻑ ﻣﻦ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺴﺪﺍﺳﻲ ﻋﺸﺮ ﻭ ﰲ ﺍﻟﻨﻈﺎﻡ ﺍﻟﻌﺸﺮﻱ ﻫﻮ ﺍﻟﻌﺪﺩ .١٥ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﺻﻔﺮ ﺃﻱ ﺧﺎﻃﺌـﺔ ،ﻷﻥ ﺍﻟﺮﻗﻢ ٧١ﻫﻮ ﺍﳊﺮﻑ Gﰲ ﺟﺪﻭﻝ ،ASCIIﻭ ﻫﻮ ﺍﳊﺮﻑ Gﻟﻴﺲ ﻣﻦ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺴﺪﺍﺳﻲ ﻋﺸﺮ. F ٣,٥,٢,١٢ﺍﻟﺪﺍﻟﺘﲔ toupperﻭ :tolower ﺍﻟﺪﺍﻟﺔ toupperﺗﻘﻮﻡ ﺑﺘﺤﻮﻳﻞ ﺍﻷﺣﺮﻑ ﺍﻟﺼﻐﲑ ﺇﱃ ﺍﻷﺣﺮﻑ ﺍﻟﻜﺒﲑﺓ ،ﻭ ﺍﻟﺪﺍﻟﺔ tolowerﺗﻘﻮﻡ ﺑﺘﺤﻮﻳـﻞ ﺍﻷﺣـﺮﻑ ﺍﻟﻜﺒﲑﺓ ﺇﱃ ﺃﺣﺮﻑ ﺻﻐﲑﺓ ﺃﻱ ﻋﻜﺲ ﻣﺎ ﺗﻘﻮﻡ ﺑﻪ ﺍﻟﺪﺍﻟﺔ ،toupperﻣﺜﺎﻝ: >#include<stdio.h >#include<ctype.h {)(main ;'int c = 'a', c2 = 'B ;))printf("%c = %c\n", c, toupper(c ;))printf("%c = %c\n", c2, tolower(c2 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١٣ﺍﻟﺪﺍﻟﺘﲔ toupperﻭ } 1 2 3 4 5 6 7 8 9 tolower ﰲ ﻫﺬﺍ ﺍﻟﱪﻧﺎﻣﺞ ﻳﺘﻢ ﻃﺒﺎﻋﺔ ﺍﳊﺮﻑ aﻭ ﻫﻮ ﻋﻠﻰ ﺷﻜﻞ ﺣﺮﻑ ﺻﻐﲑ ،ﰒ ﺇﻋﺎﺩﺓ ﻛﺘﺎﺑﺘﻪ ﺑﻌﺪ ﲤﺮﻳﺮﻩ ﻟﺪﺍﻟﺔ toupperﺣﻴـﺚ ﺳﻴﺼﺒﺢ ﻣﻦ ﺍﻷﺣﺮﻑ ﺍﻟﻜﺒﲑﺓ ،ﻭ ﺳﺘﺘﻢ ﻃﺒﺎﻋﺔ ﺍﳊﺮﻑ Bﻋﻠﻰ ﺷﻜﻞ ﺣﺮﻑ ﻛﺒﲑ ،ﰒ ﺇﻋﺎﺩﺓ ﻛﺘﺎﺑﺘﻪ ﺑﻌـﺪ ﲤﺮﻳـﺮﻩ ﻟﺪﺍﻟـﺔ tolowerﺣﻴﺚ ﲢﻮﻳﻠﻪ ﺇﱃ ﺣﺮﻑ ﺻﻐﲑ. ٣,٥,٣ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ :errno.h ﻳﻮﺟﺪ ﰲ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ errno.hﳎﻤﻮﻋﺔ ﻣﻦ ﺍﳌﺨﺘﺼﺮﺍﺕ ﺗﺴﺘﻌﻤﻞ ﻟﻜﺸﻒ ﺍﻷﺧﻄﺎﺀ ﺃﺛﻨﺎﺀ ﻭﻗﺖ ﺗـﺸﻐﻴﻞ ﺍﻟﱪﻧـﺎﻣﺞ. ﺣﻴﺚ ﺗﺴﺘﻌﻤﻞ ﺗﻠﻚ ﺍﳌﺨﺘﺼﺮﺍﺕ ﻣﻊ ﺍﻟﺪﺍﻟﺔ .perror ٣,٥,٣,١ﺍﻟﺪﺍﻟﺔ :perror 202 ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ perrorﳐﺘﺼﺮ ﻣﻦ ،print errorﻭ ﻫﻲ ﺩﺍﻟﺔ ﺗﻘﻮﻡ ﺑﻄﺒﺎﻋﺔ ﺃﺧﻄﺎﺀ ﺧﺎﺻﺔ ﺑﺎﳌﻠﻔﺎﺕ .ﻟﺪﺍﻟﺔ ﻭﺳﻴﻂ ﻭﺍﺣﺪ ﻭ ﻫﻮ ﺳﻠﺴﻠﺔ ﳊﺮﻭﻑ ﺍﻟﱵ ﺳﺘﺘﻢ ﻃﺒﺎﻋﺘﻬﺎ ﻗﺒﻞ ﻃﺒﺎﻋﺔ ﺍﳋﻄﺄ ،ﺃﻭ ﳝﻜﻦ ﺗﺮﻙ ﺍﻟﺴﻠﺴﻠﺔ ﻓﺮﺍﻏﻪ ﺇﻥ ﱂ ﻧﺮﻳﺪ ﺇﺿﺎﻓﺔ ﺷـﻲﺀ ﺇﱃ ﺭﺳـﺎﻟﺔ ﺍﳋﻄﺄ ،ﻣﺜﺎﻝ ﺣﻮﻝ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ: >#include<stdio.h >#include<stdlib.h >#include<errno.h {)(main ;FILE *File ;]char FileName[255 ;)"perror("situation ;)" printf("Enter The File Name: ;)gets(FileName ;)"File = fopen(FileName, "r {)if(!File ;)"perror("situation ;)printf("errno = %d\n", errno ;)exit(1 {}else ;)"perror("situation ;)"printf("File Founded!\n ;)fclose(File } ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١٤ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 perror ﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺘﺎﺳﻊ ﻗﻤﻨﺎ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ perrorﻣﻊ ﲤﺮﻳﺮ ﳍﺎ ﺍﻟﻨﺺ situationﻭ ﺍﻟﱵ ﺳﺘﻜﻮﻥ ﻫﺬﻩ ﺍﻟﻜﻠﻤﺔ ﻗﺒـﻞ ﺭﺳـﺎﻟﺔ ﺍﳋﻄﺄ ،ﻭ ﻟﻜﻦ ﻫﻨﺎ ﻻ ﻳﻮﺟﺪ ﺃﻱ ﺧﻄﺄ ﻭ ﺍﻟﺮﺳﺎﻟﺔ ﺳﺘﻜﻮﻥ .No errorﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ perrorﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺴﺎﺑﻊ ﻋﺸﺮ ،ﻓﺈﻥ ﻛﺎﻥ ﺍﺳﻢ ﺍﳌﻠﻒ ﺍﻟﺬﻱ ﻃﻠﺒﻪ ﺍﳌﺴﺘﺨﺪﻡ ﻏﲑ ﻣﻮﺟﻮﺩ ﻓﺴﻴﺘﻢ ﻃﺒﺎﻋﺔ ﺍﻟﺮﺳﺎﻟﺔ ﻋﺪﻡ ﻭﺟﻮﺩ ﺍﳌﻠﻒ ،ﻭ ﺃﻳـﻀﺎ ﻗﻤﻨـﺎ ﺑﺎﺳـﺘﻌﻤﺎﻝ ﺍﳌﺨﺘﺼﺮ errnoﰲ ﺍﻟﺴﻄﺮ ﺍﻟﺜﺎﻣﻦ ﻋﺸﺮ ﻋﱪ ﺍﻟﺪﺍﻟﺔ ،printfﺣﻴﺚ ﺳﺘﻢ ﻃﺒﺎﻋﺔ ﺭﻗﻢ ﺭﺳﺎﻟﺔ ﺍﳋﻄﺄ ﺍﻟﺬﻱ ﰎ ﺇﳚﺎﺩﻩ ،ﺭﺳـﺎﻟﺔ ﺍﳋﻄﺄ ﻫﻨﺎ ﺭﻗﻤﻬﺎ .٢ﻭ ﻟﻠﻤﺨﺘﺼﺮ errnoﺛﻮﺍﺑﺖ ﺗﺴﺘﻌﻤﻞ ﻟﺘﺒﲔ ﻋﻠﻰ ﺭﺳﺎﻟﺔ ﺍﳋﻄﺄ ﺍﻟﱵ ﻧﺮﻳﺪ ﺇﺭﺳﺎﳍﺎ ،ﻣﻦ ﺃﻫﻢ ﺗﻠﻚ ﺍﻟﺜﻮﺍﺑﺖ ﻫﻲ: ﺍﺳﻢ ﺍﻟﺜﺎﺑﺖ EINVAL ERANGE EBADF EDOM EACCES ﺍﻟﺮﺳﺎﻟﺔ Invalid argument Result too large Bad file descriptor Domain error Permission denied 203 Too many open files File exists Arg list too long Improper link No child processes Resource temporarily unavailable Exec format error Not enough space No such file or directory No space left on device errno EMFILE EEXIST E2BIG EXDEV ECHILD EAGAIN ENOEXEC ENOMEM ENOENT ENOSPC ﺛﻮﺍﺑﺖ ﺍﳌﺨﺘﺼﺮ:٣,٥,١ ﺍﳉﺪﻭﻝ : ﻣﺜﺎﻝ،ﻭ ﺗﻮﺟﺪ ﺭﺳﺎﺋﻞ ﺃﺧﺮﻯ ﳝﻜﻦ ﺭﺃﻳﺘﻬﺎ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺘﻜﺮﺍﺭ 1 2 3 4 5 6 7 8 9 10 11 12 #include<stdio.h> #include<errno.h> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define main(){ int i; } for(i=0;i<=42;i++){ errno = i; printf("%d:", i); perror(""); } (٢) perror ﺍﻟﺪﺍﻟﺔ:٣,٥,١٥ ﺍﻟﱪﻧﺎﻣﺞ : ﻭ ﻫﻲ ﻋﻠﻰ ﺍﻟﺸﻜﻞ ﺍﻟﺘﺎﱄ،errno.h ﻭ ﻛﻞ ﺭﻗﻢ ﻣﻨﻬﺎ ﻟﻪ ﺛﺎﺑﺖ ﻣﻌﺮﻑ ﰲ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ EPERM ENOENT ESRCH EINTR EIO ENXIO E2BIG ENOEXEC EBADF ECHILD EAGAIN ENOMEM EACCES EFAULT EBUSY EEXIST EXDEV ENODEV ENOTDIR EISDIR EINVAL ENFILE 1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 17 18 19 20 21 22 23 204 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define EMFILE ENOTTY EFBIG ENOSPC ESPIPE EROFS EMLINK EPIPE EDOM ERANGE EDEADLK ENAMETOOLONG ENOLCK ENOSYS ENOTEMPTY EILSEQ 24 25 27 28 29 30 31 32 33 34 36 38 39 40 41 42 errno.h ﺛﻮﺍﺑﺖ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ:٣,٥,١٦ ﺍﻟﱪﻧﺎﻣﺞ :float.h ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ٣,٥,٤ : ﻭ ﺗﻠﻚ ﺍﻟﺜﻮﺍﺑﺖ ﻫﻲ،ﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻟﺜﺎﺑﺖ ﺧﺎﺻﺔ ﺑﺎﻷﻋﺪﺍﺩ ﺍﳊﻘﻴﻘﻴﺔ ﻳﻮﺟﺪ ﻗﻴﻤﺘﻪ ﺍﺳﻢ ﺍﻟﺜﺎﺑﺖ 2 1 1E+37 128 E 1 +37 1024 6 15 1E-5 1E-9 24 53 1E-37 -125 1E-37 -1021 float.h FLT_RADIX FLT_ROUNDS FLT_MAX FLT_MAX_EXP DBL_MAX DBL_MAX_EXP FLT_DIG DBL_DIG FLT_EPSILON DBL_EPSILON FLT_MANT_DIG DBL_MANT_DIG FLT_MIN FLT_MIN_EXP DBL_MIN DBL_MIN_EXP ﺛﻮﺍﺑﺖ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ:٣,٥,٢ ﺍﳉﺪﻭﻝ ﺗﻮﺟﺪ ﺛﻮﺍﺑﺖ ﺃﺧﺮﻯ ﻛﺜﲑﺓ ﳝﻜﻦ ﺭﺃﻳﺘﻪ ﰲ ﺍﳌﻠﻒ،float.h ﺗﻌﺘﱪ ﻫﺬﺍ ﺍﻟﺜﻮﺍﺑﺖ ﻣﻦ ﺃﻫﻢ ﺍﻟﺜﻮﺍﺑﺖ ﺍﳌﻮﺟﻮﺩ ﰲ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ .float.h ﺍﻟﺮﺃﺳﻲ :limits.h ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ٣,٥,٥ : ﺍﻟﺜﻮﺍﺑﺖ ﻫﻲ،ﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻟﺜﻮﺍﺑﺖ ﻷﺣﺠﺎﻡ ﲨﻴﻊ ﺍﻷﻧﻮﺍﻉ ﺍﳌﺘﻜﺎﻣﻠﺔ 205 ﺍﺳﻢ ﺍﻟﺜﺎﺑﺖ CHAR_BIT CHAR_MIN INT_MIN LONG_MIN SHRT_MIN SCHAR_MIN LONG_MAX SCHAR_MAX SHRT_MAX UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX INT_MAX CHAR_MAX ﻗﻴﻤﺘﻪ 8 -128 -32767 -2147483647 -32768 -128 2147483647 127 32767 255 65535 4294967295 65535 32767 127 ﺍﳉﺪﻭﻝ :٣,٥,١ﺛﻮﺍﺑﺖ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ limits.h ﻭ ﺗﻮﺟﺪ ﺛﻮﺍﺑﺖ ﺃﺧﺮﻯ ﳝﻜﻦ ﺭﺃﻳﺘﻬﺎ ﰲ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ .limits.h ٣,٥,٦ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ :locale.h ﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﳎﻤﻮﻋﺔ ﻣﻦ ﺗﺮﺍﻛﻴﺐ ،ﺛﻮﺍﺑﺖ ،ﳐﺘﺼﺮﺍﺕ ﻭ ﺩﻭﺍﻝ ﻣﺴﺘﻌﻤﻞ ﻣﻦ ﻗﺒﻞ ﺭﻭﺗﻴﻨﻴﺎﺕ ﺍﳌﻮﺍﻗـﻊ )ﺍﳌﻨـﺎﻃﻖ(، ﺛﻮﺍﺑﺖ ﻫﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﻋﻠﻰ ﺍﻟﺸﻜﻞ ﺍﻟﺘﺎﱄ: 0 1 2 3 4 5 LC_ALL LC_TIME ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١٧ﺛﻮﺍﺑﺖ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME LC_MIN LC_MAX #define #define #define #define #define #define #define #define 1 2 3 4 5 6 7 8 locale.h ﻻ ﻳﻌﺘﱪ ﻫﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﻣﻬﻢ ،ﻫﻮ ﺧﺎﺹ ﺑﺘﺤﺪﻳﺪ ﺍﳌﻨﻄﻘﺔ ﺃﻭ ﺍﻟﺒﻼﺩ ﺍﻟﱵ ﺗﺮﻳﺪ ﺍﺳﺘﻌﻤﺎﻝ ﺃﺻﻨﺎﻓﻬﺎ ﰲ ﺑﺮﻧﺎﳎﻚ ،ﻣﻨﻬﺎ ﺍﻟﻠﻐﺔ. ﺃﻟﻘﻲ ﻟﻨﻈﺮﺓ ﻋﻠﻰ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ locale.hﻟﺮﺅﻳﺔ ﺑﺎﻗﻲ ﳏﺘﻮﻳﺎﺗﻪ. ٣,٥,٧ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ :math.h ﳛﻤﻞ ﻫﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻟﺜﻮﺍﺑﺖ ﻭ ﺍﳌﺨﺘﺼﺮﺍﺕ ﻭ ﺍﻟﺪﻭﺍﻝ ﺍﳋﺎﺹ ﺑﺎﻟﺮﻳﺎﺿﻴﺎﺕ .ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﺜﻮﺍﺑﺖ ﻓﻬﻲ ﻣﻌﺮﻓﺔ ﻋﻠﻰ ﺍﻟﺸﻜﻞ ﺍﻟﺘﺎﱄ: 206 1 2 3 4 5 6 7 8 9 10 11 12 13 #define #define #define #define #define #define #define #define #define #define #define #define #define M_E M_LOG2E M_LOG10E M_LN2 M_LN10 M_PI M_PI_2 M_PI_4 M_1_PI M_2_PI M_2_SQRTPI M_SQRT2 M_SQRT1_2 2.71828182845904523536 1.44269504088896340736 0.434294481903251827651 0.693147180559945309417 2.30258509299404568402 3.14159265358979323846 1.57079632679489661923 0.785398163397448309616 0.318309886183790671538 0.636619772367581343076 1.12837916709551257390 1.41421356237309504880 0.707106781186547524401 math.h ﺛﻮﺍﺑﺖ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ:٣,٥,١٨ ﺍﻟﱪﻧﺎﻣﺞ .math.h ﺃﻣﺎ ﺍﻟﺒﺎﻗﻲ ﻓﻴﻤﻜﻦ ﺭﺃﻳﺘﻬﺎ ﻣﻦ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ،ﺃﻣﺎ ﺍﳌﺨﺘﺼﺮﺍﺕ ﻭ ﺍﻟﺪﻭﺍﻝ ﻓﺴﻨﺪﺭﺱ ﺃﳘﻬﺎ :sin ﺍﻟﺪﺍﻟﺔ٣,٥,٧,١ ، ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﰎ ﲤﺮﻳﺮﻫﺎ ﺇﻟﻴﻬـﺎsine ﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﺈﺭﺟﺎﻉ ﺟﻴﺐ،double ﻭﺳﻴﻂ ﻭﺍﺣﺪ ﻭ ﻫﻮ ﳌﺘﻐﲑ ﻣﻦ ﻧﻮﻉsin ﻟﺪﺍﻟﺔ :ﻣﺜﺎﻝ 1 2 3 4 5 6 7 8 #include<stdio.h> #include<math.h> main(){ double x = 3.14/2; printf("sine x = %f\n", sin(x)); } sin ﺍﻟﺪﺍﻟﺔ:٣,٥,١٩ ﺍﻟﱪﻧﺎﻣﺞ :cos ﺍﻟﺪﺍﻟﺔ٣,٥,٧,٢ ﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﺈﺭﺟﺎﻉ ﺟﻴﺐ ﺍﻟﺘﻤﺎﻡ ﻟﻠﻘﻴﻤـﺔ،double ﻭ ﳍﺎ ﻭﺳﻴﻂ ﻭﺍﺣﺪ ﻣﻦ ﻧﻮﻉ،cosine ﳐﺘﺼﺮ ﻣﻦcos ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ : ﻣﺜﺎﻝ،ﺍﻟﱵ ﰎ ﲤﺮﻳﺮﻫﺎ ﺇﻟﻴﻬﺎ 1 2 3 4 5 6 7 8 #include<stdio.h> #include<math.h> main(){ double x = 3.14/2; } printf("cosine x = %f\n", cos(x)); 207 ٣,٥,٧,٣ﺍﻟﺪﺍﻟﺔ :tan ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٠ﺍﻟﺪﺍﻟﺔ cos ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ tanﳐﺘﺼﺮ ﻣﻦ ،tangentﻭ ﳍﺎ ﻭﺳﻴﻂ ﻭﺍﺣﺪ ﳌﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ،doubleﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﺈﺭﺟﺎﻉ ﺍﻟﻈﻞﹼ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﰎ ﲤﺮﻳﺮﻫﺎ ﺇﻟﻴﻬﺎ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<math.h {)(main ;double x = 3.14/4 ;))printf("tangent x = %f\n", tan(x ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢١ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 tan ٣,٥,٧,٤ﺍﻟﺪﺍﻟﺔ :exp ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ expﳐﺘﺼﺮ ﻣﻦ ،exponentialﻭ ﳍﺎ ﻭﺳﻴﻂ ﻭﺍﺣﺪ ﻣﻦ ﻧﻮﻉ ،doubleﺣﻴﺚ ﺗﻜﻮﻥ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﻟﻪ ﻫـﻲ ﺃﺱ ،e ﻣﺜﺎﻝ: >#include<stdio.h >#include<math.h {)(main ;double x = 3.0 ;))printf("exponential x = %f\n", exp(x ٣,٥,٧,٥ﺍﻟﺪﺍﻟﺔ :log ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٢ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 exp ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ logﳐﺘﺼﺮ ﻣﻦ ،logarithmﻭ ﺎ ﻭﺳﻴﻂ ﻭﺍﺣﺪ ﻭ ﻫﻮ ﳌﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ،doubleﻭ ﺗﻘﻮﻡ ﺍﻟﺪﺍﻟـﺔ ﺑﺈﺭﺟـﺎﻉ ﻟﻮﻏﺎﺭﻳﺘﻤﻴﺔ ﺍﻟﻘﻴﻤﺔ ﺍﻟﱵ ﰎ ﲤﺮﻳﺮﻫﺎ ﺇﻟﻴﻬﺎ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<math.h {)(main ;double x = 100.0 ;))printf("logarithm x = %f\n", log(x ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٣ﺍﻟﺪﺍﻟﺔ log } 1 2 3 4 5 6 7 8 208 ٣,٥,٧,٥ﺍﻟﺪﺍﻟﺔ :pow ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ powﳐﺘﺼﺮ ﻣﻦ ،powerﻭ ﺎ ﻭﺳﻴﻄﲔ ،ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻫﻮ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ،doubleﻭ ﺍﻟﺜﺎﱐ ﺃﻳﻀﺎ ﻣـﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ،doubleﺣﻴﺚ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻳﻜﻮﻥ ﻋﺪﺩ ﺃﺱ ﻗﻴﻤﺔ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<math.h {)(main ;double x=5.0, y=3.0 ;))printf("%f\n", pow(x, y ٣,٥,٧,٦ﺍﻟﺪﺍﻟﺔ :sqrt ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٤ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 pow ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ sqrtﳐﺘﺼﺮ ﻣﻦ ،squareﻭ ﳍﺎ ﻭﺳﻴﻂ ﻭﺍﺣﺪ ﳌﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ،doubleﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﺈﺭﺟﺎﻉ ﺍﳉﺬﺭ ﺍﻟﺘﺮﺑﻴﻌﻲ ﻟﻠﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﻟﻪ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<math.h {)(main ;double x=9.0 ;))printf("%f\n", sqrt(x ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٥ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 sqrt ٣,٥,٧,٧ﺍﻟﺪﺍﻟﺔ :ceil ﻟﻠﺪﺍﻟﺔ ceilﻭﺳﻴﻂ ﻭﺍﺣﺪ ﻭ ﻫﻮ ﳌﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ،doubleﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﺄﺧﺬ ﺍﻟﻌﺪﺩ ﺍﳌﻌﻄﺎﺓ ﳍﺎ ﻋﻠـﻰ ﺷـﻜﻞ ﻋـﺪﺩ ﺻﺤﻴﺢ ،ﻓﺈﺫﺍ ﻛﺎﻧﺖ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﳍﺎ ﻫﻲ ٣,١ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ،٤ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻧﺖ ٣,٠ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﻫـﻲ ﻧﻔـﺴﻬﺎ ،٣,٠ﻣﺜﺎﻝ: >#include<stdio.h >#include<math.h {)(main ;double x=9.5 ;))printf("%f\n", ceil(x ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٦ﺍﻟﺪﺍﻟﺔ ceil } 1 2 3 4 5 6 7 8 209 ٣,٥,٧,٨ﺍﻟﺪﺍﻟﺔ :floor ﺍﻟﺪﺍﻟﺔ floorﻫﻲ ﻣﻌﺎﻛﺲ ﻟﺪﺍﻟﺔ ،ceilﻓﺈﺫﺍ ﻛﺎﻧﺖ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﳍﺎ ٣,١ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ،٣,٠ﻣﺜﺎﻝ: >#include<stdio.h >#include<math.h {)(main ;double x=10.5 ;))printf("%f\n", floor(x ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٧ﺍﻟﺪﺍﻟﺔ ٣,٥,٧,٩ﺍﻟﺪﺍﻟﺔ :fabs ﺍﺳﻢ ﺍﻟﺪﺍﻟﺔ fabsﳐﺘﺼﺮ ﻣﻦ ﻣﺜﺎﻝ: absolute } floor ،floatﻭ ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺈﺭﺟﺎﻉ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻄﻠﻘﺔ ﻟﻠﻌﺪﺩ ﺍﻟﺬﻱ ﰎ ﲤﺮﻳـﺮﻩ ﳍـﺎ، >#include<stdio.h >#include<math.h {)(main ;double x=-10.5, y=10.5 ;))printf("%f\n", fabs(x ;))printf("%f\n", fabs(y ٣,٥,٧,١٠ﺍﻟﺪﺍﻟﺔ :ldexp 1 2 3 4 5 6 7 8 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٨ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 fabs ﳍﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻭﺳﻴﻄﲔ ،ﺍﻷﻭﻝ ﳌﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ،doubleﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ،intﺣﻴﺚ ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟـﺔ ﺑﻀﺮﺏ ﻗﻴﻤﺔ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﰲ ٢ﺃﺱ ﻗﻴﻤﺔ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<math.h {)(main ;double x=2.0, y=4.0 printf("%f\n", ldexp(x, y)); /*y = 2*2*2*2, x = 2; x*y = 32.000000*/ ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٩ﺍﻟﺪﺍﻟﺔ ٣,٥,٧,١١ﺍﻟﺪﺍﻟﺔ :fmod ldexp } 1 2 3 4 5 6 7 8 210 ﳍﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻭﺳﻴﻄﲔ ،ﻛﻼﳘﺎ ﻣﺘﻐﲑﺍﻥ ﻣﻦ ﻧﻮﻉ ،doubleﺣﻴﺚ ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﻘﺴﻤﺔ ﻗﻴﻤﺔ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻋﻠﻰ ﻗﻴﻤﺔ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<math.h {)(main ;double x=2.0, y=4.0 ;))printf("%f\n", fmod(x, y ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣٠ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 fmod ٣,٥,٨ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ :setjmp.h ﳛﺘﻮﻱ ﻫﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﻋﻠﻰ ﺩﺍﻟﺘﲔ ﳘﺎ setjmpﻭ ،longjmpﺣﻴﺚ ﲢﺘﻮﻱ ﺍﻟﺪﺍﻟﺔ setjmpﻋﻠﻰ ﻭﺳﻴﻂ ﻭﺍﺣـﺪ ﻭ ﻫﻮ ﻣﺆﺷﺮ ﻟﺒﻨﻴﺔ jmp_bufﻭ ﻫﻲ ﻣﻌﺮﻓﺔ ﰲ ﻧﻔﺲ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،ﻭ ﲢﺘﻮﻱ ﺍﻟﺪﺍﻟﺔ longjmpﻋﻠﻰ ﻭﺳﻴﻄﲔ ،ﺍﻷﻭﻝ ﻟﻠﺒﻨﻴـﺔ jmp_bufﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﳌﺘﻐﲑ ﻣﻦ ﻧﻮﻉ .intﺗﺴﺘﻌﻤﻞ ﺍﻟﺪﺍﻟﺔ setjmpﻣﻊ ﺍﻟﺪﺍﻟﺔ ،longjmpﻭ ﺍﳍﺪﻑ ﻣﻨﻬﻤﺎ ﻫﻮ ﺍﻟﻘﻔﺰ ﺇﱃ ﳐﺘﻠﻒ ﺃﻣﺎﻛﻦ ﺍﻟﱪﻧﺎﻣﺞ ،ﻓﻤﺜﻼ ﻧﺴﺘﻌﻤﻞ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ gotoﻟﻠﻘﻔﺰ ﻣﻦ ﻣﻜﺎﻥ ﻵﺧﺮ ﰲ ﺩﺍﻟـﺔ ﻣﻌﻨﻴـﺔ ،ﻭ ﻻ ﳝﻜـﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﻟﻠﻘﻔﺰ ﺍﻟﻌﺎﻡ ) ،(Globalﻣﺜﺎﻝ: >#include<stdio.h >#include<setjmp.h >#include<stdlib.h ;)void Return(void ;jmp_buf jmp {)(main ;int value ;)value = setjmp(jmp { ;)"printf("Block 1:\n {)if(value==1 ;)printf("longjmp = %d\n", value ;)exit(1 } } ;)"printf("Block 2:\n ;)"printf("Call Return...\n ;)(Return { } } {)void Return(void 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 211 ;)longjmp(jmp, 1 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣١ﺍﻟﺪﺍﻟﺔ ،setjmpﻭ ﺍﻟﺒﻨﻴﺔ } 28 29 jmp_buf ٣,٥,٩ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ :signal.h ﳛﺘﻮﻱ ﻫﺬﻩ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﻋﻠﻰ ﺩﺍﻟﺘﲔ ﳘﺎ signalﻭ ،raiseﻭ ﺍﻟﺪﺍﻟﺔ ﺍﳌﺴﺘﻌﻤﻠﺔ ﺑﻜﺜﺮﺓ ﻫﻲ ﺍﻟﺪﺍﻟﺔ .raise ٣,٥,٩,١ﺍﻟﺪﺍﻟﺔ :raise ﲢﺘﻮﻱ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻋﻠﻰ ﻭﺳﻴﻂ ﻣﻦ ﻧﻮﻉ ،intﻭ ﻋﻤﻠﻬﺎ ﻫﻮ ﺇﺎﺀ ﺍﻟﱪﻧﺎﻣﺞ ﰲ ﺣﺎﻻﺕ ﻣﺜﻞ ﺣﺪﻭﺙ ﺇﻧﺘﻬﺎﻙ ﰲ ﺫﺍﻛـﺮﺓ ﺍﳊﺎﺳﻮﺏ ،ﻭ ﺗﻮﺟﺪ ﺛﻮﺍﺑﺖ ﺧﺎﺻﺔ ﺎ ﰲ ﻧﻔﺲ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،ﻭ ﻛﻞ ﺛﺎﺑﺖ ﻭ ﺣﺎﻟﺘﻪ ،ﻭ ﻫﺬﺍ ﺟﺪﻭﻝ ﻷﻫﻢ ﺍﻟﺜﻮﺍﺑـﺖ ﺍﻟـﱵ ﺗﺴﺘﻌﻤﻞ ﻣﻊ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ: ﺍﺳﻢ ﺍﻟﺜﺎﺑﺖ ﻗﻴﻤﺘﻪ ﺍﻟﺸﺮﺡ SIGABRT ٢٢ ﰲ ﺣﺎﻟﺔ ﺍﻹﻧﺘﻬﺎﺀ ﺍﻟﻐﲑ ﺍﻟﻄﺒﻴﻌﻲ ﻟﻠﱪﻧﺎﻣﺞ ،ﻳﺴﺘﺪﻋﻲ ﺍﻟﺪﺍﻟﺔ SIGFPE ٨ ﰲ ﺣﺎﻟﺔ ﺧﻄﺄ ﺭﻳﺎﺿﻲ SIGILL ٤ ﰲ ﺣﺎﻟﺔ ﺣﺪﻭﺙ ﺃﻣﺮ ﻏﲑ ﺷﺮﻋﻲ SIGINT ٢ ﺍﳌﻘﺎﻃﻌﺔ SIGSEGV ١١ ﰲ ﺣﺎﻟﺔ ﺣﺪﻭﺙ ﺇﻧﺘﻬﺎﻙ ﻟﺬﺍﻛﺮﺓ SIGTERM ١٥ ﺇﺎﺀ ﺍﻟﱪﻧﺎﻣﺞ ﺍﳉﺪﻭﻝ :٣,٥,١ﺃﻫﻢ ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﱵ ﺗﺴﺘﻌﻤﻞ ﻣﻊ ﺍﻟﺪﺍﻟﺔ abort raise ٣,٥,١٠ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ :stdarg.h ﺍﺳﻢ ﻫﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﳐﺘﺼﺮ ﻣﻦ ،standard argumentﻭ ﻫﻮ ﺧﺎﺹ ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﻟﻮﺳﺎﺋﻂ ﺍﳌﺘﻌﺪﺩﺓ ﻟـﺪﻭﺍﻝ .ﳛﺘـﻮﻱ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ stdarg.hﻋﻠﻰ ﺍﳌﺆﺷﺮ ،va_listﻭ ﻫﻮ ﺍﻟﺬﻱ ﺳﻴﺤﻤﻞ ﻋﺪﺩ ﺍﻟﻮﺳﺎﺋﻂ ﺃﻭ ﻭﺳﺎﺋﻂ ﺍﻟﱵ ﺳﻴﺘﻢ ﺍﺳـﺘﻌﻤﺎﳍﺎ ﰲ ﺍﻟﺪﺍﻟﺔ ،ﻭ ﳚﺐ ﺩﺍﺋﻤﺎ ﺗﺸﻐﻴﻞ initializeﺍﳌﺆﺷﺮ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﳌﺨﺘﺼﺮ ،va_startﺣﻴﺚ ﳛﺘﻮﻱ ﻫـﺬﺍ ﺍﳌﺨﺘـﺼﺮ ﻋﻠـﻰ ﻭﺳﻴﻄﲔ ،ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻫﻮ ﳌﺆﺷﺮ va_listﺍﻟﺬﻱ ﺳﻴﺘﻢ ﺗﺸﻐﻴﻠﻪ ،ﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻫﻮ ﺍﺳﻢ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻟﺪﺍﻟﺔ .ﻭ ﺑﻌﺪ ﺫﻟﻚ ﻧﺴﺘﻌﻤﻞ ﺍﳌﺨﺘﺼﺮ ،va_argﻭ ﺍﻟﺬﻱ ﳛﺘﻮﻱ ﻋﻠﻰ ﻭﺳﻴﻄﲔ ،ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻫﻮ ﻣﺆﺷﺮ ﻟـ val_listﺍﻟﺬﻱ ﺳـﻴﺘﻢ ﺍﺳﺘﻌﻤﺎﻟﻪ ﰲ ﺍﻟﺪﺍﻟﺔ ،ﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻧﻀﻊ ﻓﻴﻪ ﻧﻮﻉ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺬﻱ ﺳﻴﺘﻢ ﺃﺧﺬﻩ ،ﻭ ﰲ ﺍﻟﻨﻬﺎﻳﺔ ﻧﻘﻮﻡ ﺑﺈﺎﺀ ﺗـﺸﻐﻴﻞ ﺍﳌﺆﺷـﺮ va_listﻭ ﺫﻟﻚ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﳌﺨﺘﺼﺮ ،va_endﻣﺜﺎﻝ: >#include<stdio.h 1 212 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #include<stdarg.h> void Arg_List(int list, ...); /*Function prototype*/ main(){ Arg_List(5, 10, 20, 30, 40, 50); } void Arg_List(int list, ...){ va_list pList; int iArg=0, i; printf("There are %d argument(s)\n", list); va_start(pList, list); /*initialize the pList pointer*/ for(i=01;i<=list;i++){ iArg = va_arg(pList, int); printf("argument %d = %d\n", i, iArg); } va_end(pList); } va_list ﻭ ﺍﳌﺆﺷﺮ،va_end ﻭ ﺍﻟﺪﺍﻟﺔva_arg ﺍﻟﺪﺍﻟﺔ،va_start ﺍﻟﺪﺍﻟﺔ:٣,٥,٣٢ ﺍﻟﱪﻧﺎﻣﺞ ﻭ ﻫﻮ ﻣﻌﺮﻑ ﻋﻠﻰ ﺍﻟﺸﻜﻞNULL ﻭ ﻫﻮ ﳛﺘﻮﻱ ﻋﻠﻰ ﺍﻟﺜﺎﺑﺖ،Standard #define NULL :stddef.h ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ٣,٥,١١ Definition ﺍﺳﻢ ﻫﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﳐﺘﺼﺮ ﻣﻦ :ﺍﻟﺘﺎﱄ 0 : ﻭ ﻫﻮ ﻣﻌﺮﻑ ﻋﻠﻰ ﺍﻟﺸﻜﻞ ﺍﻟﺘﺎﱄsize_t ﻭ ﳛﺘﻮﻱ ﻋﻠﻰ ﺍﳌﺘﻐﲑ typedef unsigned size_t; :ﻭ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻟﻪ ﻛﺘﺎﱄ 1 2 3 4 5 6 7 8 #include<stdio.h> #include<stddef.h> main(){ size_t uInt = 65535; printf("%u\n", uInt); } 213 ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣٣ﺍﳌﺘﻐﲑ size_t ﻭ ﳛﺘﻮﻱ ﺃﻳﻀﺎ ﻋﻠﻰ ﺍﳌﺘﻐﲑ ،ptrdiff_tﻭ ﻫﻮ ﻣﻌﺮﻑ ﺑﻄﺮﻳﻘﺘﲔ ﳘﺎ: ;ptrdiff_t typedef long ﻭ ﺍﻟﻄﺮﻳﻘﺔ: ;typedef int ptrdiff_t ﺣﻴﺚ ﻳﺘﻢ ﺇﺧﺘﻴﺎﺭ ﻭﺍﺣﺪ ﻣﻦ ﺍﻟﻄﺮﻳﺘﲔ ﺣﺴﺐ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻌﻄﺎﺓ ﺃﻭ ﺍﳌﺴﺘﻌﻤﻠﺔ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<stddef.h {)(main ;ptrdiff_t Int = 65535 ;ptrdiff_t Long = 2147483647 ;)printf("Int = %d\n", Int ;)printf("Long = %d\n", Long ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣٤ﺍﳌﺘﻐﲑ } 1 2 3 4 5 6 7 8 9 10 ptrdiff_t ٣,٥,١٢ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ :stdio.h ﻳﻌﱪ ﻣﻦ ﺃﻫﻢ ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ،ﻭ ﺍﲰﻪ ﳐﺘﺼﺮ ﻣﻦ ،Standard Input Outputﺣﻴﺚ ﳛﺘﻮﻱ ﻋﻠﻰ ﺃﻫﻢ ﺍﻟﺪﻭﺍﻝ ﻭ ﺍﳌﺨﺘﺼﺮﺍﺕ ﺍﻟﱵ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﳍﺎ ﰲ ﺃﻏﻠﺐ ﺍﻟﱪﺍﻣﺞ ،ﻭ ﺩﺭﺍﺳﺔ ﲨﻴﻊ ﺗﻠﻚ ﺍﻟﺪﻭﺍﻝ ﻭ ﺍﳌﺨﺘﺼﺮﺍﺕ ﺑﺄﻣﺜﻞ ﻳﺄﺧﺬ ﺍﻟﻜـﺜﲑ ﻣـﻦ ﺍﻟﺼﻔﺤﺎﺕ ﻟﺬﺍ ﻧﻜﺘﻔﻲ ﲟﻌﺮﻓﺔ ﺃﲰﺎﺀ ﺗﻠﻚ ﺍﻟﺪﻭﺍﻝ ﻭ ﺍﳌﺨﺘﺼﺮﺍﺕ ﻭ ﺍﳍﺪﻑ ﻣﻨﻬﺎ .ﻳﻨﻘﺴﻢ ﻫﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﺇﱃ ﺃﺻﻨﺎﻑ ،ﻟﻜﻞ ﺻﻨﻒ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻟﺪﻭﺍﻝ ﻭ ﺍﳌﺨﺘﺼﺮﺍﺕ ﺍﳋﺎﺻﺔ ﺑﻪ. ٣,٥,١٢,١ﺍﻟﺪﺍﻟﺔ :printf ﲢﺘﻮﻱ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻋﻠﻰ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ ،ﺗﺘﺰﺍﻳﺪ ﺣﺴﺐ ﺭﻏﺒﺔ ﺍﳌﱪﻣﺞ ،ﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ ﻛﻞ ﻣﻦ ﺍﻷﺣـﺮﻑ ﻭ ﺍﻷﺭﻗﺎﻡ ﻭ ﺍﻟﻨﺼﻮﺹ ،ﻣﺜﺎﻝ: >#include<stdio.h {)(main 1 2 3 214 4 5 6 7 8 9 10 11 int Number = 100; char Char = 'A'; char String[] = "Hello, World!\n"; printf("%d\n", Number); printf("%c\n", Char); printf(String); } printf ﺍﻟﺪﺍﻟﺔ:٣,٥,٣٥ ﺍﻟﱪﻧﺎﻣﺞ :sprintf ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٢ ﻭ ﻟﻜﻦ ﻟﺪﻳﻪ ﻭﺳﻴﻂ ﺇﺿﺎﰲ ﰲ ﺑﺪﺍﻳﺘﻬﺎ ﺣﻴﺚ ﻫﻮ ﻋﺒﺎﺭﺓ ﻋـﻦ ﻣـﺘﻐﲑ،ﺃﻳﻀﺎ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﲢﺘﻮﻱ ﻋﻠﻰ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﻭﺩﺓ : ﻣﺜﺎﻝ، ﻭ ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﻜﺘﺎﺑﺔ ﻧﺺ ﰲ ﺗﻠﻚ ﺍﻟﺴﻠﺴﻠﺔ ﺍﻟﻨﺼﻴﺔ،ﻟﺴﻠﺴﻠﺔ ﺣﺮﻭﻑ 1 2 3 4 5 6 7 8 9 10 #include<stdio.h> main(){ char Buffer[255]; sprintf(Buffer, "Number = %d\nCharacter = %c\nString = %s\n", 100, 'A', "Hello, World!"); } printf(Buffer); sprintf ﺍﻟﺪﺍﻟﺔ:٣,٥,٣٦ ﺍﻟﱪﻧﺎﻣﺞ :vprintf ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٣ : ﻣﺜﺎﻝ،va_list ﻭ ﻟﻜﻨﻬﺎ ﺗﺄﺧﺬ ﺍﻟﻮﺳﺎﺋﻂ ﻋﻠﻰ ﺷﻜﻞprintf ﻣﺜﻞ ﺍﻟﺪﺍﻟﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #include<stdio.h> #include<stdarg.h> void ArgLst(char *format, ...); main(){ int Number = 100; char Char = 'A'; char String[] = "Hello, World!"; } ArgLst("Number = %d\nChar = %c\nStrin = %s\n",\ Number, Char, String); void ArgLst(char *format, ...){ va_list Lst; va_start(Lst, format); vprintf(format, Lst); va_end(Lst); } 215 vprintf ﺍﻟﺪﺍﻟﺔ:٣,٥,٣٧ ﺍﻟﱪﻧﺎﻣﺞ :vfprintf ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٤ : ﻣﺜﺎﻝ، ﻓﻘﻂ ﻫﻲ ﺧﺎﺻﺔ ﺑﺎﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﻠﻔﺎﺕvprintf ﻫﻲ ﻣﻄﺎﺑﻘﺔ ﻟﺪﺍﻟﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #include<stdio.h> #include<stdarg.h> void ArgLst(char *format, ...); main(){ int Number = 100; char Char = 'A'; char String[] = "Hello, World!"; } ArgLst("Number = %d\nChar = %c\nStrin = %s\n",\ Number, Char, String); void ArgLst(char *format, ...){ va_list Lst; FILE *File; File = fopen("Info.txt", "w"); va_start(Lst, format); vfprintf(File, format, Lst); va_end(Lst); fclose(File); } vfprintf ﺍﻟﺪﺍﻟﺔ:٣,٥,٣٨ ﺍﻟﱪﻧﺎﻣﺞ :vsprintf ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٥ : ﻣﺜﺎﻝ،vprintf ﻭ ﺍﻟﺪﺍﻟﺔsprintf ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻣﺪﳎﺔ ﻣﻊ ﻛﻞ ﻣﻦ ﺍﻟﺪﺍﻟﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> #include<stdarg.h> void ArgLst(char *format, ...); main(){ int Number = 100; char Char = 'A'; char String[] = "Hello, World!"; char buffer[255]; ArgLst(buffer, "Number = %d\nChar = %c\nStrin = %s\n",\ Number, Char, String); } printf(buffer); 216 17 18 19 20 21 22 23 24 void ArgLst(char *buffer, char *format, ...){ va_list Lst; va_start(Lst, format); vsprintf(buffer, format, Lst); va_end(Lst); } vsprintf ﺍﻟﺪﺍﻟﺔ:٣,٥,٣٩ ﺍﻟﱪﻧﺎﻣﺞ :scanf ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٦ : ﻣﺜﺎﻝ، ﻭ ﻫﻲ ﺩﺍﻟﺔ ﺧﺎﺻﺔ ﺑﺎﻹﺩﺧﺎﻝ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺎﺳﺘﻘﺒﺎﻝ ﺍﻟﺮﻣﻮﺯ ﻣﻦ ﻟﻮﺣﺔ ﺍﳌﻔﺎﺗﻴﺢ 1 2 3 4 5 6 7 8 9 #include<stdio.h> main(){ char string[255]; } printf("Your name, Please: "); scanf("%s", string); printf("Nice to meet you %s!\n", string); scanf ﺍﻟﺪﺍﻟﺔ:٣,٥,٤٠ ﺍﻟﱪﻧﺎﻣﺞ :fscanf ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٧ : ﻣﺜﺎﻝ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺄﺧﺬ ﺭﻣﻮﺯ ﻣﻦ ﻣﻠﻒ ﻧﺼﻲ ﺇﻣﺎ ﻋﻠﻰ ﺷﻜﻞ ﺃﺭﻗﺎﻡ ﺃﻭ ﺃﺣﺮﻑ ﺃﻭ ﺳﻠﺴﻠﺔ ﻧﺼﻮﺹ 1 2 3 4 5 6 7 8 9 10 11 12 #include<stdio.h> main(){ FILE *File; char buffer[255]; File = fopen("Info.txt", "r"); fscanf(File, "%s", buffer); printf("%s\n", buffer); } fscanf ﺍﻟﺪﺍﻟﺔ:٣,٥,٤١ ﺍﻟﱪﻧﺎﻣﺞ :sscanf ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٨ : ﻣﺜﺎﻝ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﻨﺸﺮ ﺳﻠﺴﻠﺔ ﺣﺮﻭﻑ ﻋﻠﻰ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﳌﺘﻐﲑﺍﺕ ﺑﺸﻜﻞ ﻣﻨﻔﺼﻞ 1 2 3 4 #include<stdio.h> main(){ char buffer[] = "Hello, World! 15"; 217 5 6 7 8 9 10 11 12 13 char string1[255], string2[255]; int number; sscanf(buffer, "%s%s%d", string1, string2, &number); } printf("String = %s %s\n", string1, string2); printf("Number = %d\n", number); sscanf ﺍﻟﺪﺍﻟﺔ:٣,٥,٤٢ ﺍﻟﱪﻧﺎﻣﺞ :fgetc ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٩ : ﻣﺜﺎﻝ، ﺣﻴﺚ ﻛﻠﻤﺎ ﻳﺘﻢ ﺍﺳﺘﻌﻤﺎﻝ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻳﺘﻘﺪﻡ ﻣﺆﺷﺮ ﺍﳌﻠﻒ ﲞﻄﻮﺓ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺄﺧﺬ ﺃﺣﺮﻑ ﻣﻦ ﻣﻠﻒ ﻧﺼﻲ 1 2 3 4 5 6 7 8 9 10 11 12 13 #include<stdio.h> main(){ FILE *File; char ch; File = fopen("Info.txt", "r"); } while(feof(File)==0){ ch = fgetc(File); printf("%c", ch); } fgetc ﺍﻟﺪﺍﻟﺔ:٣,٥,٤٣ ﺍﻟﱪﻧﺎﻣﺞ :fgets ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,١٠ : ﻣﺜﺎﻝ، ﻓﻘﻂ ﺗﺄﺧﺬ ﺳﻄﺮ ﻛﺎﻣﻞ ﺑﺪﻝ ﺣﺮﻑ ﻭﺍﺣﺪfgetc ﻣﺜﻞ ﺍﻟﺪﺍﻟﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include<stdio.h> main(){ FILE *File; char buffer[255]; File = fopen("Info.txt", "r"); while(feof(File)==0){ fgets(buffer, 255, File); printf(buffer); } } fclose(File); fgets ﺍﻟﺪﺍﻟﺔ:٣,٥,٤٤ ﺍﻟﱪﻧﺎﻣﺞ 218 :fputc ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,١١ : ﻣﺜﺎﻝ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﻜﺘﺎﺑﺔ ﺣﺮﻑ ﺇﱃ ﻣﻠﻒ ﻧﺼﻲ 1 2 3 4 5 6 7 8 9 10 #include<stdio.h> main(){ FILE *File; File = fopen("Info.txt", "w"); } fputc('A', File); fclose(File); fputc ﺍﻟﺪﺍﻟﺔ:٣,٥,٤٥ ﺍﻟﱪﻧﺎﻣﺞ :fputs ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,١٢ : ﻣﺜﺎﻝ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﻜﺘﺎﺑﺔ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﰲ ﻣﻠﻒ ﻧﺼﻲ 1 2 3 4 5 6 7 8 9 10 #include<stdio.h> main(){ FILE *File; File = fopen("Info.txt", "w"); } fputs("Hello, World!", File); fclose(File); fputs ﺍﻟﺪﺍﻟﺔ:٣,٥,٤٩ ﺍﻟﱪﻧﺎﻣﺞ :getc ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,١٣ : ﻣﺜﺎﻝ، ﻭ ﻟﻜﻨﻬﺎ ﻻ ﲢﺘﻮﻱ ﻋﻠﻰ ﻭﺳﺎﺋﻂfgetc ﻣﺜﻞ ﺍﻟﺪﺍﻟﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include<stdio.h> main(){ FILE *File; char ch; File = fopen("Info.txt", "r"); while(feof(File)==0){ ch = getc(File); printf("%c", ch); } fclose(File); 219 15 } getc ﺍﻟﺪﺍﻟﺔ:٣,٥,٤٧ ﺍﻟﱪﻧﺎﻣﺞ :getchar ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,١٤ : ﻣﺜﺎﻝ، ﺣﻴﺚ ﺗﺴﺘﻘﺒﻞ ﺣﺮﻑ ﻭﺍﺣﺪ ﻓﻘﻂ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺎﻹﺩﺧﺎﻝ 1 2 3 4 5 6 7 8 9 #include<stdio.h> main(){ char ch; printf("Enter a character: "); ch = getchar(); printf("Your character is: %c\n", ch); } getchar ﺍﻟﺪﺍﻟﺔ:٣,٥,٤٨ ﺍﻟﱪﻧﺎﻣﺞ :gets ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,١٥ : ﻣﺜﺎﻝ، ﻭ ﻫﻲ ﺗﺴﺘﻘﺒﻞ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﻣﻦ ﺍﳌﺴﺘﺨﺪﻡ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺍﻹﺩﺧﺎﻝ ﺃﻳﻀﺎ 1 2 3 4 5 6 7 8 9 #include<stdio.h> main(){ char str[255]; } printf("Enter a string(Max character 255): "); gets(str); printf("Your string are: %s\n", str); gets ﺍﻟﺪﺍﻟﺔ:٣,٥,٤٩ ﺍﻟﱪﻧﺎﻣﺞ :putc ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,١٦ : ﻣﺜﺎﻝ،fputc ﻣﺜﻞ ﺍﻟﺪﺍﻟﺔ 1 2 3 4 5 6 7 8 9 10 #include<stdio.h> main(){ FILE *File; File = fopen("Info.txt", "w"); } putc('A', File); fclose(File); putc ﺍﻟﺪﺍﻟﺔ:٣,٥,٥٠ ﺍﻟﱪﻧﺎﻣﺞ 220 :putchar ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,١٧ : ﻣﺜﺎﻝ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﻄﺒﺎﻋﺔ ﺣﺮﻑ ﻋﻠﻰ ﺷﺎﺷﺔ ﺍﳊﺎﺳﻮﺏ 1 2 3 4 5 6 7 8 9 #include<stdio.h> main(){ char ch = 'A'; printf("ch = "); putchar(ch); putchar('\n'); } putchar ﺍﻟﺪﺍﻟﺔ:٣,٥,٥١ ﺍﻟﱪﻧﺎﻣﺞ :puts ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,١٨ ﺣﻴﺚ ﻳﺘﻢ ﺍﻟﺮﺟﻮﻉ ﺇﱃ ﺳﻄﺮ ﺟﺪﻳـﺪ ﰲ ﻛـﻞ ﺳﻠـﺴﻠﺔ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﻄﺒﺎﻋﺔ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﻋﻠﻰ ﺷﺎﺷﺔ ﺍﳊﺎﺳﻮﺏ : ﻣﺜﺎﻝ،ﺣﺮﻓﻴﺔ 1 2 3 4 5 6 7 8 9 #include<stdio.h> main(){ char str1[] = "Line 1: Hello, World!"; char str2[] = "Line 2: Hello, World!"; } puts(str1); puts(str2); puts ﺍﻟﺪﺍﻟﺔ:٣,٥,٥٢ ﺍﻟﱪﻧﺎﻣﺞ :ungetc ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,١٩ : ﻣﺜﺎﻝ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﲝﺬﻑ ﺣﺮﻑ ﻣﻦ ﻣﻠﻒ ﻧﺼﻲ 1 2 3 4 5 6 7 8 9 10 #include<stdio.h> main(){ FILE *File; File = fopen("Info.txt", "w"); } ungetc('A', File); fclose(File); ungetc ﺍﻟﺪﺍﻟﺔ:٣,٥,٥٣ ﺍﻟﱪﻧﺎﻣﺞ :fopen ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٢٠ 221 ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻟﺴﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﺍﻟﱵ ﻫﻲ ﺍﺳﻢ، ﺣﻴﺚ ﲢﺘﻮﻱ ﻋﻠﻰ ﻭﺳﻴﻄﲔ،ﺗﺴﺘﻌﻤﻞ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻟﻘﺮﺍﺀﺓ ﻭ ﻛﺘﺎﺑﺔ ﺍﳌﻠﻔﺎﺕ ﺣﻴﺚ ﻳﻜﻮﻥ ﺫﻟﻚ ﺍﻟﻨﻤﻂ ﺇﻣـﺎ، ﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻫﻮ ﺍﻟﻨﻤﻂ ﺍﻟﺬﻱ ﺳﻴﺘﻢ ﺍﺳﺘﻌﻤﺎﻟﻪ ﻣﻊ ﺍﳌﻠﻒ،ﺍﳌﻠﻒ ﺍﻟﺬﻱ ﺳﻴﺘﻢ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻌﻪ : ﻣﺜﺎﻝ،ﻟﻠﻜﺘﺎﺑﺔ ﺃﻭ ﺍﻟﻘﺮﺍﺀﺓ ﺃﻭ ﻛﻠﻬﻤﺎ ﻋﻠﻰ ﺍﳌﻠﻔﺎﺕ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #include<stdio.h> main(){ FILE *File; File = fopen("FileName.Ext", "r"); if(File==NULL) printf("File does not exist!\n"); else printf("File exist now!\n"); File = fopen("FileName.Ext", "w"); if(File!=NULL) printf("File Created!\n"); if(File==NULL) printf("File does not exist!\n"); else printf("File exist now!\n"); } fclose(File); fopen ﺍﻟﺪﺍﻟﺔ:٣,٥,٥٤ ﺍﻟﱪﻧﺎﻣﺞ :freopen ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٢١ ﺃﻭstdout ،stdin ﻭ ﺍﻟﺬﻱ ﻳﻜﻮﻥ ﺇﻣـﺎFILE ﻣﻊ ﻭﺳﻴﻂ ﺇﺿﺎﰲ ﳌﺆﺷﺮ ﺑﻴﻨﺔfopen ﺗﺴﺘﻌﻤﻞ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻣﺜﻞ ﺍﻟﺪﺍﻟﺔ : ﻣﺜﺎﻝ،stderr 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #include<stdio.h> main(){ FILE *File; File = freopen("Info.txt", "w", stderr); if(!File) fprintf(stdout, "Error!\n"); else fprintf(File, "String!"); fclose(File); } freopen ﺍﻟﺪﺍﻟﺔ:٣,٥,٥٥ ﺍﻟﱪﻧﺎﻣﺞ 222 ﻭ ﻫﻲ ﺗﻘﻮﻡ ﺑﻐﻠﻖ ﲨﻴـﻊ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 :fclose ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٢٢ _fcloseall ﻭ ﺗﻮﺟﺪ ﺍﻟﺪﺍﻟﺔ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﻐﻠﻖ ﻣﻠﻒ ﺣﻴﺚ ﳝﻜﻦ ﺍﺳﺘﻌﻤﺎﻟﻪ ﻣﺮﺓ ﺃﺧﺮﻯ : ﻣﺜﺎﻝ،ﺍﳌﻠﻔﺎﺕ ﺍﻟﻐﲑ ﻣﻐﻠﻖ ﻭ ﺗﺮﺟﻊ ﻗﻴﻤﺔ ﻟﻌﺪﺩ ﺍﳌﻠﻔﺎﺕ ﺍﻟﱵ ﰎ ﺇﻏﻼﻗﻬﺎ #include<stdio.h> main(){ FILE *File1, *File2, *File3; File1 = fopen("Info1.txt", "w"); File2 = fopen("Info2.txt", "w"); File3 = fopen("Info3.txt", "w"); fclose(File1); printf("%d file(s) closed by _fcloseall()\n",\ _fcloseall()); } fclose ﺍﻟﺪﺍﻟﺔ:٣,٥,٥٦ ﺍﻟﱪﻧﺎﻣﺞ :remove ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٢٣ : ﻣﺜﺎﻝ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﲝﺬﻑ ﺍﳌﻠﻔﺎﺕ 1 2 3 4 5 6 7 8 9 10 11 12 #include<stdio.h> main(){ FILE *File; /*Create temporary.tmp*/ File = fopen("temporary.tmp", "w"); fclose(File); /*remove temporary.tmp*/ remove("temporary.tmp"); } remove ﺍﻟﺪﺍﻟﺔ:٣,٥,٥٧ ﺍﻟﱪﻧﺎﻣﺞ :rename ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٢٤ : ﻣﺜﺎﻝ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺈﻋﺎﺩﺓ ﺗﺴﻤﻴﺔ ﻣﻠﻒ 1 2 3 4 5 6 #include<stdio.h> main(){ printf("Rename Info.txt To Data.dat...\n"); rename("Info.txt", "Data.dat"); printf("Operation Terminate...\n"); 223 ٣,٥,١٢,٢٥ﺍﻟﺪﺍﻟﺔ :tmpfile ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺈﻧﺸﺎﺀ ﻣﻠﻒ ﻣﺆﻗﺖ ﺍﻟﱪﻧﺎﻣﺞ ﺃﻭ ﺎﻳﺔ ﺍﻟﱪﻧﺎﻣﺞ ،ﻣﺜﺎﻝ: } ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٥٨ﺍﻟﺪﺍﻟﺔ file 7 rename temporaryﻟﻠﱪﻧﺎﻣﺞ ،ﺣﻴﺚ ﻳﺘﻢ ﺣﺬﻑ ﺍﳌﻠﻒ ﺍﳌﺆﻗﺖ ﻋﻨـﺪ ﺍﳋـﺮﻭﺝ ﻣـﻦ >#include<stdio.h {)(main ;FILE *File ;)"printf("Create a Temporary File...\n ;)(File = tmpfile ;)"printf("Temporary File Created...\n /*At exit*/ ;)"printf("Temporary File deleted...\n ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٥٩ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 12 tmpfile ٣,٥,١٢,٢٦ﺍﻟﺪﺍﻟﺔ :fread ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﻘﺮﺍﺀﺓ ﳏﺘﻮﻯ ﻣﻠﻒ ﻭ ﻭﺿﻊ ﻧﺴﺨﺔ ﳍﺎ ﰲ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ،ﻭ ﲢﺘﻮﻱ ﻋﻠﻰ ﺃﺭﺑﻌﺔ ﻭﺳﺎﺋﻂ ،ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻫﻮ ﻟﺴﻠﺴﻠﺔ ﺍﳊﺮﻓﻴﺔ ﺍﻟﱵ ﺳﻴﺘﻢ ﻭﺿﻊ ﻓﻴﻬﺎ ﻧﺴﺨﺔ ﻣﻦ ﻧﺺ ﺍﳌﻠﻒ ،ﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻫﻮ ﺣﺠﻢ ﺍﶈﺘﻮﻯ ﺍﻟﻮﺍﺣﺪ ﺑﺎﻟﺒﺎﻳﺘـﺎﺕ ،ﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﻟﺚ ﻫﻮ ﻋﺪﺩ ﺍﻷﺣﺮﻑ ﺍﻟﱵ ﻧﺮﻳﺪ ﻧﺴﺨﻬﺎ ،ﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻷﺧﲑ ﻭ ﻣﺆﺷﺮ ﻟﻠﺒﻨﻴﺔ ،FILEﻣﺜﺎﻝ: >#include<stdio.h {)(main ;FILE *File ;]char buffer[255 ;)"File = fopen("Info.txt", "r ;)fread(buffer, sizeof(char), 255, File ;)printf("%s\n", buffer ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٠ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 fread ٣,٥,١٢,٢٧ﺍﻟﺪﺍﻟﺔ :fwrite ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺎﻟﻜﺘﺎﺑﺔ ﻋﻠﻰ ﺍﳌﻠﻔﺎﺕ ،ﻭ ﻫﻲ ﺍﻟﺪﺍﻟﺔ ﺍﳌﻌﺎﻛﺴﺔ ﻟﺪﺍﻟﺔ ،freadﻭ ﳍﺎ ﻧﻔﺲ ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ ،freadﻣﺜﺎﻝ: >#include<stdio.h 1 2 224 3 4 5 6 7 8 9 10 11 main(){ FILE *File; char buffer[] = "String!"; File = fopen("Info.txt", "w"); } fwrite(buffer, sizeof(char), 7, File); fclose(File); fwrite ﺍﻟﺪﺍﻟﺔ:٣,٥,٦١ ﺍﻟﱪﻧﺎﻣﺞ :fseek ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٢٨ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻫـﻮ ﻣﺆﺷـﺮ، ﺣﻴﺚ ﲢﺘﻮﻱ ﻋﻠﻰ ﺛﻼﺛﺔ ﻭﺳﺎﺋﻂ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺎﻟﺘﺤﻜﻢ ﰲ ﻣﻜﺎﻥ ﻣﺆﺷﺮ ﳌﻠﻒ ﻧﺼﻲ ﻭ ﻫﻮ ﻋﺪﺩ ﺍﻟﺒﺎﻳﺘﺎﺕlong ﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻫﻮ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ، ﻭ ﻫﻮ ﺍﳌﻠﻒ ﺍﻟﺬﻱ ﺳﻴﺘﻢ ﲢﺪﻳﺪ ﻣﻜﺎﻥ ﻣﺆﺷﺮﻩFILE ﻟﻠﺒﻨﻴﺔ ، ﻓﺴﻴﺘﻢ ﲡﺎﻫﻞ ﲬﺴﺔ ﺑﺎﻳﺘﺎﺕ ﺑﻌﺪ ﺍﳌﺆﺷﺮ ﺍﻟﺬﻱ ﰎ ﲢﺪﻳﺪﻩ ﰲ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﻟﺚ٥ ﻣﺜﻼ ﺇﺫﺍ ﺃﻋﻄﻴﻨﺎﻩ ﺍﻟﻘﻴﻤﺔ،ﻣﻦ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﻟﺚ ﻭ ﻟﻪ ﺛﻮﺍﺑﺖ ﻭ ﻫـﻲ، ﻭ ﻣﻦ ﻫﺬﺍ ﺍﻟﻮﺳﻴﻂ ﻧﻘﻮﻡ ﺑﺘﺤﺪﻳﺪ ﺍﳌﺆﺷﺮ ﻟﻨﺺ،int ﻭ ﻫﻮ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ،ﻭ ﺃﺧﲑﺍ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﻟﺚ : ﻣﺜﺎﻝ،SEEK_END ﻭSEEK_SET ﻭSEEK_CUR 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #include<stdio.h> main(){ FILE *File; char ch_set, ch_cur, ch_end; File = fopen("Info.txt", "r"); /*Beginning of file*/ fseek(File, 0L, SEEK_SET); printf("SEEK_SET Begin:\n"); while(feof(File)==0){ ch_set = fgetc(File); printf("%c", ch_set); } printf("\nSEEK_SET End.\n"); /*Current position of file pointer*/ fseek(File, 0L, SEEK_CUR); printf("SEEK_CUR Begin:\n"); while(feof(File)==0){ ch_cur = fgetc(File); printf("%c", ch_cur); } printf("\nSEEK_CUR End.\n"); /*End of file*/ fseek(File, 0L, SEEK_END); printf("SEEK_END Begin:\n"); 225 33 34 35 36 37 38 while(feof(File)==0){ ch_end = fgetc(File); printf("%c", ch_end); } printf("\nSEEK_END End.\n"); } fseek ﺍﻟﺪﺍﻟﺔ:٣,٥,٦٢ ﺍﻟﱪﻧﺎﻣﺞ :ftell ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٢٩ : ﻣﺜﺎﻝ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺈﺭﺟﺎﻉ ﻗﻴﻤﺔ ﳌﻜﺎﻥ ﻣﺆﺷﺮ ﺍﻟﻨﺺ ﺍﳊﺎﱄ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include<stdio.h> main(){ FILE *File; int Position; char buff[3]; File = fopen("Info.txt", "r"); /* Move the pointer of file 3 bytes by reading character*/ fread(buff, sizeof(char), 3, File); Position = ftell(File); printf("Position after read 3 characters is %d\n",\ Position); } ftell : ﻣﺜﺎﻝ،fseek(File, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ﺍﻟﺪﺍﻟﺔ:٣,٥,٦٣ ﺍﻟﱪﻧﺎﻣﺞ :rewind ﺍﻟﺪﺍﻟﺔ٣,٥,١٢,٣٠ 0L, SEEK_SET) ﻭ ﻫﻲ ﻣﻜﺎﻓﺌﺔ ﻟـ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺈﺭﺟﺎﻉ ﻣﺆﺷﺮ ﻣﻠﻒ ﺇﱃ ﺍﻟﺒﺪﺍﻳﺔ #include<stdio.h> main(){ FILE *File; char ch; File = fopen("Info.txt", "r"); fseek(File, 0L, SEEK_END); printf("fseek(File, 0L, SEEK_END):\n"); while(feof(File)==0){ ch = fgetc(File); printf("%c", ch); } printf("\n----------------\n"); rewind(File); 226 ;)"printf("rewind(File):\n {)while(feof(File)==0 ;)ch = fgetc(File ;)printf("%c", ch } ;)"printf("\n ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٤ﺍﻟﺪﺍﻟﺔ } 19 20 21 22 23 24 25 26 rewind ٣,٥,١٢,٣١ﺍﻟﺪﺍﻟﺔ :feof ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺈﺧﺘﺒﺎﺭ ﺇﺫﺍ ﻛﺎﻥ ﻣﺆﺷﺮ ﻣﻠﻒ ﻗﺪ ﻭﺻﻞ ﺇﱃ ﺎﻳﺔ ﺍﳌﻠﻒ ،ﺣﻴﺚ ﺗﺮﺟﻊ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺍﻟﻘﻴﻤﺔ ٠ﺇﺫﺍ ﻣﺆﺷـﺮ ﺍﳌﻠﻒ ﰲ ﺍﻟﻨﻬﺎﻳﺔ ،ﻭ ﺗﺮﺟﻊ ﻗﻴﻤﺔ ﻏﲑ ﺍﻟﺼﻔﺮ ﺇﻥ ﱂ ﻳﻜﻦ ﺍﳌﺆﺷﺮ ﰲ ﺎﻳﺔ ﺍﳌﻠﻒ ،ﻣﺜﺎﻝ: >#include<stdio.h {)(main ;FILE *File ;)"File = fopen("Info.txt", "r ;)fseek(File, 0L, SEEK_END )if(feof(File)==0 ;)"printf("Position of pointer is in the end of file\n else ;)"printf("Position of pointer is not in the end of file\n ٣,٥,١٣ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ :stdlib.h ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٥ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 12 13 feof ﺍﻻﺳﻢ stdlibﳐﺘﺼﺮ ﻣﻦ ،Standard Libraryﺣﻴﺚ ﳛﺘﻮﻱ ﻫﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ﻋﻠﻰ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻟﺪﻭﺍﻝ ﰲ ﻛـﻞ ﻣـﻦ ﺩﻭﺍﻝ ﲢﻮﻳﻞ ﺍﻷﺭﻗﺎﻡ ،ﺩﻭﺍﻝ ﲣﺼﻴﺺ ﺍﻟﺬﺍﻛﺮﺓ )ﺍﻟﺘﺨﺰﻳﻦ( ﻭ ﺩﻭﺍﻝ ﺃﺧﺮﻯ. ٣,٥,١٣,١ﺍﻟﺪﺍﻟﺔ :atof ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺘﺤﻮﻳﻞ ﺃﻋﺪﺍﺩ ﻣﻮﺟﻮﺩ ﰲ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﺇﱃ ﺃﻋﺪﺍﺩ ﺣﻘﻴﻘﻴﺔ ﻣﻦ ﻧﻮﻉ ،doubleﺣﻴﺚ ﳝﻜﻦ ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺗﻠﻚ ﺍﻷﺭﻗﺎﻡ ﺑﺴﻬﻮﻟﺔ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<stdlib.h {)(main ;"char str[3] = "123 ;double num 1 2 3 4 5 6 7 227 ;)num = atof(str ;)printf("%f\n", num ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٦ﺍﻟﺪﺍﻟﺔ } 8 9 10 11 atof ٣,٥,١٣,٢ﺍﻟﺪﺍﻟﺔ :atoi ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﻨﻔﺲ ﻣﺎ ﺗﻘﻮﻡ ﺑﻪ ﺍﻟﺪﺍﻟﺔ atofﺇﻻ ﺃﺎ ﲢﻮﻝ ﺃﻋﺪﺍﺩ ﺍﻟﺴﻠﺴﻠﺔ ﺍﳊﺮﻓﻴﺔ ﺇﱃ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ﻣﻦ ﻧﻮﻉ ،int ﻣﺜﺎﻝ: >#include<stdio.h >#include<stdlib.h {)(main ;"char str[3] = "123 ;int num ;)num = atoi(str ;)printf("%d\n", num ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٧ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 atoi ٣,٥,١٣,٣ﺍﻟﺪﺍﻟﺔ :atol ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﻨﻔﺲ ﻣﺎ ﺗﻘﻮﻡ ﺑﻪ ﺍﻟﺪﺍﻟﺔ atoiﺇﻻ ﺃﺎ ﲢﻮﻝ ﺃﻋﺪﺍﺩ ﺍﻟﺴﻠﺴﻠﺔ ﺍﳊﺮﻓﻴﺔ ﺇﱃ ﺃﻋﺪﺍﺩ ﺻﺤﻴﺤﺔ ﻣـﻦ ﻧـﻮﻉ ،longﻣﺜﺎﻝ: >#include<stdio.h >#include<stdlib.h {)(main ;"char str[3] = "123 ;long num ;)num = atoi(str ;)printf("%ld\n", num ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٨ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 atol ٣,٥,١٣,٤ﺍﻟﺪﺍﻟﺔ :rand ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺘﻮﻟﻴﺪ ﺃﺭﻗﺎﻡ ﻋﺸﻮﺍﺋﻴﺔ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<stdlib.h 1 2 228 {)(main ;int i, j=0 {)for(i=0;i<=10;i++ ;j=rand()%100 ;)printf("j = %d\n", j } } ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٩ﺍﻟﺪﺍﻟﺔ 3 4 5 6 7 8 9 10 rand ﻭ ﻫﻨﺎ ﻟﻦ ﺗﺘﻌﺪ ﺍﻷﻋﺪﺍﺩ ﺍﻟﻌﺸﻮﺍﺋﻴﺔ ﺍﻟﻌﺪﺩ ،١٠٠ﻭ ﳝﻜﻨﻨﺎ ﺃﻥ ﳒﻌﻠﻬﺎ ﺃﻛﺜﺮ ﺃﻭ ﺃﻗﻞ ﻣﻦ ﺫﻟﻚ ﻓﻘﻂ ﻧﻘﻮﻡ ﺑﺎﻟﺘﻐﲑ ﰲ ﺍﻟﻌﺪﺩ ١٠٠ ﺍﻟﺬﻱ ﻣﻮﺟﻮﺩ ﺑﻌﺪ ﺭﺍﻣﺰ ﺑﺎﻗﻲ ﺍﻟﻘﺴﻤﺔ. ٣,٥,١٣,٥ﺍﻟﺪﺍﻟﺔ :srand ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺘﺸﻐﻴﻞ ﻣﻮﻟﺪ ﺍﻷﺭﻗﺎﻡ ﺍﻟﻌﺸﻮﺍﺋﻴﺔ ،randﺣﻴﺚ ﳚﻌﻞ ﺗﻠﻚ ﺍﻟﻘﻴﻢ ﺍﻟﻌﺸﻮﺍﺋﻴﺔ ﻣﺘﻐﲑ ﻣﻦ ﳊﻈـﺔ ﻷﺧـﺮﻯ ﻋﻨﺪﻣﺎ ﳕﺮﺭ ﻟﻪ ﺍﻟﺪﺍﻟﺔ ،timeﻣﺜﺎﻝ: >#include<stdio.h >#include<stdlib.h >#include<time.h {)(main ;int i ;))srand(time(NULL {)for(i=0;i<=10;i++ ;)printf("%d\n", rand()%100 } ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧٠ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 12 13 srand ٣,٥,١٣,٦ﺍﻟﺪﺍﻟﺔ :abort ﺗﺴﺘﻌﻤﻞ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﰲ ﺣﺎﻟﺔ ﻭﺟﻮﺩ ﺃﺧﻄﺎﺀ ﰲ ﺍﻟﱪﻧﺎﻣﺞ ،ﺣﻴﺚ ﺗﻘﻮﻡ ﺑﺈﻳﻘﺎﻑ ﺍﻟﱪﻧﺎﻣﺞ ﻭ ﺇﻇﻬﺎﺭ ﺭﺳﺎﻟﺔ ﲣﱪ ﺍﳌﺴﺘﺨﺪﻡ ﺃﻥ ﻃﺮﻳﻘﺔ ﺇﻧﺘﻬﺎﺀ ﺍﻟﱪﻧﺎﻣﺞ ﻏﲑ ﻃﺒﻴﻌﻴﺔ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<stdlib.h {)(main ;FILE *File {)))"if(!(File=fopen("FileName.txt", "r ;)"printf("Can't open file\n ;)(abort 1 2 3 4 5 6 7 8 9 229 } ;)fclose(File } ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧١ﺍﻟﺪﺍﻟﺔ 10 11 12 13 abort ٣,٥,١٣,٧ﺍﻟﺪﺍﻟﺔ :exit ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺎﻹﺎﺀ ﺍﻟﱪﻧﺎﻣﺞ ﺇﺫﺍ ﰎ ﺍﻟﺘﻤﺮﻳﺮ ﺇﻟﻴﻬﺎ ﺍﻟﻘﻴﻤﺔ ،١ﺣﻴﺚ ﻳﻮﺟﺪ ﺛﻮﺍﺑﺖ ﺑﺎﺳـﻢ EXIT_FAILUREﻭ ﻫـﻮ ﻧﻔﺴﻪ ﺍﻟﻘﻴﻤﺔ ،١ﻭ ﺍﻟﺜﺎﺑﺖ EXIT_SUCCESSﻭ ﻫﻮ ﺍﻟﻘﻴﻤﺔ ٠ﻭ ﺍﻟﺬﻱ ﻳﻌﲏ ﺍﳋﺮﻭﺝ ﺍﻟﺴﻠﻴﻢ ﻟﻠﱪﻧﺎﻣﺞ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<stdlib.h {)(main ;FILE *File {)))"if(!(File=fopen("FileName.txt", "r ;)"printf("Can't open file\n ;)exit(EXIT_FAILURE }else ;)exit(EXIT_SUCCESS ;)fclose(File ٣,٥,١٣,٨ﺍﻟﺪﺍﻟﺔ :atexit ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧٢ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 exit ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺎﺳﺘﻌﺪﺍﺀ ﺩﻭﺍﻝ ﺃﺧﺮﻯ ،ﺣﻴﺚ ﻳﺘﻢ ﺗﻨﻔﻴﺬ ﺗﻠﻚ ﺍﻟﺪﻭﺍﻝ ﻋﻨﺪ ﺎﻳﺔ ﺍﻟﱪﻧﺎﻣﺞ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<stdlib.h {)(void AtExit ;)"printf("Program - end\n } {)(main ;)atexit(AtExit ;)"printf("Program - start\n ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧٣ﺍﻟﺪﺍﻟﺔ ٣,٥,١٣,٩ﺍﻟﺪﺍﻟﺔ :system } atexit ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺘﻨﻔﻴﺬ ﺃﻭﺍﻣﺮ ﺍﻟﻨﻈﺎﻡ ﻣﺜﻼ ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﻣﺴﺢ ﺷﺎﺷﺔ ﺍﳉﻬﺎﺯ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺃﻭﺍﻣﺮ ﺍﻟﻨﻈﺎﻡ ﻧﻜﺘﺐ: 1 2 3 4 5 6 7 8 9 10 11 12 230 1 2 3 4 5 6 7 8 9 10 11 12 13 #include<stdio.h> #include<stdlib.h> main(){ printf("Message!\n"); /*In DOS OS*/ system("cls"); /*In Unix/Linux OS*/ system("clear"); } system ﺍﻟﺪﺍﻟﺔ:٣,٥,٧٤ ﺍﻟﱪﻧﺎﻣﺞ :abs ﺍﻟﺪﺍﻟﺔ٣,٥,١٣,١٠ : ﻣﺜﺎﻝ، ﻟﻠﻌﺪﺩ ﺍﻟﺬﻱ ﰎ ﲤﺮﻳﺮﻩ ﺇﻟﻴﻬﺎint ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺈﺭﺟﺎﻉ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻄﻠﻘﺔ ﻣﻦ ﺍﻟﻨﻮﻉ 1 2 3 4 5 6 7 8 9 #include<stdio.h> #include<stdlib.h> main(){ int i=-10, j=20; } printf("absolute value if 'i' is %d\n", abs(i)); printf("absolute value if 'j' is %d\n", abs(j)); ﺍﻟﺪﺍﻟﺔ:٣,٥,٧٥ ﺍﻟﱪﻧﺎﻣﺞ abs :labs ﺍﻟﺪﺍﻟﺔ٣,٥,١٣,١١ : ﻣﺜﺎﻝ،long ﺎ ﺗﺮﺟﻊ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻄﻠﻖ ﻣﻦ ﺍﻟﻨﻮﻉ ﺇﻻ ﺃabs ﻧﻔﺲ ﺍﻟﺪﺍﻟﺔ 1 2 3 4 5 6 7 8 9 #include<stdio.h> #include<stdlib.h> main(){ long i=-10, j=20; printf("absolute value if 'i' is %d\n", labs(i)); printf("absolute value if 'j' is %d\n", labs(j)); } labs ﺍﻟﺪﺍﻟﺔ:٣,٥,٧٦ ﺍﻟﱪﻧﺎﻣﺞ :div ﺍﻟﺪﺍﻟﺔ٣,٥,١٣,١٢ : ﻣﺜﺎﻝ،int ﻭ ﺍﻟﻨﺎﺗﺞ ﻳﻜﻮﻥ ﻣﻦ ﻧﻮﻉ،ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺘﻘﺴﻴﻢ ﻗﻴﻤﺔ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻋﻠﻰ ﻗﻴﻤﺔ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ 1 2 #include<stdio.h> #include<stdlib.h> 231 {)(main ;int a=12, b=6 ;))printf("%d/%d = %d\n", a, b, div(a, b ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧٧ﺍﻟﺪﺍﻟﺔ } 3 4 5 6 7 8 div ٣,٥,١٣,١٣ﺍﻟﺪﺍﻟﺔ :ldiv ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺘﻘﺴﻴﻢ ﻗﻴﻤﺔ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻋﻠﻰ ﻗﻴﻤﺔ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ،ﻭ ﺍﻟﻨﺎﺗﺞ ﻳﻜﻮﻥ ﻣﻦ ﻧﻮﻉ ،longﻣﺜﺎﻝ: >#include<stdio.h >#include<stdlib.h {)(main ;long a=12, b=6 ;))printf("%d/%d = %d\n", a, b, ldiv(a, b ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧٨ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 ldiv ٣,٥,١٤ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ :string.h ﰲ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ string.hﺗﻮﺟﺪ ﳎﻤﻮﻋﺘﲔ ﻣﻦ ﺍﻟﺪﻭﺍﻝ ،ﺍﻤﻮﻋﺔ ﺍﻷﻭﱃ ﺗﺒﺪﺃ ﺃﲰﺎﺀﻫﺎ ﺑـ strﻭ ﻫﻲ ﺗﻌﲏ ،string ﻭ ﺍﻤﻮﻋﺔ ﺍﻟﺜﺎﻧﻴﺔ ﺗﺒﺪﺃ ﺃﲰﺎﺀﻫﺎ ﺑـ memﻭ ﻫﻲ ﺗﻌﲏ .memoryﺳﻨﺪﺭﺱ ﺃﻫﻢ ﺩﻭﺍﻝ ﻫﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،ﻭ ﺍﻟﱵ ﺃﻏﻠﺒﻬﺎ ﺗﺒـﺪﺃ ﺑـ .str ٣,٥,١٤,١ﺍﻟﺪﺍﻟﺔ strcpyﻭ ﺍﻟﺪﺍﻟﺔ :strncpy ﺗﻘﻮﻡ ﻛﻼ ﻣﻦ ﺍﻟﺪﺍﻟﺘﲔ ﺑﻨﺴﺦ ﻧﺺ ﺇﱃ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ،ﺍﻟﺪﺍﻟﺔ ﺍﻷﻭﱃ strcpyﺎ ﻭﺳﻴﻄﲔ ،ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻫﻮ ﺳﻠـﺴﻠﺔ ﺍﳊﺮﻭﻑ ﺍﻟﱵ ﺳﻴﺘﻢ ﻧﺴﺦ ﻓﻴﻬﺎ ﺍﻟﻨﺺ ،ﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻫﻮ ﺍﻟﻨﺺ ﺍﻟﺬﻱ ﺳﻴﺘﻢ ﻧﺴﺨﻪ .ﻭ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺜﺎﻧﻴﺔ strncpyﺎ ﺛﻼﺛـﺔ ﻭﺳﺎﺋﻂ ،ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻭ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﳘﺎ ﻧﻔﺲ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻭ ﺍﻟﺜﺎﱐ ﻟﺪﺍﻟﺔ ،strcpyﺃﻣﺎ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﻟﺚ ﻓﻬﻮ ﻋـﺪﺩ ﺍﻷﺣﺮﻑ ﺍﻟﱵ ﻧﺮﻳﺪ ﻧﺴﺨﻬﺎ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<string.h {)(main ;"char str[] = "Hello ;]char empty[5 ;]char empty2[5 ;)strcpy(empty, str ;)strncpy(empty2, str, 3 1 2 3 4 5 6 7 8 9 10 11 232 12 13 14 } printf("empty = %s\n", empty); printf("empty2 = %s\n", empty2); strncpy ﻭ ﺍﻟﺪﺍﻟﺔstrcpy ﺍﻟﺪﺍﻟﺔ:٣,٥,٧٩ ﺍﻟﱪﻧﺎﻣﺞ : ﻣﺜﺎﻝ، ﻓﺴﻴﺘﻢ ﺣﺬﻓﻪ،ﺎ ﻧﺺ ﺳﺎﺑﻘﺎ empty ﺃﻣﺎ ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﻟﺴﻠﺴﻠﺔ 1 2 3 4 5 6 7 8 9 10 11 #include<stdio.h> #include<string.h> main(){ char str[] = "Hello"; char empty[5] = "empty"; strcpy(empty, str); } printf("empty = %s\n", empty); (٢) strcpy ﺍﻟﺪﺍﻟﺔ:٣,٥,٨٠ ﺍﻟﱪﻧﺎﻣﺞ :strncat ﻭ ﺍﻟﺪﺍﻟﺔstrcat ﺍﻟﺪﺍﻟﺔ٣,٥,١٤,٢ ﺗﻘﻮﻡ ﺑﻨﺴﺦ ﻧﺺ ﻭ ﺇﺿﺎﻓﺘﻪ ﺇﱃstrncat ﻭ ﺃﻳﻀﺎ ﺍﻟﺪﺍﻟﺔ، ﺑﻨﺴﺦ ﻧﺺ ﻭ ﺇﺿﺎﻓﺘﻪ ﺇﱃ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔstrcat ﺗﻘﻮﻡ ﺍﻟﺪﺍﻟﺔ :strcat ﻣﺜﺎﻝ ﻟﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ،ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﻣﻊ ﲢﺪﻳﺪ ﻋﺪﺩ ﺍﻷﺣﺮﻑ ﺍﻟﱵ ﻧﺮﻳﺪ ﺇﺿﺎﻓﺘﻬﺎ 1 2 3 4 5 6 7 8 9 10 #include<stdio.h> #include<string.h> main(){ char str[] = "Hello"; printf("str = %s\n", str); strcat(str, ", World"); printf("str = %s\n", str); } strcat ﺍﻟﺪﺍﻟﺔ:٣,٥,٨١ ﺍﻟﱪﻧﺎﻣﺞ :strncat ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻟﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ 1 2 3 4 5 6 7 8 9 10 #include<stdio.h> #include<string.h> main(){ char str[] = "Hello"; } printf("str = %s\n", str); strncat(str, ", World", 3); printf("str = %s\n", str); strncat ﺍﻟﺪﺍﻟﺔ:٣,٥,٨٢ ﺍﻟﱪﻧﺎﻣﺞ 233 ٣,٥,١٤,٣ﺍﻟﺪﺍﻟﺔ strcmpﻭ ﺍﻟﺪﺍﻟﺔ :strncmp ﺗﻘﻮﻡ ﺍﻟﺪﺍﻟﺔ strcmpﺑﺎﳌﻘﺎﺭﻧﺔ ﺑﲔ ﺳﻠﺴﻠﺘﲔ ،ﺇﺫﺍ ﻛﺎﻧﺖ ﺍﻟﺴﻠﺴﻠﺔ ﺍﳊﺮﻓﻴﺔ ﺍﻷﻭﱃ ﻫﻲ ﺍﻷﻛﱪ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﺃﻛﱪ ﻣـﻦ ،٠ﻭ ﰲ ﺣﺎﻟﺔ ﺃﻥ ﺍﻟﺴﻠﺴﻠﺔ ﺍﳊﺮﻓﻴﺔ ﺍﻟﺜﺎﻧﻴﺔ ﻫﻲ ﺍﻷﻛﱪ ﻓﺴﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ ﺃﺻﻐﺮ ﻣﻦ ،٠ﻭ ﺃﻳـﻀﺎ ﺍﻟﺪﺍﻟـﺔ strncmpﺗﻘـﻮﻡ ﺑﺎﳌﻘﺎﺭﻧﺔ ﺑﲔ ﺳﻠﺴﻠﺘﲔ ﻣﻊ ﲢﺪﻳﺪ ﻋﺪﺩ ﺣﺮﻭﻑ ﺍﻟﺴﻠﺴﻠﺔ ﺍﳊﺮﻓﻴﺔ ﺍﻷﻭﱃ ﺍﻟﱵ ﻧﺮﻳﺪ ﻣﻘﺎﺭﻧﺘﻬﺎ ﻣﻊ ﺍﻟﺴﻠﺴﻠﺔ ﺍﳊﺮﻓﻴﺔ ﺍﻟﺜﺎﻧﻴﺔ ،ﻣﺜﺎﻝ ﺣﻮﻝ ﻃﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ :strcmp >#include<stdio.h >#include<string.h {)(main ;"char str1[] = "Hello ;"char str2[] = "Hello2 ;)int cmp = strcmp(str1, str2 )if(cmp>0 ;)"printf("str1 > str2\n else ;)"printf("str1 < str2\n ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٨٣ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 12 13 strcmp ﻭ ﻫﺬﺍ ﻣﺜﺎﻝ ﻟﻄﺮﻳﻘﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ :strncmp >#include<stdio.h >#include<string.h {)(main ;"char str1[] = "Hello ;"char str2[] = "Hello2 ;)int cmp = strncmp(str1, str2, 3 )if(cmp>0 ;)"printf("str1 > str2\n else ;)"printf("str1 < str2\n ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٨٤ﺍﻟﺪﺍﻟﺔ } 1 2 3 4 5 6 7 8 9 10 11 12 13 strncmp ٣,٥,١٤,٤ﺍﻟﺪﺍﻟﺔ strchrﻭ ﺍﻟﺪﺍﻟﺔ :strrchr ﺗﺴﺘﻌﻤﻞ ﺍﻟﺪﺍﻟﺔ strchrﻟﻠﺒﺤﺚ ﻋﻦ ﻣﻜﺎﻥ ﺣﺮﻑ ﰲ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ،ﻭ ﺇﺫﺍ ﻛﺎﻥ ﺍﳊﺮﻑ ﺍﻟﺬﻱ ﻧﺮﻳﺪ ﺍﻟﺒﺤﺚ ﻋﻨـﻪ ﰲ ﺍﻟﺴﻠﺴﻠﺔ ﺍﳊﺮﻓﻴﺔ ﻣﻮﺟﻮﺩ ﻣﺮﺗﲔ ﻓﺴﻴﺘﻢ ﺃﺧﺬ ﻣﻜﺎﻥ ﺃﻭﻝ ﺣﺮﻑ ،ﻭ ﺍﻟﺪﺍﻟﺔ strrchrﻣﺜﻞ ﺍﻟﺪﺍﻟﺔ strchrﻭ ﻟﻜﻨـﻬﺎ ﺗﺄﺧـﺬ ﺍﳊﺮﻑ ﺍﻷﺧﲑ ﺑﺪﻝ ﺍﻷﻭﻝ ،ﻣﺜﺎﻝ: >#include<stdio.h 1 234 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include<string.h> main(){ char str[] = "Hello", *strdest; char ch = 'l'; int result; printf("%s\n", str); printf("12345\n"); strdest = strchr(str, ch); result = (int)(strdest-str+1); printf("First '%c' in position %d\n", ch, result); strdest = strrchr(str, ch); result = (int)(strdest-str+1); printf("Last '%c' in position %d\n", ch, result); } strrchr ﻭ ﺍﻟﺪﺍﻟﺔstrchr ﺍﻟﺪﺍﻟﺔ:٣,٥,٨٥ ﺍﻟﱪﻧﺎﻣﺞ :strcspn ﻭ ﺍﻟﺪﺍﻟﺔstrspn ﺍﻟﺪﺍﻟﺔ٣,٥,١٤,٥ ﺣﻴﺚ ﳚـﺐ ﺃﻥ ﺗﻜـﻮﻥ ﺗﻠـﻚ، ﳝﻜﻦ ﻣﻌﺮﻓﺔ ﻋﺪﺩ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻷﺣﺮﻑ ﰲ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔstrspn ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺪﺍﻟﺔ ﻓﻬﻲ ﺗﻘﻮﻡ ﺑﺘﺤﺪﻳﺪ ﻣﻜﺎﻥ ﳎﻤﻮﻋﺔ ﻣﻦstrcspn ﺃﻣﺎ ﺍﻟﺪﺍﻟﺔ،٠ ﺍﻷﺣﺮﻑ ﻫﻲ ﺑﺪﺍﻳﺔ ﺍﻟﺴﻠﺴﻠﺔ ﺍﳊﺮﻓﻴﺔ ﻭ ﺇﻻ ﺳﺘﻜﻮﻥ ﺍﻟﻨﺘﻴﺠﺔ : ﻣﺜﺎﻝ،ﺍﳊﺮﻭﻑ ﰲ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include<stdio.h> #include<string.h> main(){ char str1[] = "HHHeeelllooo"; char str2[] = "He"; char str3[] = "lllooo"; int result; result = strspn(str1, str2); printf("There are %d character(s) of '%s' in string '%s'\n",\ result, str2, str1); } result = strcspn(str1, str3); printf("First '%s' in string '%s' is start at character %d\n",\ str3, str1, result); strcspn ﻭ ﺍﻟﺪﺍﻟﺔstrspn ﺍﻟﺪﺍﻟﺔ:٣,٥,٨٦ ﺍﻟﱪﻧﺎﻣﺞ . ﻟﺬﺍ ﻳﻔﻀﻞ ﺃﻥ ﻳﺘﻢ ﻛﺘﺎﺑﺘﻬﻤﺎ ﻣﻦ ﺟﺪﻳﺪ ﻋﻠﻰ ﺣﺴﺐ ﺭﻏﺒﺎﺕ ﺍﳌﱪﻣﺞ،ﻭ ﻟﻜﻦ ﻣﺮﻭﻧﺔ ﺍﻟﺪﺍﻟﺘﲔ ﻟﻴﺴﺖ ﻛﺒﲑﺓ :strpbrk ﺍﻟﺪﺍﻟﺔ٣,٥,١٤,٦ 235 ﺣﻴﺚ ﳚﺐ ﺃﻥ ﻧﻘﻮﻡ ﺑﺘﺤﺪﻳـﺪ ﺑﺪﺍﻳـﺔ، ﺑﻨﺴﺦ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﻭ ﻟﺼﻘﻬﺎ ﰲ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﺃﺧﺮﻯstrpbrk ﺗﻘﻮﻡ ﺍﻟﺪﺍﻟﺔ : ﻣﺜﺎﻝ،ﺍﻟﻨﺴﺨﺔ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺃﺣﺮﻑ 1 2 3 4 5 6 7 8 9 #include<stdio.h> #include<string.h> main(){ char str[] = "Hello"; char *result = strpbrk(str, "l"); } printf("%s\n", result); strpbrk ﺍﻟﺪﺍﻟﺔ:٣,٥,٨٧ ﺍﻟﱪﻧﺎﻣﺞ :strstr ﺍﻟﺪﺍﻟﺔ٣,٥,١٤,٧ : ﻣﺜﺎﻝ،ﺎ ﺗﺒﺤﺚ ﻋﻦ ﻣﻜﺎﻥ ﻧﺺ ﺑﺪﻝ ﺣﺮﻑ ﻭﺍﺣﺪ ﰲ ﺇﺧﺘﻼﻑ ﺑﺴﻴﻂ ﻭ ﻫﻲ ﺃstrchr ﻣﻄﺎﺑﻘﺔ ﻟﺪﺍﻟﺔstrstr ﺍﻟﺪﺍﻟﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 #include<stdio.h> #include<string.h> main(){ char str1[] = "Hello, World!", str2[] = "World"; char *strdest = strstr(str1, str2); int result; result = (int)(strdest-str1+1); printf("The word '%s' is at position %d in string '%s'\n",\ str2, result, str1); } strstr ﺍﻟﺪﺍﻟﺔ:٣,٥,٨٨ ﺍﻟﱪﻧﺎﻣﺞ :strlen ﺍﻟﺪﺍﻟﺔ٣,٥,١٤,٨ : ﻣﺜﺎﻝ،ﺗﻘﻮﻡ ﲝﺴﺐ ﻋﺪﺩ ﺃﺣﺮﻑ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ 1 2 3 4 5 6 7 8 9 #include<stdio.h> #include<string.h> main(){ char str[] = "Hello"; int result = strlen(str); printf("'%s' = %d character(s)\n", str, result); } strlen ﺍﻟﺪﺍﻟﺔ:٣,٥,٨٩ ﺍﻟﱪﻧﺎﻣﺞ :strerror ﺍﻟﺪﺍﻟﺔ٣,٥,١٤,٩ 236 : ﻣﺜﺎﻝ،ﲢﻤﻞ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﳎﻤﻮﻋﺔ ﻣﻦ ﺭﺳﺎﺋﻞ ﺍﻷﺧﻄﺎﺀ ﺍﳋﺎﺹ ﺑﺎﻟﺴﻼﺳﻞ ﺍﳊﺮﻓﻴﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include<stdio.h> #include<string.h> #include<stdlib.h> main(){ char str[10]; printf("Enter a string (Max 10 characters): "); if((strlen(gets(str)))>10){ printf("%s\n", strerror(12)); exit(1); }else printf("'%s' = %d character(s)\n",\ str, strlen(str)); } strerror ﺍﻟﺪﺍﻟﺔ:٣,٥,٩٠ ﺍﻟﱪﻧﺎﻣﺞ .ﻭ ﳝﻜﻦ ﺭﺅﻳﺔ ﺑﺎﻗﻲ ﺍﻟﺮﺳﺎﺋﻞ ﺑﺎﺳﺘﺨﺪﺍﻡ ﺍﻟﺘﻜﺮﺍﺭ :strtok ﺍﻟﺪﺍﻟﺔ٣,٥,١٤,١٠ : ﻣﺜﺎﻝ، ﳓﺪﺩ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻷﺣﺮﻑ ﺃﻭ ﺍﻟﺮﻣﻮﺯ ﻟﺴﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ﺣﻴﺚ ﻻ ﻳﺘﻢ ﻃﺒﺎﻋﺘﻬﺎstrtok ﺑﺎﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> #include<string.h> main(){ char *string, str[] = "(Hello, World)", tok[] = " (),I"; int i; string = strtok(str, tok); for(i=0;i<2;i++){ printf("%s\n", string); string = strtok(NULL, tok); } } strtok ﺍﻟﺪﺍﻟﺔ:٣,٥,٩١ ﺍﻟﱪﻧﺎﻣﺞ :time.h ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ٣,٥,١٥ ﻭ ﳛﺘﻮﻱ ﻫﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ، ﻋﻠﻰ ﳎﻤﻮﻋﺔ ﻣﻦ ﺍﻟﺪﻭﺍﻝ ﺍﳋﺎﺻﺔ ﲟﻌﺎﳉﺔ ﺍﻟﺘﺎﺭﻳﺦ ﻭ ﺍﻟﻮﻗﺖtime.h ﳛﺘﻮﻱ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ : ﻭ ﻫﻲ ﻣﻌﺮﻓﺔ ﺑﺎﻟﺸﻜﻞ ﺍﻟﺘﺎﱄtm ﻋﻠﻰ ﺑﻨﻴﺔ ﺑﺎﺳﻢ 237 tm { ;tm_sec ;tm_min ;tm_hour ;tm_mday ;tm_mon ;tm_year ;tm_wday ;tm_yday ;tm_isdst struct int int int int int int int int int ;} 1 2 3 4 5 6 7 8 9 10 11 ﻭ ﳛﺘﻮﻱ ﺃﻳﻀﺎ ﻋﻠﻰ ﻣﺘﻐﲑﻳﻦ ﺑﺎﺳﻢ clock_tﻭ time_tﻭ ﳘﺎ ﻣﻌﺮﻓﺎﻥ ﻋﻠﻰ ﺍﻟﺸﻜﻞ ﺍﻟﺘﺎﱄ: ;typedef long time_t ;typedef long clock_t ﺳﻨﺘﺤﺪﺙ ﻋﻦ ﺃﻫﻢ ﺩﻭﺍﻝ ﻫﺬﺍ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ،ﺃﻣﺎ ﺍﻟﺒﺎﻗﻲ ﺍﻟﺪﻭﺍﻝ ﳝﻜﻦ ﺭﺃﻳﺘﻬﺎ ﰲ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ .time.h ٣,٥,١٥,١ﺍﻟﺪﺍﻟﺔ :clock ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺎﻟﻌﺪ ،ﺣﻴﺚ ﻳﺒﺪﺃ ﻋﺪﻫﺎ ﻋﻨﺪ ﺑﺪﺍﻳﺔ ﺍﻟﱪﻧﺎﻣﺞ ،ﺇﺑﺘﺪﺍﺀﺍ ﻣﻦ ﺍﻟﺼﻔﺮ ،ﻭ ﻗﺴﻤﺔ ﻗﻴﻤﺔ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻋﻠﻰ ﺍﻟﺜﺎﺑﺖ CLOCKS_PER_SECﺃﻭ CLK_PER_SECﻳﺮﺟﻊ ﺍﻟﻮﻗﺖ ﺑﺎﻟﺜﻮﺍﱐ ،ﻣﺜﺎﻝ: >#include<stdio.h >#include<time.h {)(main {);;(for ;)printf("%d\n", clock()/CLOCKS_PER_SEC )if((clock()/CLOCKS_PER_SEC)==5 ;break } } ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٩٢ﺍﻟﺪﺍﻟﺔ 1 2 3 4 5 6 7 8 9 10 clock ﻭ ﳝﻜﻦ ﺃﻥ ﳒﻌﻞ ﺍﻟﻌﺪ ﺑﺎﻟﺪﻗﺎﺋﻖ ﺃﻭ ﺍﻟﺴﺎﻋﺎﺕ ﺃﻭ ﺍﻷﻳﺎﻡ ،ﻓﻘﻂ ﻧﻘﻮﻡ ﺑﻘﺴﻢ ﺍﻟﻄﺮﻳﻘﺔ ﺍﻟﺴﺎﺑﻘﺔ ﻋﻠﻰ ٦٠ﰲ ﺣﺎﻟﺔ ﺃﺭﺩﻧـﺎ ﺍﻟﻌـﺪ ﺑﺎﻟﺪﻗﺎﺋﻖ ،ﻭ ﻧﺰﻳﺪ ﺍﻟﻘﺴﻤﺔ ﻋﻠﻰ ٦٠ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﺍﻟﻌﺪ ﻳﻜﻮﻥ ﺑﺎﻟﺴﺎﻋﺎﺕ ،ﻭ ﻧﺰﻳﺪ ﺃﻳﻀﺎ ﺍﻟﻘﺴﻤﺔ ﻋﻠﻰ ٢٤ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﺃﻥ ﻳﻜـﻮﻥ ﺍﻟﻌﺪ ﺑﺎﻷﻳﺎﻡ .ﻭ ﺑﺎﺳﺘﺨﺪﺍﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﳝﻜﻦ ﻋﻤﻞ ﺩﺍﻟﺔ ﺗﺄﺧﺮ ﺗﺴﺎﻋﺪﻧﺎ ﻛﺜﲑﺍ ﰲ ﺑﺮﺍﳎﻨﺎ ،ﺍﻟﺪﺍﻟﺔ ﺳﺘﻜﻮﻥ ﻛﺘﺎﱄ: >#include<stdio.h >#include<time.h 1 2 238 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 void delay(int second); main(){ int waitsec; printf("wait(in seconds): "); scanf("%d", &waitsec); delay(waitsec); printf("Time terminated...\n"); } void delay(int second){ int sec; } for(;;){ sec = clock()/CLOCKS_PER_SEC; if(sec==second) break; } ﺇﻧﺸﺎﺀ ﺩﺍﻟﺔ ﻧﻘﻮﻡ ﺑﺎﻹﻧﺘﻈﺎﺭ ﻟﻮﻗﺖ ﳏﺪﺩ:٣,٥,٩٣ ﺍﻟﱪﻧﺎﻣﺞ :time ﺍﻟﺪﺍﻟﺔ٣,٥,١٥,٢ : ﻣﺜﺎﻝ،١٩٧٠ ﺟﺎﻧﻔﻲ١ ﰲ ﺍﻟﻴﻮﻡ٠٠:٠٠ ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺈﺭﺟﺎﻉ ﻋﺪﺩ ﺍﻟﺜﻮﺍﱐ ﺍﻟﱵ ﻣﺮﺕ ﻣﻦ ﺍﻟﺴﺎﻋﺔ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> #include<time.h> main(){ time_t Seconds, Minutes, Hours, Days; Seconds Minutes Hours Days = = = = time(NULL); Seconds/60; Minutes/60; Hours/24; printf("%ld\tseconds since 01/01/1970.\n", Seconds); printf("%ld\tminutes since 01/01/1970.\n", Minutes); printf("%ld\t\thours since 01/01/1970.\n", Hours); printf("%ld\t\tdays since 01/01/1970.\n", Days); } time ﺍﻟﺪﺍﻟﺔ:٣,٥,٩٤ ﺍﻟﱪﻧﺎﻣﺞ ﻭ ﳝﻜﻦ ﻛﺘﺎﺑـﺔ،NULL ﻷﻥ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺬﻱ ﰎ ﲤﺮﻳﺮﻩ ﺇﻟﻴﻪ ﻓﺎﺭﻍSeconds ﺑﺈﺭﺟﺎﻉ ﻗﻴﻤﺔ ﻟﻠﻤﺘﻐﲑtime ﻫﻨﺎ ﺳﺘﻘﻮﻡ ﺍﻟﺪﺍﻟﺔ :ﺍﳌﺜﺎﻝ ﺍﻟﺴﺎﺑﻘﺔ ﺑﺎﻟﻄﺮﻳﻘﺔ ﺍﻟﺘﺎﻟﻴﺔ 1 2 3 4 #include<stdio.h> #include<time.h> main(){ 239 5 6 7 8 9 10 11 12 13 14 15 16 time_t Seconds, Minutes, Hours, Days; time(&Seconds); Minutes = Seconds/60; Hours = Minutes/60; Days = Hours/24; } printf("%ld\tseconds since 01/01/1970.\n", Seconds); printf("%ld\tminutes since 01/01/1970.\n", Minutes); printf("%ld\t\thours since 01/01/1970.\n", Hours); printf("%ld\t\tdays since 01/01/1970.\n", Days); (٢) time ﺍﻟﺪﺍﻟﺔ:٣,٥,٩٥ ﺍﻟﱪﻧﺎﻣﺞ :difftime ﺍﻟﺪﺍﻟﺔ٣,٥,١٥,٣ ﻭ ﺍﻟﺪﺍﻟﺔ ﺗﻘﻮﻡ ﺑﺈﺭﺟﺎﻉ ﺍﻟﻔﺮﻕ ﺑﲔ ﺍﻟﻮﻗﺖ ﺍﻷﻭﻝ ﺍﳌﻮﺟـﻮﺩ ﰲ،time_t ﻛﻼﳘﺎ ﳌﺘﻐﲑﺍﺕ ﻣﻦ ﻧﻮﻉ،ﳍﺬﻩ ﺍﻟﺪﺍﻟﺔ ﻭﺳﻴﻄﲔ ﺃﻱ ﺗﻘﻮﻡ ﺑﻄﺮﺡ ﻗﻴﻤﺔ ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻋﻠﻰ ﺍﻟﻮﺳﻴﻂ،ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﻝ ﻭ ﺑﲔ ﺍﻟﻮﻗﺖ ﺍﻟﺜﺎﱐ ﻭ ﺍﳌﻮﺟﻮﺩ ﰲ ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﺑﺎﻟﺜﻮﺍﱐ : ﻣﺜﺎﻝ،ﺍﻟﺜﺎﱐ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> #include<time.h> main(){ time_t Start, End; int i; Start = time(NULL); for(i=0;i<=40000;i++){ printf("%d\n", i); } End = time(NULL); } printf("Loop taken %.0f seconds to terminate...\n",\ difftime(End, Start)); difftime ﺍﻟﺪﺍﻟﺔ:٣,٥,٩٦ ﺍﻟﱪﻧﺎﻣﺞ :localtime ﺍﻟﺪﺍﻟﺔ٣,٥,١٥,٤ : ﻣﺜﺎﻝ،tm ﺇﱃ ﺍﻟﺘﻮﻗﻴﺖ ﳏﻠﻲ ﰒ ﲤﺮﻳﺮﻫﺎ ﺇﱃ ﺃﻋﻀﺎﺀ ﺍﻟﺒﻨﻴﺔ١٩٠٠ ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺘﺤﻮﻳﻞ ﻋﺪﺩ ﺍﻟﺜﻮﺍﱐ ﻣﻦ ﻋﺎﻡ 1 2 3 4 5 6 7 8 9 #include<stdio.h> #include<time.h> main(){ time_t Seconds; int Year, Month, Day, Hour, Minute, Second; struct tm* Time; time(&Seconds); 240 10 11 12 13 14 15 16 17 18 19 20 Time = localtime(&Seconds); Year = Time->tm_year+1900, Month= Time->tm_mon+1, Day = Time->tm_mday; Hour = Time->tm_hour, Minute = Time->tm_min, Second = Time->tm_sec; printf("Date: %.4d/%.2d/%.2d\n",Year, Month, Day); printf("Time: %.2d:%.2d:%.2d\n", Hour, Minute, Second); } localtime ﺍﻟﺪﺍﻟﺔ:٣,٥,٩٧ ﺍﻟﱪﻧﺎﻣﺞ :asctime ﺍﻟﺪﺍﻟﺔ٣,٥,١٥,٥ DDD MMM D HH :MM :SS 1 2 3 4 5 6 7 8 9 10 11 12 13 ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺘﺤﻮﻳﻞ ﺑﻴﺎﻧﺎﺕ ﺍﻟﺒﻨﻴﺔ ﺍﻟﱵ ﰎ ﲤﺮﻳﺮﻫﺎ ﺇﻟﻴﻬﺎ ﺇﱃ ﺳﻠﺴﻠﺔ ﺣﺮﻭﻑ ﻣﻦ ﺍﻟﺸﻜﻞ : ﻣﺜﺎﻝ،YYYY #include<stdio.h> #include<time.h> main(){ time_t Seconds; struct tm* Time; time(&Seconds); Time = localtime(&Seconds); printf("Date/Time: %s", asctime(Time)); } asctime ﺍﻟﺪﺍﻟﺔ:٣,٥,٩٨ ﺍﻟﱪﻧﺎﻣﺞ :ctime ﺍﻟﺪﺍﻟﺔ٣,٥,١٥,٦ DDD MMM D HH :MM :SS 1 2 3 4 5 6 7 8 9 10 ﺇﱃ ﺳﻠﺴﻠﺔ ﺣﺮﻭﻑ ﻣﻦ ﺍﻟـﺸﻜﻞtime() ﺗﻘﻮﻡ ﻫﺬﻩ ﺍﻟﺪﺍﻟﺔ ﺑﺘﺤﻮﻳﻞ ﻋﺪﺩ ﺍﻟﺜﻮﺍﱐ ﺍﻟﺪﺍﻟﺔ : ﻣﺜﺎﻝ،YYYY #include<stdio.h> #include<time.h> main(){ time_t Seconds; time(&Seconds); } printf("Date/Time: %s", ctime(&Seconds)); ctime ﺍﻟﺪﺍﻟﺔ:٣,٥,٩٩ ﺍﻟﱪﻧﺎﻣﺞ 241 ﻛﻞ ﺍﻟﻄﺮﻕ ﺗﺆﺩﻱ ﺇﱃ ﺭﻭﻣﺎ ،ﻭ ﻟﻨﻔﺮﺽ ﺃﻥ ﺭﻭﻣﺎ ﻫﻲ ﻫﺪﻓﻨﺎ ﰲ ﺍﻟﱪﳎﺔ )ﺃﻱ ﺍﻟﱪﻧﺎﻣﺞ ﺍﻟﺬﻱ ﺳﻨﻘﻮﻡ ﺑﱪﳎﺘﻪ( ،ﻭ ﻧـﻀﻊ ﺍﻟﻄﺮﻕ ﺍﻟﱵ ﺗﺆﺩﻱ ﺇﱃ ﺭﻭﻣﺎ ﻫﻲ ﺍﻟﻠﻐﺎﺕ ﺍﻟﱪﳎﺔ .ﺳﻨﺠﺪ ﺃﻥ ﺍﻟﻔﺮﻕ ﺑﲔ ﻃﺮﻳﻖ ﻭ ﺃﺧﺮﻯ ﻟﻴﺲ ﺑﻜﺒﲑ ،ﻓﻤﺜﻼ ﺭﲟﺎ ﻧﺬﻫﺐ ﻋﻠﻰ ﻃﺮﻳﻖ ﳒﺪﻩ ﺳﻬﻞ ،ﺃﻭ ﻃﺮﻳﻖ ﳒﺪﻩ ﺻﻌﺐ ،ﺃﻭ ﻃﺮﻳﻖ ﺳﺮﻳﻊ ﺃﻭ ﺑﻄﻲﺀ ،ﺃﻭ ،...ﻭ ﻫﺬﻩ ﻫﻮ ﺍﻟﻔﺮﻕ ﺑﲔ ﻟﻐﺔ ﺑﺮﳎـﺔ ﻭ ﺃﺧـﺮﻯ، ﻣﺜﺎﻝ: ﺍﻟﻔﺮﻕ ﺑﲔ ﻟﻐﺔ C++ﻭ ﻟﻐﺔ ) Assemblyﺍﻟﺘﺠﻤﻴﻊ( ﻫﻮ: § ﺳﺘﺠﺪ ﺳﻬﻮﻟﺔ ﻛﺒﲑﺓ ﰲ ﻓﻬﻢ ﻟﻐﺔ ،C++ﻷﺎ ﻟﻐﺔ ﻋﺎﻟﻴﺔ ﺍﳌﺴﺘﻮﻯ ،ﻭ ﻣﻦ ﻣﻴﺰﺍﺕ ﺍﻟﻠﻐﺎﺕ ﺍﻟﻌﺎﻟﻴﺔ ﺍﳌﺴﺘﻮﻯ ﻫﻲ ﺟﻌﻠﻬﺎ ﻟﻐﺔ ﲢﺎﻛﻲ ﻟﻐﺔ ﺍﻹﻧﺴﺎﻥ ،ﺃﻣﺎ ﻟﻐﺔ ﺍﻟﺘﺠﻤﻴﻊ ﻫﻲ ﻟﻐﺔ ﻣﻨﺨﻔﻀﺔ ﺍﳌﺴﺘﻮﻯ ،ﻭ ﺍﻟﻠﻐﺎﺕ ﺍﳌﻨﺨﻔﻀﺔ ﺍﳌﺴﺘﻮﻯ ﻫـﻲ ﻟﻐـﺎﺕ ﲢﺎﻛﻲ ﻟﻐﺔ ﺍﳊﺎﺳﻮﺏ ﳑﺎ ﳚﻌﻠﻬﺎ ﻟﻐﺔ ﺻﻌﺒﺔ. § ﺳﺘﺠﺪ ﺣﺠﻢ ﺑﺮﻧﺎﻣﺞ ﻣﻜﺘﻮﺏ ﺑﻠﻐﺔ ﺍﻟﺘﺠﻤﻴﻊ ﺃﺻﻐﲑ ﻣﻦ ﺣﺠﻢ ﺑﺮﻧﺎﻣﺞ ﻣﻜﺘﻮﺏ ﺑﻠﻐﺔ .C++ ﻭ ﻫﺬﺍ ﻫﻮ ﺍﻟﻔﺮﻕ ﺑﲔ ﻛﻞ ﻟﻐﺔ ﻭ ﺃﺧﺮﻯ ﺗﻘﺮﻳﺒﺎ. ﺧﻠﻴﻞ ﺃﻭﻧﻴﺲ ﺟﺪﻭﻝ ﺍﻷﺷﻜﺎﻝ )ﺍﻟﺼﻮﺭ( ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ........................................................................... C ١,١ﺍﻷﺩﻭﺍﺕ ﺍﻟﻼﺯﻣﺔ .................................................................................. ﺍﻟﺸﻜﻞ :١,١,١ﻣﺮﺣﻠﺔ ﺇﻧﺸﺎﺀ ﻣﻠﻒ ﺗﻨﻔﻴﺬﻱ ٢٤........................................................ ١,٢ﺍﻟﺒﺪﺀ ﻣﻊ ﻟﻐﺔ .................................................................................... C ﺍﻟﺸﻜﻞ ٢٦.......................................................................... block :١,٢,١ ١,٣ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ ................................................... Variables and Constants ﺍﻟﺸﻜﻞ :١,٣,١ﺍﻟﺬﺍﻛﺮﺓ ﻭ ﺍﻟﻌﻨﺎﻭﻳﻦ ﰲ ﺍﻟﻨﻤﻂ ﺍﳊﻘﻴﻘﻲ ٣٤.................................... real mode ﺍﻟﺸﻜﻞ :١,٣,٢ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ٣٥.......................................................... ﺍﻟﺸﻜﻞ :١,٣,٣ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ ٤٣.......................................................... ١,٤ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ............................................................................ Comments ١,٥ﺍﻹﺩﺧﺎﻝ ................................................................................... input ١,٦ﺍﳌﺆﺛﺮﺍﺕ .............................................................................. Operators ﺍﻟﺸﻜﻞ :١,٦,١ﺍﻹﺯﺍﺣﺔ ﺇﱃ ﺍﻟﻴﺴﺎﺭ ٥٦................................................................ ﺍﻟﺸﻜﻞ :١,٦,٢ﺍﻹﺯﺍﺣﺔ ﺇﱃ ﳝﲔ ٥٦.................................................................. ﺍﻟﺸﻜﻞ :١,٦,٣ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﺃﻭ | ٥٧........................................................... OR ﺍﻟﺸﻜﻞ :١,٦,٤ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﻭ & ٥٨.......................................................... AND ﺍﻟﺸﻜﻞ :١,٦,٥ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ^ ٥٨............................................................ XOR ١,٧ﺍﻟﻘﺮﺍﺭﺍﺕ ....................................................................... if, else, else…if ﺍﻟﺸﻜﻞ :١,٧,١ﻃﺮﻳﻘﺔ ﺇﻋﻼﻥ ﺷﺮﻁ ﺫﺍﺕ ﺃﻣﺮ ﻭﺍﺣﺪ ٦٠................................................. ﺍﻟﺸﻜﻞ :١,٧,٢ﻃﺮﻳﻘﺔ ﺇﻋﻼﻥ ﺷﺮﻁ ﺫﺍﺕ ﻋﺪﺓ ﺃﻭﺍﻣﺮ ٦٠................................................ ﺍﻟﺸﻜﻞ :١,٧,٣ﻃﺮﻳﻘﺔ ﻋﻤﻞ ifﻭ ٦٢............................................................. else ١,٨ﻋﻨﺎﺻﺮ ﻟﻐﺔ ...................................................................................... C ١,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻷﻭﻝ ،ﻣﻊ ﺇﺿﺎﻓﺎﺕ ................................................................ ﺍﻟﺸﻜﻞ :١,٩,١ﻃﺮﻳﻘﺔ ﻋﻤﻞ ﺍﻟﺪﺍﻟﺔ ٦٩.......................................................... printf ﺍﻟﺸﻜﻞ :١,٩,٢ﻃﺮﻳﻘﺔ ﻋﻤﻞ ﺍﻟﺪﺍﻟﺔ ٦٩.......................................................... scanf ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﱐ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ....................................................................... (٢) C ٢,١ﺍﻟﻘﺮﺍﺭ .................................................................................... Switch ٢,٢ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ .................................................................. Repeated loop ﺍﻟﺸﻜﻞ :٢,٢,١ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٨٦........................................................... while ﺍﻟﺸﻜﻞ :٢,٢,٢ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٨٩...................................................... do…while ﺍﻟﺸﻜﻞ :٢,٢,٣ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٩١.............................................................. for ﺍﻟﺸﻜﻞ :٢,٢,٤ﻃﺮﻳﻘﺔ ﺍﻟﺬﻫﺎﺏ ﺇﱃ ﻣﻜﺎﻥ ﻣﺎ ﰲ ﺍﻟﱪﻧﺎﻣﺞ ﻋﱪ ٩٢.................................. goto ﺍﻟﺸﻜﻞ :٢,٢,٥ﺇﻧﺸﺎﺀ ﺇﺳﻢ ﳌﻜﺎﻥ ﳝﻜﻦ ﺍﻟﺬﻫﺎﺏ ﺇﻟﻴﻪ ﻋﱪ ٩٢...................................... goto ﺍﻟﺸﻜﻞ :٢,٢,٦ﺷﺮﺡ ﻟﻌﻤﻠﻴﺔ ﺍﻟﺘﻜﺮﺍﺭ ﰲ ٩٥.................................................... while ﺍﻟﺸﻜﻞ :٢,٢,٧ﺷﺮﺡ ﻟﻌﻤﻠﻴﺔ ﺍﻟﺘﻜﺮﺍﺭ ﰲ ٩٥................................................ do…while ﺍﻟﺸﻜﻞ :٢,٢,٨ﺷﺮﺡ ﻟﻌﻤﻠﻴﺔ ﺍﻟﺘﻜﺮﺍﺭ ﰲ ٩٥...................................................... for ﺍﻟﺸﻜﻞ for :٢,٢,٩ﺑﻄﺮﻳﻘﺔ ﺃﺧﺮﻯ ٩٦.............................................................. ٢,٣ﺍﳌﺼﻔﻮﻓﺎﺕ ................................................................................ Arrays ﺍﻟﺸﻜﻞ :٢,٣,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺔ ١٠١...................................................... ﺍﻟﺸﻜﻞ :٢,٣,٢ﻃﺮﻳﻘﺔ ﻭﺿﻊ ﺍﻟﺒﻴﺎﻧﺎﺕ ﰲ ﺍﳌﺼﻔﻮﻓﺎﺕ ١٠٨.............................................. ٢,٤ﺍﳌﺆﺷﺮﺍﺕ ............................................................................... Pointers ﺍﻟﺸﻜﻞ :٢,٤,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺆﺷﺮ ١١٤........................................................ ﺍﻟﺸﻜﻞ :٢,٤,٢ﺍﻟﺬﺍﻛﺮﺓ ﻭ ﺍﻟﻌﻨﺎﻭﻳﻦ ١١٦.............................................................. ٢,٥ﺍﻟﺪﻭﺍﻝ ................................................................................ Functions ﺍﻟﺸﻜﻞ :٢,٥,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ١٢٥.......................................................... ٢,٦ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ..................................................................... Header files ٢,٧ﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ ﰲ ﺍﳌﻠﻔﺎﺕ .......................................................... Files I/O ﺍﻟﺸﻜﻞ :٢,٧,١ﻃﺮﻳﻘﺔ ﻓﺘﺢ ﻣﻠﻒ ١٤١................................................................ ٢,٨ﺍﻟﺘﺮﺍﻛﻴﺐ ............................................................................. structures ﺍﻟﺸﻜﻞ :٢,٨,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺑﻨﻴﺔ ١٤٧.......................................................... ٢,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻟﺜﺎﱐ ،ﻣﻌﺎ ﺇﺿﺎﻓﺎﺕ ................................................................. ﺍﻟﺸﻜﻞ :٢,٩,١ﺟﺪﻭﻝ ﺃﺳﻜﻲ ١٦٨.................................................................. ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﻟﺚ – ﺍﻟﺘﻘﺪﻡ ﰲ ﻟﻐﺔ .............................................................................. C ٣,١ﺍﳊﺴﺎﺏ ........................................................................... Enumeration ﺍﻟﺸﻜﻞ :٣,١,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺍﳊﺴﺎﺏ ١٧٦..................................................... ٣,٢ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ .............................................. Command-line Arguments ٣,٣ﺍﻟﺘﻮﺟﻴﻬﺎﺕ )........................................................... Directives(Preprocessor ٣,٤ﺩﻭﺍﻝ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ ...................................................................... ٣,٥ﺍﳌﻜﺘﺒﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ................................................................ Standard Library ﺟﺪﻭﻝ ﺍﳉﺪﺍﻭﻝ ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ........................................................................... C ١,١ﺍﻷﺩﻭﺍﺕ ﺍﻟﻼﺯﻣﺔ .................................................................................. ١,٢ﺍﻟﺒﺪﺀ ﻣﻊ ﻟﻐﺔ .................................................................................... C ١,٣ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ ................................................... Variables and Constants ﺍﳉﺪﻭﻝ :١,٣,١ﺃﻧﻮﺍﻉ ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺃﺣﺠﺎﻣﻬﺎ ٤١....................................................... ١,٤ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ............................................................................ Comments ١,٥ﺍﻹﺩﺧﺎﻝ ................................................................................... input ١,٦ﺍﳌﺆﺛﺮﺍﺕ .............................................................................. Operators ١,٧ﺍﻟﻘﺮﺍﺭﺍﺕ ....................................................................... if, else, else…if ١,٨ﻋﻨﺎﺻﺮ ﻟﻐﺔ ...................................................................................... C ﺍﳉﺪﻭﻝ :١,٨,١ﺍﻟﻜﻠﻤﺎﺕ ﺍﶈﺠﻮﺯﺓ ﻟﻠﻐﺔ ٦٤......................................................... C ﺍﳉﺪﻭﻝ :١,٨,٢ﺣﺪﻭﺩ ﺃﲰﺎﺀ ﺍﳌﻌﺮﻓﺎﺕ ٦٥............................................................. ﺍﳉﺪﻭﻝ ٦٥....................................................................... Trigraphs :١,٨,٣ ﺍﳉﺪﻭﻝ :١,٨,٤ﺛﻮﺍﺑﺖ ﺧﺎﺻﺔ ﺑﻠﻐﺔ ٦٧.............................................................. C ١,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻷﻭﻝ ،ﻣﻊ ﺇﺿﺎﻓﺎﺕ ................................................................ ﺍﳉﺪﻭﻝ :١,٩,١ﺭﻣﻮﺯ ﺍﻟﺪﺍﻟﺔ ٧٨................................................................ printf ﺍﳉﺪﻭﻝ :١,٩,٢ﺭﻣﻮﺯ ﺍﻟﺪﺍﻟﺔ ٧٩................................................................ scanf ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﱐ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ....................................................................... (٢) C ٢,١ﺍﻟﻘﺮﺍﺭ .................................................................................... Switch ٢,٢ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ .................................................................. Repeated loop ٢,٣ﺍﳌﺼﻔﻮﻓﺎﺕ ................................................................................ Arrays ٢,٤ﺍﳌﺆﺷﺮﺍﺕ ............................................................................... Pointers ٢,٥ﺍﻟﺪﻭﺍﻝ ................................................................................ Functions ٢,٦ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ..................................................................... Header files ٢,٧ﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ ﰲ ﺍﳌﻠﻔﺎﺕ .......................................................... Files I/O ٢,٨ﺍﻟﺘﺮﺍﻛﻴﺐ ............................................................................. structures ٢,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻟﺜﺎﱐ ،ﻣﻌﺎ ﺇﺿﺎﻓﺎﺕ ................................................................. ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﻟﺚ – ﺍﻟﺘﻘﺪﻡ ﰲ ﻟﻐﺔ .............................................................................. C ٣,١ﺍﳊﺴﺎﺏ ........................................................................... Enumeration ٣,٢ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ .............................................. Command-line Arguments ٣,٣ﺍﻟﺘﻮﺟﻴﻬﺎﺕ )........................................................... Directives(Preprocessor ﺍﳉﺪﻭﻝ :٣,٣,١ﺍﻷﲰﺎﺀ ﺍﳌﻌﺮﻓﺔ ١٩٠.................................................................. ٣,٤ﺩﻭﺍﻝ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ ...................................................................... ٣,٥ﺍﳌﻜﺘﺒﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ................................................................ Standard Library ﺍﳉﺪﻭﻝ :٣,٥,١ﺛﻮﺍﺑﺖ ﺍﳌﺨﺘﺼﺮ ٢٠٣......................................................... errno ﺍﳉﺪﻭﻝ :٣,٥,٢ﺛﻮﺍﺑﺖ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠٤..................................................... float.h ﺍﳉﺪﻭﻝ :٣,٥,١ﺛﻮﺍﺑﺖ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠٥.................................................... limits.h ﺍﳉﺪﻭﻝ :٣,٥,١ﺃﻫﻢ ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﱵ ﺗﺴﺘﻌﻤﻞ ﻣﻊ ﺍﻟﺪﺍﻟﺔ ٢١١....................................... raise ﺟﺪﻭﻝ ﺍﻟﱪﺍﻣﺞ ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ........................................................................... C ١,١ﺍﻷﺩﻭﺍﺕ ﺍﻟﻼﺯﻣﺔ .................................................................................. ١,٢ﺍﻟﺒﺪﺀ ﻣﻊ ﻟﻐﺔ .................................................................................... C ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ ٢٥.......................................................... C ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٢ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ ٢٦...................................................... (٢) C ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٣ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ ٢٧...................................................... (٣) C ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٤ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ ٢٧...................................................... (٤) C ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٥ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ ٢٧...................................................... (٥) C ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٦ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ ٢٧...................................................... (٦) C ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٧ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ ٢٨...................................................... (٧) C ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٨ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ ٢٨...................................................... (٨) C ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٩ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ ٢٨...................................................... (٩) C ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٠ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ ٢٨.................................................. (١٠) C ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١١ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ ٢٨.................................................. (١١) C ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٢ﺍﻟﱪﻧﺎﻣﺞ ﺍﻷﻭﻝ ﰲ ﻟﻐﺔ ٢٩.................................................. (١٢) C ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٣ﻃﺒﺎﻋﺔ ﻋﺪﺩ ﺻﺤﻴﺢ ٣٠.............................................................. ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٤ﺍﺳﺘﻌﻤﺎﻝ ﺍﳉﻤﻊ ٣٠................................................................ ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٥ﻃﺒﻊ ﻋﺪﺩﻳﻦ ٣٠................................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٦ﻋﻤﻠﻴﺔ ﲨﻊ ٣٠.................................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٧ﲨﻊ ﻭ ﺇﻇﻬﺎﺭ ﺃﻋﺪﺍﺩ ﺣﻘﻴﻘﻴﺔ ٣١..................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٨ﻃﺒﺎﻋﺔ ﺣﺮﻑ ٣١.................................................................. ﺍﻟﱪﻧﺎﻣﺞ :١,٢,١٩ﻃﺒﺎﻋﺔ ﺣﺮﻑ )٣١.............................................................. (٢ ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٢٠ﻃﺒﺎﻋﺔ ﻧﺺ ٣٢.................................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٢١ﻃﺒﺎﻋﺔ ﻧﺺ )٣٢................................................................ (٢ ﺍﻟﱪﻧﺎﻣﺞ :١,٢,٢٢ﺍﳋﻄﺄ ٣٢....................................................................... ١ ١,٣ﺍﳌﺘﻐﲑﺍﺕ ﻭ ﺍﻟﺜﻮﺍﺑﺖ ................................................... Variables and Constants ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ ٣٥..................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٢ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺣﻘﻴﻘﻲ ٣٦..................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٣ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺣﻘﻴﻘﻲ )٣٦................................. (٢ ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٤ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ )٣٦................................. (٢ ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٥ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ )٣٦................................. (٣ ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٦ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﺣﺮﰲ ٣٧........................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٧ﻃﺮﻳﻘﺔ ﻃﺒﺎﻋﺔ ﳏﺘﻮﻯ ﻣﺘﻐﲑ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ ٣٨.................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٨ﻃﺮﻳﻘﺔ ﲢﺪﻳﺚ ﻗﻴﻤﺔ ﻣﺘﻐﲑ ﻭ ﻃﺒﻌﻬﺎ ٣٨................................................. ﺍﻟﱪﻧﺎﻣﺞ :١,٣,٩ﻃﺮﻳﻘﺔ ﲢﺪﻳﺚ ﻗﻴﻤﺔ ﻣﺘﻐﲑ ﻣﻌﻄﺎﺓ ﻣﻦ ﻣﺘﻐﲑ ﺁﺧﺮ ٣٨..................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٠ﻧﺎﺗﺞ ﲨﻊ ﺑﲔ ﻋﺪﺩﻳﻦ ﺻﺤﻴﲔ ﰲ ﻣﺘﻐﲑ ٣٩........................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١١ﻃﺮﻳﻘﺔ ﻃﺒﺎﻋﺔ ﺣﺮﻑ ﻣﻮﺟﻮﺩ ﰲ ﻣﺘﻐﲑ ﺣﺮﰲ ٣٩....................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٢ﻃﺮﻳﻘﺔ ﻃﺒﺎﻋﺔ ﺣﺮﻑ ﺑﺎﻹﻋﺘﻤﺎﺩ ﻋﻠﻰ ﺭﻗﻤﻪ ﰲ ﺟﺪﻭﻝ ﺃﺳﻜﻲ ٣٩......................... ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٣ﻣﺘﻐﲑ ﺫﺍﺕ ﺇﺷﺎﺭﺓ ٤٠............................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٤ﻣﺘﻐﲑ ﺑﺪﻭﻥ ﺇﺷﺎﺭﺓ ٤٠.............................................................. ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٥ﻃﺮﻳﻘﺔ ﲢﺪﻳﺚ ﻗﻴﻤﺔ ﻣﺘﻐﲑ ٤١....................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٦ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ ﻭ ﺍﻟﺘﺤﺪﻳﺚ ﰲ ﻗﻴﻤﺘﻪ ٤٢.................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٧ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ ٤٢........................................................ ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٨ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ )٤٢................................................... (٢ ﺍﻟﱪﻧﺎﻣﺞ :١,٣,١٩ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺛﺎﺑﺖ )٤٣................................................... (٣ ١,٤ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ............................................................................ Comments ﺍﻟﱪﻧﺎﻣﺞ :١,٤,١ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺑﺎﻟﻨﺼﻮﺹ ﺍﻟﻄﻮﻳﻠﺔ ٤٥...................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٤,٢ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ﺍﻟﺴﻄﺮﻳﺔ ٤٦............................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٤,٣ﻛﻴﻔﻴﺔ ﺍﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻌﻠﻴﻘﺎﺕ ٤٦......................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٤,٤ﺍﳋﻄﺄ ٤٦........................................................................ ١ ﺍﻟﱪﻧﺎﻣﺞ :١,٤,٥ﺍﳋﻄﺄ ٤٧........................................................................ ٢ ١,٥ﺍﻹﺩﺧﺎﻝ ................................................................................... input ﺍﻟﱪﻧﺎﻣﺞ :١,٥,١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ scanfﻹﺩﺧﺎﻝ ﻗﻴﻤﺔ ﺻﺤﻴﺤﺔ ٤٨................................. ﺍﻟﱪﻧﺎﻣﺞ :١,٥,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ scanfﻹﺩﺧﺎﻝ ﺣﺮﻑ ٤٩........................................ ﺍﻟﱪﻧﺎﻣﺞ :١,٥,٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ scanfﻹﺩﺧﺎﻝ ﻗﻴﻤﺔ ﺻﺤﻴﺤﺔ )٤٩............................. (٢ ﺍﻟﱪﻧﺎﻣﺞ :١,٥,٤ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ scanfﻹﺩﺧﺎﻝ ﻗﻴﻤﺔ ﺻﺤﻴﺤﺔ )٤٩............................. (٣ ١,٦ﺍﳌﺆﺛﺮﺍﺕ .............................................................................. Operators ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ ٥١...................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ )٥٢.................................................. (٢ ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﺰﻳﺎﺩﺓ )٥٢.................................................. (٣ ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٤ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﻨﻘﺼﺎﻥ ٥٣..................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٥ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺍﻟﻨﻘﺼﺎﻥ )٥٣................................................ (٢ ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٦ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺛﺮ ﺑﺎﻗﻲ ﺍﻟﻘﺴﻤﺔ ٥٣................................................. ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٧ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮﺍﺕ ﺍﻟﻌﻼﻗﻴﺔ ٥٤.................................................. ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٨ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮﺍﺕ ﺍﳌﻨﻄﻘﻴﺔ ٥٥.................................................. ﺍﻟﱪﻧﺎﻣﺞ :١,٦,٩ﻣﺆﺛﺮ ﺍﻹﺯﺍﺣﺔ ﺇﱃ ﺍﻟﻴﺴﺎﺭ ٥٥.......................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٠ﻣﺆﺛﺮ ﺍﻹﺯﺍﺣﺔ ﺇﱃ ﺍﻟﻴﻤﲔ ٥٦......................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ٥٦........................................................ # ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮﻳﻦ ٥٧..................................................... ## ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﺃﻭ | ٥٨................................................... OR ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٤ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﻭ & ٥٨................................................. AND ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٥ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ^ ٥٩................................................... XOR ﺍﻟﱪﻧﺎﻣﺞ :١,٦,١٦ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺛﺮ ﻻ ~ ٥٩................................................. NOT ١,٧ﺍﻟﻘﺮﺍﺭﺍﺕ ....................................................................... if, else, else…if ﺍﻟﱪﻧﺎﻣﺞ :١,٧,١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ٦١.............................................................. if ﺍﻟﱪﻧﺎﻣﺞ :١,٧,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ٦١.......................................................... (٢) if ﺍﻟﱪﻧﺎﻣﺞ :١,٧,٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ٦٢............................................................ else ﺍﻟﱪﻧﺎﻣﺞ :١,٧,٤ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ٦٣........................................................ else…if ١,٨ﻋﻨﺎﺻﺮ ﻟﻐﺔ ...................................................................................... C ﺍﻟﱪﻧﺎﻣﺞ :١,٨,١ﺇﺳﺘﻌﻤﺎﻝ ﺭﻣﻮﺯ ٦٥....................................................... Trigraphs ﺍﻟﱪﻧﺎﻣﺞ :١,٨,٢ﺇﺳﺘﻌﻤﺎﻝ ﺭﻣﻮﺯ ٦٥.................................................... (٢) Trigraphs ﺍﻟﱪﻧﺎﻣﺞ :١,٨,٣ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﻨﺼﻴﺔ ٦٦.................................................................. ﺍﻟﱪﻧﺎﻣﺞ :١,٨,٤ﺛﺎﺑﺖ ﺣﺮﰲ ٦٦..................................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٨,٥ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﺮﻗﻤﻴﺔ ٦٧.................................................................. ﺍﻟﱪﻧﺎﻣﺞ :١,٨,٦ﺍﻟﺜﻮﺍﺑﺖ ﺍﻟﺮﻗﻤﻴﺔ )٦٨............................................................. (٢ ١,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻷﻭﻝ ،ﻣﻊ ﺇﺿﺎﻓﺎﺕ ................................................................ ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١ﻋﻤﺮ ﺍﳌﺴﺘﺨﺪﻡ ٧٠................................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٢ﺁﻟﺔ ﺣﺎﺳﺒﺔ ﺑﺴﻴﻄﺔ ٧١................................................................ ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٣ﺍﺳﺘﺨﺮﺍﺝ ﺍﻟﻘﻴﻤﺔ ﺍﳌﻄﻠﻘﺔ ٧١.......................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٤ﺃﺧﺬ ﺍﻟﻌﺪﺩ ﺍﻟﻜﺒﲑ ٧٢................................................................ ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٥ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ ٧٣.................................................. putchar ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٦ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ ٧٣.................................................. getchar ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٧ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ ٧٤...................................................... puts ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٨ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ wprintﻭ ﺍﻟﺪﺍﻟﺔ ٧٤................................... wscanf ﺍﻟﱪﻧﺎﻣﺞ :١,٩,٩ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ getchﻭ ﺍﻟﺪﺍﻟﺔ ٧٥..................................... putch ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١٠ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ getchﻭ ﺍﻟﺪﺍﻟﺔ ٧٦............................... (٢) putch ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ ٧٦................................................. getche ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ٧٦...................................... wchar_t ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١٣ﺍﻟﺪﺍﻟﺔ ٧٧.................................................................. wmain ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١٤ﺍﻟﺪﺍﻟﺔ ٧٧................................................................... main ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١٥ﺇﺭﺟﺎﻉ ﻗﻴﻤﺔ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ٧٧...................................................... ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١٦ﺇﺭﺟﺎﻉ ﻗﻴﻤﺔ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ )٧٧.................................................. (٢ ﺍﻟﱪﻧﺎﻣﺞ :١,٩,١٧ﺗﻔﺎﺩﻱ ﺇﺭﺟﺎﻉ ﻗﻴﻤﺔ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ٧٨................................................ ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﱐ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ....................................................................... (٢) C ٢,١ﺍﻟﻘﺮﺍﺭ .................................................................................... Switch ﺍﻟﱪﻧﺎﻣﺞ :٢,١,١ﺁﻟﺔ ﺣﺎﺳﺒﺔ ﺑﺴﻴﻄﺔ ﺑﺈﺳﺘﺨﺪﺍﻡ ٨١................................. if, else, else…if ﺍﻟﱪﻧﺎﻣﺞ :٢,١,٢ﺁﻟﺔ ﺣﺎﺳﺒﺔ ﺑﺴﻴﻄﺔ ﺑﺈﺳﺘﺨﺪﺍﻡ ٨٢............................................. switch ﺍﻟﱪﻧﺎﻣﺞ :٢,١,٣ﺍﳋﻄﺄ ٨٥........................................................................ ١ ٢,٢ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ .................................................................. Repeated loop ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٨٧.......................................................... while ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٢ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٨٧...................................................... (٢) while ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٣ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٨٨...................................................... (٣) while ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٤ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٨٨...................................................... (٤) while ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٥ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٨٩...................................................... do…while ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٦ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٩٠................................................. (٢) do…while ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٧ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٩١............................................................. for ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٨ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٩٢........................................................ (٢) for ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,٩ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ٩٢........................................................... goto ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١٠ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ٩٣..................................................... (٢) goto ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١١ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٩٣.......................................................... goto ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١٢ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻄﺔ ٩٤.................................................... (٥) while ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١٣ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻴﻄﺔ ٩٦...................................................... (٣) for ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١٤ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻴﻄﺔ ٩٦...................................................... (٤) for ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١٥ﺍﻟﺘﻜﺮﺍﺭ ﺑﻮﺍﺳﻴﻄﺔ ٩٧................................................... (٦) while ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١٦ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ٩٨.................................................... continue ﺍﻟﱪﻧﺎﻣﺞ :٢,٢,١٧ﻃﺒﺎﻋﺔ ﺟﺪﻭﻝ ASCIIﺑﺈﺳﺘﺨﺪﺍﻡ ﺣﻠﻘﺎﺕ ﺍﻟﺘﻜﺮﺍﺭ ٩٨................................... ٢,٣ﺍﳌﺼﻔﻮﻓﺎﺕ ................................................................................ Arrays ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١ﺑﺮﻧﺎﻣﺞ ﺑﻪ ﺃﻛﺜﺮ ﻣﻦ ٢٠ﻣﺘﻐﲑ ١٠٠................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٢ﺑﺮﻧﺎﻣﺞ ﺑﻪ ﺃﻛﺜﺮ ﻣﻦ ٢٠ﻣﺘﻐﲑ ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﳌﺼﻔﻮﻓﺎﺕ ١٠١............................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٣ﻃﺮﻳﻘﺔ ﺇﻋﻄﺎﺀ ﻗﻴﻢ ﳌﺼﻔﻮﻓﺔ ١٠١....................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٤ﻃﺮﻳﻘﺔ ﺇﻋﻄﺎﺀ ﻗﻴﻢ ﳌﺼﻔﻮﻓﺔ )١٠٢.................................................. (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٥ﻃﺮﻳﻘﺔ ﺇﻋﻄﺎﺀ ﻗﻴﻢ ﳌﺼﻔﻮﻓﺔ )١٠٢.................................................. (٣ ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٦ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺎﺕ ﺛﻨﺎﺋﻴﺔ ﺍﻷﺑﻌﺎﺩ ١٠٣....................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٧ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺎﺕ ﺛﻨﺎﺋﻴﺔ ﺍﻷﺑﻌﺎﺩ )١٠٣.................................. (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٨ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺎﺕ ﺛﻼﺛﻴﺔ ﺍﻷﺑﻌﺎﺩ ١٠٤...................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٩ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺎﺕ ﺛﻼﺛﻴﺔ ﺍﻷﺑﻌﺎﺩ )١٠٥.................................. (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٠ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺼﻔﻮﻓﺔ ﺫﺍﺕ ﺣﺠﻢ ﻏﲑ ﻣﻌﺮﻭﻑ ١٠٥............................ ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ ١٠٦.............................................. ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٢ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺳﻠﺴﻠﺔ ﺣﺮﻓﻴﺔ )١٠٧.......................................... (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٣ﺣﺴﺎﺏ ﻋﺪﺩ ﺃﺣﺮﻑ ﺇﺳﻢ ﻣﺴﺘﺨﺪﻡ ١٠٧............................................ ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٤ﺣﺴﺎﺏ ﻋﺪﺩ ﺃﺣﺮﻑ ﺇﺳﻢ ﻣﺴﺘﺨﺪﻡ )١٠٨........................................ (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٥ﺍﻟﺪﺍﻟﺔ ١٠٩................................................................. gets ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٦ﺍﻟﺪﺍﻟﺔ ١٠٩.............................................................. strcpy ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٧ﺍﻟﺪﺍﻟﺔ ١١٠............................................................ strncpy ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٨ﺍﻟﺪﺍﻟﺔ ١١٠......................................................... (٢) strcpy ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,١٩ﺍﻟﺪﺍﻟﺔ ١١١.............................................................. strcat ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٢٠ﺍﻟﺪﺍﻟﺔ ١١١............................................................. strncat ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٢١ﻃﺮﻕ ﺃﺧﺮﻯ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺼﻔﻮﻓﺎﺕ ١١١............................................. ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٢٢ﻃﺮﻕ ﺃﺧﺮﻯ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺼﻔﻮﻓﺎﺕ )١١٢........................................ (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٣,٢٣ﻃﺮﻕ ﺃﺧﺮﻯ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺼﻔﻮﻓﺎﺕ )١١٢........................................ (٣ ٢,٤ﺍﳌﺆﺷﺮﺍﺕ ............................................................................... Pointers ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﻣﺆﺷﺮ ١١٥....................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺷﺮ ١١٥.......................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﻣﺆﺷﺮ )١١٦..................................................... (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٤ﺇﺳﺘﻌﻤﺎﻝ ﺍﳌﺆﺷﺮ ﻋﻠﻰ ﻃﺮﻳﻘﺔ ﺍﳌﺼﻔﻮﻓﺎﺕ ١١٧.......................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٥ﻃﺮﻳﻘﺔ ﺃﺧﺮﻯ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺆﺷﺮﺍﺕ ١١٧............................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٦ﻃﺮﻳﻘﺔ ﺃﺧﺮﻯ ﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﳌﺆﺷﺮﺍﺕ )١١٨.......................................... (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٧ﺇﻣﻜﺎﻧﻴﺎﺕ ﺍﳌﺆﺷﺮ ﻣﻘﺎﺭﻧﺔ ﻣﻊ ﺍﳌﺼﻮﻓﺎﺕ ١١٨........................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٨ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ ١١٨........................................ ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٩ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ )١١٩.................................... (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٠ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ )١١٩.................................. (٣ ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١١ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ )١١٩.................................. (٤ ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٢ﺍﻟﺘﻌﺎﻣﻞ ﻣﻊ ﺍﻟﻨﺼﻮﺹ ﺑﺈﺳﺘﺨﺪﺍﻡ ﺍﳌﺆﺷﺮﺍﺕ )١٢٠.................................. (٥ ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٣ﺍﳌﺮﺟﻊ ١٢٠....................................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٤ﻣﺆﺷﺮ ﻟـ ١٢١............................................................. void ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٥ﻣﺆﺷﺮ ﳌﺼﻔﻮﻓﺔ ١٢١............................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٦ﻣﺆﺷﺮ ﳌﺼﻔﻮﻓﺔ )١٢٢........................................................... (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٧ﻣﺆﺷﺮ ﳌﺆﺷﺮ ١٢٢................................................................. ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٨ﻣﺆﺷﺮ ﳌﺆﺷﺮ )١٢٢............................................................. (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,١٩ﺍﳋﻄﺄ ١٢٣..................................................................... ١ ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٢٠ﺍﳋﻄﺄ ١٢٣..................................................................... ٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٢١ﺍﳋﻄﺄ ١٢٣..................................................................... ٣ ﺍﻟﱪﻧﺎﻣﺞ :٢,٤,٢٢ﺍﻟﺘﻤﺮﻳﻦ ١٢٤................................................................... ١ ٢,٥ﺍﻟﺪﻭﺍﻝ ................................................................................ Functions ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ١٢٥......................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٢ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ )١٢٦.................................................... (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٣ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ )١٢٦.................................................... (٣ ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٤ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﺫﺍﺕ ﻭﺳﻴﻂ ١٢٦............................................. ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٥ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﺫﺍﺕ ﻭﺳﻴﻄﲔ ١٢٧............................................ ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٦ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﺫﺍﺕ ﺃﻛﺜﺮ ﻣﻦ ﻭﺳﻴﻄﲔ ١٢٨................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٧ﺇﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﻣﻦ ﻧﻮﻉ ﻋﺪﺩ ﺻﺤﻴﺢ ١٢٨............................................ ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٨ﺍﻟﻮﺿﻊ ﺍﻹﻓﺘﺮﺍﺿﻲ ﻟﺪﺍﻟﺔ ﺑﺪﻭﻥ ﲢﺪﻳﺪ ﻧﻮﻋﻬﺎ ١٢٩....................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,٩ﻃﺮﻳﻘﺔ ﺃﺧﺮﻯ ﻟﻺﻋﻼﻥ ﻋﻦ ﻭﺳﻴﻂ ﻟﺪﺍﻟﺔ ١٢٩........................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١٠ﺍﻟﻄﺮﻳﻘﺔ ﺍﻹﻓﺘﺮﺍﺿﻴﺔ ﻟﻺﻋﻼﻥ ﻋﻦ ﻭﺳﻴﻂ ﻟﺪﺍﻟﺔ ١٣٠.................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١١ﺇﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﻣﻦ ﻧﻮﻉ ١٣٠............................................... short ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١٢ﺇﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﻣﻦ ﻧﻮﻉ ١٣٠................................................. char ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١٣ﺇﻋﻄﺎﺀ ﳌﺘﻐﲑ ﻗﻴﻤﺔ ﺗﺮﺟﻌﻬﺎ ﺩﺍﻟﺔ ١٣١.................................................. ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١٤ﺇﻋﻼﻥ ﻋﻦ ﺩﺍﻟﺔ ﻣﻦ ﻧﻮﻉ *١٣١............................................... char ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١٥ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻋﻦ ﳐﺘﺼﺮ ١٣٢...................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١٦ﺇﺳﺘﺪﻋﺎﺀ ﺩﺍﻟﺔ ﻣﻦ ﳐﺘﺼﺮ ١٣٢....................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١٧ﺩﺍﻟﺔ ﺫﺍﺕ ﻭﺳﻴﻂ ﻟﺪﺍﻟﺔ ﺃﺧﺮﻯ ١٣٣.................................................. ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١٨ﺩﺍﻟﺔ ﺫﺍﺕ ﻭﺳﻴﻂ ﻟﺪﺍﻟﺔ ﺃﺧﺮﻯ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ١٣٣...................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٥,١٩ﺍﳋﻄﺄ ١٣٤..................................................................... ١ ٢,٦ﺍﳌﻠﻔﺎﺕ ﺍﻟﺮﺃﺳﻴﺔ ..................................................................... Header files ﺍﻟﱪﻧﺎﻣﺞ :٢,٦,١ﺇﻧﺸﺎﺀ ﻣﻠﻒ ﺭﺃﺳﻲ ١٣٥.............................................................. ﺍﻟﱪﻧﺎﻣﺞ :٢,٦,٢ﺿﻢ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ١٣٥.............................................................. ﺍﻟﱪﻧﺎﻣﺞ :٢,٦,٣ﺿﻢ ﻣﻠﻒ ﺭﺃﺳﻲ ﻣﻮﺟﻮﺩ ﺑﺎﻠﺪ ١٣٦.......................................... include ٢,٧ﺍﻹﺩﺧﺎﻝ ﻭ ﺍﻹﺧﺮﺍﺝ ﰲ ﺍﳌﻠﻔﺎﺕ .......................................................... Files I/O ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,١ﻃﺮﻳﻘﺔ ﻓﺘﺢ ﻣﻠﻒ ١٣٨............................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,٢ﻃﺮﻳﻘﺔ ﺇﻧﺸﺎﺀ ﻣﻠﻒ ١٣٩.............................................................. ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,٣ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ CreateFileﻣﻦ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ١٤٠.............................. fileio.h ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,٤ﺇﻧﺸﺎﺀ ﺩﺍﻟﺔ ﺗﻘﻮﻡ ﺑﻌﺮﺽ ﳏﺘﻮﻯ ﻣﻠﻒ ١٤٢.............................................. ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,٥ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ fprintfﻭ ﺍﻟﺪﺍﻟﺔ ١٤٤............................................ fscanf ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,٦ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ ١٤٥........................................................ fputs ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,٧ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ fgetcﻭ ﺍﻟﺪﺍﻟﺔ ١٤٥......................................... fputc ﺍﻟﱪﻧﺎﻣﺞ :٢,٧,٨ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ fgetcﻭ ﺍﻟﺪﺍﻟﺔ ١٤٦.................................... (٢) fputc ٢,٨ﺍﻟﺘﺮﺍﻛﻴﺐ ............................................................................. structures ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,١ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻭ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺒﻨﻴﺎﺕ ١٤٨............................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,٢ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻭ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺒﻨﻴﺎﺕ )١٤٩.......................................... (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,٣ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﻭ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺒﻨﻴﺎﺕ )١٥٠.......................................... (٣ ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,٤ﺇﻋﻄﺎﺀ ﻗﻴﻢ ﻷﻋﻀﺎﺀ ﺑﻨﻴﺔ ﻣﺒﺎﺷﺮﺓ ﺑﻌﺪ ﺍﻟﺘﻌﲑ ﻋﻦ ﺇﺳﻢ ﺍﳌﺒﻨﻴﺔ ١٥٠........................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,٥ﺃﻓﻀﻞ ﻣﻦ ﺇﺳﺘﻌﻤﺎﻝ ﺃﻋﻀﺎﺀ ﺍﻟﺒﻨﻴﺔ ١٥١................................................. ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,٦ﻃﺮﻳﻘﺔ ﺇﺳﺘﺨﺪﺍﻡ ﺑﻨﻴﺔ ﻣﻌﺮﻓﺔ ﺑـ ١٥١........................................... union ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,٧ﻃﺮﻳﻘﺔ ﺇﺳﺘﺨﺪﺍﻡ ﺑﻨﻴﺔ ﻣﻌﺮﻓﺔ ﺑـ ١٥٢...................................... (٢) union ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,٨ﻃﺮﻳﻘﺔ ﺇﺳﺘﺨﺪﺍﻡ ﺑﻨﻴﺔ ﻣﻌﺮﻓﺔ ﺑـ ١٥٢...................................... (٣) union ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,٩ﻃﺮﻳﻘﺔ ﺇﺳﺘﺨﺪﺍﻡ ﺑﻨﻴﺔ ﻣﻌﺮﻓﺔ ﺑـ ١٥٣...................................... (٤) union ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,١١ﺍﳌﺼﻔﻮﻓﺎﺕ ﻋﻠﻰ ﺍﻟﺒﻨﻴﺎﺕ ١٥٣....................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,١٢ﺍﳌﺼﻔﻮﻓﺎﺕ ﻋﻠﻰ ﺍﻟﺒﻨﻴﺎﺕ )١٥٤.................................................. (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,١٣ﺍﳌﺆﺷﺮﺍﺕ ﻋﻠﻰ ﺍﻟﺒﻨﻴﺎﺕ ١٥٤........................................................ ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,١٤ﺇﻋﻼﻥ ﺑﻨﻴﺔ ﺩﺍﺧﻞ ﺑﻨﻴﺔ ١٥٥......................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٨,١٥ﺍﳋﻄﺄ ١٥٦..................................................................... ١ ٢,٩ﻣﻠﺨﺺ ﻟﻠﻔﺼﻞ ﺍﻟﺜﺎﱐ ،ﻣﻌﺎ ﺇﺿﺎﻓﺎﺕ ................................................................. ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١ﺍﻟﺪﺍﻟﺔ ١٥٧.................................................................. scanf ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢ﻣﻌﲎ ﺩﺍﻟﺔ ﺎ ﻭﺳﻴﻂ ١٥٧...................................................... void ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٣ﻣﻌﲎ ﺩﺍﻟﺔ ﺎ ﻭﺳﻴﻂ ١٥٧.................................................. (٢) void ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٤ﻣﻌﲎ ﺩﺍﻟﺔ ﺎ ﻭﺳﻴﻂ ١٥٨.................................................. (٣) void ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٥ﻣﻌﲎ ﺩﺍﻟﺔ ﺎ ﻭﺳﻴﻂ ١٥٨.................................................. (٣) void ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٦ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٥٩........................................ static ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٧ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٥٩................................... (٢) static ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٨ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٦٠...................................... typedef ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٩ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٦٠.................................. (٢) typedef ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١٠ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٦١................................ (٣) typedef ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٦١................................ (٤) typedef ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١٢ﺍﻟﻨﺴﺦ ،ﺍﳌﻠﻒ ١٦١......................................................... str.h ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١٣ﺍﻟﻨﺴﺦ ،ﺍﳌﻠﻒ ﺍﻟﺮﺋﻴﺴﻲ ١٦٢........................................................ ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١٤ﺗﺒﺎﺩﻝ ﻗﻴﻢ ﺑﲔ ﻭﺳﻴﻄﲔ ١٦٣........................................................ ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١٥ﺗﻐﲑ ﻗﻴﻤﺔ ﺛﺎﺑﺖ ١٦٣............................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١٦ﻋﻜﺲ ﺳﻠﺴﻠﺔ ﻧﺼﻴﺔ ١٦٤.......................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١٧ﺍﻟﺘﺤﻮﻳﻞ ﻣﻦ ﺍﻟﻨﻈﺎﻡ ﺍﻟﻌﺸﺮﻱ ﺇﱃ ﺍﻟﻨﻈﺎﻡ ﺍﻟﺜﻨﺎﺋﻲ ١٦٤................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١٨ﺍﻟﺘﺤﻮﻳﻞ ﻣﻦ ﺍﳊﺮﻭﻑ ﺍﻟﺼﻐﲑﺓ ﺇﱃ ﺍﳊﺮﻭﻑ ﺍﻟﻜﺒﲑﺓ ١٦٥............................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,١٩ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ ١٦٥................................................ wcscpy ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٠ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ ١٦٦............................................... wcsncpy ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ wcscatﻭ ﺍﻟﺪﺍﻟﺔ ١٦٦.............................. wcsncat ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ getwcharﻭ ﺍﻟﺪﺍﻟﺔ ١٦٧.......................... putwchar ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺪﺍﻟﺔ _getwsﻭ ﺍﻟﺪﺍﻟﺔ ١٦٧............................... _putws ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٤ﻃﺒﺎﻋﺔ ﺣﺮﻑ ﻋﱪ ﺭﻗﻤﻪ ﰲ ﺟﺪﻭﻝ ﺃﺳﻜﻲ١٦٧........................................ ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٥ﺍﳌﺘﻐﲑﺍﺕ ﺍﶈﻠﻴﺔ ١٦٨............................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٦ﺍﳌﺘﻐﲑﺍﺕ ﺍﳋﺎﺭﺟﻴﺔ ١٦٩............................................................ ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٧ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٧٠..................................... extern ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٨ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٧٠................................. (٢) extern ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٢٩ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٧١........................................ auto ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٣٠ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٧١................................... register ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٣١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﻜﻠﻤﺔ ﺍﶈﺠﻮﺯﺓ ١٧٢...................................... sizeof ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٣٢ﺍﺳﺘﺪﻋﺎﺀ ﺩﺍﻟﺔ ﻟﻨﻔﺴﻬﺎ ١٧٢.......................................................... ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٣٣ﺍﺳﺘﺪﻋﺎﺀ ﺩﺍﻟﺔ ﻟﻨﻔﺴﻬﺎ )١٧٣..................................................... (٢ ﺍﻟﱪﻧﺎﻣﺞ :٢,٩,٣٤ﻃﺮﻳﻘﺔ ﺍﻟﺘﺤﻜﻢ ﰲ ﻃﺒﺎﻋﺔ ﺍﻟﻨﺘﺎﺋﺞ ١٧٣................................................ ﺍﻟﻔﺼﻞ ﺍﻟﺜﺎﻟﺚ – ﺍﻟﺘﻘﺪﻡ ﰲ ﻟﻐﺔ .............................................................................. C ٣,١ﺍﳊﺴﺎﺏ ........................................................................... Enumeration ﺍﻟﱪﻧﺎﻣﺞ :٣,١,١ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ١٧٧.......................................................... enum ﺍﻟﱪﻧﺎﻣﺞ :٣,١,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ١٧٨..................................................... (٢) enum ﺍﻟﱪﻧﺎﻣﺞ :٣,١,٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ١٧٩..................................................... (٣) enum ﺍﻟﱪﻧﺎﻣﺞ :٣,١,٤ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ١٧٩..................................................... (٤) enum ﺍﻟﱪﻧﺎﻣﺞ :٣,١,٥ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ١٧٩..................................................... (٥) enum ﺍﻟﱪﻧﺎﻣﺞ :٣,١,٦ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ١٨٠..................................................... (٦) enum ﺍﻟﱪﻧﺎﻣﺞ :٣,١,٧ﺍﳋﻄﺄ ١٨٠....................................................................... ١ ٣,٢ﻭﺳﺎﺋﻂ ﺍﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ .............................................. Command-line Arguments ﺍﻟﱪﻧﺎﻣﺞ :٣,٢,١ﺍﻟﻮﺳﻴﻂ ﺍﻷﻭﱃ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ١٨٢.................................................... ﺍﻟﱪﻧﺎﻣﺞ :٣,٢,٢ﺍﻟﻮﺳﻴﻂ ﺍﻟﺜﺎﱐ ﻟﺪﺍﻟﺔ ﺍﻟﺮﺋﻴﺴﻴﺔ ١٨٣..................................................... ﺍﻟﱪﻧﺎﻣﺞ :٣,٢,٣ﺑﺮﻧﺎﻣﺞ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ﻳﻘﻮﻡ ﲝﺬﻑ ﻣﻠﻔﺎﺕ ١٨٤......................................... ٣,٣ﺍﻟﺘﻮﺟﻴﻬﺎﺕ )........................................................... Directives(Preprocessor ﺍﻟﱪﻧﺎﻣﺞ :٣,٣,١ﳐﺘﺼﺮ ﻳﻘﻮﻡ ﺑﻌﻤﻠﻴﺔ ﲨﻊ ١٨٦......................................................... ﺍﻟﱪﻧﺎﻣﺞ :٣,٣,٢ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻮﺟﻴﻪ ١٨٧................................................ #undef ﺍﻟﱪﻧﺎﻣﺞ :٣,٣,٣ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻮﺟﻴﻬﺎﺕ #else ،#elif ،#ifﻭ ١٨٨.................... #endif ﺍﻟﱪﻧﺎﻣﺞ :٣,٣,٤ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻮﺟﻴﻪ ١٨٨................................................ #ifdef ﺍﻟﱪﻧﺎﻣﺞ :٣,٣,٥ﻃﺮﻳﻘﺔ ﺃﺧﺮﻯ ﻣﻜﺎﻓﺌﺔ ﻟـ ١٨٨............................................... #ifdef ﺍﻟﱪﻧﺎﻣﺞ :٣,٣,٦ﻃﺮﻳﻘﺔ ﺇﺳﺘﻌﻤﺎﻝ ﺍﻟﺘﻮﺟﻴﻪ ١٨٩.............................................. #ifndef ﺍﻟﱪﻧﺎﻣﺞ :٣,٣,٧ﻃﺮﻳﻘﺔ ﺃﺧﺮﻯ ﻣﻜﺎﻓﺌﺔ ﻟـ ١٩٠............................................. #ifndef ﺍﻟﱪﻧﺎﻣﺞ :٣,٣,٩ﺇﺳﺘﻌﻤﺎﻝ ﺍﻷﲰﺎﺀ ﺍﳌﻌﺮﻓﺔ ١٩٠......................................................... ٣,٤ﺩﻭﺍﻝ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ ...................................................................... ﺍﻟﱪﻧﺎﻣﺞ :٣,٤,١ﺗﻮﻓﲑ ﺛﻼﺛﺔ ﻭﺳﺎﺋﻂ ﻟﺪﺍﻟﺔ ﺎ ﻭﺳﻴﻄﲔ ١٩٢............................................. ﺍﻟﱪﻧﺎﻣﺞ :٣,٤,٢ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﺩﺍﻟﺔ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ ١٩٣....................................... ﺍﻟﱪﻧﺎﻣﺞ :٣,٤,٣ﻃﺮﻳﻘﺔ ﺍﻹﻋﻼﻥ ﺩﺍﻟﺔ ﺫﺍﺕ ﻭﺳﺎﺋﻂ ﻏﲑ ﳏﺪﺩﺓ )١٩٤.................................. (٢ ٣,٥ﺍﳌﻜﺘﺒﺔ ﺍﻟﻘﻴﺎﺳﻴﺔ ................................................................ Standard Library ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١ﺍﻟﺪﺍﻟﺔ/ﺍﳌﺨﺘﺼﺮ ١٩٥........................................................ assert ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢ﺍﻟﺪﺍﻟﺔ ١٩٦.............................................................. isalnum ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣ﺍﻟﺪﺍﻟﺔ ١٩٦............................................................... isalpha ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٤ﺍﻟﺪﺍﻟﺔ ١٩٧............................................................... iscntrl ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٥ﺍﻟﺪﺍﻟﺔ ١٩٧............................................................... isdigit ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦ﺍﻟﺪﺍﻟﺔ ١٩٨............................................................... isgraph ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧ﺍﻟﺪﺍﻟﺔ ١٩٨............................................................... islower ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٨ﺍﻟﺪﺍﻟﺔ ١٩٩............................................................... isprint ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٩ﺍﻟﺪﺍﻟﺔ ١٩٩............................................................... ispunct ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١٠ﺍﻟﺪﺍﻟﺔ ٢٠٠............................................................ isspace ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١١ﺍﻟﺪﺍﻟﺔ ٢٠٠.............................................................. isupper ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١٢ﺍﻟﺪﺍﻟﺔ ٢٠١............................................................ isxdigit ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١٣ﺍﻟﺪﺍﻟﺘﲔ toupperﻭ ٢٠١............................................... tolower ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١٤ﺍﻟﺪﺍﻟﺔ ٢٠٢............................................................... perror ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١٥ﺍﻟﺪﺍﻟﺔ ٢٠٣.......................................................... (٢) perror ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١٦ﺛﻮﺍﺑﺖ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠٤............................................... errno.h ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١٧ﺛﻮﺍﺑﺖ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠٥.............................................. locale.h ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١٨ﺛﻮﺍﺑﺖ ﺍﳌﻠﻒ ﺍﻟﺮﺃﺳﻲ ٢٠٦................................................. math.h ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,١٩ﺍﻟﺪﺍﻟﺔ ٢٠٦................................................................... sin ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٠ﺍﻟﺪﺍﻟﺔ ٢٠٧................................................................... cos ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢١ﺍﻟﺪﺍﻟﺔ ٢٠٧................................................................... tan ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٢ﺍﻟﺪﺍﻟﺔ ٢٠٧................................................................... exp ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٣ﺍﻟﺪﺍﻟﺔ ٢٠٧................................................................... log ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٤ﺍﻟﺪﺍﻟﺔ ٢٠٨................................................................... pow ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٥ﺍﻟﺪﺍﻟﺔ ٢٠٨.................................................................. sqrt ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٦ﺍﻟﺪﺍﻟﺔ ٢٠٨................................................................. ceil ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٧ﺍﻟﺪﺍﻟﺔ ٢٠٩................................................................ floor ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٨ﺍﻟﺪﺍﻟﺔ ٢٠٩................................................................. fabs ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٢٩ﺍﻟﺪﺍﻟﺔ ٢٠٩................................................................ ldexp ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣٠ﺍﻟﺪﺍﻟﺔ ٢١٠.................................................................. fmod ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣١ﺍﻟﺪﺍﻟﺔ ،setjmpﻭ ﺍﻟﺒﻨﻴﺔ ٢١١............................................ jmp_buf ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣٢ﺍﻟﺪﺍﻟﺔ ،va_startﺍﻟﺪﺍﻟﺔ va_argﻭ ﺍﻟﺪﺍﻟﺔ ،va_endﻭ ﺍﳌﺆﺷﺮ ٢١٢........ va_list ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣٣ﺍﳌﺘﻐﲑ ٢١٣............................................................... size_t ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣٤ﺍﳌﺘﻐﲑ ٢١٣........................................................... ptrdiff_t ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣٥ﺍﻟﺪﺍﻟﺔ ٢١٤.............................................................. printf ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣٦ﺍﻟﺪﺍﻟﺔ ٢١٤............................................................. sprintf ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣٧ﺍﻟﺪﺍﻟﺔ ٢١٥............................................................. vprintf ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣٨ﺍﻟﺪﺍﻟﺔ ٢١٥............................................................ vfprintf ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٣٩ﺍﻟﺪﺍﻟﺔ ٢١٦............................................................ vsprintf ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٤٠ﺍﻟﺪﺍﻟﺔ ٢١٦................................................................ scanf ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٤١ﺍﻟﺪﺍﻟﺔ ٢١٦............................................................... fscanf ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٤٢ﺍﻟﺪﺍﻟﺔ ٢١٧............................................................... sscanf ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٤٣ﺍﻟﺪﺍﻟﺔ ٢١٧................................................................ fgetc ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٤٤ﺍﻟﺪﺍﻟﺔ ٢١٧................................................................ fgets ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٤٥ﺍﻟﺪﺍﻟﺔ ٢١٨................................................................ fputc ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٤٩ﺍﻟﺪﺍﻟﺔ ٢١٨................................................................ fputs ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٤٧ﺍﻟﺪﺍﻟﺔ ٢١٩................................................................. getc ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٤٨ﺍﻟﺪﺍﻟﺔ ٢١٩............................................................. getchar ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٤٩ﺍﻟﺪﺍﻟﺔ ٢١٩................................................................. gets ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٥٠ﺍﻟﺪﺍﻟﺔ ٢١٩................................................................. putc ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٥١ﺍﻟﺪﺍﻟﺔ ٢٢٠............................................................. putchar ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٥٢ﺍﻟﺪﺍﻟﺔ ٢٢٠................................................................. puts ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٥٣ﺍﻟﺪﺍﻟﺔ ٢٢٠............................................................... ungetc ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٥٤ﺍﻟﺪﺍﻟﺔ ٢٢١................................................................ fopen ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٥٥ﺍﻟﺪﺍﻟﺔ ٢٢١............................................................. freopen ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٥٦ﺍﻟﺪﺍﻟﺔ ٢٢٢............................................................... fclose ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٥٧ﺍﻟﺪﺍﻟﺔ ٢٢٢............................................................... remove ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٥٨ﺍﻟﺪﺍﻟﺔ ٢٢٣............................................................... rename ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٥٩ﺍﻟﺪﺍﻟﺔ ٢٢٣............................................................. tmpfile ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٠ﺍﻟﺪﺍﻟﺔ ٢٢٣................................................................ fread ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦١ﺍﻟﺪﺍﻟﺔ ٢٢٤............................................................... fwrite ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٢ﺍﻟﺪﺍﻟﺔ ٢٢٥................................................................ fseek ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٣ﺍﻟﺪﺍﻟﺔ ٢٢٥................................................................ ftell ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٤ﺍﻟﺪﺍﻟﺔ ٢٢٦............................................................... rewind ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٥ﺍﻟﺪﺍﻟﺔ ٢٢٦................................................................. feof ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٦ﺍﻟﺪﺍﻟﺔ ٢٢٧................................................................. atof ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٧ﺍﻟﺪﺍﻟﺔ ٢٢٧................................................................. atoi ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٨ﺍﻟﺪﺍﻟﺔ ٢٢٧................................................................. atol ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٦٩ﺍﻟﺪﺍﻟﺔ ٢٢٨................................................................. rand ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧٠ﺍﻟﺪﺍﻟﺔ ٢٢٨................................................................ srand ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧١ﺍﻟﺪﺍﻟﺔ ٢٢٩................................................................ abort ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧٢ﺍﻟﺪﺍﻟﺔ ٢٢٩................................................................. exit ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧٣ﺍﻟﺪﺍﻟﺔ ٢٢٩............................................................... atexit ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧٤ﺍﻟﺪﺍﻟﺔ ٢٣٠............................................................... system ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧٥ﺍﻟﺪﺍﻟﺔ ٢٣٠................................................................... abs ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧٦ﺍﻟﺪﺍﻟﺔ ٢٣٠................................................................. labs ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧٧ﺍﻟﺪﺍﻟﺔ ٢٣١................................................................... div ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧٨ﺍﻟﺪﺍﻟﺔ ٢٣١................................................................. ldiv ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٧٩ﺍﻟﺪﺍﻟﺔ strcpyﻭ ﺍﻟﺪﺍﻟﺔ ٢٣٢............................................. strncpy ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٨٠ﺍﻟﺪﺍﻟﺔ ٢٣٢.......................................................... (٢) strcpy ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٨١ﺍﻟﺪﺍﻟﺔ ٢٣٢............................................................... strcat ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٨٢ﺍﻟﺪﺍﻟﺔ ٢٣٢.............................................................. strncat ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٨٣ﺍﻟﺪﺍﻟﺔ ٢٣٣............................................................... strcmp ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٨٤ﺍﻟﺪﺍﻟﺔ ٢٣٣.............................................................. strncmp ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٨٥ﺍﻟﺪﺍﻟﺔ strchrﻭ ﺍﻟﺪﺍﻟﺔ ٢٣٤............................................. strrchr ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٨٦ﺍﻟﺪﺍﻟﺔ strspnﻭ ﺍﻟﺪﺍﻟﺔ ٢٣٤............................................. strcspn ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٨٧ﺍﻟﺪﺍﻟﺔ ٢٣٥.............................................................. strpbrk ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٨٨ﺍﻟﺪﺍﻟﺔ ٢٣٥............................................................... strstr ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٨٩ﺍﻟﺪﺍﻟﺔ ٢٣٥............................................................... strlen ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٩٠ﺍﻟﺪﺍﻟﺔ ٢٣٦............................................................ strerror ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٩١ﺍﻟﺪﺍﻟﺔ ٢٣٦............................................................... strtok ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٩٢ﺍﻟﺪﺍﻟﺔ ٢٣٧................................................................ clock ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٩٣ﺇﻧﺸﺎﺀ ﺩﺍﻟﺔ ﻧﻘﻮﻡ ﺑﺎﻹﻧﺘﻈﺎﺭ ﻟﻮﻗﺖ ﳏﺪﺩ ٢٣٨........................................... ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٩٤ﺍﻟﺪﺍﻟﺔ ٢٣٨.................................................................. time ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٩٥ﺍﻟﺪﺍﻟﺔ ٢٣٩............................................................. (٢) time ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٩٦ﺍﻟﺪﺍﻟﺔ ٢٣٩............................................................ difftime ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٩٧ﺍﻟﺪﺍﻟﺔ ٢٤٠........................................................... localtime ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٩٨ﺍﻟﺪﺍﻟﺔ ٢٤٠.............................................................. asctime ﺍﻟﱪﻧﺎﻣﺞ :٣,٥,٩٩ﺍﻟﺪﺍﻟﺔ ٢٤٠................................................................ ctime ﺃﻫﻢ ﺍﳌﺮﺍﺟﻊ The C Programming Language Book, Second Edition By Brian Kernighan And Dennis Ritchie [Prentice Hall 1988; ISBN 0-131-10362-8] Fundamentals Programming Family Book, First Edition By IBM International 1985 Turbo C Manuel De Référence Book, By Borland International 1988 [FR] Wikipedia, the free encyclopedia: www.wikipedia.org CProgramming.com Your resource for C and C++: www.cprogramming.com C Pocket Reference Book, By Peter Prinz And Ulla Kirch-Prinz [O'Reilly November 2002; ISBN : 0-596-00436-2] UNIX System Calls and Subroutines using C Book, By Nikos Drakos 1997 Teach Yourself C in 21 Days Book, By Peter Aitken And Bradley L. Jones [Macmillan Computer Publishing] The End
© Copyright 2024