كتاب لغة C الشامل، الإصدار الثاني

‫ﳏﺘﻮﻳﺎﺕ ﺍﻟﻜﺘﺎﺏ ﺑﻨﻈﺮﺓ ﺳﺮﻳﻌﺔ‬
‫ﺣﻮﻝ ﺍﻟﻜﺘﺎﺏ ‪١٨.............................................................................................‬‬
‫ﺍﳌﻘﺪﻣﺔ ‪١٩...................................................................................................‬‬
‫ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ – ﺃﺳﺎﺳﻴﺎﺕ ﰲ ﻟﻐﺔ ‪........................................................................... 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‬ﺍﻟﺸﺎﻣﻞ‪ ،‬ﻭ ﺍﻟﻴﻮﻡ ﻗﻤﺖ ﺑﺈﻧﺸﺎﺀ ﺍﻟﻠﻨـﺴﺨﺔ‬
‫ﺍﻟﺜﺎﻧﻴﺔ ﻣﻨﻪ‪ ،‬ﻭ ﻟﻜﻦ ﻫﺬﻩ ﺍﻟﻨﺴﺨﺔ ﱂ ﺃﺭﻛﺰ ﻋﻠﻰ ﺍﻟﺘﻮﺳﻴﻊ ﻓﻴﻬﺎ ﻋﻠﻰ ﺍﺳﺎﺑﻘﺔ‪ ،‬ﺇﳕﺎ ﺭﻛﺰﺕ ﻋﻠﻰ ﺗﺼﺤﻴﺢ ﺃﺧﻄﺎﺀﻫﺎ‪ ،‬ﺻـﺤﺤﺖ‬
‫ﺍﻟﺬﻱ ﺍﺳﺘﻄﻌﺖ ﻣﻼﺣﻈﺘﻪ‪ ،‬ﻭ ﻻﹶﺯِﻟﹾﺖ‪ ‬ﺃﻧﺘﻈﺮ ﻣﻼﺣﻈﺔ ﺃﺧﻄﺎﺀ ﺃﺧﺮﻯ ﻣﻦ ﻗﹸﺮﺍﺀ ﻫﺬﻩ ﺍﻟﻜﺘﺎﺏ‪ ،‬ﻟﺬﺍ ﺃﺭﺟﻮ ﻟﻜﻞ ﻣﻦ ﻗﺮﺃ ﺍﻟﻜﺘﺎﺏ ﻭ‬
‫ﻭﺟﺪ ﺑﻪ ﺃﺧﻄﺎﺀ ﺳﻮﺍﺀ ﻛﺎﻧﺖ ﺃﺧﻄﺎﺀ ﺇﻣﻼﺋﻴﺔ ﺃﻭ ﻣﻌﻨﻮﻳﺔ )ﻭ ﺧﺎﺻﺔ ﺍﳌﻌﻨﻮﻳﺔ( ﺃﻥ ﻳﻘﻮﻡ ﺑﺘﻨﺒﻴﻬﻲ ﻋﻠـﻰ ﺑﺮﻳـﺪﻱ ﺍﻹﻟﻴﻜﺘـﺮﻭﱐ‬
‫‪ ،[email protected]‬ﺃﻭ ﳝﻜﻦ ﺃﻥ ﻳﻮﺿﻊ ﺍﳋﻄﺄ ﰲ ﻣﻮﺿﻮﻉ ﻫﺬﺍ ﺍﻟﻜﺘﺎﺏ‪ .‬ﺣﻴﺚ ﺳﻴﺘﻢ ﺇﻧﺸﺎﺀ ﻗﺎﺋﻤﺔ ﻷﲰﺎﺀ ﻣ‪‬ﻼﺣﻈﻲ‬
‫ﺃﺧﻄﺎﺀ ﻫﺬﺍ ﺍﻟﻜﺘﺎﺏ ﻭ ﻭﺿ‪‬ﻌﻬﺎ ﰲ ﺍﻟﺼﻔﺤﺎﺕ ﺍﻷﻭﱃ ﻣﻦ ﺍﻟﻜﺘﺎﺏ )ﻳﻌﲏ ﻋﻤﻞ ﲨﺎﻋﻲ(‪.‬‬
‫ﻭ ﻣﻦ ﺃﺧﻄﺎﺀ ﺍﻟﻨﺴﺨﺔ ﺍﻷﻭﱃ)ﻫﺬﺍ ﻟﻜﻲ ﺃﺑﲔ ﻟﻘﺮﺍﺀ ﺍﻟﻨﺴﺨﺔ ﺍﻷﻭﱃ ﻣﻦ ﻫﺬﺍ ﺍﻟﻜﺘﺎﺏ ﺃﻱ ﳝﻜﻨﻬﻢ ﺇﻋﺎﺩﺓ ﺍﻟﻘﺮﺍﺀﺓ( ﻣـﻦ ﻫـﺬﺍ‬
‫ﺍﻟﻜﺘﺎﺏ ﻛﺎﻧﺖ ﰲ ﻛﻞ ﻣﻦ‪ :‬ﺍﻟﻔﺼﻞ ﺍﻷﻭﻝ‪ ،‬ﺑﻌﺾ ﺍﻷﺧﻄﺎﺀ ﰲ ﺍﳉﺰﺀ "ﺍﻟﺒﺪﺀ ﻣﻊ ﻟﻐﺔ ‪ ،"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