home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / help / cpplib.inf (.txt) < prev    next >
Encoding:
OS/2 Help File  |  1996-02-09  |  1.1 MB  |  38,541 lines

Text Truncated. Only the first 1MB is shown below. Download the file for the complete contents.
  1.  
  2. ΓòÉΓòÉΓòÉ 1. About this Reference ΓòÉΓòÉΓòÉ
  3.  
  4. The VisualAge for C++ C Library Reference describes the the VisualAge for C++ 
  5. implementation of the C runtime library. Use it to find information about what 
  6. the different library functions do and how to declare and use them. This 
  7. reference also provides code examples that you can copy to a file and paste 
  8. into your own applications. 
  9.  
  10. This document is a reference rather than a tutorial.  It assumes you are 
  11. already familiar with C and C++ programming concepts. Information applies to 
  12. the C language, but you can also call the functions and macros from C++ 
  13. applications. 
  14.  
  15. For a list of other information that you might also find helpful, see Other 
  16. Information You Might Find Helpful. 
  17.  
  18. Before you begin to use this information, it would be helpful to understand how 
  19. to navigate through it. You can use the Table of Contents and Index facility to 
  20. locate topics and the Search facility to search the text of this document. You 
  21. can use hypertext links to acquire related information on the current topic. 
  22. Hypertext links appear in a different color. For example, here is a link to 
  23. another panel: Communicating Your Comments to IBM. By double-clicking on the 
  24. text of the link or by pressing Enter on a highlighted link, you will open a 
  25. panel of related information. When you open a panel, the first link has the 
  26. focus; to shift the focus to other links, use the Tab key. 
  27.  
  28. You should also understand: 
  29.  
  30.      How to Use the Contents 
  31.      How to Obtain Additional Information 
  32.      How to Use Menu Bar Choices 
  33.      How to Cut and Paste Examples 
  34.  
  35.  
  36. ΓòÉΓòÉΓòÉ 1.1. Notices ΓòÉΓòÉΓòÉ
  37.  
  38. (C) Copyright International Business Machines Corporation, 1995, 1996. All 
  39. rights reserved. 
  40.  
  41. Note to U.S. Government Users - Documentation related to restricted rights - 
  42. Use, duplication, or disclosure is subject to restrictions set forth in GSA ADP 
  43. Schedule Contract with IBM Corp. 
  44.  
  45. This edition applies to Version 3.5 of IBM VisualAge for C++ for Windows 
  46. (33H4979, 33H4980) and to all subsequent releases and modifications until 
  47. otherwise indicated in new editions.  Make sure you are using the correct 
  48. edition for the level of the product. 
  49.  
  50. This publication could include technical inaccuracies or typographical errors. 
  51. Changes are periodically made to the information herein; any such changes will 
  52. be reported in subsequent revisions. 
  53.  
  54. Requests for publications and for technical information about IBM products 
  55. should be made to your IBM Authorized Dealer or your IBM Marketing 
  56. Representative. 
  57.  
  58. When you send information to IBM, you grant IBM a nonexclusive right to use or 
  59. distribute the information in any ways it believes appropriate without 
  60. incurring any obligation to you. 
  61.  
  62. Any reference to an IBM licensed program in this publication is not intended to 
  63. state or imply that only IBM's licensed program may be used. Any functionally 
  64. equivalent product, program, or service that does not infringe any of IBM's 
  65. intellectual property rights may be used instead of the IBM product, program, 
  66. or service. Evaluation and verification of operation in conjunction with other 
  67. products, except those expressly designated by IBM, is the user's 
  68. responsibility. 
  69.  
  70. IBM may have patents or pending patent applications covering subject matter in 
  71. this document.  The furnishing of this document does not give you any license 
  72. to these patents.  You can send license inquiries, in writing, to the IBM 
  73. Director of Licensing, IBM Corporation, 500 Columbus Avenue, Thornwood, NY, 
  74. 10594, USA. 
  75.  
  76. Licensees of this program who wish to have information about it for the purpose 
  77. of enabling: (i) the exchange of information between independent created 
  78. programs and other programs (including this one) and (ii) the mutual use of the 
  79. information which has been exchanged, should contact IBM Canada Ltd., 
  80. Department 071, 1150 Eglinton Avenue East, North York, Ontario M3C 1H7, Canada. 
  81. Such information may be available, subject to appropriate terms and conditions, 
  82. including in some cases payment of a fee. 
  83.  
  84. This publication contains examples of data and reports used in daily business 
  85. operations. To illustrate them as completely as possible, the examples include 
  86. the names of individuals, companies, brands, and products. All of these names 
  87. are fictitious and any similarity to the names and addresses used by an actual 
  88. business enterprise is entirely coincidental. 
  89.  
  90.  
  91. ΓòÉΓòÉΓòÉ 1.2. Trademarks and Service Marks ΓòÉΓòÉΓòÉ
  92.  
  93. The following terms used in this publication are trademarks or service marks of 
  94. IBM Corporation in the United States or other countries: 
  95.  
  96.       AIX 
  97.       IBM 
  98.       IBMLink 
  99.       SAA 
  100.       Systems Application Architecture 
  101.       VisualAge 
  102.       WorkFrame 
  103.  
  104.  Windows is a trademark of Microsoft Corporation. 
  105.  
  106.  Other company, product, and service names, which may be denoted by a double 
  107.  asterisk(**), may be trademarks or service marks of others. 
  108.  
  109.  IBM's VisualAge products and services are not associated with or sponsored by 
  110.  Visual Edge Software, Ltd.. 
  111.  
  112.  
  113. ΓòÉΓòÉΓòÉ 1.3. How to Use the Contents ΓòÉΓòÉΓòÉ
  114.  
  115. When the Contents window first appears, some topics have a plus (+) sign beside 
  116. them. The plus sign indicates that additional topics are available. 
  117.  
  118. To expand the Contents if you are using a mouse, click on the plus sign. If you 
  119. are using the keyboard, use the Up or Down Arrow key to highlight the topic, 
  120. and press the Plus (+) key. For example, How to Use the Contents has a plus 
  121. sign beside it.  To see additional topics for that heading, click on the plus 
  122. sign or highlight that topic and press the Plus (+) key. 
  123.  
  124. To view a topic, double-click on the topic (or press the Up or Down Arrow key 
  125. to highlight the topic, and then press the Enter key). 
  126.  
  127.  
  128. ΓòÉΓòÉΓòÉ 1.4. How to Obtain Additional Information ΓòÉΓòÉΓòÉ
  129.  
  130. After you select a topic, the information for that topic appears in a window. 
  131. Highlighted words or phrases indicate that additional information is available. 
  132. Certain words and phrases are highlighted in a different color from the 
  133. surrounding text. These are called hypertext terms. 
  134.  
  135. If you are using a mouse, double-click on the highlighted word.  If you are 
  136. using a keyboard, press the Tab key to move to the highlighted word, and then 
  137. press the Enter key.  Additional information then appears in a window. 
  138.  
  139.  
  140. ΓòÉΓòÉΓòÉ 1.5. How to Use Menu Bar Choices ΓòÉΓòÉΓòÉ
  141.  
  142. Several choices are available for managing the information presented in this 
  143. document. There are three choices on the menu bar: the Services menu, the 
  144. Options menu, and the Help menu. 
  145.  
  146. Use the Services menu to operate the active window currently displayed on the 
  147. screen. Available actions include the following: 
  148.  
  149.  Placing Bookmarks 
  150.    You can set a placeholder so you can retrieve information of interest to 
  151.    you. 
  152.  
  153.  Searching for Information 
  154.    You can find occurrences of a word or phrase in the current topic, selected 
  155.    topics, or all topics. 
  156.  
  157.  Printing Information 
  158.    You can print one or more topics. You can also print a set of topics by 
  159.    first marking the topics in the Contents list. 
  160.  
  161.  Copying Information to a File 
  162.    You can copy a topic that you are viewing to the System Clipboard or to a 
  163.    file that you can edit. This method is particularly useful for copying 
  164.    syntax definitions and program samples into the application that you are 
  165.    developing. 
  166.  
  167.  Select actions from the Options menu, to change the way your Contents list is 
  168.  displayed. To expand the Contents and show all levels for all topics, choose 
  169.  Expand all from the Options pull-down. You can also press the Ctrl, Shift, and 
  170.  * keys together. 
  171.  
  172.  You can select various types of help information from the Help menu. 
  173.  
  174.  For information about any of the menu choices, highlight the choice in the 
  175.  menu and press F1. 
  176.  
  177.  
  178. ΓòÉΓòÉΓòÉ 1.5.1. Placing Bookmarks ΓòÉΓòÉΓòÉ
  179.  
  180. When you place a bookmark on a topic, it is added to a list of bookmarks you 
  181. have previously set.  You can view the list, and you can remove one or all 
  182. bookmarks from the list.  If you have not set any bookmarks, the list is empty. 
  183.  
  184. To set a bookmark, do the following: 
  185.  
  186.    1. Select a topic from the Contents. 
  187.    2. When that topic appears, select the Bookmark option from the Services 
  188.       menu. 
  189.    3. If you want to change the name used for the bookmark, type the new name 
  190.       in the field. 
  191.    4. Click on the Place radio button (or press the Up or Down Arrow key to 
  192.       select it). 
  193.    5. Click on OK (or select it and press Enter). The bookmark is then added to 
  194.       the bookmark list. 
  195.  
  196.  
  197. ΓòÉΓòÉΓòÉ 1.5.2. Searching for Information ΓòÉΓòÉΓòÉ
  198.  
  199. You can specify a word or phrase to be searched.  You can also limit the search 
  200. to a set of topics by first marking the topics in the Contents list. 
  201.  
  202. To search for a word or phrase in all topics, do the following: 
  203.  
  204.    1. Select the Search option from the Services menu. 
  205.    2. Type the word or words to be searched for. 
  206.    3. Click on All sections (or press the Up or Down Arrow keys to select it). 
  207.    4. Click on Search (or select it and press Enter) to begin the search. 
  208.    5. The list of topics where the word or phrase appears is displayed. 
  209.  
  210.  
  211. ΓòÉΓòÉΓòÉ 1.5.3. Printing Information ΓòÉΓòÉΓòÉ
  212.  
  213. You can print one or more topics, the index, or the table of contents.  Make 
  214. sure that your printer is connected to the serial port, configured correctly, 
  215. and ready for input. To print: 
  216.  
  217.    1. Select Print from the Services pull-down menu. 
  218.    2. Select what you want to print. Note that the This section and Marked 
  219.       sections choices are only available if you are viewing a topic or if you 
  220.       have marked topics, respectively.  To mark topics in the table of 
  221.       contents, press the Ctrl key and click on the topics, or use the arrow 
  222.       keys. 
  223.    3. Select Print to print what you've chosen. 
  224.  
  225.  
  226. ΓòÉΓòÉΓòÉ 1.5.4. Copying Information to a File ΓòÉΓòÉΓòÉ
  227.  
  228. You can copy a topic that you are viewing in two ways: 
  229.  
  230.      Copy copies the topic that you are viewing into the System Clipboard. 
  231.  
  232.      Copy to file copies the topic that you are viewing into a temporary file 
  233.       named text.tmp.  You can later edit that file by using any editor. The 
  234.       text.tmp file is placed in the directory where your viewable document 
  235.       resides. This copy function does not apply if you are viewing the 
  236.       document from the CD-ROM. 
  237.  
  238.  To copy a topic, do the following: 
  239.  
  240.    1. Expand the Contents list and select a topic. 
  241.    2. When the topic appears, select Copy to file from the Services menu. 
  242.    3. The system puts the text pertaining to that topic into the temporary file 
  243.       text.tmp. 
  244.  
  245.  
  246. ΓòÉΓòÉΓòÉ 1.6. How to Cut and Paste Examples ΓòÉΓòÉΓòÉ
  247.  
  248. You can copy examples (or information) from this reference/guide/book to 
  249. compile, link, and run them, or to paste them into your own code. 
  250.  
  251. To copy an example or information: 
  252.  
  253.    1. Make the topic you want to copy the active window. 
  254.  
  255.    2. From the Services menu, select Copy to file. The text in that topic is 
  256.       placed in the temporary file text.tmp, in the same directory as this 
  257.       reference. This copy function does not apply if you are viewing the 
  258.       document from the CD-ROM. 
  259.  
  260.    3. You can then modify or use text.tmp as you want. 
  261.  
  262.  Note:  Because the system copies the entire contents of the topic to the file, 
  263.  you may need to edit it to remove additional text. Most examples in this 
  264.  reference are ready to compile, link, and run as they appear, and do not 
  265.  require any editing. 
  266.  
  267.  
  268. ΓòÉΓòÉΓòÉ 1.7. Other Information You Might Find Helpful ΓòÉΓòÉΓòÉ
  269.  
  270. This product provides a number of online guides and references that we hope 
  271. you'll find helpful as you develop applications. This information includes 
  272. User's Guides, References, and How Do I help that gives you specific 
  273. instructions for performing common tasks. You can get to this online 
  274. information from the Information folder inside the main product folder.  You 
  275. can also get to it from the Help menu in any of the components of the product. 
  276.  
  277.  
  278. ΓòÉΓòÉΓòÉ 1.8. Communicating Your Comments to IBM ΓòÉΓòÉΓòÉ
  279.  
  280. If there is something you like, or dislike, about this book, please let us 
  281. know.  You can use one of the methods listed below to send your comments to 
  282. IBM.  Please be sure to include the complete title of the publication that you 
  283. are commenting on. 
  284.  
  285. The comments you send should only pertain to the information in this document 
  286. and its presentation.  To request additional publications or to ask questions 
  287. or make comments about the functions of IBM products or systems, you should 
  288. talk to your IBM representative or your authorized IBM remarketer. 
  289.  
  290. When you send comments to IBM, you grant IBM a nonexclusive right to use or 
  291. distribute your comments in any way it believes appropriate without incurring 
  292. any obligation to you. 
  293.  
  294. You can send your comments to IBM in the following ways: 
  295.  
  296.      By mail to the following address: 
  297.  
  298.             IBM Canada Ltd. Laboratory
  299.             Information Development
  300.             2G/345/1150/TOR
  301.             1150 EGLINTON AVENUE EAST
  302.             NORTH YORK, ONTARIO
  303.             CANADA M3C 1H7
  304.  
  305.      By FAX to the following number: 
  306.  
  307.         -  United States and Canada: (416) 448-6161 
  308.         -  Other countries (+1) 416-448-6161 
  309.  
  310.      By electronic mail to one of the following IDs.  Be sure to include your 
  311.       entire network address if you wish to get a reply. 
  312.  
  313.         -  Internet: torrcf@vnet.ibm.com 
  314.         -  IBMLink: toribm(torrcf) 
  315.         -  IBM/PROFS: torolab4(torrcf) 
  316.         -  IBMMAIL: ibmmail(caibmwt9) 
  317.  
  318.  
  319. ΓòÉΓòÉΓòÉ 2. The C Library ΓòÉΓòÉΓòÉ
  320.  
  321. This section summarizes the available C library functions. It also briefly 
  322. describes what the function does. Each library function is listed according to 
  323. the type of function it performs. 
  324.  
  325.      Error Handling 
  326.      Process Control 
  327.      File and Directory Management 
  328.      Searching and Sorting 
  329.      Regular Expressions 
  330.      Mathematical 
  331.      Fast RAM Semaphores 
  332.      Floating-Point Unit Control 
  333.      Date, Time, and Monetary Manipulation 
  334.      Type Conversion 
  335.      Stream Input/Output 
  336.      Low-Level Input/Output 
  337.      Handling Argument Lists 
  338.      Pseudorandom Numbers 
  339.      Dynamic Memory Management 
  340.      Memory Objects 
  341.      Environment and Locale Interaction 
  342.      String Operations 
  343.      Character Testing 
  344.      Case Mapping 
  345.      Multibyte Character Manipulation 
  346.  
  347.  
  348. ΓòÉΓòÉΓòÉ 2.1. Error Handling Functions ΓòÉΓòÉΓòÉ
  349.  
  350.      assert - Verify Condition 
  351.      atexit - Record Program Termination Function 
  352.      clearerr - Reset Error Indicators 
  353.      ferror - Test for Read/Write Errors 
  354.      _matherr - Process Math Library Errors 
  355.      perror - Print Error Message 
  356.      raise - Send Signal 
  357.      _set_crt_msg_handle - Change Runtime Message Output Destination 
  358.      signal - Handle Interrupt Signals 
  359.      strerror - Set Pointer to Runtime Error Message 
  360.      _strerror - Set Pointer to System Error String 
  361.  
  362.  
  363. ΓòÉΓòÉΓòÉ 2.2. Process Control Functions ΓòÉΓòÉΓòÉ
  364.  
  365.      _beginthread - Create New Thread 
  366.      _cwait - Wait for Child Process 
  367.      _disable - Disable Interrupts 
  368.      _enable - Enable Interrupts 
  369.      _endthread - Terminate Current Thread 
  370.      execl - _execvpe - Load and Run Child Process 
  371.      _exit - End Process 
  372.      _freemod - Free User DLL 
  373.      getpid - Get Process Identifier 
  374.      _interrupt - Call Interrupt  Procedure 
  375.      _loadmod - Load DLL 
  376.      _onexit - Record Termination Function 
  377.      putenv - Modify Environment Variables 
  378.      _searchenv - Search for File 
  379.      _spawnl - _spawnvpe - Start and Run Child Processes 
  380.      _threadstore - Access Thread-Specific Storage 
  381.  
  382.  
  383. ΓòÉΓòÉΓòÉ 2.3. File and Directory Management Functions ΓòÉΓòÉΓòÉ
  384.  
  385.      chdir - Change Current Working Directory 
  386.      _chdrive - Change Current Working Drive 
  387.      fstat - Information about Open File 
  388.      _fullpath - Get Full Path Name of Partial Path 
  389.      _getcwd - Get Path Name of Current Directory 
  390.      _getdcwd - Get Full Path Name of Current Directory 
  391.      _getdrive - Get Current Working Drive 
  392.      _makepath - Create Path 
  393.      mkdir - Create New Directory 
  394.      rmdir - Remove Directory 
  395.      _splitpath - Decompose Path Name 
  396.      stat - Get Information about File or Directory 
  397.  
  398.  
  399. ΓòÉΓòÉΓòÉ 2.4. Searching and Sorting Functions ΓòÉΓòÉΓòÉ
  400.  
  401.      bsearch - Search Arrays 
  402.      lfind - lsearch - Find Key in Array 
  403.      lfind - lsearch - Find Key in Array 
  404.      qsort - Sort Array 
  405.  
  406.  
  407. ΓòÉΓòÉΓòÉ 2.5. Regular Expression Functions ΓòÉΓòÉΓòÉ
  408.  
  409.      regcomp - Compile Regular Expression 
  410.      regerror - Return Error Message for Regular Expression 
  411.      regexec - Execute Compiled Regular Expression 
  412.      regfree - Free Memory for Regular Expression 
  413.  
  414.  
  415. ΓòÉΓòÉΓòÉ 2.6. Mathematical Functions ΓòÉΓòÉΓòÉ
  416.  
  417.      abs - Calculate Integer Absolute Value 
  418.      _cabs - Calculate Absolute Value of Complex Number 
  419.      ceil - Find Integer >= Argument 
  420.      div  - Calculate Quotient and Remainder 
  421.      erf - erfc - Calculate Error Functions 
  422.      exp - Calculate Exponential Function 
  423.      fabs - Calculate Floating-Point Absolute Value 
  424.      floor - Integer <= Argument 
  425.      fmod - Calculate Floating-Point Remainder 
  426.      frexp - Separate Floating-Point Value 
  427.      _fsqrt -  Calculate Square Root 
  428.      _fyl2x - Calculate y * log2(x) 
  429.      _fyl2xp1 -  Calculate y * log2(x + 1) 
  430.      _f2xm1 -  Calculate (2**x) - 1 
  431.      gamma - Gamma Function 
  432.      hypot - Calculate Hypotenuse 
  433.      labs - Calculate Absolute Value of Long Integer 
  434.      ldexp - Multiply by a Power of Two 
  435.      ldiv - Perform Long Division 
  436.      log - Calculate Natural Logarithm 
  437.      log10 - Calculate Base 10 Logarithm 
  438.      max - Return Larger of Two Values 
  439.      min - Return Lesser of Two Values 
  440.      modf - Separate Floating-Point Value 
  441.      pow - Compute Power 
  442.      sqrt - Calculate Square Root 
  443.      Bessel Functions - Solve Differential Equations 
  444.  
  445.  Trigonometric Functions 
  446.  
  447.      acos - Calculate Arccosine 
  448.      asin - Calculate Arcsine 
  449.      atan - atan2 - Calculate Arctangent 
  450.      cos - Calculate Cosine 
  451.      cosh - Calculate Hyperbolic Cosine 
  452.      _facos - Calculate Arccosine 
  453.      _fasin - Calculate Arcsine 
  454.      _fcos - Calculate Cosine 
  455.      _fcossin - Calculate Cosine and Sine 
  456.      _fpatan - Calculate Arctangent 
  457.      _fptan - Calculate Tangent 
  458.      _fsin - Calculate Sine 
  459.      _fsincos - Calculate Sine and Cosine 
  460.      sin - Calculate Sine 
  461.      sinh - Calculate Hyperbolic Sine 
  462.      tan - Calculate Tangent 
  463.      tanh - Calculate Hyperbolic Tangent 
  464.  
  465.  Bit Rotation 
  466.  
  467.      _crotl - _crotr - Rotate Bits of Character Value 
  468.      _lrotl - _lrotr - Rotate Bits of Unsigned Long Value 
  469.      _rotl - _rotr - Rotate Bits of Unsigned Integer 
  470.      _srotl - _srotr - Rotate Bits of Unsigned Short Value 
  471.  
  472.  
  473. ΓòÉΓòÉΓòÉ 2.7. Fast RAM Semaphore Functions ΓòÉΓòÉΓòÉ
  474.  
  475.      __cxchg - Exchange Character Value with Memory 
  476.      __lxchg - Exchange Integer Value with Memory 
  477.      __sxchg - Exchange Integer Value with Memory 
  478.  
  479.  
  480. ΓòÉΓòÉΓòÉ 2.8. Floating-Point Unit Control Functions ΓòÉΓòÉΓòÉ
  481.  
  482.      _clear87 - Clear Floating-Point Status Word 
  483.      _control87 - Set Floating-Point Control Word 
  484.      _fpreset - Reset Floating-Point Unit 
  485.      _status87 - Get Floating-Point Status Word 
  486.  
  487.  
  488. ΓòÉΓòÉΓòÉ 2.9. Date, Time, and Monetary Manipulation Functions ΓòÉΓòÉΓòÉ
  489.  
  490.      asctime - Convert Time to Character String 
  491.      clock  - Determine Processor Time 
  492.      ctime - Convert Time to Character String 
  493.      difftime - Compute Time Difference 
  494.      _ftime - Store Current Time 
  495.      gmtime - Convert Time 
  496.      localtime - Convert Time 
  497.      mktime - Convert Local Time 
  498.      _strdate - Copy Current Date 
  499.      strfmon - Convert Monetary Value to String 
  500.      strftime - Convert to Formatted Time 
  501.      strptime - Convert to Formatted Date and Time 
  502.      _strtime - Copy Time 
  503.      time - Determine Current Time 
  504.      tzset - Assign Values to Locale Information 
  505.      utime - Set Modification Time 
  506.      wcsftime - Convert to Formatted Date and Time 
  507.  
  508.  
  509. ΓòÉΓòÉΓòÉ 2.10. Type Conversion Functions ΓòÉΓòÉΓòÉ
  510.  
  511.      atof - Convert Character String to Float 
  512.      atoi - Convert Character String to Integer 
  513.      atol - Convert Character String to Long Integer 
  514.      _atold - Convert Character String to Long Double 
  515.      _ecvt - Convert Floating-Point to Character 
  516.      _fcvt - Convert Floating-Point to String 
  517.      _gcvt - Convert Floating-Point to String 
  518.      _itoa - Convert Integer to String 
  519.      _ltoa - Convert Long Integer to String 
  520.      strtod - Convert Character String to Double 
  521.      strtol - Convert Character String to Long Integer 
  522.      strtold - Convert String to Long Double 
  523.      strtoul - Convert String Segment to Unsigned Integer 
  524.      _ultoa - Convert Unsigned Long Integer to String 
  525.      wcstod - Convert Wide-Character String to Double 
  526.      wcstol - Convert Wide-Character to Long Integer 
  527.      wcstoul - Convert Wide-Character String to Unsigned Long 
  528.      wctob - Convert Wide Character to Byte 
  529.  
  530.  Multibyte and Wide-Character Type Conversion 
  531.  
  532.      mbrtowc - Convert Multibyte Character to Wide Character 
  533.      mbsrtowcs - Convert Multibyte String to Wide-Character String 
  534.      mbstowcs - Convert Multibyte String to Wide-Character String 
  535.      mbtowc - Convert Multibyte Character to Wide Character 
  536.      wcrtomb - Convert Wide Character to Multibyte Character 
  537.      wcsrtombs - Convert Wide-Character String to Multibyte String 
  538.      wcstombs - Convert Wide-Character String to Multibyte String 
  539.      wctomb -  Convert Wide Character to Multibyte Character 
  540.  
  541.  
  542. ΓòÉΓòÉΓòÉ 2.11. Stream Input/Output Functions ΓòÉΓòÉΓòÉ
  543.  
  544. Formatted Input/Output 
  545.  
  546.      fprintf - Write Formatted Data to a Stream 
  547.      fscanf - Read Formatted Data 
  548.      printf - Print Formatted Characters 
  549.      scanf - Read Data 
  550.      sprintf - Print Formatted Data to Buffer 
  551.      sscanf - Read Data 
  552.      swprintf - Format and Write Wide Characters to Buffer 
  553.      swscanf - Read Wide Characters from Buffer 
  554.      vfprintf - Print Argument Data to Stream 
  555.      vprintf - Print Argument Data 
  556.      vsprintf - Print Argument Data to Buffer 
  557.      vswprintf - Format and Write Wide Characters to Buffer 
  558.  
  559.  Character and String Input/Output 
  560.  
  561.      fgetc - Read a Character 
  562.      _fgetchar - Read Single Character from stdin 
  563.      fgets - Read a String 
  564.      fputc - Write Character 
  565.      _fputchar - Write Character 
  566.      fputs - Write String 
  567.      getc - getchar - Read a Character 
  568.      gets - Read a Line 
  569.      putc - putchar - Write a Character 
  570.      puts - Write a String 
  571.      ungetc - Push Character onto Input Stream 
  572.  
  573.  Wide Character and String Input/Output 
  574.  
  575.      fgetwc - Read Wide Character from Stream 
  576.      fgetwc - Read Wide Character from Stream 
  577.      fputwc - Write Wide Character 
  578.      fputws - Write Wide-Character String 
  579.      getwc - Read Wide Character from Stream 
  580.      getwchar - Get Wide Character from stdin 
  581.      putwc - Write Wide Character 
  582.      putwchar - Write Wide Character to stdout 
  583.      ungetwc - Push Wide Character onto Input Stream 
  584.  
  585.  Direct Input/Output 
  586.  
  587.      clearerr - Reset Error Indicators 
  588.      feof - Test End-of-File Indicator 
  589.      ferror - Test for Read/Write Errors 
  590.      fread - Read Items 
  591.      fwrite - Write Items 
  592.  
  593.  File Positioning 
  594.  
  595.      fgetpos - Get File Position 
  596.      fseek - Reposition File Position 
  597.      fsetpos - Set File Position 
  598.      ftell - Get Current Position 
  599.      lseek - Move File Pointer 
  600.      rewind - Adjust Current File Position 
  601.  
  602.  File Access 
  603.  
  604.      fclose - Close Stream 
  605.      _fcloseall - Close All Open Streams 
  606.      fdopen - Associates Input Or Output With File 
  607.      fflush - Write Buffer to File 
  608.      _flushall - Write Buffers to Files 
  609.      fopen - Open Files 
  610.      freopen - Redirect Open Files 
  611.      setbuf - Control Buffering 
  612.      _setmode - Set File Translation Mode 
  613.      setvbuf - Control Buffering 
  614.  
  615.  File Operations 
  616.  
  617.      fileno - Determine File Handle 
  618.      remove - Delete File 
  619.      rename - Rename File 
  620.      _rmtmp - Remove Temporary Files 
  621.      tempnam - Produce Temporary File Name 
  622.      tmpfile - Create Temporary File 
  623.      tmpnam - Produce Temporary File Name 
  624.      umask - Sets File Mask of Current Process 
  625.      unlink - Delete File 
  626.  
  627.  
  628. ΓòÉΓòÉΓòÉ 2.12. Low-Level Input/Output Functions ΓòÉΓòÉΓòÉ
  629.  
  630. Port Input/Output 
  631.  
  632.      _inp - Read Byte from Input Port 
  633.      _inpd - Read Doubleword from Input Port 
  634.      _inpw - Read Unsigned Short from Input Port 
  635.      _outp - Write Byte to Output Port 
  636.      _outpd - Write Double Word to Output Port 
  637.      _outpw - Write Word to Output Port 
  638.      umask - Sets File Mask of Current Process 
  639.  
  640.  Character and String Input/Output 
  641.  
  642.      _cgets - Read String of Characters from Keyboard 
  643.      _cprintf - Print Characters to Screen 
  644.      _cputs - Write String to Screen 
  645.      _cscanf - Read Data from Keyboard 
  646.      _getch - _getche - Read Character from Keyboard 
  647.      _kbhit - Test for Keystroke 
  648.      _putch - Write Character to Screen 
  649.      _ungetch - Push Character Back to Keyboard 
  650.  
  651.  Direct Input/Output 
  652.  
  653.      read - Read Into Buffer 
  654.      write - Writes from Buffer to File 
  655.  
  656.  File Positioning 
  657.  
  658.      __eof - Determine End of File 
  659.      _tell - Get Pointer Position 
  660.  
  661.  File Access 
  662.  
  663.      access - Determine Access Mode 
  664.      chmod - Change File Permission Setting 
  665.      close - Close File Associated with Handle 
  666.      creat - Create New File 
  667.      dup - Associate Second Handle with Open File 
  668.      dup2 - Associate Second Handle with Open File 
  669.      isatty - Test Handle for Character Device 
  670.      open - Open File 
  671.      _sopen - Open Shared File 
  672.  
  673.  File Operations 
  674.  
  675.      _chsize - Alter Length of File 
  676.      _filelength - Determine File Length 
  677.  
  678.  
  679. ΓòÉΓòÉΓòÉ 2.13. Functions for Handling Argument Lists ΓòÉΓòÉΓòÉ
  680.  
  681.      va_arg - va_end - va_start - Access Function Arguments 
  682.      vfprintf - Print Argument Data to Stream 
  683.      vprintf - Print Argument Data 
  684.      vsprintf - Print Argument Data to Buffer 
  685.      vswprintf - Format and Write Wide Characters to Buffer 
  686.  
  687.  
  688. ΓòÉΓòÉΓòÉ 2.14. Pseudorandom Number Functions ΓòÉΓòÉΓòÉ
  689.  
  690.      rand - Generate Random Number 
  691.      srand - Set Seed for rand Function 
  692.  
  693.  
  694. ΓòÉΓòÉΓòÉ 2.15. Dynamic Memory Management Functions ΓòÉΓòÉΓòÉ
  695.  
  696.      _alloca - Temporarily Reserve Storage Block 
  697.      calloc - Reserve and Initialize Storage 
  698.      _debug_calloc - Allocate and Initialize Memory 
  699.      _debug_free - Release Memory 
  700.      _debug_heapmin - Release Unused Memory in the Default Heap 
  701.      _debug_malloc - Allocate Memory 
  702.      _debug_realloc - Reallocate Memory Block 
  703.      _debug_ucalloc - Reserve and Initialize Memory from User Heap 
  704.      _debug_uheapmin - Release Unused Memory in User Heap 
  705.      _debug_umalloc - Reserve Memory Blocks from User Heap 
  706.      free - Release Storage Blocks 
  707.      _heapmin - Release Unused Memory from Default Heap 
  708.      malloc - Reserve Storage Block 
  709.      realloc - Change Reserved Storage Block Size 
  710.  
  711.  Heap Information and Checking 
  712.  
  713.      _dump_allocated - Get Information about Allocated Memory 
  714.      _dump_allocated_delta - Get Information about Allocated Memory 
  715.      _heap_check - Validate Default Memory Heap 
  716.      _heapchk - Validate Default Memory Heap 
  717.      _heapset - Validate and Set Default Heap 
  718.      _heap_walk - Return Information about Default Heap 
  719.      _mheap - Query Memory Heap for Allocated Object 
  720.      _msize - Return Number of Bytes Allocated 
  721.      _udump_allocated - Get Information about Allocated Memory in Heap 
  722.      _udump_allocated_delta - Get Information about Allocated Memory in Heap 
  723.      _uheap_check - Validate User Memory Heap 
  724.      _uheapchk - Validate Memory Heap 
  725.      _uheapset - Validate and Set Memory Heap 
  726.      _uheap_walk - Return Information about Memory Heap 
  727.      _ustats - Get Information about Heap 
  728.  
  729.  Heap Creation and Management 
  730.  
  731.      _uaddmem - Add Memory to a Heap 
  732.      _uclose - Close Heap from Use 
  733.      _ucreate - Create a Memory Heap 
  734.      _udefault - Change the Default Heap 
  735.      _udestroy - Destroy a Heap 
  736.      _uopen - Open Heap for Use 
  737.  
  738.  
  739. ΓòÉΓòÉΓòÉ 2.16. Memory Object Functions ΓòÉΓòÉΓòÉ
  740.  
  741.      memccpy - Copy Bytes 
  742.      memchr - Search Buffer 
  743.      memcmp - Compare Buffers 
  744.      memcpy - Copy Bytes 
  745.      memicmp - Compare Bytes 
  746.      memmove - Copy Bytes 
  747.      memset - Set Bytes to Value 
  748.      swab - Swap Adjacent Bytes 
  749.  
  750.  
  751. ΓòÉΓòÉΓòÉ 2.17. Environment and Locale Interaction Functions ΓòÉΓòÉΓòÉ
  752.  
  753.      abort - Stop a Program 
  754.      exit - End Program 
  755.      getenv - Search for Environment Variables 
  756.      longjmp - Restore Stack Environment 
  757.      setjmp - Preserve Environment 
  758.      system - Invoke the Command Processor 
  759.  
  760.  Setting and Querying Locale 
  761.  
  762.      csid - Determine Character Set ID for Multibyte Character 
  763.      getsyntx - Return LC_SYNTAX Characters 
  764.      iconv - Convert Characters to New Code Set 
  765.      iconv_close - Remove Conversion Descriptor 
  766.      iconv_open - Create Conversion Descriptor 
  767.      localdtconv - Return Date and Time Formatting Convention 
  768.      localeconv - Retrieve Information from the Environment 
  769.      nl_langinfo - Retrieve Locale Information 
  770.      setlocale - Set Locale 
  771.      wcsid - Determine Character Set ID for Wide Character 
  772.      wctype - Get Handle for Character Property Classification 
  773.  
  774.  
  775. ΓòÉΓòÉΓòÉ 2.18. String Operation Functions ΓòÉΓòÉΓòÉ
  776.  
  777.      strcat - Concatenate Strings 
  778.      strchr - Search for Character 
  779.      strcmp - Compare Strings 
  780.      strcmpi - Compare Strings Without Case Sensitivity 
  781.      strcoll - Compare Strings Using Collation Rules 
  782.      strcpy - Copy Strings 
  783.      strcspn - Compare Strings for Substrings 
  784.      strdup - Duplicate String 
  785.      stricmp - Compare Strings as Lowercase 
  786.      strlen - Determine String Length 
  787.      strncat - Concatenate Strings 
  788.      strncmp - Compare Strings 
  789.      strncpy - Copy Strings 
  790.      strnicmp - Compare Strings Without Case Sensitivity 
  791.      strnset - strset - Set Characters in String 
  792.      strpbrk - Find Characters in String 
  793.      strrchr - Find Last Occurrence of Character in String 
  794.      strrev - Reverse String 
  795.      strnset - strset - Set Characters in String 
  796.      strspn - Search Strings 
  797.      strstr - Locate Substring 
  798.      strtok - Tokenize String 
  799.      strxfrm - Transform String 
  800.  
  801.  
  802. ΓòÉΓòÉΓòÉ 2.19. Character Testing Functions ΓòÉΓòÉΓòÉ
  803.  
  804.      isalnum to isxdigit - Test Integer Value 
  805.      isascii - Test Integer Values 
  806.      isblank - Test for Blank Character Classification 
  807.      _iscsym - _iscsymf - Test Integer 
  808.      _iscsym - _iscsymf - Test Integer 
  809.      iswalnum to iswxdigit - Test Wide Integer Value 
  810.      iswblank - Test for Wide Blank Character Classification 
  811.      iswctype - Test for Character Property 
  812.      wcwidth - Determine Display Width of Wide Character 
  813.  
  814.  
  815. ΓòÉΓòÉΓòÉ 2.20. Case Mapping Functions ΓòÉΓòÉΓòÉ
  816.  
  817.      strlwr - Convert Uppercase to Lowercase 
  818.      strupr - Convert Lowercase to Uppercase 
  819.      tolower() - toupper() - Convert Character Case 
  820.      tolower() - toupper() - Convert Character Case 
  821.      _toascii - _tolower - _toupper - Convert Character 
  822.      towlower - towupper - Convert Wide Character Case 
  823.  
  824.  
  825. ΓòÉΓòÉΓòÉ 2.21. Wide Character String Operation Functions ΓòÉΓòÉΓòÉ
  826.  
  827.      mblen - Determine Length of Multibyte Character 
  828.      wcscat - Concatenate Wide-Character Strings 
  829.      wcschr - Search for Wide Character 
  830.      wcscmp - Compare Wide-Character Strings 
  831.      wcscoll - Compare Wide-Character Strings 
  832.      wcscpy - Copy Wide-Character Strings 
  833.      wcscspn - Find Offset of First Wide-Character Match 
  834.      wcslen - Calculate Length of Wide-Character String 
  835.      wcsncat - Concatenate Wide-Character Strings 
  836.      wcsncmp - Compare Wide-Character Strings 
  837.      wcsncpy - Copy Wide-Character Strings 
  838.      wcspbrk - Locate Wide Characters in String 
  839.      wcsspn - Search Wide-Character Strings 
  840.      wcsrchr - Locate Wide Character in String 
  841.      wcsstr - Locate Wide-Character Substring 
  842.      wcstok - Tokenize Wide-Character String 
  843.      wcswcs - Locate Wide-Character Substring 
  844.      wcswidth - Determine Display Width of Wide-Character String 
  845.      wcsxfrm - Transform Wide-Character String 
  846.  
  847.  
  848. ΓòÉΓòÉΓòÉ 3. Additional VisualAge for C++ Library Features ΓòÉΓòÉΓòÉ
  849.  
  850. Many of the functions in the VisualAge for C++ runtime library are extensions 
  851. to the ANSI standard.  This section describes some of the additional support 
  852. the VisualAge for C++ library provides and the behavior of certain features. 
  853.  
  854.      Intrinsic Functions 
  855.      Differentiating between the Memory Management Functions 
  856.      Infinity and NaN Support 
  857.      Using Low-Level I/O Functions 
  858.  
  859.  
  860. ΓòÉΓòÉΓòÉ 3.1. Intrinsic Functions ΓòÉΓòÉΓòÉ
  861.  
  862. The VisualAge for C++ compiler inlines some functions instead of generating a 
  863. function call for them. Some of these functions are always inlined; others are 
  864. inlined only when you compile with the optimization option (/O or /Oc) on. 
  865.  
  866.      Functions that Are Inlined when Optimization Is On 
  867.      Functions that Are Always Inlined 
  868.  
  869.  
  870. ΓòÉΓòÉΓòÉ 3.1.1. Functions that Are Inlined when Optimization Is On ΓòÉΓòÉΓòÉ
  871.  
  872. When optimization is on (/O+), VisualAge for C++ compiler by default inlines 
  873. (generates code instead of a function call) the following C library functions: 
  874.  
  875.  _clear87            _control87 
  876.  memchr              memcmp 
  877.  memcpy              memmove 
  878.  memset              _status87 
  879.  strcat              strchr 
  880.  strcmp              strcpy 
  881.  strlen              strncat 
  882.  strncmp             strncpy 
  883.  strrchr             wcscat 
  884.  wcschr              wcscmp 
  885.  wcscpy              wcslen 
  886.  wcsncat             wcsncmp 
  887.  wcsncpy             wcsrchr 
  888.  
  889.  The compiler inlines these functions when you include the appropriate header 
  890.  file that contains the function prototype and the #define and #pragma 
  891.  statements for the function. 
  892.  
  893.  If you program in C, you can override the inlining either by undefining the 
  894.  macro or by placing the name of the function in parentheses, thus disabling 
  895.  the preprocessor substitution. The function then remains a function call, and 
  896.  is not replaced by the code. The size of your object module is reduced, but 
  897.  your application program runs more slowly. 
  898.  
  899.  Note:  The optimize-for-size compiler option (/Oc) also disables the inlining 
  900.  of non-intrinsic functions. It should be /O+ /Oc-. 
  901.  
  902.  
  903. ΓòÉΓòÉΓòÉ 3.1.2. Functions that Are Always Inlined ΓòÉΓòÉΓòÉ
  904.  
  905. The following functions are built-in functions, meaning they do not have any 
  906. backing library functions, and are always inlined: 
  907.  
  908.  abs                 _alloca 
  909.  _crotl              _crotr 
  910.  __cxchg             _disable 
  911.  _enable             _facos 
  912.  _fasin              _fcos 
  913.  _fcossin            _fpatan 
  914.  _fptan              _fsin 
  915.  _fsincos            _fsqrt 
  916.  _fyl2x              _fyl2xp1 
  917.  _f2xm1              _inpd 
  918.  _inpw               _interrupt 
  919.  fabs                labs 
  920.  llabs               _llrotl 
  921.  _llrotr             _lrotl 
  922.  _lrotr              __lxchg 
  923.  _outp               _outpd 
  924.  _outpw              _rotl 
  925.  _rotr               _srotl 
  926.  _srotr              __sxchg 
  927.  
  928.  Do not parenthesize the names of these functions. 
  929.  
  930.  The built-in functions are all defined in <builtin.h>, in addition to the 
  931.  standard header definitions. 
  932.  
  933.  
  934. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  935.  
  936.      Functions that Are Inlined when Optimization Is On 
  937.      Functions that Are Always Inlined 
  938.      #include in the Language Reference 
  939.      #define in the Language Reference 
  940.      #pragma in the Language Reference 
  941.      /O option in the User's Guide 
  942.      <builtin.h> 
  943.  
  944.  
  945. ΓòÉΓòÉΓòÉ 3.2. Differentiating between Memory Management Functions ΓòÉΓòÉΓòÉ
  946.  
  947. The memory management functions defined by ANSI are calloc, malloc, realloc, 
  948. and free. These regular functions allocate and free memory from the default 
  949. runtime heap. (VisualAge for C++ has added another function, _heapmin, to 
  950. return unused memory to the system.) VisualAge for C++ also provides different 
  951. versions of each of these functions as extensions to the ANSI definition. 
  952.  
  953. All the versions actually work the same way; they differ only in what heap they 
  954. allocate from, and in whether they save information to help you debug memory 
  955. problems. The memory allocated by all of these functions is suitably aligned 
  956. for storing any type of object. 
  957.  
  958. The following table summarizes the different versions of memory management 
  959. functions, using malloc as an example of how the names of the functions change 
  960. for each version. They are all described in greater detail in this section. 
  961.  
  962. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  963. Γöé             Γöé REGULAR VERSION      Γöé DEBUG VERSION      Γöé
  964. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  965. Γöé DEFAULT HEAP       Γöé malloc          Γöé _debug_malloc      Γöé
  966. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  967. Γöé USER HEAP        Γöé _umalloc         Γöé _debug_umalloc      Γöé
  968. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  969.  
  970. To use these extensions, you must set the language level to extended, either 
  971. with the /Se compiler option or the #pragma langlvl(extended) directive. 
  972.  
  973.  
  974. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  975.  
  976.      Differentiating between Memory Management Functions 
  977.      Heap-Specific Functions 
  978.      Debug Functions 
  979.      Heap-Specific Debug Functions 
  980.      "Managing Memory" in the Programming Guide 
  981.      "Debugging Your Heaps" in the Programming Guide 
  982.  
  983.  
  984. ΓòÉΓòÉΓòÉ 3.2.1. Heap-Specific Functions ΓòÉΓòÉΓòÉ
  985.  
  986. Use the heap-specific versions to allocate and free memory from a user-created 
  987. heap that you specify.  (You can also explicitly use the runtime heap if you 
  988. want.)  Their names are prefixed by _u (for "user heaps"), for example, 
  989. _umalloc, and they are defined in <umalloc.h>. 
  990.  
  991. The functions provided are: 
  992.  
  993.      _ucalloc 
  994.      _umalloc 
  995.      _uheapmin 
  996.  
  997.  Notice there is no heap-specific version of realloc or free. Because they both 
  998.  always check what heap the memory was allocated from, you can always use the 
  999.  regular versions regardless of what heap the memory came from. 
  1000.  
  1001.  For more information about creating your own heaps and using the heap-specific 
  1002.  memory management functions, see Managing Memory with Multiple Heaps in the 
  1003.  Programming Guide. 
  1004.  
  1005.  
  1006. ΓòÉΓòÉΓòÉ 3.2.2. Debug Functions ΓòÉΓòÉΓòÉ
  1007.  
  1008. Use these functions to allocate and free memory from the default runtime heap, 
  1009. just as you would use the regular versions. They also provide information that 
  1010. you can use to debug memory problems. 
  1011.  
  1012. Note:  The information provided by these functions is Diagnosis, Modification, 
  1013. and Tuning information only.  It is not intended to be used as a programming 
  1014. interface. 
  1015.  
  1016. When you use the debug memory compiler option, /Tm, all calls to the regular 
  1017. memory management functions are mapped to their debug versions. You can also 
  1018. call the debug versions explicitly. 
  1019.  
  1020. Note:  If you parenthesize the calls to the regular memory management 
  1021. functions, they are not mapped to their debug versions. 
  1022.  
  1023. We recommend you place a #pragma strings(readonly) directive at the top of each 
  1024. source file that will call debug functions, or in a common header file that 
  1025. each includes. This directive is not essential, but it ensures that the file 
  1026. name passed to the debug functions can't be overwritten, and that only one copy 
  1027. of the file name string is included in the object module. 
  1028.  
  1029. The names of the debug versions are prefixed by _debug_, for example, 
  1030. _debug_malloc, and they are defined in <malloc.h> and <stdlib.h>. 
  1031.  
  1032. The functions provided are: 
  1033.  
  1034.      _debug_calloc 
  1035.      _debug_free 
  1036.      _debug_heapmin 
  1037.      _debug_malloc 
  1038.      _debug_realloc 
  1039.  
  1040.  In addition to their usual behavior, these functions also store information 
  1041.  (file name and line number) about each call made to them.  Each call also 
  1042.  automatically checks the heap by calling _heap_check (described below). 
  1043.  
  1044.  Three additional debug memory management functions do not have regular 
  1045.  counterparts: 
  1046.  
  1047.      _dump_allocated 
  1048.  
  1049.       Prints information to file standard error handle (the usual destination 
  1050.       of stderr) about each memory block currently allocated by the debug 
  1051.       functions. You can change the destination of the information with the 
  1052.       _set_crt_msg_handle function. 
  1053.  
  1054.      _dump_allocated_delta 
  1055.  
  1056.       Prints information to file standard error handle about each memory block 
  1057.       allocated by the debug functions since the last call to _dump_allocated 
  1058.       or _dump_allocated_delta. Again, you can change the destination of the 
  1059.       information with the _set_crt_msg_handle function. 
  1060.  
  1061.      _heap_check 
  1062.  
  1063.       Checks all memory blocks allocated or freed by the debug functions to 
  1064.       make sure that no overwriting has occurred outside the bounds of 
  1065.       allocated blocks or in a free memory block. 
  1066.  
  1067.  The debug functions call _heap_check automatically; you can also call it 
  1068.  explicitly. To use _dump_allocated and _dump_allocated_delta, you must call 
  1069.  them explicitly. 
  1070.  
  1071.  In VisualAge C++ releases prior to VisualAge for C++ Version 3.0, you could 
  1072.  not mix debug and regular versions of the memory management functions. For 
  1073.  example, you could not allocate memory with malloc and free it with 
  1074.  _debug_free. This restriction no longer applies; realloc and free (debug or 
  1075.  otherwise) can now handle memory allocated by any other allocation function. 
  1076.  
  1077.  
  1078. ΓòÉΓòÉΓòÉ 3.2.3. Heap-Specific Debug Functions ΓòÉΓòÉΓòÉ
  1079.  
  1080. The heap-specific functions also have debug versions that work just like the 
  1081. regular debug versions.  Use these functions to allocate and free memory from 
  1082. the user-created heap you specify, and also provide information that you can 
  1083. use to debug memory problems in your own heaps. 
  1084.  
  1085. Note:  The information provided by these functions is Diagnosis, Modification, 
  1086. and Tuning information only.  It is not intended to be used as a programming 
  1087. interface. 
  1088.  
  1089. You can call them explicitly, or you can use the debug memory compiler option, 
  1090. /Tm, to map calls to the heap-specific functions to their debug counterparts. 
  1091.  
  1092. Note:  If you parenthesize the calls to the heap-specific memory management 
  1093. functions, they are not mapped to their debug versions. 
  1094.  
  1095. The names of the heap-specific debug versions are prefixed by _debug_u, for 
  1096. example, _debug_umalloc, and they are defined in <umalloc.h>. 
  1097.  
  1098. The functions provided are: 
  1099.  
  1100.      _debug_ucalloc 
  1101.      _debug_uheapmin 
  1102.      _debug_umalloc 
  1103.      _udump_allocated 
  1104.      _udump_allocated_delta 
  1105.      _uheap_check 
  1106.  
  1107.  Notice there is no heap-specific debug version of realloc or free. Because 
  1108.  they both always check what heap the memory was allocated from, you always use 
  1109.  the regular debug versions (_debug_realloc and _debug_free), regardless of 
  1110.  what heap the memory came from. 
  1111.  
  1112.  For more information about debugging memory problems in your own heaps, see 
  1113.  "Debugging Your Heaps" in the Programming Guide. 
  1114.  
  1115.  
  1116. ΓòÉΓòÉΓòÉ 3.3. Infinity and NaN Support ΓòÉΓòÉΓòÉ
  1117.  
  1118. VisualAge for C++ compiler supports the use of infinity and NaN (not-a-number) 
  1119. values. Infinity is a value with an associated sign that is mathematically 
  1120. greater in magnitude than any binary floating-point number. A NaN is a value in 
  1121. floating-point computations that is not interpreted as a mathematical value, 
  1122. and that contains a mask state and a sequence of binary digits. 
  1123.  
  1124. The value of infinity can be computed from 1.0 / 0.0. The value of a NaN can be 
  1125. computed from 0.0 / 0.0. 
  1126.  
  1127. Depending on its bit pattern, a NaN can be either quiet (NaNQ) or signalling 
  1128. (NaNS), as defined in the ANSI/IEEE Standard for Binary Floating-Point 
  1129. Arithmetic (754-1982). A NaNQ is masked and never generates exceptions. A NaNS 
  1130. may be masked and may generate an exception, but does not necessarily do so. 
  1131. VisualAge for C++ compiler supports only quiet NaN values; all NaN values 
  1132. discussed below refer to quiet NaNs. 
  1133.  
  1134. NaN and infinity values are defined as macro constants in the <float.h> header 
  1135. file. The macros are: 
  1136.  
  1137.  Macro                Description 
  1138.  _INFINITYF           Infinity of type float 
  1139.  _INFINITY            Infinity of type double 
  1140.  _INFINITYL           Infinity of type long double 
  1141.  
  1142.  _INFF                Same as _INFINITYF 
  1143.  _INF                 Same as _INFINITY 
  1144.  _INFL                Same as _INFINITYL 
  1145.  
  1146.  _NANF                Quiet NaN of type float 
  1147.  _NAN                 Quiet NaN of type double 
  1148.  _NANL                Quiet NaN of type long double. 
  1149.  
  1150.  You can get the corresponding negative values by using the unary minus 
  1151.  operator (for example, -_INF). 
  1152.  
  1153.  Note:  The value of 0.0 can also be positive or negative. For example, 1.0 / 
  1154.  (-0.0) results in -_INF. 
  1155.  
  1156.  Because these macros are actually references to constant variables, you cannot 
  1157.  use them to initialize static variables. For example, the following statements 
  1158.  are not allowed: 
  1159.  
  1160.      static double infval = _INF;
  1161.      static float nanval = 1.0 + _NANF;
  1162.  
  1163.  However, you can initialize static variables to the numeric values of infinity 
  1164.  and NaN: 
  1165.  
  1166.      static double infval = 1.0 / 0.0;
  1167.      static float nanval =  0.0 / 0.0;
  1168.  
  1169.  Note:  Although positive and negative infinities are specific bit patterns, 
  1170.         NaNs are not. A NaN value is not equal to itself or to any other value. 
  1171.         For example, if you assign a NaN value to a variable x, you cannot 
  1172.         check the value of x with the statement if (_NAN == x). Instead, use 
  1173.         the statement if (x != x). 
  1174.  
  1175.  All relational and equality expressions involving NaN values always evaluate 
  1176.  to FALSE or zero (0), with the exception of not equal (!=), which always 
  1177.  evaluates to TRUE or one (1). 
  1178.  
  1179.  For information on the bit mapping and storage mapping of NaN and infinity 
  1180.  values, see the User's Guide. 
  1181.  
  1182.  
  1183. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1184.  
  1185.      Infinity and NaN in Library Functions 
  1186.      Assignment Expression 
  1187.      Equality 
  1188.      Relational 
  1189.      <float.h> 
  1190.  
  1191.  
  1192. ΓòÉΓòÉΓòÉ 3.3.1. Infinity and NaN in Library Functions ΓòÉΓòÉΓòÉ
  1193.  
  1194. When the language level is set to extended (using the /Se option or the #pragma 
  1195. langlvl(extended) directive), which is the default, infinity and NaN values can 
  1196. be passed as arguments to the scanf and printf families of library functions, 
  1197. and to the string conversion and math functions. At other language levels, 
  1198. these functions work as described in this reference. 
  1199.  
  1200. The following sections describe how the library functions handle the infinity 
  1201. and NaN values: 
  1202.  
  1203.      scanf Family 
  1204.      printf Family 
  1205.      String Conversion Functions 
  1206.      Math Functions 
  1207.  
  1208.  
  1209. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1210.  
  1211.      Infinity and NaN Support 
  1212.      scanf Family 
  1213.      printf Family 
  1214.      String Conversion Functions 
  1215.      Math Functions 
  1216.      #pragma langlvl 
  1217.      /Se option. 
  1218.  
  1219.  
  1220. ΓòÉΓòÉΓòÉ 3.3.1.1. scanf Family ΓòÉΓòÉΓòÉ
  1221.  
  1222. The scanf family of functions includes the functions scanf, fscanf, sscanf, and 
  1223. swscanf. When reading in floating-point numbers, these functions convert the 
  1224. strings INFINITY, INF, and NAN (in upper-, lower-, or mixed case) to the 
  1225. corresponding floating-point value. The sign of the value is determined by the 
  1226. format specification. 
  1227.  
  1228. Given a string that consists of NAN, INF, or INFINITY, followed by other 
  1229. characters, the scanf functions read in only the NaN or infinity value, and 
  1230. consider the rest of the string to be a second input field. For example, Nancy 
  1231. would be scanned as two fields, Nan and cy. 
  1232.  
  1233. Note:  In the case of a string that begins with INF, the functions check the 
  1234.        fourth letter. If that letter is not I (in upper- or lowercase), INF is 
  1235.        read and converted and the rest of the string is left for the next 
  1236.        format specification. If the fourth letter is I, the functions continue 
  1237.        to scan for the full INFINITY string. If the string is other than 
  1238.        INFINITY, the entire string is discarded. 
  1239.  
  1240.  
  1241. ΓòÉΓòÉΓòÉ <hidden> Example of fscanf with NaN and Infinity Values ΓòÉΓòÉΓòÉ
  1242.  
  1243. /************************************************************************
  1244. *
  1245.  
  1246. In the following example, fscanf converts NaN and infinity strings to their 
  1247. numeric values. 
  1248.  
  1249.                                                                         *
  1250. ************************************************************************/
  1251.  
  1252. #include <stdio.h>
  1253.  
  1254. int main(void)
  1255. {
  1256.    int n, count;
  1257.    double d1, d2, d3;
  1258.    FILE *stream;
  1259.  
  1260.    stream = tmpfile();
  1261.  
  1262.    fputs(" INFINITY NAn INF", stream);
  1263.  
  1264.    rewind(stream);
  1265.  
  1266.    n = fscanf(stream, "%lF%lf%lF%n", &d1, &d2, &d3, &count);
  1267.  
  1268.    if (n != EOF)
  1269.    {
  1270.       printf("Number of fields converted = %d\n", n);
  1271.       printf("Number of characters read = %d\n", count);
  1272.       printf("Output = %f %F %F\n", d1, d2, d3);
  1273.    }
  1274.  
  1275.    return 0;
  1276.  
  1277.    /* The expected output is:
  1278.  
  1279.       Number of fields converted = 3
  1280.       Number of characters read = 17
  1281.       Output = infinity NAN INFINITY  */
  1282.  
  1283. }
  1284.  
  1285.  
  1286. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1287.  
  1288. Example 
  1289.  
  1290.      Infinity and NaN Support 
  1291.      fscanf - Read Formatted Data 
  1292.      scanf - Read Data 
  1293.      sscanf - Read Data 
  1294.      swscanf - Read Wide Characters from Buffer 
  1295.  
  1296.  
  1297. ΓòÉΓòÉΓòÉ 3.3.1.2. printf Family ΓòÉΓòÉΓòÉ
  1298.  
  1299. The printf family of functions includes the functions printf, fprintf, sprintf, 
  1300. swprintf, vfprintf, vprintf, vsprintf, and vswprintf. These functions convert 
  1301. floating-point values of infinity and NaN to the strings "INFINITY" or 
  1302. "infinity" and "NAN" or "nan". 
  1303.  
  1304. The case is determined by the format specification, as is the sign (positive or 
  1305. negative). When converting these values, the printf functions ignore the 
  1306. precision width given by the format specification. 
  1307.  
  1308.  
  1309. ΓòÉΓòÉΓòÉ <hidden> Example of printf with Nan and Infinity Values ΓòÉΓòÉΓòÉ
  1310.  
  1311. /************************************************************************
  1312. *
  1313.  
  1314. In the following example, printf converts the NaN and infinity values and 
  1315. prints out the corresponding string. 
  1316.  
  1317.                                                                         *
  1318. ************************************************************************/
  1319.  
  1320. #include <stdio.h>
  1321. #include <float.h>
  1322.  
  1323. int main(void)
  1324. {
  1325.    double infval = -(_INF);
  1326.    float nanval = _NANF;
  1327.  
  1328.    printf("-_INF is the same as %-15.30f\n", infval);
  1329.    printf("_NANF is the same as %-15.30F\n", nanval);
  1330.  
  1331.    return 0;
  1332.  
  1333.    /* The expected output is:
  1334.  
  1335.       -_INF is the same as -infinity
  1336.       _NANF is the same as NAN        */
  1337.  
  1338. }
  1339.  
  1340.  
  1341. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1342.  
  1343. Example 
  1344.  
  1345.      Infinity and NaN Support 
  1346.      fprintf - Write Formatted Data to a Stream 
  1347.      printf - Print Formatted Characters 
  1348.      sprintf - Print Formatted Data to Buffer 
  1349.      swprintf - Format and Write Wide Characters to Buffer 
  1350.      vfprintf - Print Argument Data to Stream 
  1351.      vprintf - Print Argument Data 
  1352.      vsprintf - Print Argument Data to Buffer 
  1353.      vswprintf - Format and Write Wide Characters to Buffer 
  1354.  
  1355.  
  1356. ΓòÉΓòÉΓòÉ 3.3.1.3. String Conversion Functions ΓòÉΓòÉΓòÉ
  1357.  
  1358. The string conversion functions that support infinity and NaN representations 
  1359. include the functions atof, _atold, _ecvt, _fcvt, _gcvt, strtod, strtold, and 
  1360. wcstod. 
  1361.  
  1362. The atof, _atold, strtod, strtold, and wcstod functions accept the strings 
  1363. INFINITY, INF, and NAN (in upper-, lower-, or mixed case) as input, and convert 
  1364. these strings to the corresponding macro value defined in <float.h>. The _ecvt, 
  1365. _fcvt, and _gcvt functions convert infinity and NaN values to the strings 
  1366. INFINITY and NAN, respectively. 
  1367.  
  1368. Note:  If a signalling NaN string is passed to a string conversion function, a 
  1369. quiet NaN value is returned, and no signal is raised. 
  1370.  
  1371.  
  1372. ΓòÉΓòÉΓòÉ <hidden> Example of atof with NaN and Infinity Values ΓòÉΓòÉΓòÉ
  1373.  
  1374. /************************************************************************
  1375. *
  1376.  
  1377. The following example uses atof to convert the strings "naN" and "inf" to the 
  1378. corresponding macro value. 
  1379.  
  1380.                                                                         *
  1381. ************************************************************************/
  1382.  
  1383. #include <stdlib.h>
  1384. #include <stdio.h>
  1385.  
  1386. int main(void)
  1387. {
  1388.    char *nanstr;
  1389.    char *infstr;
  1390.  
  1391.    nanstr = "naN";
  1392.    printf( "Result of atof = %.10e\n", atof(nanstr) );
  1393.  
  1394.    infstr = "inf";
  1395.    printf( "Result of atof = %.10E\n", atof(infstr) );
  1396.  
  1397.    return 0;
  1398.  
  1399.    /* The expected output is:
  1400.  
  1401.       Result of atof = nan
  1402.       Result of atof = INFINITY  */
  1403.  
  1404. }
  1405.  
  1406.  
  1407. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1408.  
  1409. Example 
  1410.  
  1411.      Infinity and NaN Support 
  1412.      atof - Convert Character String to Float 
  1413.      _atold - Convert Character String to Long Double 
  1414.      _ecvt - Convert Floating-Point to Character 
  1415.      _fcvt - Convert Floating-Point to String 
  1416.      _gcvt - Convert Floating-Point to String 
  1417.      strtod - Convert Character String to Double 
  1418.      strtold - Convert String to Long Double 
  1419.  
  1420.  
  1421. ΓòÉΓòÉΓòÉ 3.3.1.4. Math Functions ΓòÉΓòÉΓòÉ
  1422.  
  1423. Most math functions accept infinity, negative infinity, and NaN values as 
  1424. input. (For information on those functions that do not accept these values, see 
  1425. Math Functions without Infinity and NaN Support.) In general, a NaN value as 
  1426. input results in a NaN value as output, and infinity values as input usually 
  1427. result in infinity values. If the input value is outside the domain or range of 
  1428. the function, errno is set to EDOM or ERANGE, respectively. 
  1429.  
  1430. The following tables display the results of each math function when NaN or 
  1431. infinity values are input, and the associated errno value if one exists. The 
  1432. first table lists the functions that take only one argument; the second lists 
  1433. those that take two arguments. 
  1434.  
  1435. Note:  In some cases, infinity is always a valid input value for the function 
  1436. regardless of the language level (for example, atan). These cases do not appear 
  1437. in these two tables. 
  1438.  
  1439. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  1440. Γöé Table 1. NaN and Infinity Values in Math Functions              Γöé
  1441. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1442. Γöé FUNCTION      Γöé INPUT       Γöé RESULT       Γöé "ERRNO" VALUE   Γöé
  1443. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1444. Γöé "         Γöé NaN        Γöé NaN "       Γöé          Γöé
  1445. Γöé acos        Γöé infinity      Γöé 0         Γöé EDOM       Γöé
  1446. Γöé asin "       Γöé -infinity     Γöé 0 "        Γöé EDOM       Γöé
  1447. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1448. Γöé "atan"       Γöé NaN        Γöé NaN        Γöé          Γöé
  1449. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1450. Γöé "         Γöé NaN        Γöé NaN        Γöé          Γöé
  1451. Γöé ceil        Γöé infinity      Γöé infinity      Γöé          Γöé
  1452. Γöé floor "      Γöé -infinity     Γöé -infinity     Γöé          Γöé
  1453. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1454. Γöé "         Γöé NaN        Γöé NaN        Γöé EDOM       Γöé
  1455. Γöé cos        Γöé infinity      Γöé NaN        Γöé ERANGE      Γöé
  1456. Γöé tan "       Γöé -infinity     Γöé NaN        Γöé ERANGE      Γöé
  1457. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1458. Γöé "cosh"       Γöé NaN        Γöé NaN        Γöé          Γöé
  1459. Γöé          Γöé infinity      Γöé infinity      Γöé ERANGE      Γöé
  1460. Γöé          Γöé -infinity     Γöé infinity      Γöé ERANGE      Γöé
  1461. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1462. Γöé "erf"       Γöé NaN        Γöé NaN "       Γöé EDOM       Γöé
  1463. Γöé          Γöé infinity      Γöé 1         Γöé          Γöé
  1464. Γöé          Γöé -infinity     Γöé -1 "        Γöé          Γöé
  1465. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1466. Γöé "erfc"       Γöé NaN        Γöé NaN "       Γöé EDOM       Γöé
  1467. Γöé          Γöé infinity      Γöé 0         Γöé          Γöé
  1468. Γöé          Γöé -infinity     Γöé 2 "        Γöé          Γöé
  1469. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1470. Γöé "exp"       Γöé NaN        Γöé NaN        Γöé          Γöé
  1471. Γöé          Γöé infinity      Γöé infinity "     Γöé ERANGE      Γöé
  1472. Γöé          Γöé -infinity     Γöé 0 "        Γöé ERANGE      Γöé
  1473. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1474. Γöé "fabs"       Γöé NaN        Γöé NaN        Γöé          Γöé
  1475. Γöé          Γöé infinity      Γöé infinity      Γöé          Γöé
  1476. Γöé          Γöé -infinity     Γöé infinity      Γöé          Γöé
  1477. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1478. Γöé "frexp"      Γöé NaN        Γöé NaN, "0"      Γöé EDOM       Γöé
  1479. Γöé          Γöé infinity      Γöé NaN, "0"      Γöé EDOM       Γöé
  1480. Γöé          Γöé -infinity     Γöé NaN, "0"      Γöé EDOM       Γöé
  1481. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1482. Γöé "gamma"      Γöé NaN        Γöé NaN        Γöé EDOM       Γöé
  1483. Γöé          Γöé infinity      Γöé infinity      Γöé ERANGE      Γöé
  1484. Γöé          Γöé -infinity     Γöé NaN        Γöé EDOM       Γöé
  1485. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1486. Γöé "         Γöé NaN        Γöé NaN        Γöé          Γöé
  1487. Γöé log        Γöé infinity "     Γöé infinity      Γöé          Γöé
  1488. Γöé log10 "      Γöé 0         Γöé -infinity     Γöé ERANGE      Γöé
  1489. Γöé          Γöé <0 "        Γöé NaN        Γöé EDOM       Γöé
  1490. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1491. Γöé "modf"       Γöé NaN        Γöé NaN, NaN      Γöé EDOM       Γöé
  1492. Γöé          Γöé infinity      Γöé NaN, infinity   Γöé EDOM       Γöé
  1493. Γöé          Γöé -infinity     Γöé NaN, -infinity   Γöé EDOM       Γöé
  1494. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1495. Γöé "sin"       Γöé NaN        Γöé NaN        Γöé EDOM       Γöé
  1496. Γöé          Γöé infinity      Γöé NaN        Γöé ERANGE      Γöé
  1497. Γöé          Γöé -infinity     Γöé NaN        Γöé ERANGE      Γöé
  1498. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1499. Γöé "sinh"       Γöé NaN        Γöé NaN        Γöé EDOM       Γöé
  1500. Γöé          Γöé infinity      Γöé infinity      Γöé ERANGE      Γöé
  1501. Γöé          Γöé -infinity     Γöé -infinity     Γöé ERANGE      Γöé
  1502. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1503. Γöé "sqrt"       Γöé NaN        Γöé NaN        Γöé          Γöé
  1504. Γöé          Γöé infinity      Γöé infinity "     Γöé          Γöé
  1505. Γöé          Γöé -infinity     Γöé 0 "        Γöé EDOM       Γöé
  1506. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1507. Γöé "tanh"       Γöé NaN        Γöé NaN "       Γöé EDOM       Γöé
  1508. Γöé          Γöé infinity      Γöé 1         Γöé          Γöé
  1509. Γöé          Γöé -infinity     Γöé -1 "        Γöé          Γöé
  1510. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  1511.  
  1512. The functions in the following table take two arguments. The results from NaN 
  1513. and infinity values vary depending on which argument they are passed as. 
  1514.  
  1515. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  1516. Γöé Table 2. Infinity and NaN Values in Math Functions              Γöé
  1517. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1518. Γöé FUNCTION    Γöé ARGUMENT 1   Γöé ARGUMENT 2   Γöé RESULT     Γöé "ERRNO"    Γöé
  1519. Γöé        Γöé        Γöé        Γöé        Γöé VALUE     Γöé
  1520. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1521. Γöé "atan2"    Γöé NaN      Γöé any number   Γöé NaN      Γöé EDOM     Γöé
  1522. Γöé        Γöé any number   Γöé NaN      Γöé NaN      Γöé        Γöé
  1523. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1524. Γöé "fmod"     Γöé NaN      Γöé any number   Γöé NaN      Γöé EDOM     Γöé
  1525. Γöé        Γöé any number   Γöé NaN      Γöé NaN      Γöé EDOM     Γöé
  1526. Γöé        Γöé ╤æinfinity   Γöé any number   Γöé 0       Γöé EDOM     Γöé
  1527. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1528. Γöé "ldexp"    Γöé infinity    Γöé any number   Γöé infinity    Γöé ERANGE    Γöé
  1529. Γöé        Γöé -infinity   Γöé any number   Γöé -infinity   Γöé ERANGE    Γöé
  1530. Γöé        Γöé NaN      Γöé any number   Γöé NaN      Γöé EDOM     Γöé
  1531. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1532. Γöé "pow"     Γöé ╤æinfinity   Γöé "0"      Γöé NaN      Γöé EDOM     Γöé
  1533. Γöé        Γöé infinity    Γöé -infinity   Γöé NaN      Γöé EDOM     Γöé
  1534. Γöé        Γöé -infinity   Γöé ╤æinfinity   Γöé NaN      Γöé EDOM     Γöé
  1535. Γöé        Γöé -infinity   Γöé <-1      Γöé NaN      Γöé EDOM     Γöé
  1536. Γöé        Γöé -infinity   Γöé <1, >-1    Γöé NaN      Γöé EDOM     Γöé
  1537. Γöé        Γöé -infinity   Γöé >1       Γöé NaN      Γöé EDOM     Γöé
  1538. Γöé        Γöé NaN      Γöé any number   Γöé NaN      Γöé EDOM     Γöé
  1539. Γöé        Γöé any number   Γöé NaN      Γöé NaN      Γöé EDOM     Γöé
  1540. Γöé        Γöé <=0      Γöé infinity    Γöé NaN      Γöé EDOM     Γöé
  1541. Γöé        Γöé 1       Γöé ╤æinfinity   Γöé NaN      Γöé EDOM     Γöé
  1542. Γöé        Γöé ╤æinfinity   Γöé ╤æ1       Γöé 0       Γöé ERANGE    Γöé
  1543. Γöé        Γöé >0, <1     Γöé infinity    Γöé 0       Γöé ERANGE    Γöé
  1544. Γöé        Γöé >0, <1     Γöé -infinity   Γöé infinity    Γöé ERANGE    Γöé
  1545. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  1546.  
  1547. Note:  If a signalling NaN is passed to a math function, the behavior is 
  1548.        undefined. 
  1549.  
  1550.  
  1551. ΓòÉΓòÉΓòÉ 3.3.1.5. Math Functions without Infinity and NaN Support ΓòÉΓòÉΓòÉ
  1552.  
  1553. The following floating-point unit functions are not supported for use with 
  1554. infinity or NaN values. In general, a NaN or infinity value as input for these 
  1555. functions results in an undefined value, an invalid operation exception, or 
  1556. both. These functions do not set errno. 
  1557.  
  1558.  _facos      _fasin 
  1559.  _fcos       _fcossin 
  1560.  _fpatan     _fptan 
  1561.  _fsin       _fsincos 
  1562.  _fsqrt      _fyl2x 
  1563.  _fyl2xp1    _f2xm1 
  1564.  
  1565.  Note:  If you expect the return value of a math function to be infinity or 
  1566.  NaN, you should use the functions that are supported for these values. The 
  1567.  advantage in using the floating-point unit math functions is a reduction in 
  1568.  the processing time and in the size of your executable file. 
  1569.  
  1570.  
  1571. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1572.  
  1573.      Infinity and NaN Support 
  1574.      <math.h> 
  1575.      acos - Calculate Arccosine 
  1576.      asin - Calculate Arcsine 
  1577.      atan - atan2 - Calculate Arctangent 
  1578.      ceil - Find Integer >= Argument 
  1579.      cos - Calculate Cosine 
  1580.      cosh - Calculate Hyperbolic Cosine 
  1581.      erf - erfc - Calculate Error Functions 
  1582.      exp - Calculate Exponential Function 
  1583.      fabs - Calculate Floating-Point Absolute Value 
  1584.      floor - Integer <= Argument 
  1585.      fmod - Calculate Floating-Point Remainder 
  1586.      frexp - Separate Floating-Point Value 
  1587.      gamma - Gamma Function 
  1588.      ldexp - Multiply by a Power of Two 
  1589.      log - Calculate Natural Logarithm 
  1590.      log10 - Calculate Base 10 Logarithm 
  1591.      modf - Separate Floating-Point Value 
  1592.      pow - Compute Power 
  1593.      sin - Calculate Sine 
  1594.      sinh - Calculate Hyperbolic Sine 
  1595.      sqrt - Calculate Square Root 
  1596.      tan - Calculate Tangent 
  1597.      tanh - Calculate Hyperbolic Tangent 
  1598.  
  1599.  
  1600. ΓòÉΓòÉΓòÉ 3.4. Using Low-Level I/O Functions ΓòÉΓòÉΓòÉ
  1601.  
  1602. The VisualAge for C++ compiler supports both stream and low-level I/O. The 
  1603. primary difference between the two types of I/O is that low-level I/O leaves 
  1604. the responsibility of buffering and formatting up to you. 
  1605.  
  1606. In general, you should not mix input or output from low-level I/O with that 
  1607. from stream I/O. The only way to communicate between stream I/O and low-level 
  1608. I/O is by using the fdopen or fileno functions. 
  1609.  
  1610. The low-level I/O functions include: 
  1611.  
  1612.  access         fstat 
  1613.  chmod          isatty 
  1614.  _chsize        lseek 
  1615.  close          open 
  1616.  creat          read 
  1617.  dup            _setmode 
  1618.  dup2           _sopen 
  1619.  __eof          stat 
  1620.  fdopen         _tell 
  1621.  _filelength    umask 
  1622.  fileno         write 
  1623.  
  1624.  When you use the low-level I/O functions, you should be aware of the 
  1625.  following: 
  1626.  
  1627.      A handle is a value that identifies a file.  It is created by the system 
  1628.       and used by low-level I/O functions. For VisualAge for C++, the handle 
  1629.       returned by low-level I/O functions like open (called the C_handle) is 
  1630.       the same as that returned by CreateFile (called the API_handle). As a 
  1631.       result, you can get a file handle using the low-level I/O functions, and 
  1632.       then use it with Win32 APIs. 
  1633.  
  1634.       Portability Note  Other compilers may map the file handle so that the 
  1635.       C_handle and API_handle are different.  If you will be compiling your 
  1636.       programs with other compilers, do not write code that depends on the file 
  1637.       handles being the same. 
  1638.  
  1639.       You can pass handles between library environments without restriction. If 
  1640.       you acquire a handle other than by using the VisualAge for C++ library 
  1641.       functions open, creat, _sopen, or fileno, you must run _setmode for that 
  1642.       handle before you use it with other VisualAge for C++ library functions. 
  1643.  
  1644.      The default open-sharing mode is SH_DENYWR. Use _sopen to obtain other 
  1645.       sharing modes. 
  1646.  
  1647.      Text mode deletes '\r' characters on input and changes '\n' to '\r\n' on 
  1648.       output. 
  1649.  
  1650.      In a multithread environment, you must ensure that two threads do not 
  1651.       attempt to perform low-level I/O operations on the same file at the same 
  1652.       time. You must make sure that one I/O process is completed before another 
  1653.       begins. 
  1654.  
  1655.      If the file mode is text, the low-level I/O functions treat the character 
  1656.       'x1a' in the following ways: 
  1657.  
  1658.         -  If it is detected in a nonseekable file, 'x1a' is treated as 
  1659.            end-of-file. In a seekable file, it is treated as end-of-file only 
  1660.            if it is the last character. 
  1661.         -  If a file is opened as text with either the O_APPEND or O_RDWR flags 
  1662.            and 'x1a' is the last character of the file, the last character of 
  1663.            the file is deleted. 
  1664.  
  1665.  
  1666. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1667.  
  1668.      Low-Level Input/Output Functions 
  1669.      Performing I/O Operations in the Programming Guide 
  1670.      access - Determine Access Mode 
  1671.      chmod - Change File Permission Setting 
  1672.      _chsize - Alter Length of File 
  1673.      close - Close File Associated with Handle 
  1674.      creat - Create New File 
  1675.      dup - Associate Second Handle with Open File 
  1676.      dup2 - Associate Second Handle with Open File 
  1677.      __eof - Determine End of File 
  1678.      fdopen - Associates Input Or Output With File 
  1679.      _filelength - Determine File Length 
  1680.      fileno - Determine File Handle 
  1681.      fstat - Information about Open File 
  1682.      isatty - Test Handle for Character Device 
  1683.      lseek - Move File Pointer 
  1684.      open - Open File 
  1685.      read - Read Into Buffer 
  1686.      _setmode - Set File Translation Mode 
  1687.      _sopen - Open Shared File 
  1688.      stat - Get Information about File or Directory 
  1689.      _tell - Get Pointer Position 
  1690.      umask - Sets File Mask of Current Process 
  1691.      write - Writes from Buffer to File 
  1692.  
  1693.  
  1694. ΓòÉΓòÉΓòÉ 4. Library Functions ΓòÉΓòÉΓòÉ
  1695.  
  1696. The VisualAge for C++ libraries are divided into two parts: 
  1697.  
  1698.      Standard libraries, which define the SAA features and the VisualAge for 
  1699.       C++ standard extensions to SAA 
  1700.  
  1701.      Subsystem libraries, which are a subset of the standard libraries, and 
  1702.       are used for subsystem development. The functions in these libraries do 
  1703.       not require a runtime environment. 
  1704.  
  1705.  This section lists alphabetically and describes all the functions that the 
  1706.  VisualAge for C++ product offers, including the extensions to the ANSI/ISO C 
  1707.  definition. For information on the subsystem libraries and the functions in 
  1708.  them, see the chapter called "Developing Subsystems" in the Programming Guide. 
  1709.  
  1710.  Each function description includes the following subsections: 
  1711.  
  1712.  Format 
  1713.        The prototyped declaration of the function and the header file in which 
  1714.        it is found. To include the declaration in your code, include the header 
  1715.        file. 
  1716.  
  1717.  Description 
  1718.        A brief description of what the function does, what parameters it takes, 
  1719.        and how to use the function. 
  1720.  
  1721.  Language Level 
  1722.        The C language standard that each function belongs to (some fall under 
  1723.        more than one): 
  1724.  
  1725.        ANSI           ANSI/ISO 9899-1990[1992] C standard (commonly referred to 
  1726.                       as the ANSI C standard or ANSI/ISO C standard). 
  1727.        ANSI 93        A subset of the ISO/IEC 9899:1990/Amendment 1:1993(E). 
  1728.        POSIX          ISO/IEC 9945-1:1990/IEEE POSIX 1003.1-1990 standard. 
  1729.        XPG4           X/Open Common Applications Environment Specification, 
  1730.                       System Interfaces and Headers, Issue 4. 
  1731.        SAA            IBM Systems Application Architecture Common Programming 
  1732.                       Interface (SAA CPI) Level 2 definition. 
  1733.        Extension      Extensions to the conventional standards, often specific 
  1734.                       to VisualAge for C++.  (These include standard functions 
  1735.                       that have additional features under VisualAge for C++.) 
  1736.  
  1737.                       Note:  To use the library extensions, you must set the 
  1738.                       language level to extended (with the #pragma 
  1739.                       langlvl(extended) directive or the /Se option); note that 
  1740.                       this is the default. 
  1741.  
  1742.  Example 
  1743.        A short example of how to use the function. From the online C Library 
  1744.        Reference, you can use the IPF Copy to File choice from the Services 
  1745.        pull-down to copy a function example to a separate file (called TEXT.TMP 
  1746.        by default). You can then compile, link, and run the example, or use the 
  1747.        example code in your own source files. 
  1748.  
  1749.  Related Information 
  1750.        A list of other functions that are similar to or related to the 
  1751.        function, and of other topics that provide additional information that 
  1752.        help you use the function. 
  1753.  
  1754.  
  1755. ΓòÉΓòÉΓòÉ 4.1. abort - Stop a Program ΓòÉΓòÉΓòÉ
  1756.  
  1757.  
  1758. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  1759.  
  1760. #include <stdlib.h>
  1761. void abort(void);
  1762.  
  1763.  
  1764. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  1765.  
  1766. Language Level:  ANSI, SAA, POSIX, XPG4, Extension 
  1767.  
  1768. abort causes an abnormal program termination and returns control to the host 
  1769. environment. It is similar to exit, except that abort does not flush buffers 
  1770. and close open files before ending the program. Calls to abort raise the 
  1771. SIGABRT signal. 
  1772.  
  1773. Return Value 
  1774. There is no return value. 
  1775.  
  1776.  
  1777. ΓòÉΓòÉΓòÉ <hidden> Example of abort ΓòÉΓòÉΓòÉ
  1778.  
  1779. /************************************************************************
  1780.  
  1781. This example tests for successful opening of the file myfile.mjq. If an error 
  1782. occurs, an error message is printed and the program ends with a call to abort. 
  1783.  
  1784. ************************************************************************/
  1785.  
  1786. #include <stdio.h>
  1787. #include <stdlib.h>
  1788.  
  1789. int main(void)
  1790. {
  1791.    FILE *stream;
  1792.  
  1793.    if (NULL == (stream = fopen("myfile.mjq", "r"))) {
  1794.       perror("Could not open data file");
  1795.       abort();
  1796.    }
  1797.    return 0;
  1798.  
  1799.    /****************************************************************************
  1800.       If myfile.mjq doesn't exist, the output should be:
  1801.  
  1802.       Could not open data file: The file cannot be found.
  1803.    ****************************************************************************/
  1804. }
  1805.  
  1806.  
  1807. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1808.  
  1809. Example of abort 
  1810.  
  1811.      exit - End Program 
  1812.      _exit - End Process 
  1813.      signal - Handle Interrupt Signals 
  1814.      <stdlib.h> 
  1815.  
  1816.  
  1817. ΓòÉΓòÉΓòÉ 4.2. abs - Calculate Integer Absolute Value ΓòÉΓòÉΓòÉ
  1818.  
  1819.  
  1820. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  1821.  
  1822. #include <stdlib.h>
  1823. int abs(int n);
  1824.  
  1825.  
  1826. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  1827.  
  1828. Language Level:  ANSI, SAA, POSIX, XPG4, Extension 
  1829.  
  1830. abs returns the absolute value of an integer argument n. 
  1831.  
  1832. Return Value 
  1833. There is no error return value.  The result is undefined when the absolute 
  1834. value of the argument cannot be represented as an integer. The value of the 
  1835. minimum allowable integer is defined by -INT_MAX in the <limits.h> include 
  1836. file. 
  1837.  
  1838.  
  1839. ΓòÉΓòÉΓòÉ <hidden> Example of abs ΓòÉΓòÉΓòÉ
  1840.  
  1841. /************************************************************************
  1842.  
  1843. This example calculates the absolute value of an integer x and assigns it to y. 
  1844.  
  1845. ************************************************************************/
  1846.  
  1847. #include <stdio.h>
  1848. #include <stdlib.h>
  1849.  
  1850. int main(void)
  1851. {
  1852.    int x = -4,y;
  1853.  
  1854.    y = abs(x);                                            /* y = 4            */
  1855.    printf("abs( %d ) = %d\n", x, y);
  1856.    return 0;
  1857.  
  1858.    /****************************************************************************
  1859.       The output should be:
  1860.  
  1861.       abs( -4 ) = 4
  1862.    ****************************************************************************/
  1863. }
  1864.  
  1865.  
  1866. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1867.  
  1868. Example of abs 
  1869.  
  1870.      _cabs - Calculate Absolute Value of Complex Number 
  1871.      fabs - Calculate Floating-Point Absolute Value 
  1872.      labs - Calculate Absolute Value of Long Integer 
  1873.      <limits.h> 
  1874.      <stdlib.h> 
  1875.  
  1876.  
  1877. ΓòÉΓòÉΓòÉ 4.3. access - Determine Access Mode ΓòÉΓòÉΓòÉ
  1878.  
  1879.  
  1880. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  1881.  
  1882. #include <io.h>
  1883. int access(char *pathname, int mode);
  1884.  
  1885.  
  1886. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  1887.  
  1888. Language Level:  POSIX, XPG4, Extension 
  1889.  
  1890. access determines whether the specified file exists and whether you can get 
  1891. access to it in the given mode. Possible values for the mode and their meaning 
  1892. in the access call are: 
  1893.  
  1894.  Value    Meaning 
  1895.   06      Check for permission to read from and write to the file. 
  1896.   04      Check for permission to read from the file. 
  1897.   02      Check for permission to write to the file. 
  1898.   00      Check only for the existence of the file. 
  1899.  
  1900.  Note:  In earlier releases of VisualAge C++, access began with an underscore 
  1901.  (_access). Because it is defined by the X/Open standard, the underscore has 
  1902.  been removed. For compatibility, VisualAge for C++ will map _access to access 
  1903.  for you. 
  1904.  
  1905.  Return Value 
  1906.  access returns 0 if you can get access to the file in the specified mode. A 
  1907.  return value of -1 shows that the file does not exist or is inaccessible in 
  1908.  the given mode, and the system sets errno to one of the following values: 
  1909.  
  1910.  Value          Meaning 
  1911.  EACCESS        Access is denied; the permission setting of the file does not 
  1912.                 allow you to get access to the file in the specified mode. 
  1913.  ENOENT         The system cannot find the file or the path that you specified, 
  1914.                 or the file name was incorrect. 
  1915.  EINVAL         The mode specified was not valid. 
  1916.  EOS2ERR        The call to the operating system was not successful. 
  1917.  
  1918.  
  1919. ΓòÉΓòÉΓòÉ <hidden> Example of _access ΓòÉΓòÉΓòÉ
  1920.  
  1921. /************************************************************************
  1922.  
  1923. This example checks for the existence of the file sample.dat. If the file does 
  1924. not exist, it is created. 
  1925.  
  1926. ************************************************************************/
  1927.  
  1928. #include <io.h>
  1929. #include <stdio.h>
  1930. #include <stdlib.h>
  1931.  
  1932. int main(void)
  1933. {
  1934.    if (-1 == access("sample.dat", 00)) {
  1935.       printf("File sample.dat does not exist.\n");
  1936.       printf("Creating sample.dat.\n");
  1937.       system("echo Sample Program > sample.dat");
  1938.       if (0 == access("sample.dat", 00))
  1939.          printf("File sample.dat created.\n");
  1940.    }
  1941.    else
  1942.       printf("File sample.dat exists.\n");
  1943.    return 0;
  1944.  
  1945.    /****************************************************************************
  1946.       The output should be:
  1947.  
  1948.       File sample.dat does not exist.
  1949.       Creating sample.dat.
  1950.       File sample.dat created.
  1951.    ****************************************************************************/
  1952. }
  1953.  
  1954.  
  1955. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1956.  
  1957. Example of access 
  1958.  
  1959.      chmod - Change File Permission Setting 
  1960.      _sopen - Open Shared File 
  1961.      umask - Sets File Mask of Current Process 
  1962.      <io.h> 
  1963.  
  1964.  
  1965. ΓòÉΓòÉΓòÉ 4.4. acos - Calculate Arccosine ΓòÉΓòÉΓòÉ
  1966.  
  1967.  
  1968. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  1969.  
  1970. #include <math.h>
  1971. double acos(double x);
  1972.  
  1973.  
  1974. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  1975.  
  1976. Language Level:  ANSI, SAA, POSIX, XPG4 
  1977.  
  1978. acos calculates the arccosine of x, expressed in radians, in the range 0 to pi. 
  1979.  
  1980. Return Value 
  1981. acos returns the arccosine of x. The value of x must be between -1 and 1 
  1982. inclusive. If x is less than -1 or greater than 1, acos sets errno to EDOM and 
  1983. returns 0. 
  1984.  
  1985.  
  1986. ΓòÉΓòÉΓòÉ <hidden> Example of acos ΓòÉΓòÉΓòÉ
  1987.  
  1988. /************************************************************************
  1989.  
  1990. This example prompts for a value for x. It prints an error message if x is 
  1991. greater than 1 or less than -1; otherwise, it assigns the arccosine of x to y. 
  1992.  
  1993. ************************************************************************/
  1994.  
  1995. #include <stdio.h>
  1996. #include <stdlib.h>
  1997. #include <math.h>
  1998.  
  1999. #define  MAX           1.0
  2000. #define  MIN          -1.0
  2001.  
  2002. int main(void)
  2003. {
  2004.    double x,y;
  2005.  
  2006.    printf("Enter x\n");
  2007.    scanf("%lf", &x);
  2008.  
  2009.    /* Output error if not in range */
  2010.    if (x > MAX)
  2011.       printf("Error: %lf too large for acos\n", x);
  2012.    else
  2013.       if (x < MIN)
  2014.          printf("Error: %lf too small for acos\n", x);
  2015.       else {
  2016.          y = acos(x);
  2017.          printf("acos( %lf ) = %lf\n", x, y);
  2018.       }
  2019.    return 0;
  2020.  
  2021.    /****************************************************************************
  2022.       For the following input: 0.4
  2023.  
  2024.       The output should be:
  2025.  
  2026.       Enter x
  2027.       acos( 0.400000 ) = 1.159279
  2028.    ****************************************************************************/
  2029. }
  2030.  
  2031.  
  2032. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2033.  
  2034. Example of acos 
  2035.  
  2036.      asin - Calculate Arcsine 
  2037.      atan - atan2 - Calculate Arctangent 
  2038.      cos - Calculate Cosine 
  2039.      cosh - Calculate Hyperbolic Cosine 
  2040.      _facos - Calculate Arccosine 
  2041.      _fcos - Calculate Cosine 
  2042.      _fcossin - Calculate Cosine and Sine 
  2043.      _fsincos - Calculate Sine and Cosine 
  2044.      sin - Calculate Sine 
  2045.      sinh - Calculate Hyperbolic Sine 
  2046.      tan - Calculate Tangent 
  2047.      tanh - Calculate Hyperbolic Tangent 
  2048.      <math.h> 
  2049.  
  2050.  
  2051. ΓòÉΓòÉΓòÉ 4.5. _alloca - Temporarily Reserve Storage Block ΓòÉΓòÉΓòÉ
  2052.  
  2053.  
  2054. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2055.  
  2056. #include <stdlib.h>  /* also in <malloc.h> and <builtin.h> */
  2057. void *_alloca(size_t size);
  2058.  
  2059.  
  2060. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2061.  
  2062. Language Level:  Extension 
  2063.  
  2064. _alloca is a built-in function that temporarily allocates size bytes of storage 
  2065. space from the program's stack. The memory space is automatically freed when 
  2066. the function that called _alloca returns. 
  2067.  
  2068. Note:  _alloca is faster than other allocation functions such as malloc, but it 
  2069. has several limitations: 
  2070.  
  2071.      Because it is a built-in function, which means it is implemented as an 
  2072.       inline instruction and has no backing code in the library: 
  2073.         -  You cannot take the address of _alloca. 
  2074.         -  You cannot parenthesize a call to _alloca. (Parentheses specify a 
  2075.            call to the function's backing code, and _alloca has none). 
  2076.      Because _alloca automatically frees storage after the function that calls 
  2077.       it returns, you cannot pass the pointer value returned by _alloca as an 
  2078.       argument to the free function. 
  2079.  
  2080.  Because _alloca uses automatic storage, programs calling _alloca must not be 
  2081.  compiled using the /Gs+ switch. This switch disables stack probes and does not 
  2082.  guarantee that enough stack storage will be available. You should use the /Gs- 
  2083.  switch, which is the default setting. 
  2084.  
  2085.  Return Value 
  2086.  _alloca returns a pointer to the reserved space. If _alloca cannot reserve the 
  2087.  requested space, the program gets an out of stack exception. 
  2088.  
  2089.  
  2090. ΓòÉΓòÉΓòÉ <hidden> Example of _alloca ΓòÉΓòÉΓòÉ
  2091.  
  2092. /************************************************************************
  2093.  
  2094. This example uses srand to generate five random numbers.  The numbers determine 
  2095. how much space _alloca is to allocate for the array barstr.  The result is a 
  2096. ragged two-dimensional array of strings. 
  2097.  
  2098. ************************************************************************/
  2099.  
  2100. #include <stdio.h>
  2101. #include <stdlib.h>
  2102. #include <string.h>
  2103. #include <time.h>
  2104.  
  2105. int main(void)
  2106. {
  2107.    char *fullbar = "1 2 3 4 5";
  2108.    int range,rval;
  2109.    char *barstr[5];
  2110.    int i;
  2111.  
  2112.    printf("Bar representation of 5 random numbers ");
  2113.    printf("(each generated from 1 to 5):\n\n");
  2114.  
  2115.    /* set seed for rand function using time in seconds                        */
  2116.    srand((unsigned int)time(NULL));
  2117.  
  2118.    for (i = 0; i < 5; i++) {
  2119.       rval = (rand()+1)%5; /* generate random number from 0 to 4              */
  2120.  
  2121.       /* for partial copy of fullbar, allocate space on stack for barstr
  2122.          from 2 to 10 characters long + one space for a null character        */
  2123.  
  2124.       barstr[i] =(char *) _alloca((rval *sizeof(char) << 1)+3);
  2125.       memset(barstr[i], '\0', (rval *sizeof(char) << 1)+3);
  2126.  
  2127.       /* copy random sized portion of fullbar                                 */
  2128.  
  2129.       strncpy(barstr[i], fullbar, ((rval+1)*2));
  2130.       printf("%s\n", barstr[i]);             /* print random length bar       */
  2131.    }
  2132.    return 0;
  2133.  
  2134.    /****************************************************************************
  2135.       The output should be similar to :
  2136.  
  2137.         Bar representation of 5 random numbers (each generated from 1 to 5):
  2138.         1
  2139.         1 2 3 4
  2140.         1 2 3
  2141.         1 2 3 4 5
  2142.         1 2
  2143.    ****************************************************************************/
  2144. }
  2145.  
  2146.  
  2147. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2148.  
  2149. Example 
  2150.  
  2151.      calloc - Reserve and Initialize Storage 
  2152.      free - Release Storage Blocks 
  2153.      malloc - Reserve Storage Block 
  2154.      realloc - Change Reserved Storage Block Size 
  2155.      /Gs option in the User's Guide 
  2156.      <malloc.h> 
  2157.      <stdlib.h> 
  2158.  
  2159.  
  2160. ΓòÉΓòÉΓòÉ 4.6. asctime - Convert Time to Character String ΓòÉΓòÉΓòÉ
  2161.  
  2162.  
  2163. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2164.  
  2165. #include <time.h>
  2166. char *asctime(const struct tm *time);
  2167.  
  2168.  
  2169. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2170.  
  2171. Language Level:  ANSI, SAA, POSIX, XPG4 
  2172.  
  2173. The asctime function converts time, stored as a structure pointed to by time, 
  2174. to a character string. You can obtain the time value from a call to gmtime or 
  2175. localtime; either returns a pointer to a tm structure defined in <time.h>. See 
  2176. gmtime - Convert Time for a description of the tm structure fields. 
  2177.  
  2178. The string result that asctime produces contains exactly 26 characters and has 
  2179. the format: 
  2180.  
  2181.    "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n"
  2182.  
  2183. See printf - Print Formatted Characters for a description of format 
  2184. specifications. The following are examples of the string returned: 
  2185.  
  2186.    Sat Jul 16 02:03:55 1994\n\0
  2187. or
  2188.    Sat Jul 16  2:03:55 1994\n\0
  2189.  
  2190. The asctime function uses a 24-hour-clock format.  The days are abbreviated to: 
  2191. Sun, Mon, Tue, Wed, Thu, Fri, and Sat.  The months are abbreviated to: Jan, 
  2192. Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, and Dec. All fields have 
  2193. constant width. Dates with only one digit are preceded either with a zero or a 
  2194. blank space. The new-line character (\n) and the null character (\0) occupy the 
  2195. last two positions of the string. 
  2196.  
  2197. The time and date functions begin at 00:00:00 Universal Time, January 1, 1970. 
  2198.  
  2199. Return Value 
  2200. The asctime function returns a pointer to the resulting character string. 
  2201. There is no error return value. 
  2202.  
  2203. Note:  asctime, ctime, and other time functions may use a common, statically 
  2204. allocated buffer to hold the return string. Each call to one of these functions 
  2205. may destroy the result of the previous call. 
  2206.  
  2207.  
  2208. ΓòÉΓòÉΓòÉ <hidden> Example of asctime ΓòÉΓòÉΓòÉ
  2209.  
  2210. /************************************************************************
  2211.  
  2212. This example polls the system clock and prints a message giving the current 
  2213. time. 
  2214.  
  2215. ************************************************************************/
  2216.  
  2217. #include <time.h>
  2218. #include <stdio.h>
  2219.  
  2220. int main(void)
  2221. {
  2222.    struct tm *newtime;
  2223.    time_t ltime;
  2224.  
  2225.    /* Get the time in seconds */
  2226.    time(<ime);
  2227.  
  2228.    /* Convert it to the structure tm */
  2229.    newtime = localtime(<ime);
  2230.  
  2231.    /* Print the local time as a string */
  2232.    printf("The current date and time are %s", asctime(newtime));
  2233.    return 0;
  2234.  
  2235.    /****************************************************************************
  2236.       The output should be similar to :
  2237.  
  2238.       The current date and time are Fri Jun 28 13:51 1994
  2239.    ****************************************************************************/
  2240. }
  2241.  
  2242.  
  2243. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2244.  
  2245. Example of asctime 
  2246.  
  2247.      ctime - Convert Time to Character String 
  2248.      gmtime - Convert Time 
  2249.      localtime - Convert Time 
  2250.      mktime - Convert Local Time 
  2251.      strftime - Convert to Formatted Time 
  2252.      time - Determine Current Time 
  2253.      printf - Print Formatted Characters 
  2254.      <time.h> 
  2255.  
  2256.  
  2257. ΓòÉΓòÉΓòÉ 4.7. asin - Calculate Arcsine ΓòÉΓòÉΓòÉ
  2258.  
  2259.  
  2260. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2261.  
  2262. #include <math.h>
  2263. double asin(double x);
  2264.  
  2265.  
  2266. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2267.  
  2268. Language Level:  ANSI, SAA, POSIX, XPG4 
  2269.  
  2270. asin calculates the arcsine of x, in the range -pi/2 to pi/2 radians. 
  2271.  
  2272. Return Value 
  2273. asin returns the arcsine of x. The value of x must be between -1 and 1. If x is 
  2274. less than -1 or greater than 1, asin sets errno to EDOM, and returns a value of 
  2275. 0. 
  2276.  
  2277.  
  2278. ΓòÉΓòÉΓòÉ <hidden> Example of asin ΓòÉΓòÉΓòÉ
  2279.  
  2280. /************************************************************************
  2281.  
  2282. This example prompts for a value for x. It prints an error message if x is 
  2283. greater than 1 or less than -1; otherwise, it assigns the arcsine of x to y. 
  2284.  
  2285. ************************************************************************/
  2286.  
  2287. #include <stdio.h>
  2288. #include <stdlib.h>
  2289. #include <math.h>
  2290.  
  2291. #define  MAX           1.0
  2292. #define  MIN          -1.0
  2293.  
  2294. int main(void)
  2295. {
  2296.    double x,y;
  2297.  
  2298.    printf("Enter x\n");
  2299.    scanf("%lf", &x);
  2300.  
  2301.    /* Output error if not in range                                            */
  2302.  
  2303.    if (x > MAX)
  2304.       printf("Error: %lf too large for asin\n", x);
  2305.    else
  2306.       if (x < MIN)
  2307.  
  2308.          printf("Error: %lf too small for asin\n", x);
  2309.       else {
  2310.          y = asin(x);
  2311.          printf("asin( %lf ) = %lf\n", x, y);
  2312.       }
  2313.    return 0;
  2314.  
  2315.    /****************************************************************************
  2316.       For the following input: 0.2
  2317.  
  2318.       The output should be:
  2319.  
  2320.       Enter x
  2321.       asin( 0.200000 ) = 0.201358
  2322.    ****************************************************************************/
  2323. }
  2324.  
  2325.  
  2326. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2327.  
  2328. Example of asin 
  2329.  
  2330.      acos - Calculate Arccosine 
  2331.      atan - atan2 - Calculate Arctangent 
  2332.      cos - Calculate Cosine 
  2333.      cosh - Calculate Hyperbolic Cosine 
  2334.      _fasin - Calculate Arcsine 
  2335.      _fcossin - Calculate Cosine and Sine 
  2336.      _fsin - Calculate Sine 
  2337.      _fsincos - Calculate Sine and Cosine 
  2338.      sin - Calculate Sine 
  2339.      sinh - Calculate Hyperbolic Sine 
  2340.      tan - Calculate Tangent 
  2341.      tanh - Calculate Hyperbolic Tangent 
  2342.      <math.h> 
  2343.  
  2344.  
  2345. ΓòÉΓòÉΓòÉ 4.8. assert - Verify Condition ΓòÉΓòÉΓòÉ
  2346.  
  2347.  
  2348. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2349.  
  2350. #include <assert.h>
  2351. void assert(int expression);
  2352.  
  2353.  
  2354. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2355.  
  2356. Language Level:  ANSI, SAA, POSIX, XPG4 
  2357.  
  2358. assert prints a diagnostic message to stderr and aborts the program if 
  2359. expression is false (zero). The diagnostic message has the format: 
  2360.  
  2361. Assertion failed: expression, file filename, line line-number.
  2362.  
  2363. assert takes no action if the expression is true (nonzero). 
  2364.  
  2365. Use assert to identify program logic errors.  Choose an expression that holds 
  2366. true only if the program is operating as you intend.  After you have debugged 
  2367. the program, you can use the special no-debug identifier NDEBUG to remove the 
  2368. assert calls from the program.  If you define NDEBUG to any value with a 
  2369. #define directive, the C preprocessor expands all assert invocations to void 
  2370. expressions. If you use NDEBUG, you must define it before you include 
  2371. <assert.h> in the program. There is no return value. 
  2372.  
  2373. Note:  assert is implemented as a macro. Do not use the #undef directive with 
  2374. assert. 
  2375.  
  2376.  
  2377. ΓòÉΓòÉΓòÉ <hidden> Example of assert ΓòÉΓòÉΓòÉ
  2378.  
  2379. /************************************************************************
  2380.  
  2381. In this example, assert tests string for a null string and an empty string, and 
  2382. verifies that length is positive before processing these arguments. 
  2383.  
  2384. ************************************************************************/
  2385.  
  2386. #include <stdio.h>
  2387. #include <assert.h>
  2388.  
  2389. void analyze(char *string,int length)
  2390. {
  2391.    assert(string != NULL);                                /* cannot be NULL   */
  2392.    assert(*string != '\0');                               /* cannot be empty  */
  2393.    assert(length > 0);                                    /* must be positive */
  2394.    return;
  2395. }
  2396.  
  2397. int main(void)
  2398. {
  2399.    char *string = "ABC";
  2400.    int length = 3;
  2401.  
  2402.    analyze(string, length);
  2403.    printf("The string %s is not null or empty, and has length %d \n", string,
  2404.       length);
  2405.    return 0;
  2406.  
  2407.    /****************************************************************************
  2408.       The output should be:
  2409.  
  2410.       The string ABC is not null or empty, and has length 3
  2411.    ****************************************************************************/
  2412. }
  2413.  
  2414.  
  2415. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2416.  
  2417. Example of assert 
  2418.  
  2419.      abort - Stop a Program 
  2420.      <assert.h> 
  2421.      #define in the Language Reference 
  2422.      #undef in the Language Reference 
  2423.  
  2424.  
  2425. ΓòÉΓòÉΓòÉ 4.9. atan - atan2 - Calculate Arctangent ΓòÉΓòÉΓòÉ
  2426.  
  2427.  
  2428. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2429.  
  2430. #include <math.h>
  2431. double atan(double x);
  2432. double atan2(double y, double x);
  2433.  
  2434.  
  2435. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2436.  
  2437. Language Level:  ANSI, SAA, POSIX, XPG4 
  2438.  
  2439. atan and atan2 calculate the arctangent of x and y/x, respectively. 
  2440.  
  2441. Return Value 
  2442. atan returns a value in the range -pi/2 to pi/2 radians. atan2 returns a value 
  2443. in the range -pi to pi radians. If both arguments of atan2 are zero, the 
  2444. function sets errno to EDOM, and returns a value of 0. 
  2445.  
  2446.  
  2447. ΓòÉΓòÉΓòÉ <hidden> Example of atan - atan2 ΓòÉΓòÉΓòÉ
  2448.  
  2449. /************************************************************************
  2450.  
  2451. This example calculates arctangents using the atan and atan2 functions. 
  2452.  
  2453. ************************************************************************/
  2454.  
  2455. #include <stdio.h>
  2456. #include <math.h>
  2457.  
  2458. int main(void)
  2459. {
  2460.    double a,b,c,d;
  2461.  
  2462.    c = 0.45;
  2463.    d = 0.23;
  2464.    a = atan(c);
  2465.    b = atan2(c, d);
  2466.    printf("atan( %lf ) = %lf\n", c, a);
  2467.    printf("atan2( %lf, %lf ) = %lf\n", c, d, b);
  2468.    return 0;
  2469.  
  2470.    /****************************************************************************
  2471.       The output should be:
  2472.  
  2473.       atan( 0.450000 ) = 0.422854
  2474.       atan2( 0.450000, 0.230000 ) = 1.098299
  2475.    ****************************************************************************/
  2476. }
  2477.  
  2478.  
  2479. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2480.  
  2481. Example of atan - atan2 
  2482.  
  2483.      acos - Calculate Arccosine 
  2484.      asin - Calculate Arcsine 
  2485.      cos - Calculate Cosine 
  2486.      cosh - Calculate Hyperbolic Cosine 
  2487.      _fpatan - Calculate Arctangent 
  2488.      _fptan - Calculate Tangent 
  2489.      sin - Calculate Sine 
  2490.      sinh - Calculate Hyperbolic Sine 
  2491.      tan - Calculate Tangent 
  2492.      tanh - Calculate Hyperbolic Tangent 
  2493.      <math.h> 
  2494.  
  2495.  
  2496. ΓòÉΓòÉΓòÉ 4.10. atexit - Record Program Termination Function ΓòÉΓòÉΓòÉ
  2497.  
  2498.  
  2499. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2500.  
  2501. #include <stdlib.h>
  2502. int atexit(void (*func)(void));
  2503.  
  2504.  
  2505. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2506.  
  2507. Language Level:  ANSI, SAA, POSIX, XPG4 
  2508.  
  2509. atexit records a function, pointed to by func, that the system calls at normal 
  2510. program termination.  For portability, you should use atexit to register up to 
  2511. 32 functions only. The functions are executed in a last-in, first-out order. 
  2512.  
  2513. If your application has multiple run-time environments, only those functions 
  2514. that are registered in the environment to which the .exe file links are 
  2515. executed on termination. Assume, for example, that your application has an .exe 
  2516. and a .dll, each linking statically to the run-time (that is, compiled with 
  2517. default option -Gd-). Only those registered functions linked from the .exe file 
  2518. are executed on program termination. 
  2519.  
  2520. Return Value 
  2521. atexit returns 0 if it is successful, and nonzero if it fails. 
  2522.  
  2523.  
  2524. ΓòÉΓòÉΓòÉ <hidden> Example of atexit ΓòÉΓòÉΓòÉ
  2525.  
  2526. /************************************************************************
  2527.  
  2528. This example uses atexit to call the function goodbye at program termination. 
  2529.  
  2530. ************************************************************************/
  2531.  
  2532. #include <stdlib.h>
  2533. #include <stdio.h>
  2534.  
  2535. void _Optlink goodbye(void)
  2536. {
  2537.  
  2538.    /* This function is called at normal program termination                   */
  2539.  
  2540.    printf("The function goodbye was called at program termination\n");
  2541. }
  2542.  
  2543. int main(void)
  2544. {
  2545.    int rc;
  2546.  
  2547.    rc = atexit(goodbye);
  2548.    if (rc != 0)
  2549.       perror("Error in atexit");
  2550.    return 0;
  2551.  
  2552.    /****************************************************************************
  2553.       The output should be:
  2554.  
  2555.       The function goodbye was called at program termination
  2556.    ****************************************************************************/
  2557. }
  2558.  
  2559.  
  2560. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2561.  
  2562. Example of atexit 
  2563.  
  2564.      exit - End Program 
  2565.      _exit - End Process 
  2566.      _onexit - Record Termination Function 
  2567.      signal - Handle Interrupt Signals 
  2568.      <stdlib.h> 
  2569.  
  2570.  
  2571. ΓòÉΓòÉΓòÉ 4.11. atof - Convert Character String to Float ΓòÉΓòÉΓòÉ
  2572.  
  2573.  
  2574. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2575.  
  2576. #include <stdlib.h>
  2577. double atof(const char *string);
  2578.  
  2579.  
  2580. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2581.  
  2582. Language Level:  ANSI, SAA, POSIX, XPG4, Extension 
  2583.  
  2584. atof converts a character string to a double-precision floating-point value. 
  2585.  
  2586. The input string is a sequence of characters that can be interpreted as a 
  2587. numerical value of the specified return type.  The function stops reading the 
  2588. input string at the first character that it cannot recognize as part of a 
  2589. number;  this character can be the null character that ends the string. 
  2590.  
  2591. atof expects a string in the following form: 
  2592.  
  2593. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2594. Γöé                                        Γöé
  2595. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ>                             Γöé
  2596. Γöé   ΓööΓöÇwhitespaceΓöÇΓöÿ                              Γöé
  2597. Γöé                                        Γöé
  2598. Γöé >ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><  Γöé
  2599. Γöé   ΓööΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇdigitsΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÿ    Γöé
  2600. Γöé    Γö£ΓöÇ+ΓöÇΓöñ  Γöé     ΓööΓöÇ.ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ Γöé  ΓööΓöÇΓö¼ΓöÇeΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdigitsΓöÇΓöÿ     Γöé
  2601. Γöé    ΓööΓöÇΓö┤ΓöÇΓöÿ  Γöé        ΓööΓöÇdigitsΓöÇΓöÿ  Γöé   ΓööΓöÇEΓöÇΓöÿ  Γö£ΓöÇ+ΓöÇΓöñ          Γöé
  2602. Γöé        ΓööΓöÇ.ΓöÇΓöÇdigitsΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ      ΓööΓöÇΓö┤ΓöÇΓöÿ          Γöé
  2603. Γöé                                        Γöé
  2604. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2605.  
  2606. The white space consists of the same characters for which the isspace function 
  2607. is true, such as spaces and tabs. atof ignores leading white-space characters. 
  2608.  
  2609. For atof, digits is one or more decimal digits;  if no digits appear before the 
  2610. decimal point, at least one digit must appear after the decimal point.  The 
  2611. decimal digits can precede an exponent, introduced by the letter e or E.  The 
  2612. exponent is a decimal integer, which may be signed. The string can also be 
  2613. "infinity", "inf", or "nan". These strings are case insensitive, and can be 
  2614. preceded by a unary minus (-). They are converted to infinity and NaN values. 
  2615.  
  2616. Return Value 
  2617. atof returns a double value produced by interpreting the input characters as a 
  2618. number. The return value is 0 if the function cannot convert the input to a 
  2619. value of that type. The return value is undefined in case of overflow. 
  2620.  
  2621.  
  2622. ΓòÉΓòÉΓòÉ <hidden> Example of atof ΓòÉΓòÉΓòÉ
  2623.  
  2624. /************************************************************************
  2625.  
  2626. This example shows how to convert numbers stored as strings to numerical values 
  2627. using the atof function. 
  2628.  
  2629. ************************************************************************/
  2630.  
  2631. #include <stdio.h>
  2632. #include <stdlib.h>
  2633.  
  2634. int main(void)
  2635. {
  2636.    double x;
  2637.    char *s;
  2638.  
  2639.    s = " -2309.12E-15";
  2640.    x = atof(s);                                           /* x = -2309.12E-15 */
  2641.    printf("atof( %s ) = %G\n", s, x);
  2642.    return 0;
  2643.  
  2644.    /****************************************************************************
  2645.       The output should be:
  2646.  
  2647.       atof(  -2309.12E-15 ) = -2.30912E-12
  2648.    ****************************************************************************/
  2649. }
  2650.  
  2651.  
  2652. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2653.  
  2654. Example of atof 
  2655.  
  2656.      atoi - Convert Character String to Integer 
  2657.      atol - Convert Character String to Long Integer 
  2658.      _atold - Convert Character String to Long Double 
  2659.      strtod - Convert Character String to Double 
  2660.      strtol - Convert Character String to Long Integer 
  2661.      strtold - Convert String to Long Double 
  2662.      Infinity and NaN Support 
  2663.      <stdlib.h> 
  2664.  
  2665.  
  2666. ΓòÉΓòÉΓòÉ 4.12. atoi - Convert Character String to Integer ΓòÉΓòÉΓòÉ
  2667.  
  2668.  
  2669. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2670.  
  2671. #include <stdlib.h>
  2672. int atoi(const char *string);
  2673.  
  2674.  
  2675. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2676.  
  2677. Language Level:  ANSI, SAA, POSIX, XPG4 
  2678.  
  2679. atoi converts a character string to an integer value. 
  2680.  
  2681. The input string is a sequence of characters that can be interpreted as a 
  2682. numerical value of the specified return type.  The function stops reading the 
  2683. input string at the first character that it cannot recognize as part of a 
  2684. number;  this character can be the null character that ends the string. 
  2685.  
  2686. atoi does not recognize decimal points nor exponents. The string argument for 
  2687. this function has the form: 
  2688.  
  2689. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2690. Γöé                                        Γöé
  2691. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdigitsΓöÇΓöÇ><                     Γöé
  2692. Γöé   ΓööΓöÇwhitespaceΓöÇΓöÿ  Γö£ΓöÇ+ΓöÇΓöñ                           Γöé
  2693. Γöé           ΓööΓöÇΓö┤ΓöÇΓöÿ                           Γöé
  2694. Γöé                                        Γöé
  2695. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2696.  
  2697. where whitespace consists of the same characters for which the isspace function 
  2698. is true, such as spaces and tabs. atoi ignores leading white-space characters. 
  2699. digits is one or more decimal digits. 
  2700.  
  2701. Return Value 
  2702. atoi returns an int value produced by interpreting the input characters as a 
  2703. number.  The return value is 0 if the function cannot convert the input to a 
  2704. value of that type.  The return value is undefined in the case of an overflow. 
  2705.  
  2706.  
  2707. ΓòÉΓòÉΓòÉ <hidden> Example of atoi ΓòÉΓòÉΓòÉ
  2708.  
  2709. /************************************************************************
  2710.  
  2711. This example shows how to convert numbers stored as strings to numerical values 
  2712. using the atoi function. 
  2713.  
  2714. ************************************************************************/
  2715.  
  2716. #include <stdio.h>
  2717. #include <stdlib.h>
  2718.  
  2719. int main(void)
  2720. {
  2721.    int i;
  2722.    char *s;
  2723.  
  2724.    s = " -9885";
  2725.    i = atoi(s);                                           /* i = -9885        */
  2726.    printf("atoi(\"%s\") = %d\n", s, i);
  2727.    return 0;
  2728.  
  2729.    /****************************************************************************
  2730.       The output should be:
  2731.  
  2732.       atoi(" -9885") = -9885
  2733.    ****************************************************************************/
  2734. }
  2735.  
  2736.  
  2737. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2738.  
  2739. Example of atoi 
  2740.  
  2741.      atof - Convert Character String to Float 
  2742.      atol - Convert Character String to Long Integer 
  2743.      _atold - Convert Character String to Long Double 
  2744.      strtod - Convert Character String to Double 
  2745.      strtol - Convert Character String to Long Integer 
  2746.      strtold - Convert String to Long Double 
  2747.      <stdlib.h> 
  2748.  
  2749.  
  2750. ΓòÉΓòÉΓòÉ 4.13. atol - Convert Character String to Long Integer ΓòÉΓòÉΓòÉ
  2751.  
  2752.  
  2753. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2754.  
  2755. #include <stdlib.h>
  2756. long int atol(const char *string);
  2757.  
  2758.  
  2759. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2760.  
  2761. Language Level:  ANSI, SAA, POSIX, XPG4 
  2762.  
  2763. atol converts a character string to a long value. 
  2764.  
  2765. The input string is a sequence of characters that can be interpreted as a 
  2766. numerical value of the specified return type.  The function stops reading the 
  2767. input string at the first character that it cannot recognize as part of a 
  2768. number; this character can be the null character that ends the string. 
  2769.  
  2770. atol does not recognize decimal points nor exponents.  The string argument for 
  2771. this function has the form: 
  2772.  
  2773. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2774. Γöé                                        Γöé
  2775. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdigitsΓöÇΓöÇ><                     Γöé
  2776. Γöé   ΓööΓöÇwhitespaceΓöÇΓöÿ  Γö£ΓöÇ+ΓöÇΓöñ                           Γöé
  2777. Γöé           ΓööΓöÇΓö┤ΓöÇΓöÿ                           Γöé
  2778. Γöé                                        Γöé
  2779. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2780.  
  2781. where whitespace consists of the same characters for which the isspace function 
  2782. is true, such as spaces and tabs. atol ignores leading white-space characters. 
  2783. digits is one or more decimal digits. 
  2784.  
  2785. Return Value 
  2786. atol returns a long value produced by interpreting the input characters as a 
  2787. number.  The return value is 0L if the function cannot convert the input to a 
  2788. value of that type.  The return value is undefined in case of overflow. 
  2789.  
  2790.  
  2791. ΓòÉΓòÉΓòÉ <hidden> Example of atol ΓòÉΓòÉΓòÉ
  2792.  
  2793. /************************************************************************
  2794.  
  2795. This example shows how to convert numbers stored as strings to numerical values 
  2796. using the atol function. 
  2797.  
  2798. ************************************************************************/
  2799.  
  2800. #include <stdio.h>
  2801. #include <stdlib.h>
  2802.  
  2803. int main(void)
  2804. {
  2805.    long l;
  2806.    char *s;
  2807.  
  2808.    s = "98854 dollars";
  2809.    l = atol(s);                                           /* l = 98854        */
  2810.    printf("atol( %s ) = %d\n", s, l);
  2811.    return 0;
  2812.  
  2813.    /****************************************************************************
  2814.       The output should be similar to :
  2815.  
  2816.       atol( 98854 dollars ) = 98854
  2817.    ****************************************************************************/
  2818. }
  2819.  
  2820.  
  2821. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2822.  
  2823. Example of atol 
  2824.  
  2825.      atof - Convert Character String to Float 
  2826.      atoi - Convert Character String to Integer 
  2827.      _atold - Convert Character String to Long Double 
  2828.      strtod - Convert Character String to Double 
  2829.      strtol - Convert Character String to Long Integer 
  2830.      strtold - Convert String to Long Double 
  2831.      <stdlib.h> 
  2832.  
  2833.  
  2834. ΓòÉΓòÉΓòÉ 4.14. atoll - Convert Character String to Long Long Integer ΓòÉΓòÉΓòÉ
  2835.  
  2836.  
  2837. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2838.  
  2839. #include <stdlib.h>
  2840. long long int atoll(const char *string);
  2841.  
  2842.  
  2843. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2844.  
  2845. Language Level:  Extension 
  2846.  
  2847. atoll converts a character string to a long long value. 
  2848.  
  2849. The input string is a sequence of characters that can be interpreted as a 
  2850. numerical value of the specified return type.  The function stops reading the 
  2851. input string at the first character that it cannot recognize as part of a 
  2852. number; this character can be the null character that ends the string. 
  2853.  
  2854. atoll does not recognize decimal points nor exponents.  The string argument for 
  2855. this function has the form: 
  2856.  
  2857. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2858. Γöé                                        Γöé
  2859. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdigitsΓöÇΓöÇ><                     Γöé
  2860. Γöé   ΓööΓöÇwhitespaceΓöÇΓöÿ  Γö£ΓöÇ+ΓöÇΓöñ                           Γöé
  2861. Γöé           ΓööΓöÇΓö┤ΓöÇΓöÿ                           Γöé
  2862. Γöé                                        Γöé
  2863. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2864.  
  2865. where whitespace consists of the same characters for which the isspace function 
  2866. is true, such as spaces and tabs. atoll ignores leading white-space characters. 
  2867. digits is one or more decimal digits. 
  2868.  
  2869. Return Value 
  2870. atoll returns a long long value produced by interpreting the input characters 
  2871. as a number.  The return value is 0LL if the function cannot convert the input 
  2872. to a value of that type.  The return value is undefined in case of overflow. 
  2873.  
  2874.  
  2875. ΓòÉΓòÉΓòÉ <hidden> Example of atoll ΓòÉΓòÉΓòÉ
  2876.  
  2877. /************************************************************************
  2878.  
  2879. This example shows how to convert numbers stored as strings to numerical values 
  2880. using the atoll function. 
  2881.  
  2882. ************************************************************************/
  2883.  
  2884. #include <stdio.h>
  2885. #include <stdlib.h>
  2886.  
  2887. int main(void)
  2888. {
  2889.    long ll;
  2890.    char *s;
  2891.  
  2892.    s = "98854 dollars";
  2893.    ll = atoll(s);                                           /* ll = 98854        */
  2894.    printf("atoll( %s ) = %d\n", s, ll);
  2895.    return 0;
  2896.  
  2897.    /****************************************************************************
  2898.       The output should be similar to :
  2899.  
  2900.       atoll( 98854 dollars ) = 98854
  2901.    ****************************************************************************/
  2902. }
  2903.  
  2904.  
  2905. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2906.  
  2907. Example of atoll 
  2908.  
  2909.      atof - Convert Character String to Float 
  2910.      atoi - Convert Character String to Integer 
  2911.      _atold - Convert Character String to Long Double 
  2912.      atol - Convert Character String to Long Integer 
  2913.      strtod - Convert Character String to Double 
  2914.      strtol - Convert Character String to Long Integer 
  2915.      strtold - Convert String to Long Double 
  2916.      <stdlib.h> 
  2917.  
  2918.  
  2919. ΓòÉΓòÉΓòÉ 4.15. _atold - Convert Character String to Long Double ΓòÉΓòÉΓòÉ
  2920.  
  2921.  
  2922. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2923.  
  2924. #include <stdlib.h>    /* also defined in <math.h> */
  2925. long double _atold(const char *nptr);
  2926.  
  2927.  
  2928. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2929.  
  2930. Language Level:  Extension 
  2931.  
  2932. _atold converts a character string pointed to by nptr to a long double value. 
  2933. The function continues until it reads a character it does not recognize as part 
  2934. of a number. This character can be the ending null character. Except for its 
  2935. behavior on error, _atold is equivalent to: 
  2936.  
  2937.    strtold(nptr, (char **)NULL)
  2938.  
  2939. The string pointed to by nptr must have the following format: 
  2940.  
  2941. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2942. Γöé                                        Γöé
  2943. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ>                             Γöé
  2944. Γöé   ΓööΓöÇwhitespaceΓöÇΓöÿ                              Γöé
  2945. Γöé                                        Γöé
  2946. Γöé >ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><  Γöé
  2947. Γöé   ΓööΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇdigitsΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÿ    Γöé
  2948. Γöé    Γö£ΓöÇ+ΓöÇΓöñ  Γöé     ΓööΓöÇ.ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ Γöé  ΓööΓöÇΓö¼ΓöÇeΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdigitsΓöÇΓöÿ     Γöé
  2949. Γöé    ΓööΓöÇΓö┤ΓöÇΓöÿ  Γöé        ΓööΓöÇdigitsΓöÇΓöÿ  Γöé   ΓööΓöÇEΓöÇΓöÿ  Γö£ΓöÇ+ΓöÇΓöñ          Γöé
  2950. Γöé        ΓööΓöÇ.ΓöÇΓöÇdigitsΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ      ΓööΓöÇΓö┤ΓöÇΓöÿ          Γöé
  2951. Γöé                                        Γöé
  2952. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2953.  
  2954. digits is one or more decimal digits.  If no digits appear before the decimal 
  2955. point, at least one digit must follow the decimal point.  You can place an 
  2956. exponent expressed as a decimal integer after the digits. The exponent can be 
  2957. signed. 
  2958.  
  2959. The value of nptr can also be one of the strings infinity, inf, or nan.  These 
  2960. strings are case insensitive, and can be preceded by a unary minus (-). They 
  2961. are converted to infinity and NaN values. For more information on NaN and 
  2962. infinity values, see Infinity and NaN Support. 
  2963.  
  2964. _atold ignores any white-space characters, as defined by the isspace function. 
  2965.  
  2966. Return Value 
  2967. _atold returns the converted long double value. In the case of an underflow, it 
  2968. returns 0. In the case of a positive overflow, _atold returns positive 
  2969. _LHUGE_VAL. It returns negative _LHUGE_VAL for a negative overflow. 
  2970.  
  2971.  
  2972. ΓòÉΓòÉΓòÉ <hidden> Example of _atold ΓòÉΓòÉΓòÉ
  2973.  
  2974. /************************************************************************
  2975.  
  2976. This example uses _atold to convert two strings, "  -001234.5678e10end of 
  2977. string" and "NaNQ", to their corresponding long double values. 
  2978.  
  2979. ************************************************************************/
  2980.  
  2981. #include <stdlib.h>
  2982. #include <stdio.h>
  2983.  
  2984. int main(void)
  2985. {
  2986.    char *string;
  2987.  
  2988.    string = "  -001234.5678e10end of string";
  2989.    printf("_atold = %.10Le\n", _atold(string));
  2990.    string = "NaNQ";
  2991.    printf("_atold = %.10Le\n", _atold(string));
  2992.    return 0;
  2993.  
  2994.    /****************************************************************************
  2995.       The output should be:
  2996.  
  2997.       _atold = -1.2345678000e+13
  2998.       _atold = nan
  2999.    ****************************************************************************/
  3000.  
  3001. }
  3002.  
  3003.  
  3004. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3005.  
  3006. Example of _atold 
  3007.  
  3008.      atof - Convert Character String to Float 
  3009.      atoi - Convert Character String to Integer 
  3010.      atol - Convert Character String to Long Integer 
  3011.      strtod - Convert Character String to Double 
  3012.      strtol - Convert Character String to Long Integer 
  3013.      strtold - Convert String to Long Double 
  3014.      <stdlib.h> 
  3015.      <math.h> 
  3016.  
  3017.  
  3018. ΓòÉΓòÉΓòÉ 4.16. _beginthread - Create New Thread ΓòÉΓòÉΓòÉ
  3019.  
  3020.  
  3021. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3022.  
  3023. #include <stdlib.h>   /* also in <process.h> */
  3024. int _beginthread(void (*start_address) (void *),
  3025.                      (void *)stack,
  3026.                      unsigned stack_size,
  3027.                      void *arglist);
  3028.  
  3029.  
  3030. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3031.  
  3032. Language Level:  Extension 
  3033.  
  3034. _beginthread creates a new thread. It takes the following arguments: 
  3035.  
  3036.  start_address 
  3037.    This parameter is the address of the function that the newly created thread 
  3038.    will execute. When the thread returns from that function, it is terminated 
  3039.    automatically. You can also explicitly terminate the thread by calling 
  3040.    _endthread. 
  3041.  
  3042.  stack 
  3043.    This parameter is ignored.  It is retained for compatibility with other 
  3044.    compilers. 
  3045.  
  3046.  stack_size 
  3047.    The size of the stack, in bytes, that is to be allocated for the new thread. 
  3048.    The stack size should be a nonzero multiple of 4K and a minimum of 8K. 
  3049.    Memory is used when needed, one page at a time. 
  3050.  
  3051.  arglist 
  3052.    A parameter to be passed to the newly created thread. It is the size of a 
  3053.    pointer, and is usually the address of a data item to be passed to the new 
  3054.    thread, such as a char string. It provides _beginthread with a value to pass 
  3055.    to the child thread. NULL can be used as a placeholder. 
  3056.  
  3057.  The function that the new thread will perform must be declared and compiled 
  3058.  using _Optlink linkage. 
  3059.  
  3060.  An alternative to this function is the Win32 CreateThread API. If you use 
  3061.  CreateThread, you must also use a #pragma handler statement for the thread 
  3062.  function to ensure proper C exception handling. You should also call the 
  3063.  _fpreset function at the start of the thread to preset the 387 control status 
  3064.  word correctly. When the thread returns from the function, it is terminated 
  3065.  automatically. You can also explicitly terminate the thread by calling 
  3066.  _endthread. 
  3067.  
  3068.  Note:  When using the _beginthread and _endthread functions, you must specify 
  3069.  the /Gm+ compiler option to use the multithread libraries. 
  3070.  
  3071.  Return Value 
  3072.  If successful, _beginthread returns the thread handle of the new thread. It 
  3073.  returns -1 to indicate an error. 
  3074.  
  3075.  
  3076. ΓòÉΓòÉΓòÉ <hidden> Example of _beginthread ΓòÉΓòÉΓòÉ
  3077.  
  3078. /************************************************************************
  3079.  
  3080. This example uses _beginthread to start a new thread bonjour. 
  3081.  
  3082. Note:  To run this example, you must compile it using the /Gm+ compiler option. 
  3083.  
  3084. ************************************************************************/
  3085.  
  3086. /************************************************************************
  3087. Note:  To run this example, you must compile it using
  3088. the /Gm+ compiler option.
  3089. ***********************************************************************       */
  3090.  
  3091. #if  (1 == __TOS_OS2__)
  3092.      #define INCL_DOS                                /* OS/2 */
  3093.      #include <os2.h>
  3094.      #define SLEEP  DosSleep(0l)
  3095. #else
  3096.      #include <windows.h>                            /* Windows */
  3097.      #define SLEEP  Sleep(0l)
  3098. #endif
  3099.  
  3100. #include <stdio.h>
  3101. #include <stdlib.h>
  3102.  
  3103. static volatile int wait = 1;
  3104.  
  3105. void _Optlink bonjour(void *arg)
  3106. {
  3107.    int i = 0;
  3108.  
  3109.    while (wait)               /* wait until the thread id has been printed     */
  3110.         SLEEP;
  3111.    while (i++ <5)
  3112.       printf("Bonjour!\n");
  3113.  
  3114. }
  3115.  
  3116. int main(void)
  3117. {
  3118.    int tid;
  3119.  
  3120.    tid = _beginthread(bonjour, NULL, 8192, NULL);
  3121.    if (-1 == tid) {
  3122.       printf("Unable to start thread.\n");
  3123.       return EXIT_FAILURE;
  3124.    }
  3125.    else {
  3126.       printf("Thread started with thread identifier number %d.\n", tid);
  3127.       wait = 0;
  3128.    }
  3129. #if  (1 == __TOS_OS2__)
  3130.   DosWaitThread((PTID)&tid, DCWW_WAIT);  /* wait for thread bonjour to end    */
  3131.                                          /* before ending main thread         */
  3132. #else
  3133.   WaitForSingleObject((HANDLE)tid, INFINITE); /* wait for thread bonjour to end */
  3134.                                               /*  before ending main thread     */
  3135. #endif
  3136.  
  3137.    return 0;
  3138.  
  3139.    /****************************************************************************
  3140.       The output should be similar to:
  3141.  
  3142.        Thread started with thread identifier number 2.
  3143.        Bonjour!
  3144.        Bonjour!
  3145.        Bonjour!
  3146.        Bonjour!
  3147.        Bonjour!
  3148.    ****************************************************************************/
  3149. }
  3150.  
  3151.  
  3152. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3153.  
  3154. Example of _beginthread 
  3155.  
  3156.      _endthread - Terminate Current Thread 
  3157.      _threadstore - Access Thread-Specific Storage 
  3158.      /Gm+ option in the User's Guide 
  3159.      <stdlib.h> 
  3160.      <process.h> 
  3161.  
  3162.  
  3163. ΓòÉΓòÉΓòÉ 4.17. Bessel Functions - Solve Differential Equations ΓòÉΓòÉΓòÉ
  3164.  
  3165.  
  3166. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3167.  
  3168. #include <math.h>
  3169. double _j0(double x);
  3170. double _j1(double x);
  3171. double _jn(int n, double x);
  3172. double _y0(double x);
  3173. double _y1(double x);
  3174. double _yn(int n, double x);
  3175.  
  3176.  
  3177. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3178.  
  3179. Language Level: SAA 
  3180.  
  3181. Bessel functions solve certain types of differential equations.  The _j0, _j1, 
  3182. and _jn functions are Bessel functions of the first kind for orders 0, 1, and 
  3183. n, respectively. 
  3184.  
  3185. The _y0, _y1, and _yn functions are Bessel functions of the second kind for 
  3186. orders 0, 1, and n, respectively. The argument x must be positive. The argument 
  3187. n should be greater than or equal to zero. If n is less than zero, it will be a 
  3188. negative exponent. 
  3189.  
  3190. Return Value 
  3191. For _j0, _j1, _y0, or _y1, if the absolute value of x is too large, the 
  3192. function sets errno to ERANGE, and returns 0. For _y0, _y1, or _yn, if x is 
  3193. negative, the function sets errno to EDOM and returns the value -HUGE_VAL. For 
  3194. _y0, _y1, or _yn, if x causes an overflow, the function sets errno to ERANGE 
  3195. and returns the value -HUGE_VAL. 
  3196.  
  3197.  
  3198. ΓòÉΓòÉΓòÉ <hidden> Example of Bessel Functions ΓòÉΓòÉΓòÉ
  3199.  
  3200. /************************************************************************
  3201.  
  3202. This example computes y to be the order 0 Bessel function of the first kind for 
  3203. x, and z to be the order 3 Bessel function of the second kind for x. 
  3204.  
  3205. ************************************************************************/
  3206.  
  3207. #include <stdio.h>
  3208. #include <math.h>
  3209.  
  3210. int main(void)
  3211. {
  3212.    double x,y,z;
  3213.  
  3214.    x = 4.27;
  3215.    y = j0(x);      /* y = -0.3660 is the order 0 bessel                       */
  3216.                    /* function of the first kind for x                        */
  3217.  
  3218.    printf("j0( 4.27 ) = %5.4f\n", y);
  3219.    z = yn(3, x);   /* z = -0.0875 is the order 3 bessel                       */
  3220.                    /* function of the second kind for x                       */
  3221.  
  3222.    printf("yn( 3,4.27 ) = %5.4f\n", z);
  3223.    return 0;
  3224.  
  3225.    /****************************************************************************
  3226.       The output should be:
  3227.  
  3228.       j0( 4.27 ) = -0.3660
  3229.       yn( 3,4.27 ) = -0.0875
  3230.    ****************************************************************************/
  3231. }
  3232.  
  3233.  
  3234. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3235.  
  3236. Example of Bessel Functions 
  3237.  
  3238.      erf - erfc - Calculate Error Functions 
  3239.      gamma - Gamma Function 
  3240.      <math.h> 
  3241.  
  3242.  
  3243. ΓòÉΓòÉΓòÉ 4.18. bsearch - Search Arrays ΓòÉΓòÉΓòÉ
  3244.  
  3245.  
  3246. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3247.  
  3248. #include <stdlib.h>  /* also in <search.h> */
  3249. void *bsearch(const void *key, const void *base,
  3250.               size_t num, size_t size,
  3251.               int (*compare)(const void *key, const void *element));
  3252.  
  3253.  
  3254. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3255.  
  3256. Language Level: ANSI, SAA, POSIX, XPG, Extension 
  3257.  
  3258. bsearch performs a binary search of an array of num elements, each of size 
  3259. bytes. The array must be sorted in ascending order by the function pointed to 
  3260. by compare.  The base is a pointer to the base of the array to search, and key 
  3261. is the value being sought. 
  3262.  
  3263. The compare argument is a pointer to a function you must supply that takes a 
  3264. pointer to the key argument and to an array element, in that order. bsearch 
  3265. calls this function one or more times during the search. The function must 
  3266. compare the key and the element and return one of the following values: 
  3267.  
  3268.  Value             Meaning 
  3269.  Less than 0       key less than element 
  3270.  0                 key identical to element 
  3271.  Greater than 0    key greater than element 
  3272.  
  3273.  Return Value 
  3274.  bsearch returns a pointer to key in the array to which base points. If two 
  3275.  keys are equal, the element that key will point to is unspecified. If bsearch 
  3276.  cannot find the key, it returns NULL. 
  3277.  
  3278.  
  3279. ΓòÉΓòÉΓòÉ <hidden> Example of bsearch ΓòÉΓòÉΓòÉ
  3280.  
  3281. /************************************************************************
  3282.  
  3283. This example performs a binary search on the argv array of pointers to the 
  3284. program parameters and finds the position of the argument PATH. It first 
  3285. removes the program name from argv, and then sorts the array alphabetically 
  3286. before calling bsearch. The functions compare1 and compare2 compare the values 
  3287. pointed to by arg1 and arg2 and return the result to bsearch. 
  3288.  
  3289. ************************************************************************/
  3290.  
  3291. #include <stdlib.h>
  3292. #include <stdio.h>
  3293. #include <string.h>
  3294.  
  3295. /* ------------------------------------------------------------------         */
  3296. /* Note: Library always calls functions internally with _Optlink              */
  3297. /*       linkage convention.  Ensure that compare1() and compare2             */
  3298. /*       are always _Optlink.                                                 */
  3299. /* ------------------------------------------------------------------         */
  3300.  
  3301. int _Optlink compare1(const void *arg1,const void *arg2)
  3302. {
  3303.    return (strcmp(*(char **)arg1, *(char **)arg2));
  3304. }
  3305.  
  3306. int _Optlink compare2(const void *arg1,const void *arg2)
  3307. {
  3308.    return (strcmp((char *)arg1, *(char **)arg2));
  3309. }
  3310.  
  3311. int main(int argc,char *argv[])
  3312. {
  3313.    char **result;
  3314.    char *key = "PATH";
  3315.    int i;
  3316.    argv++;
  3317.    argc--;
  3318.  
  3319.    qsort((char *)argv, argc, sizeof(char *), compare1);
  3320.    result = (char **)bsearch(key, argv, argc, sizeof(char *), compare2);
  3321.    if (result != NULL) {
  3322.       printf("result = <%s>\n", *result);
  3323.    }
  3324.    else
  3325.       printf("result is null\n");
  3326.    return 0;
  3327.  
  3328.    /****************************************************************************
  3329.       If the program name is progname and you enter:
  3330.  
  3331.       progname where is PATH in this phrase?
  3332.  
  3333.       The output should be:
  3334.  
  3335.       result = <PATH>
  3336.    ****************************************************************************/
  3337. }
  3338.  
  3339.  
  3340. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3341.  
  3342. Example of bsearch 
  3343.  
  3344.      lfind - lsearch - Find Key in Array 
  3345.      qsort - Sort Array 
  3346.      <stdlib.h> 
  3347.  
  3348.  
  3349. ΓòÉΓòÉΓòÉ 4.19. _cabs - Calculate Absolute Value of Complex Number ΓòÉΓòÉΓòÉ
  3350.  
  3351.  
  3352. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3353.  
  3354. #include <math.h>
  3355. double _cabs(struct complex z);
  3356.  
  3357.  
  3358. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3359.  
  3360. Language Level:  Extension 
  3361.  
  3362. _cabs calculates the absolute value of a complex number.  This complex number 
  3363. is represented as a structure with the tag complex containing the real and 
  3364. imaginary parts.  The following type declaration is in <math.h>: 
  3365.  
  3366.    struct complex {double x,y;};
  3367.  
  3368. A call to _cabs is equivalent to: 
  3369.  
  3370.    sqrt(z.x * z.x + z.y * z.y)
  3371.  
  3372. Return Value 
  3373. _cabs returns the absolute value as a double value.  If an overflow results, 
  3374. _cabs calls the _matherr routine and, if necessary, sets errno to ERANGE and 
  3375. returns the value HUGE_VAL. 
  3376.  
  3377.  
  3378. ΓòÉΓòÉΓòÉ <hidden> Example of _cabs ΓòÉΓòÉΓòÉ
  3379.  
  3380. /************************************************************************
  3381.  
  3382. The following program computes the absolute value of the complex number (3.0, 
  3383. 4.0). 
  3384.  
  3385. ************************************************************************/
  3386.  
  3387. #include <math.h>
  3388. #include <stdio.h>
  3389.  
  3390. int main(void)
  3391. {
  3392.    struct complex value;
  3393.    double d;
  3394.  
  3395.    value.x = 3.0;
  3396.    value.y = 4.0;
  3397.    d = _cabs(value);
  3398.    printf("The complex absolute value of %f and %f is %f\n", value.x, value.y, d
  3399.       );
  3400.    return 0;
  3401.  
  3402.    /****************************************************************************
  3403.       The output should be:
  3404.  
  3405.       The complex absolute value of 3.000000 and 4.000000 is 5.000000
  3406.    ****************************************************************************/
  3407. }
  3408.  
  3409.  
  3410. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3411.  
  3412. Example of _cabs 
  3413.  
  3414.      abs - Calculate Integer Absolute Value 
  3415.      fabs - Calculate Floating-Point Absolute Value 
  3416.      hypot - Calculate Hypotenuse 
  3417.      labs - Calculate Absolute Value of Long Integer 
  3418.      _matherr - Process Math Library Errors 
  3419.      sqrt - Calculate Square Root 
  3420.      <math.h> 
  3421.  
  3422.  
  3423. ΓòÉΓòÉΓòÉ 4.20. calloc - Reserve and Initialize Storage ΓòÉΓòÉΓòÉ
  3424.  
  3425.  
  3426. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3427.  
  3428. #include <stdlib.h>  /* also in <malloc.h> */
  3429. void *calloc(size_t num, size_t size);
  3430.  
  3431.  
  3432. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3433.  
  3434. Language Level: ANSI, SAA, POSIX, XPG4 
  3435.  
  3436. calloc reserves storage space for an array of num elements, each of length size 
  3437. bytes. calloc then gives all the bits of each element an initial value of 0. 
  3438.  
  3439. A heap-specific version of this function (_ucalloc) is also available. calloc 
  3440. always allocates memory from the default heap.  You can also use the debug 
  3441. version of calloc, _debug_calloc, to debug memory problems. 
  3442.  
  3443. Return Value calloc returns a pointer to the reserved space.  The storage space 
  3444. to which the return value points is suitably aligned for storage of any type of 
  3445. object.  To get a pointer to a type, use a type cast on the return value.  The 
  3446. return value is NULL if there is not enough storage, or if num or size is 0. 
  3447.  
  3448.  
  3449. ΓòÉΓòÉΓòÉ <hidden> Example of calloc ΓòÉΓòÉΓòÉ
  3450.  
  3451. /************************************************************************
  3452.  
  3453. This example prompts for the number of array entries required and then reserves 
  3454. enough space in storage for the entries. If calloc is successful, the example 
  3455. prints out each entry;  otherwise, it prints out an error. 
  3456.  
  3457. ************************************************************************/
  3458.  
  3459. #include <stdio.h>
  3460. #include <stdlib.h>
  3461.  
  3462. int main(void)
  3463. {
  3464.    long *array;                             /* start of the array             */
  3465.    long *index;                             /* index variable                 */
  3466.    int i;                                   /* index variable                 */
  3467.    int num;                                 /* number of entries of the array */
  3468.  
  3469.    printf("Enter the size of the array\n");
  3470.    scanf("%i", &num);
  3471.  
  3472.    /* allocate num entries                                                    */
  3473.  
  3474.    if ((index = array = (long *)calloc(num, sizeof(long))) != NULL) {
  3475.       for (i = 0; i < num; ++i)             /* put values in array            */
  3476.          *index++ = i;                      /* using pointer notation         */
  3477.       for (i = 0; i < num; ++i)             /* print the array out            */
  3478.          printf("array[ %i ] = %i\n", i, array[i]);
  3479.    }
  3480.    else {                                                 /* out of storage   */
  3481.       perror("Out of storage");
  3482.       abort();
  3483.    }
  3484.    return 0;
  3485.  
  3486.    /****************************************************************************
  3487.       The output should be similar to :
  3488.  
  3489.       Enter the size of the array
  3490.       3
  3491.       array[ 0 ] = 0
  3492.       array[ 1 ] = 1
  3493.       array[ 2 ] = 2
  3494.    ****************************************************************************/
  3495. }
  3496.  
  3497.  
  3498. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3499.  
  3500. Example of calloc 
  3501.  
  3502.      _alloca - Temporarily Reserve Storage Block 
  3503.      _debug_calloc - Allocate and Initialize Memory 
  3504.      _debug_ucalloc - Reserve and Initialize Memory from User Heap 
  3505.      free - Release Storage Blocks 
  3506.      malloc - Reserve Storage Block 
  3507.      realloc - Change Reserved Storage Block Size 
  3508.      _ucalloc - Reserve and Initialize Memory from User Heap 
  3509.      <malloc.h> 
  3510.      <stdlib.h> 
  3511.      Managing Memory in the Programming Guide 
  3512.  
  3513.  
  3514. ΓòÉΓòÉΓòÉ 4.21. ceil - Find Integer >= Argument ΓòÉΓòÉΓòÉ
  3515.  
  3516.  
  3517. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3518.  
  3519. #include <math.h>
  3520. double ceil(double x);
  3521.  
  3522.  
  3523. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3524.  
  3525. Language Level: ANSI, SAA, POSIX, XPG4 
  3526.  
  3527. ceil computes the smallest integer that is greater than or equal to x. 
  3528.  
  3529. Return Value 
  3530. ceil returns the integer as a double value. 
  3531.  
  3532.  
  3533. ΓòÉΓòÉΓòÉ <hidden> Example of ceil ΓòÉΓòÉΓòÉ
  3534.  
  3535. /************************************************************************
  3536.  
  3537. This example sets y to the smallest integer greater than 1.05, and then to the 
  3538. smallest integer greater than -1.05.  The results are 2.0 and -1.0, 
  3539. respectively. 
  3540.  
  3541. ************************************************************************/
  3542.  
  3543. #include <stdio.h>
  3544. #include <math.h>
  3545.  
  3546. int main(void)
  3547. {
  3548.    double y,z;
  3549.  
  3550.    y = ceil(1.05);                                        /* y = 2.0          */
  3551.    printf("ceil( 1.05 ) = %5.f\n", y);
  3552.    z = ceil(-1.05);                                       /* z = -1.0         */
  3553.    printf("ceil( -1.05 ) = %5.f\n", z);
  3554.    return 0;
  3555.  
  3556.    /****************************************************************************
  3557.       The output should be:
  3558.  
  3559.       ceil( 1.05 ) =     2
  3560.       ceil( -1.05 ) =    -1
  3561.    ****************************************************************************/
  3562. }
  3563.  
  3564.  
  3565. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3566.  
  3567. Example of ceil 
  3568.  
  3569.      floor - Integer <= Argument 
  3570.      fmod - Calculate Floating-Point Remainder 
  3571.      <math.h> 
  3572.  
  3573.  
  3574. ΓòÉΓòÉΓòÉ 4.22. _cgets - Read String of Characters from Keyboard ΓòÉΓòÉΓòÉ
  3575.  
  3576.  
  3577. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3578.  
  3579. #include <conio.h>
  3580. char *_cgets(char *str);
  3581.  
  3582.  
  3583. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3584.  
  3585. Language Level:  Extension 
  3586.  
  3587. _cgets reads a string of characters directly from the keyboard and stores the 
  3588. string and its length in the location pointed to by str. 
  3589.  
  3590. _cgets continues to read characters until it meets a carriage return followed 
  3591. by a line feed (CR-LF) or until it reads the specified number of characters. It 
  3592. stores the string starting at str[2]. If _cgets reads a CR-LF combination, it 
  3593. replaces this combination with a null character ('\0') before storing the 
  3594. string. _cgets then stores the actual length of the string in the second array 
  3595. element, str[1]. 
  3596.  
  3597. The str variable must be a pointer to a character array. The first element of 
  3598. the array, str[0], must contain the maximum length, in characters, of the 
  3599. string to be read.  The array must have enough elements to hold the string, a 
  3600. final null character, and 2 additional bytes. 
  3601.  
  3602. Return Value 
  3603. If successful, _cgets returns a pointer to the actual start of the string, 
  3604. str[2]. Otherwise, _cgets returns NULL. 
  3605.  
  3606.  
  3607. ΓòÉΓòÉΓòÉ <hidden> Example of _cgets ΓòÉΓòÉΓòÉ
  3608.  
  3609. /************************************************************************
  3610.  
  3611. This example creates a buffer and initializes the first byte to the size of the 
  3612. buffer. The program then accepts an input string using _cgets and displays the 
  3613. size and text of that string. 
  3614.  
  3615. ************************************************************************/
  3616.  
  3617. #include <conio.h>
  3618. #include <stdio.h>
  3619.  
  3620. void nothing(void)
  3621. {
  3622. }
  3623.  
  3624. int main(void)
  3625. {
  3626.    char buffer[82] =  { 84,0 };
  3627.    char *buffer2;
  3628.    int i;
  3629.  
  3630.    _cputs("\nPress any key to continue.");
  3631.    printf("\n");
  3632.    while (0 == _kbhit()) {
  3633.       nothing();
  3634.    }
  3635.    _getch();
  3636.    _cputs("\nEnter a line of text:");
  3637.    printf("\n");
  3638.    buffer2 = _cgets(buffer);
  3639.    printf("\nText entered was: %s", buffer2);
  3640.    return 0;
  3641.  
  3642.    /****************************************************************************
  3643.       The output should be similar to:
  3644.  
  3645.       Press any key to continue.
  3646.  
  3647.       Enter a line of text:
  3648.       This is a simple test.
  3649.       Text entered was: This is a simple test.
  3650.  
  3651.    ****************************************************************************/
  3652. }
  3653.  
  3654.  
  3655. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3656.  
  3657. Example of _cgets 
  3658.  
  3659.      _cputs - Write String to Screen 
  3660.      fgets - Read a String 
  3661.      gets - Read a Line 
  3662.      _getch - _getche - Read Character from Keyboard 
  3663.      <conio.h> 
  3664.  
  3665.  
  3666. ΓòÉΓòÉΓòÉ 4.23. chdir - Change Current Working Directory ΓòÉΓòÉΓòÉ
  3667.  
  3668.  
  3669. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3670.  
  3671. #include <direct.h>
  3672. int chdir(char *pathname);
  3673.  
  3674.  
  3675. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3676.  
  3677. Language Level:  XPG4, Extension 
  3678.  
  3679. chdir causes the current working directory to change to the directory specified 
  3680. by pathname.  The pathname must refer to an existing directory. 
  3681.  
  3682. Note:  This function can change the current working directory on any drive.  It 
  3683. cannot change the default drive.  For example, if A:\BIN is the current working 
  3684. directory and A: is the default drive, the following changes only the current 
  3685. working directory on drive C:. 
  3686.  
  3687.    chdir ("c:\\emp");
  3688.  
  3689. A: is still the default drive. 
  3690.  
  3691. An alternative to this function is the SetCurrentDir API call. For more 
  3692. information, see Win32 Programmer's Reference. 
  3693.  
  3694. Note:  In earlier releases of VisualAge C++, chdir began with an underscore 
  3695. (_chdir). Because it is defined by the X/Open standard, the underscore has been 
  3696. removed. For compatibility, VisualAge for C++ will map _chdir to chdir for you. 
  3697.  
  3698. Return Value 
  3699. chdir returns a value of 0 if the working directory was successfully changed. A 
  3700. return value of -1 indicates an error; chdir sets errno to ENOENT, showing that 
  3701. chdir cannot find the specified path name.  No error occurs if pathname 
  3702. specifies the current working directory. 
  3703.  
  3704.  
  3705. ΓòÉΓòÉΓòÉ <hidden> Example of chdir ΓòÉΓòÉΓòÉ
  3706.  
  3707. /************************************************************************
  3708.  
  3709. This example changes the current working directory to the root directory, and 
  3710. then to the \red\green\blue directory. 
  3711.  
  3712. ************************************************************************/
  3713.  
  3714. #include <direct.h>
  3715. #include <stdio.h>
  3716.  
  3717. int main(void)
  3718. {
  3719.    printf("Changing to the root directory.\n");
  3720.    if (chdir("\\"))
  3721.       perror(NULL);
  3722.    else
  3723.       printf("Changed to the root directory.\n\n");
  3724.    printf("Changing to directory '\\red\\green\\blue'.\n");
  3725.    if (chdir("\\red\\green\\blue"))
  3726.       perror(NULL);
  3727.    else
  3728.       printf("Changed to directory '\\red\\green\\blue'.\n");
  3729.    return 0;
  3730.  
  3731.    /****************************************************************************
  3732.       If directory \red\green\blue exists, the output should be:
  3733.  
  3734.       Changing to the root directory.
  3735.       Changed to the root directory.
  3736.  
  3737.       Changing to directory '\red\green\blue'.
  3738.       Changed to directory '\red\green\blue'.
  3739.    ****************************************************************************/
  3740. }
  3741.  
  3742.  
  3743. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3744.  
  3745. Example of chdir 
  3746.  
  3747.      _chdrive - Change Current Working Drive 
  3748.      _getcwd - Get Path Name of Current Directory 
  3749.      _getdcwd - Get Full Path Name of Current Directory 
  3750.      _getdrive - Get Current Working Drive 
  3751.      system - Invoke the Command Processor 
  3752.      mkdir - Create New Directory 
  3753.      rmdir - Remove Directory 
  3754.      system - Invoke the Command Processor 
  3755.      <direct.h> 
  3756.  
  3757.  
  3758. ΓòÉΓòÉΓòÉ 4.24. _chdrive - Change Current Working Drive ΓòÉΓòÉΓòÉ
  3759.  
  3760.  
  3761. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3762.  
  3763. #include <direct.h>
  3764. int _chdrive(int drive);
  3765.  
  3766.  
  3767. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3768.  
  3769. Language Level:  Extension 
  3770.  
  3771. _chdrive changes the current working drive to the drive specified.  The drive 
  3772. variable is an integer value representing the number of the new working drive 
  3773. (A: is 1, B: is 2, and so on). 
  3774.  
  3775. An alternative to this function is the Win32 SetCurrentDirectory system call. 
  3776. For more information, see Win32 Programmer's Reference. 
  3777.  
  3778. Return Value 
  3779. _chdrive returns 0 if it is successful in changing the working drive. A return 
  3780. value of -1 indicates an error; _chdrive sets errno to EOS2ERR. 
  3781.  
  3782.  
  3783. ΓòÉΓòÉΓòÉ <hidden> Example of _chdrive ΓòÉΓòÉΓòÉ
  3784.  
  3785. /************************************************************************
  3786.  
  3787. This example uses _chdrive to change the current working drive to C:. 
  3788.  
  3789. ************************************************************************/
  3790.  
  3791. #include <direct.h>
  3792. #include <stdio.h>
  3793.  
  3794. int main(void)
  3795. {
  3796.    if (_chdrive(3))
  3797.       printf("Cannot change current working drive to 'C' drive.\n");
  3798.    else {
  3799.       printf("Current working drive changed to ");
  3800.       printf("'%c' drive.\n", ('A'+_getdrive()-1));
  3801.    }
  3802.    return 0;
  3803.  
  3804.    /****************************************************************************
  3805.       The output should be similar to :
  3806.  
  3807.       Current working drive changed to 'C' drive.
  3808.    ****************************************************************************/
  3809. }
  3810.  
  3811.  
  3812. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3813.  
  3814. Example of _chdrive 
  3815.  
  3816.      chdir - Change Current Working Directory 
  3817.      _getcwd - Get Path Name of Current Directory 
  3818.      _getdcwd - Get Full Path Name of Current Directory 
  3819.      _getdrive - Get Current Working Drive 
  3820.      mkdir - Create New Directory 
  3821.      rmdir - Remove Directory 
  3822.      <direct.h> 
  3823.  
  3824.  
  3825. ΓòÉΓòÉΓòÉ 4.25. chmod - Change File Permission Setting ΓòÉΓòÉΓòÉ
  3826.  
  3827.  
  3828. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3829.  
  3830. #include <io.h>
  3831. #include <sys\stat.h>
  3832. int chmod(char *pathname, int pmode);
  3833.  
  3834.  
  3835. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3836.  
  3837. Language Level:  XPG4, Extension 
  3838.  
  3839. chmod changes the permission setting of the file specified by pathname. The 
  3840. permission setting controls access to the file for reading or writing. You can 
  3841. use chmod only if the file is closed. 
  3842.  
  3843. The pmode expression contains one or both of the constants S_IWRITE and 
  3844. S_IREAD, defined in <sys\stat.h>. The meanings of the values of pmode are: 
  3845.  
  3846.  Value                   Meaning 
  3847.  S_IREAD                 Reading permitted 
  3848.  S_IWRITE                Writing permitted 
  3849.  S_IREAD | S_IWRITE      Reading and writing permitted. 
  3850.  
  3851.  If you do not give permission to write to the file, chmod makes the file 
  3852.  read-only. With the Windows operating system, all files are readable; you 
  3853.  cannot give write-only permission. Thus, the modes S_IWRITE and S_IREAD | 
  3854.  S_IWRITE set the same permission. 
  3855.  
  3856.  Specifying a pmode of S_IREAD is similar to making a file read-only with the 
  3857.  ATTRIB system command. 
  3858.  
  3859.  Note:  In earlier releases of VisualAge C++, chmod began with an underscore 
  3860.  (_chmod). Because it is defined by the X/Open standard, the underscore has 
  3861.  been removed. For compatibility, VisualAge for C++ will map _chmod to chmod 
  3862.  for you. 
  3863.  
  3864.  Return Value 
  3865.  chmod returns the value 0 if it successfully changes the permission setting. 
  3866.  A return value of -1 shows an error; chmod sets errno to one of the following 
  3867.  values: 
  3868.  
  3869.  Value          Meaning 
  3870.  ENOENT         The system cannot find the file or the path that you specified, 
  3871.                 or the file name was incorrect. 
  3872.  EOS2ERR        The call to the operating system was not successful. 
  3873.  EINVAL         The mode specified was not valid. 
  3874.  
  3875.  
  3876. ΓòÉΓòÉΓòÉ <hidden> Example of chmod ΓòÉΓòÉΓòÉ
  3877.  
  3878. /************************************************************************
  3879.  
  3880. This example opens the file chmod.dat for writing after checking the file to 
  3881. see if writing is permissible. It then writes from the buffer to the opened 
  3882. file. This program takes file names passed as arguments and sets each to 
  3883. read-only. 
  3884.  
  3885. ************************************************************************/
  3886.  
  3887. #include <sys\stat.h>
  3888. #include <io.h>
  3889. #include <stdio.h>
  3890. #include <stdlib.h>
  3891.  
  3892. int main(void)
  3893. {
  3894.    if (-1 == access("chmod.dat", 00))        /* Check if file exists.         */
  3895.       {
  3896.       printf("\nCreating chmod.dat.\n");
  3897.       system("echo Sample Program > chmod.dat");
  3898.       printf("chmod chmod.dat to be readonly.\n");
  3899.       if (-1 == chmod("chmod.dat", S_IREAD))
  3900.          perror("Chmod failed");
  3901.       if (-1 == access("chmod.dat", 02))
  3902.          printf("File chmod.dat is now readonly.\n\n");
  3903.       printf("Run this program again to erase chmod.dat.\n\n");
  3904.    }
  3905.    else {
  3906.       printf("\nFile chmod.dat exist.\n");
  3907.       printf("chmod chmod.dat to become writable.\n");
  3908.       if (-1 == chmod("chmod.dat", S_IWRITE))
  3909.          perror("Chmod failed");
  3910.       system("erase  chmod.dat");
  3911.       printf("File chmod.dat removed.\n\n");
  3912.    }
  3913.    return 0;
  3914.  
  3915.    /****************************************************************************
  3916.       If chmod.dat does not exist, the output should be :
  3917.  
  3918.        Creating chmod.dat.
  3919.        chmod chmod.dat to be readonly.
  3920.        File chmod.dat is now readonly.
  3921.  
  3922.        Run this program again to erase chmod.dat.
  3923.    ****************************************************************************/
  3924. }
  3925.  
  3926.  
  3927. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3928.  
  3929. Example of chmod 
  3930.  
  3931.      access - Determine Access Mode 
  3932.      _sopen - Open Shared File 
  3933.      umask - Sets File Mask of Current Process 
  3934.      <sys\stat.h> 
  3935.      <io.h> 
  3936.  
  3937.  
  3938. ΓòÉΓòÉΓòÉ 4.26. _chsize - Alter Length of File ΓòÉΓòÉΓòÉ
  3939.  
  3940.  
  3941. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3942.  
  3943. #include <io.h>
  3944. int _chsize(int handle, long size);
  3945.  
  3946.  
  3947. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3948.  
  3949. Language Level:  Extension 
  3950.  
  3951. _chsize lengthens or cuts off the file associated with handle to the length 
  3952. specified by size. You must open the file in a mode that permits writing. 
  3953. _chsize adds null characters (\0) when it lengthens the file. When _chsize cuts 
  3954. off the file, it erases all data from the end of the shortened file to the end 
  3955. of the original file. 
  3956.  
  3957. Return Value 
  3958. _chsize returns the value 0 if it successfully changes the file size. A return 
  3959. value of -1 shows an error; _chsize sets errno to one of the following values: 
  3960.  
  3961.  Value          Meaning 
  3962.  EACCESS        The specified file is locked against access. 
  3963.  EBADF          The file handle is not valid, or the file is not open for 
  3964.                 writing. 
  3965.  ENOSPC         There is no space left on the device. 
  3966.  EOS2ERR        The call to the operating system was not successful. 
  3967.  
  3968.  
  3969. ΓòÉΓòÉΓòÉ <hidden> Example of _chsize ΓòÉΓòÉΓòÉ
  3970.  
  3971. /************************************************************************
  3972.  
  3973. This example opens a file named sample.dat and returns the current length of 
  3974. that file. It then alters the size of sample.dat and returns the new length of 
  3975. that file. 
  3976.  
  3977. ************************************************************************/
  3978.  
  3979. #include <io.h>
  3980. #include <stdio.h>
  3981. #include <stdlib.h>
  3982. #include <fcntl.h>
  3983.  
  3984. int main(void)
  3985. {
  3986.    long length;
  3987.    int fh;
  3988.  
  3989.    printf("\nCreating sample.dat.\n");
  3990.    system("echo Sample Program > sample.dat");
  3991.    if (-1 == (fh = open("sample.dat", O_RDWR|O_APPEND))) {
  3992.       printf("Unable to open sample.dat.\n");
  3993.       return EXIT_FAILURE;
  3994.    }
  3995.    if (-1 == (length = _filelength(fh))) {
  3996.       printf("Unable to determine length of sample.dat.\n");
  3997.       return EXIT_FAILURE;
  3998.    }
  3999.    printf("Current length of sample.dat is %d.\n", length);
  4000.    printf("Changing the length of sample.dat to 20.\n");
  4001.    if (-1 == (_chsize(fh, 20))) {
  4002.       perror("_chsize failed");
  4003.       return EXIT_FAILURE;
  4004.    }
  4005.    if (-1 == (length = _filelength(fh))) {
  4006.       printf("Unable to determine length of sample.dat.\n");
  4007.       return EXIT_FAILURE;
  4008.    }
  4009.    printf("New length of sample.dat is %d.\n", length);
  4010.    close(fh);
  4011.    return 0;
  4012.  
  4013.    /****************************************************************************
  4014.       The output should be similar to :
  4015.  
  4016.        Creating sample.dat.
  4017.        Current length of sample.dat is 17.
  4018.        Changing the length of sample.dat to 20.
  4019.        New length of sample.dat is 20.
  4020.    ****************************************************************************/
  4021. }
  4022.  
  4023.  
  4024. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4025.  
  4026. Example of _chsize 
  4027.  
  4028.      _filelength - Determine File Length 
  4029.      lseek - Move File Pointer 
  4030.      <io.h> 
  4031.  
  4032.  
  4033. ΓòÉΓòÉΓòÉ 4.27. clearerr - Reset Error Indicators ΓòÉΓòÉΓòÉ
  4034.  
  4035.  
  4036. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4037.  
  4038. #include <stdio.h>
  4039. void clearerr (FILE *stream);
  4040.  
  4041.  
  4042. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4043.  
  4044. Language Level: ANSI, SAA, POSIX, XPG4 
  4045.  
  4046. The clearerr function resets the error indicator and end-of-file indicator for 
  4047. the specified stream. Once set, the indicators for a specified stream remain 
  4048. set until your program calls clearerr or rewind. fseek also clears the 
  4049. end-of-file indicator. 
  4050.  
  4051. Return Value 
  4052. There is no return value. 
  4053.  
  4054.  
  4055. ΓòÉΓòÉΓòÉ <hidden> Example of clearerr ΓòÉΓòÉΓòÉ
  4056.  
  4057. /************************************************************************
  4058.  
  4059. This example reads a data stream and then checks that a read error has not 
  4060. occurred. 
  4061.  
  4062. ************************************************************************/
  4063.  
  4064. #include <stdio.h>
  4065. #include <stdlib.h>
  4066.  
  4067. FILE *stream;
  4068. int c;
  4069.  
  4070. int main(void)
  4071. {
  4072.    if (NULL != (stream = fopen("file.dat", "r"))) {
  4073.       if (EOF == (c = getc(stream))) {
  4074.          if (feof(stream)) {
  4075.             perror("Read error");
  4076.             clearerr(stream);
  4077.          }
  4078.       }
  4079.    }
  4080.    return 0;
  4081.  
  4082.    /****************************************************************************
  4083.       If file.dat is an empty file, the output should be:
  4084.  
  4085.       Read error: Attempted to read past end-of-file.
  4086.  
  4087.    ****************************************************************************/
  4088. }
  4089.  
  4090.  
  4091. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4092.  
  4093. Example of clearerr 
  4094.  
  4095.      feof - Test End-of-File Indicator 
  4096.      ferror - Test for Read/Write Errors 
  4097.      perror - Print Error Message 
  4098.      rewind - Adjust Current File Position 
  4099.      strerror - Set Pointer to Runtime Error Message 
  4100.      _strerror - Set Pointer to System Error String 
  4101.      <stdio.h> 
  4102.  
  4103.  
  4104. ΓòÉΓòÉΓòÉ 4.28. _clear87 - Clear Floating-Point Status Word ΓòÉΓòÉΓòÉ
  4105.  
  4106.  
  4107. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4108.  
  4109. #include <float.h>  /* also in <builtin.h> */
  4110. unsigned int _clear87(void);
  4111.  
  4112.  
  4113. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4114.  
  4115. Language Level:  Extension 
  4116.  
  4117. _clear87 gets the floating-point status word and then clears it. The 
  4118. floating-point status word is a combination of the numeric coprocessor status 
  4119. word and other conditions that the numeric exception handler detects, such as 
  4120. floating-point stack overflow and underflow. 
  4121.  
  4122. _clear87 affects only the current thread. It does not affect any other threads 
  4123. that may be processing. 
  4124.  
  4125. Return Value 
  4126. The bits in the value returned reflect the floating-point status before the 
  4127. call to _clear87 was made. 
  4128.  
  4129.  
  4130. ΓòÉΓòÉΓòÉ <hidden> Example of _clear87 ΓòÉΓòÉΓòÉ
  4131.  
  4132. /************************************************************************
  4133.  
  4134. This example takes a number close to 0 as a double and assigns it to a float. 
  4135. The result is a loss of significance, y becomes a denormal number, and the 
  4136. underflow bit of the floating-point status word is set. _clear87 gets the 
  4137. current floating-point status word and then clears it, and printf prints it as 
  4138. immediate data. The result shows the change in the floating-point word because 
  4139. of the loss of significance. 
  4140.  
  4141. The program then assigns the denormal y to another variable, causing the 
  4142. denormal bit to be set in the floating-point status word. Again, _clear87 gets 
  4143. the current status word and clears it, and printf prints it to the screen. 
  4144.  
  4145. ************************************************************************/
  4146.  
  4147. #include <stdio.h>
  4148. #include <float.h>
  4149.  
  4150. double a = 1e-40;
  4151. double b;
  4152. float y;
  4153.  
  4154. int main(void)
  4155. {
  4156.    unsigned int statword;
  4157.    unsigned int old_cw;
  4158.  
  4159.    /*  change control word to mask all exceptions                             */
  4160.  
  4161.    _control87(0x037f, 0xffff);
  4162.  
  4163.    /* Assignment of the double to the float y is inexact;                     */
  4164.    /* the underflow bit is set.                                               */
  4165.  
  4166.    y = a;
  4167.    statword = _clear87();
  4168.    printf("floating-point status = 0x%.4x after underflow\n", statword);
  4169.    statword = _status87();
  4170.    printf("cleared floating-point status word = 0x%.4x\n", statword);
  4171.  
  4172.    /*  reset floating point status word                                       */
  4173.  
  4174.    _fpreset();
  4175.  
  4176.    /*  change control word to mask all exception                              */
  4177.  
  4178.    _control87(0x037f, 0xffff);
  4179.  
  4180.    /* Reassigning the denormal y to the double b                              */
  4181.    /*   causes the denormal bit to be set.                                    */
  4182.  
  4183.    b = y;
  4184.    statword = _clear87();
  4185.    printf("floating-point status = 0x%.4x for denormal\n", statword);
  4186.  
  4187.    /*  reset floating point status word                                       */
  4188.  
  4189.    _fpreset();
  4190.    return 0;
  4191.  
  4192.    /****************************************************************************
  4193.       The output should be:
  4194.  
  4195.       floating-point status = 0x0030 after underflow
  4196.       cleared floating-point status word = 0x0000
  4197.       floating-point status = 0x0002 for denormal
  4198.    ****************************************************************************/
  4199. }
  4200.  
  4201.  
  4202. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4203.  
  4204. Example of _clear87 
  4205.  
  4206.      _control87 - Set Floating-Point Control Word 
  4207.      _status87 - Get Floating-Point Status Word 
  4208.      _fpreset - Reset Floating-Point Unit 
  4209.      <float.h> 
  4210.  
  4211.  
  4212. ΓòÉΓòÉΓòÉ 4.29. clock  - Determine Processor Time ΓòÉΓòÉΓòÉ
  4213.  
  4214.  
  4215. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4216.  
  4217. #include <time.h>
  4218. clock_t clock(void);
  4219.  
  4220.  
  4221. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4222.  
  4223. Language Level: ANSI, SAA, XPG4 
  4224.  
  4225. clock returns an approximation of the processor time used by the program since 
  4226. the beginning of an implementation-defined time-period that is related to the 
  4227. program invocation. To obtain the time in seconds, divide the value returned by 
  4228. clock by the value of the macro CLOCKS_PER_SEC. 
  4229.  
  4230. Return Value 
  4231.  
  4232. If the value of the processor time is not available or cannot be represented, 
  4233. clock returns the value (clock_t)-1. 
  4234.  
  4235. To measure the time spent in a program, call clock at the start of the program, 
  4236. and subtract its return value from the value returned by subsequent calls to 
  4237. clock. 
  4238.  
  4239.  
  4240. ΓòÉΓòÉΓòÉ <hidden> Example of clock ΓòÉΓòÉΓòÉ
  4241.  
  4242. /************************************************************************
  4243.  
  4244. This example prints the time elapsed since the program was invoked. 
  4245.  
  4246. ************************************************************************/
  4247.  
  4248. #include <time.h>
  4249. #include <stdio.h>
  4250.  
  4251. double time1,time2,timedif;               /* use doubles to show small values */
  4252. int i;
  4253.  
  4254. int main(void)
  4255. {
  4256.    time1 = (double)clock();               /* get initial time in seconds      */
  4257.    time1 = time1/CLOCKS_PER_SEC;
  4258.  
  4259.    /* use some CPU time                                                       */
  4260.  
  4261.    for (i = 0; i < 5000000; i++) {
  4262.       int j;
  4263.  
  4264.       j = i;
  4265.    }
  4266.    time2 = (double)clock();                /* call clock a second time        */
  4267.    time2 = time2/CLOCKS_PER_SEC;
  4268.    timedif = time2-time1;
  4269.    printf("The elapsed time is %f seconds\n", timedif);
  4270.    return 0;
  4271.  
  4272.    /****************************************************************************
  4273.       The output should be similar to:
  4274.  
  4275.       The elapsed time is 0.969000 seconds
  4276.    ****************************************************************************/
  4277. }
  4278.  
  4279.  
  4280. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4281.  
  4282. Example of clock 
  4283.  
  4284.      difftime - Compute Time Difference 
  4285.      time - Determine Current Time 
  4286.      <time.h> 
  4287.  
  4288.  
  4289. ΓòÉΓòÉΓòÉ 4.30. close - Close File Associated with Handle ΓòÉΓòÉΓòÉ
  4290.  
  4291.  
  4292. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4293.  
  4294. #include <io.h>
  4295. int close(int handle);
  4296.  
  4297.  
  4298. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4299.  
  4300. Language Level:  XPG4, Extension 
  4301.  
  4302. close closes the file associated with the handle. Use close if you opened the 
  4303. handle with open. If you opened the handle with fopen, use fclose to close it. 
  4304.  
  4305. Note:  In earlier releases of VisualAge C++, close began with an underscore 
  4306. (_close). Because it is defined by the X/Open standard, the underscore has been 
  4307. removed. For compatibility, VisualAge for C++ will map _close to close for you. 
  4308.  
  4309. Return Value 
  4310. close returns 0 if it successfully closes the file. A return value of -1 shows 
  4311. an error, and close sets errno to EBADF, showing an incorrect file handle 
  4312. argument. 
  4313.  
  4314.  
  4315. ΓòÉΓòÉΓòÉ <hidden> Example of close ΓòÉΓòÉΓòÉ
  4316.  
  4317. /************************************************************************
  4318.  
  4319. This example opens the file edclose.dat and then closes it using the close 
  4320. function. 
  4321.  
  4322. ************************************************************************/
  4323.  
  4324. #include <io.h>
  4325. #include <stdio.h>
  4326. #include <fcntl.h>
  4327. #include <sys\stat.h>
  4328. #include <stdlib.h>
  4329.  
  4330. int main(void)
  4331. {
  4332.    int fh;
  4333.  
  4334.    printf("\nCreating edclose.dat.\n");
  4335.    if (-1 == (fh = open("edclose.dat", O_RDWR|O_CREAT|O_TRUNC, S_IREAD|S_IWRITE)
  4336.       )) {
  4337.       perror("Unable to open edclose.dat");
  4338.       return EXIT_FAILURE;
  4339.    }
  4340.    printf("File was successfully opened.\n");
  4341.    if (-1 == close(fh)) {
  4342.       perror("Unable to close edclose.dat");
  4343.       return EXIT_FAILURE;
  4344.    }
  4345.    printf("File was successfully closed.\n");
  4346.    return 0;
  4347.  
  4348.    /****************************************************************************
  4349.       The output should be:
  4350.  
  4351.       Creating edclose.dat.
  4352.       File was successfully opened.
  4353.       File was successfully closed.
  4354.    ****************************************************************************/
  4355. }
  4356.  
  4357.  
  4358. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4359.  
  4360. Example of close 
  4361.  
  4362.      fclose - Close Stream 
  4363.      creat - Create New File 
  4364.      open - Open File 
  4365.      _sopen - Open Shared File 
  4366.      <io.h> 
  4367.  
  4368.  
  4369. ΓòÉΓòÉΓòÉ 4.31. _control87 - Set Floating-Point Control Word ΓòÉΓòÉΓòÉ
  4370.  
  4371.  
  4372. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4373.  
  4374. #include <float.h>  /* also in <builtin.h> */
  4375. unsigned int _control87(unsigned int new, unsigned int mask);
  4376.  
  4377.  
  4378. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4379.  
  4380. Language Level:  Extension 
  4381.  
  4382. _control87 gets the current floating-point control word and then sets it. The 
  4383. floating-point control word specifies the precision, rounding, and infinity 
  4384. modes of the floating-point chip. 
  4385.  
  4386. You can mask or unmask current floating-point exceptions using _control87. If 
  4387. the value for the mask is equal to 0, _control87 gets the floating-point 
  4388. control word. If the mask is nonzero, _control87 sets a new value for the 
  4389. control word in the manner described below, and returns the previous value of 
  4390. the control word. For any bit in the mask equal to 1, the corresponding bit in 
  4391. new updates the control word. This is equivalent to the expression: 
  4392.  
  4393.    fpcntrl = ((fpcntrl & ~ mask) Γöé (new & mask))
  4394.  
  4395. where fpcntrl is the floating-point control word. 
  4396.  
  4397. _control87 is used for the current thread only. It does not affect any other 
  4398. threads that may be processing. 
  4399.  
  4400. Warning: If you change the content of the floating-point control word: 
  4401.  
  4402.      The behavior of the math functions with regard to domain and range errors 
  4403.       may be undefined. 
  4404.      Math functions may not handle infinity and NaN values correctly. 
  4405.      Some floating-point exceptions may not occur, while other new ones may 
  4406.       occur. 
  4407.      Resetting the EM_INEXACT bit may cause SIG_FPE exceptions, which decrease 
  4408.       performance. 
  4409.      If the precision or rounding bits are modified, you can reduce the 
  4410.       precision available for float and double variables. 
  4411.  For information on bits in the control word and handling floating-point 
  4412.  exceptions, see the User's Guide. 
  4413.  
  4414.  Return Value 
  4415.  The bits in the returned value reflect the floating-point control word before 
  4416.  the call. 
  4417.  
  4418.  
  4419. ΓòÉΓòÉΓòÉ <hidden> Example of _control187 ΓòÉΓòÉΓòÉ
  4420.  
  4421. /************************************************************************
  4422.  
  4423. This example prints the initial control word in hexadecimal, and then 
  4424. illustrates different representations of 0.1, depending on the precision. 
  4425.  
  4426. ************************************************************************/
  4427.  
  4428. #include <stdio.h>
  4429. #include <float.h>
  4430.  
  4431. double a = .13;
  4432.  
  4433. int main(void)
  4434. {
  4435.    printf("control = 0x%.4x\n", _control87(CW_DEFAULT, 0));/* Get control word*/
  4436.    printf("a*a = .0169 = %.15e\n", a *a);
  4437.    _control87(PC_24, MCW_PC);            /* Set precision to 24 bits          */
  4438.    printf("a*a = .0169 (rounded to 24 bits) = %.15e\n", a *a);
  4439.    _control87(CW_DEFAULT, 0xffff);             /* Restore to initial default  */
  4440.    printf("a*a = .0169 = %.15e\n", a *a);
  4441.    return 0;
  4442.  
  4443.    /****************************************************************************
  4444.       The output should be similar to:
  4445.  
  4446.        control = 0x0362
  4447.        a*a = .0169 = 1.690000000000000e-02
  4448.        a*a = .0169 (rounded to 24 bits) = 1.690000057220459e-02
  4449.        a*a = .0169 = 1.690000000000000e-02
  4450.    ****************************************************************************/
  4451. }
  4452.  
  4453.  
  4454. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4455.  
  4456. Example of _control87 
  4457.  
  4458.      _clear87 - Clear Floating-Point Status Word 
  4459.      _status87 - Get Floating-Point Status Word 
  4460.      _fpreset - Reset Floating-Point Unit 
  4461.      Floating Point Variables 
  4462.      signal - Handle Interrupt Signals 
  4463.      <float.h> 
  4464.  
  4465.  
  4466. ΓòÉΓòÉΓòÉ 4.32. cos - Calculate Cosine ΓòÉΓòÉΓòÉ
  4467.  
  4468.  
  4469. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4470.  
  4471. #include <math.h>
  4472. double cos(double x);
  4473.  
  4474.  
  4475. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4476.  
  4477. Language Level: ANSI, SAA, POSIX, XPG4 
  4478.  
  4479. cos calculates the cosine of x. The value x is expressed in radians. If x is 
  4480. too large, a partial loss of significance in the result may occur. 
  4481.  
  4482. Return Value 
  4483. cos returns the cosine of x. 
  4484.  
  4485.  
  4486. ΓòÉΓòÉΓòÉ <hidden> Example of cos ΓòÉΓòÉΓòÉ
  4487.  
  4488. /************************************************************************
  4489.  
  4490. This example calculates y to be the cosine of x. 
  4491.  
  4492. ************************************************************************/
  4493.  
  4494. #include <stdio.h>
  4495. #include <math.h>
  4496.  
  4497. int main(void)
  4498. {
  4499.    double x,y;
  4500.  
  4501.    x = 7.2;
  4502.    y = cos(x);
  4503.    printf("cos( %lf ) = %lf\n", x, y);
  4504.    return 0;
  4505.  
  4506.    /****************************************************************************
  4507.       The output should be:
  4508.  
  4509.       cos( 7.200000 ) = 0.608351
  4510.    ****************************************************************************/
  4511. }
  4512.  
  4513.  
  4514. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4515.  
  4516. Example of cos 
  4517.  
  4518.      acos - Calculate Arccosine 
  4519.      cosh - Calculate Hyperbolic Cosine 
  4520.      _facos - Calculate Arccosine 
  4521.      _fcos - Calculate Cosine 
  4522.      _fcossin - Calculate Cosine and Sine 
  4523.      _fsincos - Calculate Sine and Cosine 
  4524.      sin - Calculate Sine 
  4525.      sinh - Calculate Hyperbolic Sine 
  4526.      tan - Calculate Tangent 
  4527.      tanh - Calculate Hyperbolic Tangent 
  4528.      <math.h> 
  4529.  
  4530.  
  4531. ΓòÉΓòÉΓòÉ 4.33. cosh - Calculate Hyperbolic Cosine ΓòÉΓòÉΓòÉ
  4532.  
  4533.  
  4534. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4535.  
  4536. #include <math.h>
  4537. double cosh(double x);
  4538.  
  4539.  
  4540. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4541.  
  4542. Language Level: ANSI, SAA, POSIX, XPG4 
  4543.  
  4544. cosh calculates the hyperbolic cosine of x. The value x is expressed in 
  4545. radians. 
  4546.  
  4547. Return Value 
  4548. cosh returns the hyperbolic cosine of x. If the result is too large, cosh 
  4549. returns the value HUGE_VAL and sets errno to ERANGE. 
  4550.  
  4551.  
  4552. ΓòÉΓòÉΓòÉ <hidden> Example of cosh ΓòÉΓòÉΓòÉ
  4553.  
  4554. /************************************************************************
  4555.  
  4556. This example calculates y to be the hyperbolic cosine of x. 
  4557.  
  4558. ************************************************************************/
  4559.  
  4560. #include <stdio.h>
  4561. #include <math.h>
  4562.  
  4563. int main(void)
  4564. {
  4565.    double x,y;
  4566.  
  4567.    x = 7.2;
  4568.    y = cosh(x);
  4569.    printf("cosh( %lf ) = %lf\n", x, y);
  4570.    return 0;
  4571.  
  4572.    /****************************************************************************
  4573.      The output should be:
  4574.  
  4575.      cosh( 7.200000 ) = 669.715755
  4576.    ****************************************************************************/
  4577. }
  4578.  
  4579.  
  4580. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4581.  
  4582. Example of cosh 
  4583.  
  4584.      acos - Calculate Arccosine 
  4585.      cos - Calculate Cosine 
  4586.      _facos - Calculate Arccosine 
  4587.      _fcos - Calculate Cosine 
  4588.      _fcossin - Calculate Cosine and Sine 
  4589.      _fsincos - Calculate Sine and Cosine 
  4590.      sin - Calculate Sine 
  4591.      sinh - Calculate Hyperbolic Sine 
  4592.      tan - Calculate Tangent 
  4593.      tanh - Calculate Hyperbolic Tangent 
  4594.      <math.h> 
  4595.  
  4596.  
  4597. ΓòÉΓòÉΓòÉ 4.34. _cprintf - Print Characters to Screen ΓòÉΓòÉΓòÉ
  4598.  
  4599.  
  4600. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4601.  
  4602. #include <conio.h>
  4603. int _cprintf(char *format-string, argument-list);
  4604.  
  4605.  
  4606. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4607.  
  4608. Language Level:  Extension 
  4609.  
  4610. _cprintf formats and sends a series of characters and values directly to the 
  4611. screen, using the _putch function to send each character. 
  4612.  
  4613. The format-string has the same form and function as the format-string parameter 
  4614. for printf. Format specifications in the format-string determine the output 
  4615. format for any argument-list that follows. See printf for a description of the 
  4616. format-string. 
  4617.  
  4618. Note:  Unlike the fprintf, printf, and sprintf functions, _cprintf does not 
  4619. translate line feed characters into output of a carriage return followed by a 
  4620. line feed. 
  4621.  
  4622. Return Value 
  4623. _cprintf returns the number of characters printed. 
  4624.  
  4625.  
  4626. ΓòÉΓòÉΓòÉ <hidden> Example of _cprintf ΓòÉΓòÉΓòÉ
  4627.  
  4628. /************************************************************************
  4629.  
  4630. The following program uses _cprintf to write strings to the screen. 
  4631.  
  4632. ************************************************************************/
  4633.  
  4634. #include <conio.h>
  4635.  
  4636. int main(void)
  4637. {
  4638.    char buffer[24];
  4639.  
  4640.    _cprintf("\nPlease enter a filename:\n");
  4641.    _cscanf("%23s", buffer);
  4642.    _cprintf("\nThe file name you entered was %23s.", buffer);
  4643.    return 0;
  4644.  
  4645.    /****************************************************************************
  4646.       The output should be similar to :
  4647.  
  4648.        Please enter a filename:
  4649.                               file.dat
  4650.        The filename you entered was                file.dat.
  4651.    ****************************************************************************/
  4652. }
  4653.  
  4654.  
  4655. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4656.  
  4657. Example of _cprintf 
  4658.  
  4659.      _cscanf - Read Data from Keyboard 
  4660.      fprintf - Write Formatted Data to a Stream 
  4661.      printf - Print Formatted Characters 
  4662.      _putch - Write Character to Screen 
  4663.      sprintf - Print Formatted Data to Buffer 
  4664.      <conio.h> 
  4665.  
  4666.  
  4667. ΓòÉΓòÉΓòÉ 4.35. _cputs - Write String to Screen ΓòÉΓòÉΓòÉ
  4668.  
  4669.  
  4670. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4671.  
  4672. #include <conio.h>
  4673. int _cputs(char *str);
  4674.  
  4675.  
  4676. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4677.  
  4678. Language Level:  Extension 
  4679.  
  4680. _cputs writes the string that str points to directly to the screen. The string 
  4681. str must end with a null character (\0). The _cputs function does not 
  4682. automatically add a carriage return followed by a line feed to the string. 
  4683.  
  4684. Return Value 
  4685. If successful, _cputs returns 0. Otherwise, it returns a nonzero value. 
  4686.  
  4687.  
  4688. ΓòÉΓòÉΓòÉ <hidden> Example of _cputs ΓòÉΓòÉΓòÉ
  4689.  
  4690. /************************************************************************
  4691.  
  4692. This example outputs a prompt to the screen. 
  4693.  
  4694. ************************************************************************/
  4695.  
  4696. #include <conio.h>
  4697.  
  4698. int main(void)
  4699. {
  4700.    char *buffer = "Insert data disk in drive a: \r\n";
  4701.  
  4702.    _cputs(buffer);
  4703.    return 0;
  4704.  
  4705.    /****************************************************************************
  4706.       The output should be:
  4707.  
  4708.       Insert data disk in drive a:
  4709.    ****************************************************************************/
  4710. }
  4711.  
  4712.  
  4713. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4714.  
  4715. Example of _cputs 
  4716.  
  4717.      _cgets - Read String of Characters from Keyboard 
  4718.      fputs - Write String 
  4719.      _putch - Write Character to Screen 
  4720.      puts - Write a String 
  4721.      <conio.h> 
  4722.  
  4723.  
  4724. ΓòÉΓòÉΓòÉ 4.36. creat - Create New File ΓòÉΓòÉΓòÉ
  4725.  
  4726.  
  4727. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4728.  
  4729. #include <io.h>
  4730. #include <sys\stat.h>
  4731. int creat(char *pathname, int pmode);
  4732.  
  4733.  
  4734. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4735.  
  4736. Language Level:  XPG4, Extension 
  4737.  
  4738. creat either creates a new file or opens and truncates an existing file. If the 
  4739. file specified by pathname does not exist, creat creates a new file with the 
  4740. given permission setting and opens it for writing in text mode. If the file 
  4741. already exists, and the read-only attribute and sharing permissions allow 
  4742. writing, creat truncates the file to length 0. This action destroys the 
  4743. previous contents of the file and opens it for writing in text mode. creat 
  4744. always opens a file in text mode for reading and writing. 
  4745.  
  4746. The permission setting pmode applies to newly created files only. The new file 
  4747. receives the specified permission setting after you close it for the first 
  4748. time. The pmode integer expression contains one or both of the constants 
  4749. S_IWRITE and S_IREAD, defined in <sys\stat.h>. The values of the pmode argument 
  4750. and their meanings are: 
  4751.  
  4752.  Value                   Meaning 
  4753.  S_IREAD                 Reading permitted 
  4754.  S_IWRITE                Writing permitted 
  4755.  S_IREAD | S_IWRITE      Reading and writing permitted. 
  4756.  
  4757.  If you do not give permission to write to the file, it is a read-only file. 
  4758.  You cannot give write-only permission, thus the modes S_IWRITE and S_IREAD | 
  4759.  S_IWRITE have the same results. The creat function applies the current file 
  4760.  permission mask to pmode before setting the permissions. (See umask - Sets 
  4761.  File Mask of Current Process for more information about file permission 
  4762.  masks.) 
  4763.  
  4764.  When writing new code, you should use open rather than creat. 
  4765.  
  4766.  Specifying a pmode of S_IREAD is similar to making a file read-only with the 
  4767.  ATTRIB system command. 
  4768.  
  4769.  Note:  In earlier releases of VisualAge C++, creat began with an underscore 
  4770.  (_creat). Because it is defined by the X/Open standard, the underscore has 
  4771.  been removed. For compatibility, VisualAge for C++ will map _creat to creat 
  4772.  for you. 
  4773.  
  4774.  Return Value 
  4775.  creat returns a handle for the created file if the call is successful. A 
  4776.  return value of -1 shows an error, and creat sets errno to one of the 
  4777.  following values: 
  4778.  
  4779.  Value          Meaning 
  4780.  EACCESS        File sharing violated. 
  4781.  EINVAL         The mode specified was not valid. 
  4782.  EMFILE         No more file handles are available. 
  4783.  ENOENT         The path name was not found, or the file name was incorrect. 
  4784.  EOS2ERR        The call to the operating system was not successful. 
  4785.  
  4786.  
  4787. ΓòÉΓòÉΓòÉ <hidden> Example of creat ΓòÉΓòÉΓòÉ
  4788.  
  4789. /************************************************************************
  4790.  
  4791. This example creates the file sample.dat so it can be read from and written to. 
  4792.  
  4793. ************************************************************************/
  4794.  
  4795. #include <sys\stat.h>
  4796. #include <io.h>
  4797. #include <stdio.h>
  4798. #include <stdlib.h>
  4799.  
  4800. int main(void)
  4801. {
  4802.    int fh;
  4803.  
  4804.    fh = creat("sample.dat", S_IREAD|S_IWRITE);
  4805.    if (-1 == fh) {
  4806.       perror("Error in creating sample.dat");
  4807.       return EXIT_FAILURE;
  4808.    }
  4809.    else
  4810.       printf("Successfully created sample.dat.\n");
  4811.    close(fh);
  4812.    return 0;
  4813.  
  4814.    /****************************************************************************
  4815.       The output should be:
  4816.  
  4817.        Successfully created sample.dat.
  4818.    ****************************************************************************/
  4819. }
  4820.  
  4821.  
  4822. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4823.  
  4824. Example of creat 
  4825.  
  4826.      chmod - Change File Permission Setting 
  4827.      close - Close File Associated with Handle 
  4828.      open - Open File 
  4829.      fdopen - Associates Input Or Output With File 
  4830.      _sopen - Open Shared File 
  4831.      umask - Sets File Mask of Current Process 
  4832.      <sys\stat.h> 
  4833.      <io.h> 
  4834.  
  4835.  
  4836. ΓòÉΓòÉΓòÉ 4.37. _crotl - _crotr - Rotate Bits of Character Value ΓòÉΓòÉΓòÉ
  4837.  
  4838.  
  4839. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4840.  
  4841. #include <stdlib.h>    /* also in <builtin.h> */
  4842. unsigned char _crotl(unsigned char value, int shift);
  4843. unsigned char _crotr(unsigned char value, int shift);
  4844.  
  4845.  
  4846. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4847.  
  4848. Language Level:  Extension 
  4849.  
  4850. The _crotl and _crotr functions rotate the character value by shift bits. The 
  4851. _crotl function rotates to the left, and _crotr to the right. 
  4852.  
  4853. Note:  Both _crotl and _crotr are built-in functions, which means they are 
  4854. implemented as inline instructions and have no backing code in the library. For 
  4855. this reason: 
  4856.  
  4857.      You cannot take the address of these functions. 
  4858.      You cannot parenthesize a call to either function. (Parentheses specify a 
  4859.       call to the function's backing code, and these functions have none.) 
  4860.  
  4861.  Return Value 
  4862.  
  4863.  Both functions return the rotated value. There is no error return value. 
  4864.  
  4865.  
  4866. ΓòÉΓòÉΓòÉ <hidden> Example of _crotl - _crotr ΓòÉΓòÉΓòÉ
  4867.  
  4868. /************************************************************************
  4869.  
  4870. This example uses _crotl and _crotr with different shift values to rotate the 
  4871. character value: 
  4872.  
  4873. ************************************************************************/
  4874.  
  4875. #include <stdio.h>
  4876. #include <stdlib.h>
  4877.  
  4878. int main(void)
  4879. {
  4880.    unsigned char val = 0X01;
  4881.  
  4882.    printf("The value of 0x%2.2x rotated 4 bits to the left is 0x%2.2x\n", val,
  4883.       _crotl(val, 4));
  4884.    printf("The value of 0x%2.2x rotated 2 bits to the right is 0x%2.2x\n",
  4885.       val, _crotr(val, 2));
  4886.    return 0;
  4887.  
  4888.    /****************************************************************************
  4889.       The output should be:
  4890.  
  4891.       The value of 0x01 rotated 4 bits to the left is 0x10
  4892.       The value of 0x01 rotated 2 bits to the right is 0x40
  4893.    ****************************************************************************/
  4894. }
  4895.  
  4896.  
  4897. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4898.  
  4899. Example of _crotl - _crotr 
  4900.  
  4901.      _lrotl - _lrotr - Rotate Bits of Unsigned Long Value 
  4902.      _rotl - _rotr - Rotate Bits of Unsigned Integer 
  4903.      _srotl - _srotr - Rotate Bits of Unsigned Short Value 
  4904.      <stdlib.h> 
  4905.      <builtin.h> 
  4906.  
  4907.  
  4908. ΓòÉΓòÉΓòÉ 4.38. _CRT_init - Initialize DLL Runtime Environment ΓòÉΓòÉΓòÉ
  4909.  
  4910.  
  4911. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4912.  
  4913. int _CRT_init(void);
  4914. /* no header file - defined in the runtime startup code */
  4915.  
  4916.  
  4917. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4918.  
  4919. Language Level:  Extension 
  4920.  
  4921. _CRT_init initializes the VisualAge for C++ runtime environment for a DLL. 
  4922.  
  4923. By default, all DLLs call the VisualAge for C++ _DLL_InitTerm function, which 
  4924. in turn calls _CRT_init for you. However, if you are writing your own 
  4925. _DLL_InitTerm function (for example, to perform actions other than runtime 
  4926. initialization and termination), you must call _CRT_init from your version of 
  4927. _DLL_InitTerm before you can call any other runtime functions to insure that 
  4928. the runtime library is initialized. If _CRT_init has been called, there must be 
  4929. a matching _CRT_term to insure library termination. 
  4930.  
  4931. If your DLL contains C++ code, you must also call __ctordtorInit after 
  4932. _CRT_init to ensure that static constructors and destructors are initialized 
  4933. properly. The prototype for __ctordtorInit is 
  4934.  
  4935.    void __ctordtorInit(int flag)
  4936.  
  4937. Value 0 for flag means that destructors are called for process termination. 
  4938. Value 1 for flag means that only destructors for thread specific objects in the 
  4939. current thread should be called. 
  4940.  
  4941. Note:  If you are providing your own version of the _matherr function to be 
  4942. used in your DLL, you must also call the _exception_dllinit function after the 
  4943. runtime environment is initialized. Calling this function ensures that the 
  4944. proper _matherr function will be called during exception handling. 
  4945. _exception_dllinit is defined in the runtime startup code as: 
  4946.  
  4947.    void _Optlink _exception_dllinit( int (*)(struct exception *) );
  4948.  
  4949. The parameter required is the address of your _matherr function. 
  4950.  
  4951. Return Value 
  4952. If the runtime environment is successfully initialized, _CRT_init returns 0. A 
  4953. return code of -1 indicates an error. If an error occurs, an error message is 
  4954. written to file handle 2, which is the usual destination of stderr. 
  4955.  
  4956.  
  4957. ΓòÉΓòÉΓòÉ <hidden> Example of _CRT_init ΓòÉΓòÉΓòÉ
  4958.  
  4959. /************************************************************************
  4960.  
  4961. This example shows the _DLL_InitTerm function from the VisualAge for C++ sample 
  4962. program for building DLLs, which calls _CRT_init to initialize the library 
  4963. environment. 
  4964.  
  4965. ************************************************************************/
  4966.  
  4967. #include <windows.h>
  4968. #include <stdlib.h>
  4969. #include <stdio.h>
  4970. #include <string.h>
  4971. #define  CCHMAXPATH  255
  4972. /* _CRT_init is the C run-time environment initialization function.         */
  4973. /* It will return 0 to indicate success and -1 to indicate failure.         */
  4974.  
  4975. int _CRT_init(void);
  4976. #ifdef   STATIC_LINK
  4977.  
  4978. /* _CRT_term is the C run-time environment termination function.            */
  4979. /* It only needs to be called when the C run-time functions are statically  */
  4980. /* linked.                                                                  */
  4981. void _CRT_term(void);
  4982. #else
  4983.  
  4984.  
  4985. static void  cleanup(void);
  4986. #endif
  4987. size_t nSize;
  4988. int *pArray;
  4989.  
  4990. /* _DLL_InitTerm is the function that gets called by the operating system   */
  4991. /* loader when it loads and frees this DLL for each process that accesses   */
  4992. /* this DLL.  However, it only gets called the first time the DLL is loaded */
  4993. /* and the last time it is freed for a particular process.  The system      */
  4994. /* linkage convention MUST be used because the operating system loader is   */
  4995. /* calling this function.                                                   */
  4996.  
  4997. unsigned long _System _DLL_InitTerm(unsigned long hModule, unsigned long
  4998.                                     ulFlag, long * dummy)
  4999. {
  5000.    size_t i;
  5001.    int  rc;
  5002.    char namebuf╤ìCCHMAXPATHΓêÖ;
  5003.  
  5004.    /* If ulFlag is one then the DLL is being loaded so initialization should*/
  5005.    /* be performed.  If ulFlag is zero then the DLL is being freed so       */
  5006.    /* termination should be performed.                                      */
  5007.  
  5008.    switch (ulFlag) {
  5009.       case 1 :
  5010.  
  5011.          /*******************************************************************/
  5012.          /* The C run-time environment initialization function must be      */
  5013.          /* called before any calls to C run-time functions that are not    */
  5014.          /* inlined.                                                        */
  5015.          /*******************************************************************/
  5016.  
  5017.          if (_CRT_init() == -1)
  5018.             return 0UL;
  5019. #ifndef  STATIC_LINK
  5020.  
  5021.          /*******************************************************************/
  5022.          /* Cleanup routine is registered by atexit function to clean up    */
  5023.          /* if the runtime is dynamically linked.                           */
  5024.          /*******************************************************************/
  5025.  
  5026.             if (atexit(cleanup))
  5027.                printf("atexit for cleanup failed\n");
  5028. #endif
  5029.          if ((rc = GetModuleFileName((void *)hModule, namebuf, CCHMAXPATH)) == 0)
  5030.             printf("GetModuleFileName returned %lu\n", GetLastError());
  5031.          else
  5032.             printf("The name of this DLL is %s\n", namebuf);
  5033.          srand(17);
  5034.          nSize = (rand()%128)+32;
  5035.          printf("The array size for this process is %u\n", nSize);
  5036.          if ((pArray = malloc(nSize *sizeof(int))) == NULL) {
  5037.             printf("Could not allocate space for unsorted array.\n");
  5038.             return 0UL;
  5039.          }
  5040.          for (i = 0; i < nSize; ++i)
  5041.             pArray╤ìiΓêÖ = rand();
  5042.          break;
  5043.       case 0 :
  5044. #ifdef   STATIC_LINK
  5045.          printf("The array will now be freed.\n");
  5046.          free(pArray);
  5047.          _CRT_term();
  5048. #endif
  5049.          break;
  5050.       default  :
  5051.          printf("ulFlag = %lu\n", ulFlag);
  5052.          return 0UL;
  5053.    }
  5054.  
  5055.    /* A non-zero value must be returned to indicate success. */
  5056.  
  5057.    return 1UL;
  5058. }
  5059. #ifndef  STATIC_LINK
  5060. static void cleanup(void)
  5061. {
  5062.    printf("The array will now be freed.\n");
  5063.    free(pArray);
  5064.    return ;
  5065. }
  5066. #endif
  5067.  
  5068.  
  5069. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5070.  
  5071. Example of _CRT_init 
  5072.  
  5073.      Building Dynamic Link Libraries in the Programming Guide 
  5074.      _CRT_term - Terminate DLL Runtime Environment 
  5075.      _DLL_InitTerm - Initialize and Terminate DLL Environment 
  5076.      _rmem_init - Initialize Memory Functions for Subsystem DLL 
  5077.      _rmem_term - Terminate Memory Functions for Subsystem DLL 
  5078.  
  5079.  
  5080. ΓòÉΓòÉΓòÉ 4.39. _CRT_term - Terminate DLL Runtime Environment ΓòÉΓòÉΓòÉ
  5081.  
  5082.  
  5083. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5084.  
  5085. void _CRT_term(void);
  5086. /* no header file - defined in runtime startup code */
  5087.  
  5088.  
  5089. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5090.  
  5091. Language Level:  Extension 
  5092.  
  5093. _CRT_term terminates the VisualAge for C++ runtime environment. 
  5094.  
  5095. By default, all DLLs call the VisualAge for C++ _DLL_InitTerm function, which 
  5096. in turn calls _CRT_term for you. However, if you are writing your own 
  5097. _DLL_InitTerm function (for example, to perform actions other than runtime 
  5098. initialization and termination), you must call _CRT_term from your 
  5099. _DLL_InitTerm function. If _CRT_init has been called, there must be a matching 
  5100. _CRT_term to insure library termination. 
  5101.  
  5102. If your DLL contains C++ code, you must also call __ctordtorTerm before you 
  5103. call _CRT_term to ensure that static constructors and destructors are 
  5104. terminated correctly. 
  5105.  
  5106. The prototype for __ctordtorTerm is void_ctordtorTerm( int flag ). Value 0 for 
  5107. flag means that destructors are called for process termination. Value 1 means 
  5108. that only destructors for thread specific objects in the current thread should 
  5109. be called. 
  5110.  
  5111. Once you have called _CRT_term, you cannot call any other library functions. 
  5112.  
  5113. _CRT_term flushes the file buffers, but does not perform a complete library 
  5114. shutdown until the last user of the library calls _CRT_term. This is done by 
  5115. incrementing a use counter in _CRT_init, and decrementing it in _CRT_term. When 
  5116. the count reaches zero, the complete library shutdown occurs (files and 
  5117. semaphores are closed and the heap is destroyed). This prevents premature 
  5118. library shutdown because the DLL termination order is always predictable. 
  5119.  
  5120. Failing to provide a matching call to _CRT_term could, under some 
  5121. circumstances, cause a DLL loaded by DosLoadModule or _loadmod, to fail to 
  5122. release its resources when it is freed. 
  5123.  
  5124. Return Value 
  5125. There is no return value for _CRT_term. 
  5126.  
  5127.  
  5128. ΓòÉΓòÉΓòÉ <hidden> Example of _CRT_term ΓòÉΓòÉΓòÉ
  5129.  
  5130. /************************************************************************
  5131.  
  5132. This example shows the _DLL_InitTerm function from the VisualAge for C++ sample 
  5133. program for building DLLs, which calls _CRT_term to terminate the library 
  5134. environment. 
  5135.  
  5136. ************************************************************************/
  5137.  
  5138. #include <windows.h>
  5139. #include <stdlib.h>
  5140. #include <stdio.h>
  5141. #include <string.h>
  5142. #define  CCHMAXPATH  255
  5143. /* _CRT_init is the C run-time environment initialization function.         */
  5144. /* It will return 0 to indicate success and -1 to indicate failure.         */
  5145.  
  5146. int _CRT_init(void);
  5147. #ifdef   STATIC_LINK
  5148.  
  5149. /* _CRT_term is the C run-time environment termination function.            */
  5150. /* It only needs to be called when the C run-time functions are statically  */
  5151. /* linked.                                                                  */
  5152. void _CRT_term(void);
  5153. #else
  5154.  
  5155.  
  5156. static void  cleanup(void);
  5157. #endif
  5158. size_t nSize;
  5159. int *pArray;
  5160.  
  5161. /* _DLL_InitTerm is the function that gets called by the operating system   */
  5162. /* loader when it loads and frees this DLL for each process that accesses   */
  5163. /* this DLL.  However, it only gets called the first time the DLL is loaded */
  5164. /* and the last time it is freed for a particular process.  The system      */
  5165. /* linkage convention MUST be used because the operating system loader is   */
  5166. /* calling this function.                                                   */
  5167.  
  5168. unsigned long _System _DLL_InitTerm(unsigned long hModule, unsigned long
  5169.                                     ulFlag, long * dummy)
  5170. {
  5171.    size_t i;
  5172.    int  rc;
  5173.    char namebuf╤ìCCHMAXPATHΓêÖ;
  5174.  
  5175.    /* If ulFlag is one then the DLL is being loaded so initialization should*/
  5176.    /* be performed.  If ulFlag is zero then the DLL is being freed so       */
  5177.    /* termination should be performed.                                      */
  5178.  
  5179.    switch (ulFlag) {
  5180.       case 1 :
  5181.  
  5182.          /*******************************************************************/
  5183.          /* The C run-time environment initialization function must be      */
  5184.          /* called before any calls to C run-time functions that are not    */
  5185.          /* inlined.                                                        */
  5186.          /*******************************************************************/
  5187.  
  5188.          if (_CRT_init() == -1)
  5189.             return 0UL;
  5190. #ifndef  STATIC_LINK
  5191.  
  5192.          /*******************************************************************/
  5193.          /* Cleanup routine is registered by atexit function to clean up    */
  5194.          /* if the runtime is dynamically linked.                           */
  5195.          /*******************************************************************/
  5196.  
  5197.             if (atexit(cleanup))
  5198.                printf("atexit for cleanup failed\n");
  5199. #endif
  5200.          if ((rc = GetModuleFileName((void *)hModule, namebuf, CCHMAXPATH)) == 0)
  5201.             printf("GetModuleFileName returned %lu\n", GetLastError());
  5202.          else
  5203.             printf("The name of this DLL is %s\n", namebuf);
  5204.          srand(17);
  5205.          nSize = (rand()%128)+32;
  5206.          printf("The array size for this process is %u\n", nSize);
  5207.          if ((pArray = malloc(nSize *sizeof(int))) == NULL) {
  5208.             printf("Could not allocate space for unsorted array.\n");
  5209.             return 0UL;
  5210.          }
  5211.          for (i = 0; i < nSize; ++i)
  5212.             pArray╤ìiΓêÖ = rand();
  5213.          break;
  5214.       case 0 :
  5215. #ifdef   STATIC_LINK
  5216.          printf("The array will now be freed.\n");
  5217.          free(pArray);
  5218.          _CRT_term();
  5219. #endif
  5220.          break;
  5221.       default  :
  5222.          printf("ulFlag = %lu\n", ulFlag);
  5223.          return 0UL;
  5224.    }
  5225.  
  5226.    /* A non-zero value must be returned to indicate success. */
  5227.  
  5228.    return 1UL;
  5229. }
  5230. #ifndef  STATIC_LINK
  5231. static void cleanup(void)
  5232. {
  5233.    printf("The array will now be freed.\n");
  5234.    free(pArray);
  5235.    return ;
  5236. }
  5237. #endif
  5238.  
  5239.  
  5240. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5241.  
  5242. Example of _CRT_term 
  5243.  
  5244.      Building Dynamic Link Libraries in the Programming Guide 
  5245.      _CRT_init - Initialize DLL Runtime Environment 
  5246.      _DLL_InitTerm - Initialize and Terminate DLL Environment 
  5247.      _rmem_init - Initialize Memory Functions for Subsystem DLL 
  5248.      _rmem_term - Terminate Memory Functions for Subsystem DLL 
  5249.  
  5250.  
  5251. ΓòÉΓòÉΓòÉ 4.40. csid - Determine Character Set ID for Multibyte Character ΓòÉΓòÉΓòÉ
  5252.  
  5253.  
  5254. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5255.  
  5256. #include <stdlib.h>
  5257. int csid(const char *c);
  5258.  
  5259.  
  5260. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5261.  
  5262. Language Level:  Extension 
  5263.  
  5264. csid queries the locale and determines the character-set identifier for the 
  5265. specified character c. 
  5266.  
  5267. Return Value 
  5268. csid returns the character-set identifier, or -1 if the character is not valid. 
  5269.  
  5270.  
  5271. ΓòÉΓòÉΓòÉ <hidden> Example of csid ΓòÉΓòÉΓòÉ
  5272.  
  5273. /************************************************************************
  5274.  
  5275. This example checks the character-set ID for a character. 
  5276.  
  5277. ************************************************************************/
  5278.  
  5279. #include <locale.h>
  5280. #include <stdio.h>
  5281. #include <stdlib.h>
  5282.  
  5283. int main(void)
  5284. {
  5285.    char *string = "A";
  5286.    int   rc;
  5287.  
  5288.    rc = csid(string);
  5289.    printf("character '%s' is in character set id %i\n", string, rc);
  5290.    return 0;
  5291.  
  5292.    /****************************************************************************
  5293.       The output should be similar to :
  5294.  
  5295.       character 'A' is in character set id 0
  5296.    ****************************************************************************/
  5297. }
  5298.  
  5299.  
  5300. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5301.  
  5302. Example of csid 
  5303.  
  5304.      wcsid - Determine Character Set ID for Wide Character 
  5305.  
  5306.      <stdlib.h> 
  5307.  
  5308.  
  5309. ΓòÉΓòÉΓòÉ 4.41. _cscanf - Read Data from Keyboard ΓòÉΓòÉΓòÉ
  5310.  
  5311.  
  5312. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5313.  
  5314. #include <conio.h>
  5315. int _cscanf(char *format-string, argument-list);
  5316.  
  5317.  
  5318. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5319.  
  5320. Language Level:  Extension 
  5321.  
  5322. _cscanf reads data directly from the keyboard to the locations given by 
  5323. argument-list, if any are specified. The _cscanf function uses the _getche 
  5324. function to read characters. Each argument must be a pointer to a variable with 
  5325. a type that corresponds to a type specifier in the format-string. 
  5326.  
  5327. The format-string controls the interpretation of the input fields and has the 
  5328. same form and function as the format-string argument for the scanf function. 
  5329. See scanf for a description of the format-string. 
  5330.  
  5331. Note:  Although _cscanf normally echoes the input character, it does not do so 
  5332. if the last action was a call to _ungetch. 
  5333.  
  5334. Return Value 
  5335. _cscanf returns the number of fields that were successfully converted and 
  5336. assigned. The return value does not include fields that were read but not 
  5337. assigned. 
  5338.  
  5339. The return value is EOF for an attempt to read at the end of the file. A return 
  5340. value of 0 means that no fields were assigned. 
  5341.  
  5342.  
  5343. ΓòÉΓòÉΓòÉ <hidden> Example of _cscanf ΓòÉΓòÉΓòÉ
  5344.  
  5345. /************************************************************************
  5346.  
  5347. This example uses _cscanf to read strings from the screen. 
  5348.  
  5349. ************************************************************************/
  5350.  
  5351. #include <conio.h>
  5352.  
  5353. int main(void)
  5354. {
  5355.    char buffer[24];
  5356.  
  5357.    _cprintf("\nPlease enter a filename:\n");
  5358.    _cscanf("%23s", buffer);
  5359.    _cprintf("\nThe file name you entered was %23s.", buffer);
  5360.    return 0;
  5361.  
  5362.    /****************************************************************************
  5363.       The output should be similar to :
  5364.  
  5365.       Please enter a filename:
  5366.                               file.dat
  5367.       The filename you entered was                file.dat.
  5368.    ****************************************************************************/
  5369. }
  5370.  
  5371.  
  5372. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5373.  
  5374. Example of _cscanf 
  5375.  
  5376.      fscanf - Read Formatted Data 
  5377.      _getch - _getche - Read Character from Keyboard 
  5378.      scanf - Read Data 
  5379.      sscanf - Read Data 
  5380.      _ungetch - Push Character Back to Keyboard 
  5381.      <conio.h> 
  5382.  
  5383.  
  5384. ΓòÉΓòÉΓòÉ 4.42. ctime - Convert Time to Character String ΓòÉΓòÉΓòÉ
  5385.  
  5386.  
  5387. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5388.  
  5389. #include <time.h>
  5390. char *ctime(const time_t *time);
  5391.  
  5392.  
  5393. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5394.  
  5395. Language Level: ANSI, SAA, POSIX, XPG4 
  5396.  
  5397. ctime converts the time value pointed to by time to local time in the form of a 
  5398. character string.  A time value is usually obtained by a call to the time 
  5399. function. 
  5400.  
  5401. The string result produced by ctime contains exactly 26 characters and has the 
  5402. format: 
  5403.  
  5404.    "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n"
  5405. For example: 
  5406.  
  5407.    Mon Jul 16 02:03:55 1987\n\0
  5408.  
  5409. ctime uses a 24-hour clock format.  The days are abbreviated to: Sun, Mon, Tue, 
  5410. Wed, Thu, Fri, and Sat. The months are abbreviated to: Jan, Feb, Mar, Apr, May, 
  5411. Jun, Jul, Aug, Sep, Oct, Nov, and Dec. All fields have a constant width. Dates 
  5412. with only one digit are preceded with a blank space. The new-line character 
  5413. (\n) and the null character (\0) occupy the last two positions of the string. 
  5414.  
  5415. The time and date functions begin at 00:00:00 Universal Time, January 1, 1970. 
  5416.  
  5417. Return Value 
  5418. ctime returns a pointer to the character string result.  There is no error 
  5419. return value. A call to ctime is equivalent to: 
  5420.  
  5421.    asctime(localtime(&anytime))
  5422.  
  5423. Note:  The asctime, ctime, and other time functions may use a common, 
  5424.        statically allocated buffer for holding the return string.  Each call to 
  5425.        one of these functions may destroy the result of the previous call. 
  5426.  
  5427.  
  5428. ΓòÉΓòÉΓòÉ <hidden> Example of ctime ΓòÉΓòÉΓòÉ
  5429.  
  5430. /************************************************************************
  5431.  
  5432. This example polls the system clock using ctime. It then prints a message 
  5433. giving the current date and time. 
  5434.  
  5435. ************************************************************************/
  5436.  
  5437. #include <time.h>
  5438. #include <stdio.h>
  5439.  
  5440. int main(void)
  5441. {
  5442.    time_t ltime;
  5443.  
  5444.    time(<ime);
  5445.    printf("The time is %s", ctime(<ime));
  5446.    return 0;
  5447.  
  5448.    /****************************************************************************
  5449.       The output should be similar to :
  5450.  
  5451.       The time is Thu Dec 15 18:23 1994
  5452.    ****************************************************************************/
  5453. }
  5454.  
  5455.  
  5456. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5457.  
  5458. Example of ctime 
  5459.  
  5460.      asctime - Convert Time to Character String 
  5461.      gmtime - Convert Time 
  5462.      localtime - Convert Time 
  5463.      mktime - Convert Local Time 
  5464.      strftime - Convert to Formatted Time 
  5465.      time - Determine Current Time 
  5466.      <time.h> 
  5467.  
  5468.  
  5469. ΓòÉΓòÉΓòÉ 4.43. _cwait - Wait for Child Process ΓòÉΓòÉΓòÉ
  5470.  
  5471.  
  5472. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5473.  
  5474. #include <process.h>
  5475. int _cwait(int *stat_loc, int process_id, int action_code);
  5476.  
  5477.  
  5478. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5479.  
  5480. Language Level:  Extension 
  5481.  
  5482. _cwait delays the completion of a parent process until the child process 
  5483. specified by process_id ends. 
  5484.  
  5485. The process_id is the value returned by the _spawn function that started the 
  5486. child process. If the specified child process ends before _cwait is called, 
  5487. _cwait returns to the calling process immediately with a value of -1. If the 
  5488. value of process_id is 0, the parent process waits until all of its child 
  5489. processes end. 
  5490.  
  5491. If the variable pointed to by stat_loc is NULL, _cwait does not use it. If it 
  5492. is not NULL, _cwait places information about the return status and the return 
  5493. code of the child process in the location pointed to by stat_loc. 
  5494.  
  5495. If the child process ended normally with a call to the Win32 ExitProcess API, 
  5496. the lowest-order byte of the variable pointed to by stat_loc is 0.  The next 
  5497. highest-order byte contains the lowest-order byte of the argument passed to 
  5498. ExitProcess by the child process. The value of this byte depends on how the 
  5499. child process caused the system to call ExitProcess.  If the child called exit, 
  5500. _exit, or return from main, or used a ExitProcess coded into the program, the 
  5501. byte contains the lowest-order byte of the argument the child passed to exit, 
  5502. _exit, or return. The value of the byte is undefined if the child caused a 
  5503. ExitProcess call simply by reaching the end of main. 
  5504.  
  5505. If the child process ended abnormally (without a call to ExitProcess), the 
  5506. lowest-order byte of the variable pointed to by stat_loc contains the return 
  5507. code from the Win32 GetExitCodeProcess API, and the next higher-order byte is 
  5508. 0. 
  5509.  
  5510. The action_code specifies when the parent process is to start running again. 
  5511. Values for action_code include: 
  5512.  
  5513.  Action Code Meaning 
  5514.  WAIT_CHILD 
  5515.            The parent process waits until the specified child process ends. 
  5516.  WAIT_GRANDCHILD 
  5517.            The parent process waits until the child process and all of the 
  5518.            child processes of that process end. 
  5519.  
  5520.  The action code values are defined in <process.h>. 
  5521.  
  5522.  An alternative to this function is the WaitForSingleObject API call. 
  5523.  
  5524.  Return Value 
  5525.  At the normal end of the child process, _cwait returns the process identifier 
  5526.  of the child to the parent process. If a child process ends abnormally, _cwait 
  5527.  returns -1 to the parent process and sets errno to EINTR. In the case of an 
  5528.  error, _cwait returns immediately with a value of -1 and sets errno to one of 
  5529.  the following values: 
  5530.  
  5531.  Value     Meaning 
  5532.  EINVAL    Incorrect action code. 
  5533.  ECHILD    No child process exists, or the process identifier is incorrect. 
  5534.  
  5535.  
  5536. ΓòÉΓòÉΓòÉ <hidden> Example of _cwait ΓòÉΓòÉΓòÉ
  5537.  
  5538. /************************************************************************
  5539.  
  5540. This example creates a new process called child.exe.  The parent calls _cwait 
  5541. and waits for the child to end.  The parent then displays the child's return 
  5542. information in hexadecimal. 
  5543.  
  5544. ************************************************************************/
  5545.  
  5546. #include <stdio.h>
  5547. #include <process.h>
  5548. #include <errno.h>
  5549.  
  5550. int stat_child;
  5551.  
  5552. int main(void)
  5553. {
  5554.    int i,result;
  5555.  
  5556.    /* spawn a child and 'cwait' for it to finish                              */
  5557.  
  5558.    if ((result = _spawnl(P_NOWAIT, "child", "child", "1", NULL)) != -1) {
  5559.       if ((i = _cwait(&stat_child, result, WAIT_CHILD)) != result)
  5560.          printf("Error ...expected pid from child");
  5561.       else {
  5562.          if (0 == errno) {
  5563.             printf("Child process ended successfully and ...\n");
  5564.             printf("program returned to the Parent process.\n");
  5565.          }
  5566.          else
  5567.             printf("Child process had an error\n");
  5568.       }
  5569.    }
  5570.    else
  5571.       printf("Error ...could not spawn a child process\n");
  5572.    return 0;
  5573.  
  5574.    /****************************************************************************
  5575.  
  5576.       If the source code for child.exe is:
  5577.  
  5578.       #include <stdio.h>
  5579.  
  5580.       int main(void) {
  5581.  
  5582.          puts("This line was written by child.exe");
  5583.          return 0;
  5584.       }
  5585.  
  5586.       The output should be similar to :
  5587.  
  5588.       This line was written by child.exe
  5589.       Child process ended successfully and ...
  5590.       program returned to the Parent process.
  5591.    ****************************************************************************/
  5592. }
  5593.  
  5594.  
  5595. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5596.  
  5597. Example of cwait 
  5598.  
  5599.      exit - End Program 
  5600.      _exit - End Process 
  5601.      _spawnl - _spawnvpe - Start and Run Child Processes 
  5602.      return 
  5603.      <process.h> 
  5604.  
  5605.  
  5606. ΓòÉΓòÉΓòÉ 4.44. __cxchg - Exchange Character Value with Memory ΓòÉΓòÉΓòÉ
  5607.  
  5608.  
  5609. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5610.  
  5611. #include <builtin.h>
  5612. signed char _Builtin __cxchg(volatile signed char *lockptr,
  5613.                              signed char value);
  5614.  
  5615.  
  5616. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5617.  
  5618. Language Level:  Extension 
  5619.  
  5620. __cxchg puts the specified value in the memory location pointed to by lockptr, 
  5621. and returns the value that was previously in that location. 
  5622.  
  5623. Use this function to implement fast-RAM semaphores to serialize access to a 
  5624. critical resource (so that only one thread can use it at a time). 
  5625.  
  5626.  
  5627. You can also use Win32 semaphores to serialize resource access, but they are 
  5628. slower. Typically you would create both a fast-RAM semaphore and an Win32 
  5629. semaphore for the resource. For more details about Win32 semaphores and how to 
  5630. use them, see the Win32 Programmer's Reference. 
  5631.  
  5632. To implement a fast-RAM semaphore, allocate a volatile memory location (for 
  5633. __cxchg, it must be a signed char), and statically initialize it to 0 to 
  5634. indicate that the resource is free (not being used). To give a thread access to 
  5635. the resource, call __cxchg from the thread to exchange a nonzero value with 
  5636. that memory location. If __cxchg returns 0, the thread can access the resource; 
  5637. it has also set the memory location so that other threads can tell the resource 
  5638. is in use. When your thread no longer needs the resource, call __cxchg again to 
  5639. reset the memory location to 0. 
  5640.  
  5641. If __cxchg returns a nonzero value, another thread is already using the 
  5642. resource, and the calling thread must wait for access. You could then use the 
  5643. Windows semaphore to inform your waiting thread when the resource is unlocked 
  5644. by the thread currently using it. 
  5645.  
  5646. It is important that you set the memory to a nonzero value when you are using 
  5647. the resource.  You can use the same nonzero value for all threads, or a unique 
  5648. value for each. 
  5649.  
  5650. Note:  __cxchg is a built-in function, which means it is implemented as an 
  5651. inline instruction and has no backing code in the library.  For this reason: 
  5652.  
  5653.      You cannot take the address of __cxchg. 
  5654.      You cannot parenthesize a call to __cxchg. (Parentheses specify a call to 
  5655.       the function's backing code, and __cxchg has none.) 
  5656.  
  5657.  Return Value 
  5658.  __cxchg returns the previous value stored in the memory location pointed to by 
  5659.  lockptr. 
  5660.  
  5661.  
  5662. ΓòÉΓòÉΓòÉ <hidden> Example of __cxchg ΓòÉΓòÉΓòÉ
  5663.  
  5664. /************************************************************************
  5665.  
  5666. This example creates five separate threads, each associated with a State. At 
  5667. most two threads can have a State of Eating at the same time. When a thread 
  5668. calls PickUpChopSticks, that function checks the states of the preceding 
  5669. threads to make sure they are not already Eating. If the call to __cxchg is 
  5670. successful, the thread has locked the Lock semaphore and can change its State 
  5671. to Eating. It then calls __cxchg a second time to unlock the semaphore, and 
  5672. returns. 
  5673.  
  5674. If __cxchg cannot lock the semaphore, another thread has it locked.  The 
  5675. current thread then suspends itself briefly with Sleep and tries again. The 
  5676. semaphore is used to ensure that two threads cannot simultaneously change their 
  5677. State to Eating, which would cause a deadlock. (Note that although the 
  5678. semaphore solves the problem of deadlock, it is not an optimal solution; some 
  5679. threads may never get the semaphore or the State of Eating.) 
  5680.  
  5681. Note:  You must compile this example with the multithread (/Gm) option. The 
  5682. example runs in an infinite loop; press Ctrl-C to end it. 
  5683.  
  5684. ************************************************************************/
  5685.  
  5686.    #pragma strings(readonly)
  5687.  
  5688. #if  (1 == __TOS_OS2__)
  5689.       #define   INCL_DOS                             /*  For OS/2  */
  5690.       #include <os2.h>
  5691.       #define SLEEP  DosSleep(1)
  5692. #else
  5693.      #include <windows.h>                          /*  For Windows  */
  5694.      #define SLEEP  Sleep(1)
  5695. #endif
  5696.  
  5697.    #include <stdlib.h>
  5698.    #include <stdio.h>
  5699.    #include <builtin.h>
  5700.  
  5701.    typedef enum {
  5702.       Thinking,
  5703.       Eating,
  5704.       Hungry
  5705.    } States;
  5706.  
  5707.    #define UNLOCKED 0
  5708.    #define LOCKED   1
  5709.    #define NUM_PHILOSOPHERS 5
  5710.  
  5711.    static volatile unsigned char Lock;
  5712.    static States State[NUM_PHILOSOPHERS];
  5713.    static const int NameMap[NUM_PHILOSOPHERS] = {0, 1, 2, 3, 4};
  5714.    static const char * const Names[NUM_PHILOSOPHERS] = {"Plato",
  5715.                                                         "Socrates",
  5716.                                                         "Kant",
  5717.                                                         "Hegel",
  5718.                                                         "Nietsche"};
  5719.  
  5720.    void PickUpChopSticks(int Ident);
  5721.    void PutDownChopSticks(int Ident);
  5722.    void Think(int Ident);
  5723.    void Eat(int Ident);
  5724.    void _Optlink StartPhilosopher( void *pIdent );
  5725.  
  5726.    void _Optlink StartPhilosopher( void *pIdent )
  5727.    {
  5728.       int Ident = *(int *)pIdent;
  5729.       while (1) {
  5730.          State[Ident] = Hungry;
  5731.          printf("%s hungry.\n", Names[Ident]);
  5732.          PickUpChopSticks(Ident);
  5733.          Eat(Ident);
  5734.          PutDownChopSticks(Ident);
  5735.          Think(Ident);
  5736.       }
  5737.    }
  5738.  
  5739.    int main(int argc, char *argv[], char *envp[])
  5740.    {
  5741.       int           i;
  5742.       unsigned long tid;
  5743.  
  5744.       for (i = 0; i < NUM_PHILOSOPHERS; i++) {
  5745.          tid = _beginthread( StartPhilosopher, NULL, 8192, (void*)&NameMap[i]);
  5746.          if (tid == -1) {
  5747.  
  5748.             printf("Unable to start %s.\n", Names[i]);
  5749.          }
  5750.          else {
  5751.             printf("%s started with Thread Id = %d.\n", Names[i], tid);
  5752.          }
  5753.       }
  5754. #if  (1 == __TOS_OS2__)
  5755.       DosWaitThread(&tid, DCWW_WAIT);
  5756. #else
  5757.       WaitForSingleObject((HANDLE)tid, INFINITE);
  5758. #endif
  5759.       return 0;
  5760.    }
  5761.  
  5762.    void PickUpChopSticks(int Ident)
  5763.    {
  5764.       while (1) {
  5765.          if (State[(Ident + NUM_PHILOSOPHERS - 1) % NUM_PHILOSOPHERS] != Eating &&
  5766.              State[(Ident + 1) % NUM_PHILOSOPHERS] != Eating                    &&
  5767.              !__cxchg(&Lock, LOCKED)) {
  5768.                State[Ident] = Eating;
  5769.                __cxchg(&Lock, UNLOCKED);
  5770.                return;
  5771.          }
  5772.          else {
  5773.             SLEEP;
  5774.          }
  5775.       }
  5776.    }
  5777.  
  5778.    void PutDownChopSticks(int Ident)
  5779.    {
  5780.       State[Ident] = Thinking;
  5781.    }
  5782.  
  5783.    void Eat(int Ident)
  5784.    {
  5785.       printf("%s eating.\n", Names[Ident]);
  5786.       SLEEP;
  5787.    }
  5788.  
  5789.    void Think(int Ident)
  5790.    {
  5791.       printf("%s thinking.\n", Names[Ident]);
  5792.       SLEEP;
  5793.    }
  5794.  
  5795.  
  5796. /****************************************************************************
  5797.          The output should be similar to :
  5798.  
  5799.          Plato started with Thread Id = 2.
  5800.          Socrates started with Thread Id = 3.
  5801.          Kant started with Thread Id = 4.
  5802.          Hegel started with Thread Id = 5.
  5803.          Nietsche started with Thread Id = 6.
  5804.          Plato hungry.
  5805.          Plato eating.
  5806.          Socrates hungry.
  5807.          Kant hungry.
  5808.          Kant eating.
  5809.          Hegel hungry.
  5810.          Nietsche hungry.
  5811.          Kant thinking.
  5812.          Plato thinking.
  5813.          Plato hungry.
  5814.          Plato eating.
  5815.          Kant hungry.
  5816.          Kant eating.
  5817.             :
  5818.  
  5819. ****************************************************************************/
  5820.  
  5821.  
  5822. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5823.  
  5824. Exampleof __cxchg 
  5825.  
  5826.      __lxchg - Exchange Integer Value with Memory 
  5827.      __sxchg - Exchange Integer Value with Memory 
  5828.      <builtin.h> 
  5829.  
  5830.  
  5831. ΓòÉΓòÉΓòÉ 4.45. _debug_calloc - Allocate and Initialize Memory ΓòÉΓòÉΓòÉ
  5832.  
  5833.  
  5834. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5835.  
  5836. #include <stdlib.h>   /* also in <malloc.h> */
  5837. void *_debug_calloc(size_t num, size_t size,
  5838.                     const char *file, size_t line);
  5839.  
  5840.  
  5841. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5842.  
  5843. Language Level:  Extension 
  5844.  
  5845. _debug_calloc is the debug version of calloc. Like calloc, it allocates memory 
  5846. from the default heap for an array of num elements, each of length size bytes. 
  5847. It then initializes all bits of each element to 0. 
  5848.  
  5849. In addition, _debug_calloc makes an implicit call to _heap_check, and stores 
  5850. the name of the file file and the line number line where the storage is 
  5851. allocated. This information can be used later by the _heap_check and 
  5852. _dump_allocated or _dump_allocated_delta functions. 
  5853.  
  5854. To use _debug_calloc, you must compile with the debug memory (/Tm) compiler 
  5855. option. This option maps all calloc calls to _debug_calloc (you can also call 
  5856. _debug_calloc explicitly). 
  5857.  
  5858. Note:  The /Tm option maps all calls to memory management functions (including 
  5859. a heap-specific version) to their debug counterparts. To prevent a call from 
  5860. being mapped, parenthesize the function name. 
  5861.  
  5862. To reallocate or free memory allocated by _debug_calloc, use _debug_realloc and 
  5863. _debug_free; you can also use realloc and free if you do not want debug 
  5864. information about the operation. 
  5865.  
  5866. A heap-specific version of this function (_debug_ucalloc) is also available. 
  5867. _debug_calloc always allocates memory from the default heap. 
  5868.  
  5869. Return Value 
  5870. _debug_calloc returns a pointer to the reserved space. If not enough memory is 
  5871. available, or if num or size is 0, _debug_calloc returns NULL. 
  5872.  
  5873.  
  5874. ΓòÉΓòÉΓòÉ <hidden> Example of _debug_calloc ΓòÉΓòÉΓòÉ
  5875.  
  5876. /************************************************************************
  5877.  
  5878. This example reserves storage of 100 bytes.  It then attempts to write to 
  5879. storage that was not allocated.  When _debug_calloc is called again, 
  5880. _heap_check detects the error, generates several messages, and stops the 
  5881. program. 
  5882.  
  5883. Note:  You must compile this example with the /Tm option to map the calloc 
  5884. calls to _debug_calloc. 
  5885.  
  5886. ************************************************************************/
  5887.  
  5888. #include <stdlib.h>
  5889. #include <stdio.h>
  5890. #include <string.h>
  5891.  
  5892. int main(void)
  5893. {
  5894.    char *ptr1, *ptr2;
  5895.  
  5896.    if (NULL == (ptr1 = (char*)calloc(1, 100))) {
  5897.       puts("Could not allocate memory block.");
  5898.       exit(EXIT_FAILURE);
  5899.    }
  5900.    memset(ptr1, 'a', 105);    /* overwrites storage that was not allocated    */
  5901.    ptr2 = (char*)calloc(2, 20);      /* this call to calloc invokes _heap_check      */
  5902.    puts("_debug_calloc did not detect that a memory block was overwritten.");
  5903.    return 0;
  5904.  
  5905.    /****************************************************************************
  5906.       The output should be similar to:
  5907.  
  5908.       End of allocated object 0x00073890 was overwritten at 0x000738f4.
  5909.       The first eight bytes of the memory block (in hex) are: 6161616161616161.
  5910.       This memory block was (re)allocated at line number 9 in _debug_callo.c.
  5911.       Heap state was valid at line 9 of _debug_callo.c.
  5912.       Memory error detected at line 14 of _debug_callo.c.
  5913.    ****************************************************************************/
  5914. }
  5915.  
  5916.  
  5917. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5918.  
  5919. Example of _debug_calloc 
  5920.  
  5921.      Memory Management in the Programming Guide 
  5922.      Debugging Your Heaps in the Programming Guide 
  5923.      Differentiating between Memory Management Functions 
  5924.      <malloc.h> 
  5925.      <stdlib.h> 
  5926.      calloc - Reserve and Initialize Storage 
  5927.      _debug_ucalloc - Reserve and Initialize Memory from User Heap 
  5928.      _debug_free - Release Memory 
  5929.      _debug_malloc - Allocate Memory 
  5930.      _debug_realloc - Reallocate Memory Block 
  5931.      _dump_allocated - Get Information about Allocated Memory 
  5932.      _dump_allocated_delta - Get Information about Allocated Memory 
  5933.      _heap_check - Validate Default Memory Heap 
  5934.  
  5935.  
  5936. ΓòÉΓòÉΓòÉ 4.46. _debug_free - Release Memory ΓòÉΓòÉΓòÉ
  5937.  
  5938.  
  5939. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5940.  
  5941. #include <stdlib.h>    /* also in <malloc.h> */
  5942. void _debug_free(void *ptr, const char *file,
  5943.                         size_t line);
  5944.  
  5945.  
  5946. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5947.  
  5948. Language Level:  Extension 
  5949.  
  5950. _debug_free is the debug version of free. Like free, it frees the block of 
  5951. memory pointed to by ptr. _debug_free also sets each block of freed memory to 
  5952. 0xFB, so you can easily locate instances where your program uses the data in 
  5953. freed memory. 
  5954.  
  5955. In addition, _debug_free makes an implicit call to the _heap_check, and stores 
  5956. the file name file and the line number line where the memory is freed. This 
  5957. information can be used later by the _heap_check and _dump_allocated or 
  5958. _dump_allocated_delta functions. 
  5959.  
  5960. To use _debug_free, you must compile with the debug memory (/Tm) compiler 
  5961. option. This option maps all free calls to _debug_free (you can also call 
  5962. _debug_free explicitly). 
  5963.  
  5964. Note:  The /Tm option maps all calls to memory management functions (including 
  5965. a heap-specific version) to their debug counterparts. To prevent a call from 
  5966. being mapped, parenthesize the function name. 
  5967.  
  5968. Because _debug_free always checks what heap the memory was allocated from, you 
  5969. can use _debug_free to free memory blocks allocated by the regular, 
  5970. heap-specific, or debug versions of the memory management functions. However, 
  5971. if the memory was not allocated by the memory management functions, or was 
  5972. previously freed, _debug_free generates an error message and the program ends. 
  5973.  
  5974. Return Value 
  5975. There is no return value. 
  5976.  
  5977.  
  5978. ΓòÉΓòÉΓòÉ <hidden> Example of _debug_free ΓòÉΓòÉΓòÉ
  5979.  
  5980. /************************************************************************
  5981.  
  5982. This example reserves two blocks, one of 10 bytes and the other of 20 bytes. 
  5983. It then frees the first block and attempts to overwrite the freed storage. When 
  5984. _debug_free is called a second time, _heap_check detects the error, prints out 
  5985. several messages, and stops the program. 
  5986.  
  5987. Note:  You must compile this example with the /Tm option to map the free calls 
  5988. to _debug_free. 
  5989.  
  5990. ************************************************************************/
  5991.  
  5992. #include <stdlib.h>
  5993. #include <stdio.h>
  5994. #include <string.h>
  5995.  
  5996. int main(void)
  5997. {
  5998.    char *ptr1, *ptr2;
  5999.  
  6000.    if (NULL == (ptr1 = (char*)malloc(10)) || NULL == (ptr2 = (char*)malloc(20))) {
  6001.       puts("Could not allocate memory block.");
  6002.       exit(EXIT_FAILURE);
  6003.    }
  6004.    free(ptr1);
  6005.    memset(ptr1, 'a', 5);      /* overwrites storage that has been freed       */
  6006.    free(ptr2);                 /* this call to free invokes _heap_check       */
  6007.    puts("_debug_free did not detect that a freed memory block was overwritten.");
  6008.    return 0;
  6009.  
  6010.    /****************************************************************************
  6011.       The output should be similar to:
  6012.  
  6013.       Free heap was overwritten at 0x00073890.
  6014.       Heap state was valid at line 12 of _debug_free.c.
  6015.       Memory error detected at line 14 of _debug_free.c.
  6016.    ****************************************************************************/
  6017. }
  6018.  
  6019.  
  6020. ΓòÉΓòÉΓòÉ <hidden> Information ΓòÉΓòÉΓòÉ
  6021.  
  6022. Example of _debug_free 
  6023.  
  6024.      Memory Management in the Programming Guide 
  6025.      Debugging Your Heaps in the Programming Guide 
  6026.      Differentiating between Memory Management Functions 
  6027.      _debug_calloc - Allocate and Initialize Memory 
  6028.      _debug_malloc - Allocate Memory 
  6029.      _debug_realloc - Reallocate Memory Block 
  6030.      _dump_allocated - Get Information about Allocated Memory 
  6031.      _dump_allocated_delta - Get Information about Allocated Memory 
  6032.      free - Release Storage Blocks 
  6033.      _heap_check - Validate Default Memory Heap 
  6034.      <malloc.h> 
  6035.      <stdlib.h> 
  6036.  
  6037.  
  6038. ΓòÉΓòÉΓòÉ 4.47. _debug_heapmin - Release Unused Memory in the Default Heap ΓòÉΓòÉΓòÉ
  6039.  
  6040.  
  6041. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6042.  
  6043. #include <stdlib.h>  /* also in <malloc.h> */
  6044. int _debug_heapmin(const char *file, size_t line);
  6045.  
  6046.  
  6047. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6048.  
  6049. Language Level:  Extension 
  6050.  
  6051. _debug_heapmin is the debug version of _heapmin. Like _heapmin, It returns all 
  6052. unused memory from the default runtime heap to the operating system. 
  6053.  
  6054. In addition, _debug_heapmin makes an implicit call to _heap_check, and stores 
  6055. the file name file and the line number line where the memory is returned.  This 
  6056. information can be used later by the _heap_check function. 
  6057.  
  6058. To use _debug_heapmin, you must compile with the debug memory (/Tm) compiler 
  6059. option. This option maps all _heapmin calls to _debug_heapmin (you can also 
  6060. call _debug_heapmin explicitly). 
  6061.  
  6062. Note:  The /Tm option maps all calls to memory management functions (including 
  6063. a heap-specific version) to their debug counterparts. To prevent a call from 
  6064. being mapped, parenthesize the function name. 
  6065.  
  6066. A heap-specific version of this function (_debug_uheapmin) is also available. 
  6067. _debug_heapmin always operates on the default heap. 
  6068.  
  6069. Return Value 
  6070. If successful, _debug_heapmin returns 0; otherwise, it returns -1. 
  6071.  
  6072.  
  6073. ΓòÉΓòÉΓòÉ <hidden> Example of _debug_heapmin ΓòÉΓòÉΓòÉ
  6074.  
  6075. /************************************************************************
  6076.  
  6077. This example allocates 10000 bytes of storage, changes the storage size to 10 
  6078. bytes, and then uses _debug_heapmin to return the unused memory to the 
  6079. operating system. The program then attempts to overwrite memory that was not 
  6080. allocated. When _debug_heapmin is called again, _heap_check detects the error, 
  6081. generates several messages, and stops the program. 
  6082.  
  6083. Note:  You must compile this example with the /Tm option to map the _heapmin 
  6084. calls to _debug_heapmin. 
  6085.  
  6086. ************************************************************************/
  6087.  
  6088. #include <stdlib.h>
  6089. #include <stdio.h>
  6090.  
  6091. int main(void)
  6092. {
  6093.    char *ptr;
  6094.  
  6095.    /* Allocate a large object from the system */
  6096.    if (NULL == (ptr = (char*)malloc(100000))) {
  6097.       puts("Could not allocate memory block.");
  6098.       exit(EXIT_FAILURE);
  6099.    }
  6100.    ptr = (char*)realloc(ptr, 10);
  6101.    _heapmin();                /* No allocation problems to detect             */
  6102.  
  6103.    *(ptr - 1) = 'a';          /* Overwrite memory that was not allocated      */
  6104.    _heapmin();                /* This call to _heapmin invokes _heap_check    */
  6105.  
  6106.    puts("_debug_heapmin did not detect that a non-allocated memory block"
  6107.         "was overwritten.");
  6108.    return 0;
  6109.  
  6110.    /****************************************************************************
  6111.       Possible output is:
  6112.  
  6113.       Header information of object 0x000738b0 was overwritten at 0x000738ac.
  6114.       The first eight bytes of the memory block (in hex) are: AAAAAAAAAAAAAAAA.
  6115.       This memory block was (re)allocated at line number 13 in _debug_heapm.c.
  6116.       Heap state was valid at line 14 of _debug_heapm.c.
  6117.       Memory error detected at line 17 of _debug_heapm.c.
  6118.    ****************************************************************************/
  6119. }
  6120.  
  6121.  
  6122. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6123.  
  6124. Example of _debug_heapmin 
  6125.  
  6126.      Memory Management in the Programming Guide 
  6127.      Debugging Your Heaps in the Programming Guide 
  6128.      Differentiating between Memory Management Functions 
  6129.      _debug_heapmin - Release Unused Memory in the Default Heap 
  6130.      _dump_allocated - Get Information about Allocated Memory 
  6131.      _dump_allocated_delta - Get Information about Allocated Memory 
  6132.      _heapmin - Release Unused Memory from Default Heap 
  6133.      _heap_check - Validate Default Memory Heap 
  6134.      <malloc.h> 
  6135.      <stdlib.h> 
  6136.  
  6137.  
  6138. ΓòÉΓòÉΓòÉ 4.48. _debug_malloc - Allocate Memory ΓòÉΓòÉΓòÉ
  6139.  
  6140.  
  6141. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6142.  
  6143. #include <stdlib.h>  /* also in <malloc.h> */
  6144. void *_debug_malloc(size_t size,
  6145.                     const char *file, size_t line);
  6146.  
  6147.  
  6148. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6149.  
  6150. Language Level:  Extension 
  6151.  
  6152. _debug_malloc is the debug version of malloc. Like malloc, it reserves a block 
  6153. of storage of size bytes from the default heap. _debug_malloc also sets all the 
  6154. memory it allocates to 0xAA, so you can easily locate instances where your 
  6155. program uses the data in the memory without initializing it first. 
  6156.  
  6157. In addition, _debug_malloc makes an implicit call to _heap_check, and stores 
  6158. the file name file and the line number line where the storage is allocated. 
  6159. This information can later be used by the _heap_check and _dump_allocated or 
  6160. _dump_allocated_delta functions. 
  6161.  
  6162. To use _debug_malloc, you must compile with the debug memory (/Tm) compiler 
  6163. option. This option maps all malloc calls to _debug_malloc (you can also call 
  6164. _debug_malloc explicitly). 
  6165.  
  6166. Note:  The /Tm option maps all calls to memory management functions (including 
  6167. a heap-specific version) to their debug counterparts. To prevent a call from 
  6168. being mapped, parenthesize the function name. 
  6169.  
  6170. To reallocate or free memory allocated by _debug_malloc, use _debug_realloc and 
  6171. _debug_free; you can also use realloc and free if you do not want debug 
  6172. information about the operation. 
  6173.  
  6174. A heap-specific version of this function (_debug_umalloc) is also available. 
  6175.  
  6176.  
  6177. _debug_malloc always allocates memory from the default heap. 
  6178.  
  6179. Return Value 
  6180. _debug_malloc returns a pointer to the reserved space. If not enough memory is 
  6181. available or if size is 0, _debug_malloc returns NULL. 
  6182.  
  6183.  
  6184. ΓòÉΓòÉΓòÉ <hidden> Example of _debug_malloc ΓòÉΓòÉΓòÉ
  6185.  
  6186. /************************************************************************
  6187.  
  6188. This example allocates 100 bytes of storage.  It then attempts to write to 
  6189. storage that was not allocated. When _debug_malloc is called again, _heap_check 
  6190. detects the error, generates several messages, and stops the program. 
  6191.  
  6192. Note:  You must compile this example with the /Tm option to map the malloc 
  6193. calls to _debug_malloc. 
  6194.  
  6195. ************************************************************************/
  6196.  
  6197. #include <stdlib.h>
  6198. #include <stdio.h>
  6199.  
  6200. int main(void)
  6201. {
  6202.    char *ptr1, *ptr2;
  6203.  
  6204.    if (NULL == (ptr1 = (char*)malloc(100))) {
  6205.       puts("Could not allocate memory block.");
  6206.       exit(EXIT_FAILURE);
  6207.    }
  6208.    *(ptr1 - 1) = 'a';        /* overwrites storage that was not allocated    */
  6209.    ptr2 = (char*)malloc(10); /* this call to malloc invokes _heap_check      */
  6210.    puts("_debug_malloc did not detect that a memory block was overwritten.");
  6211.    return 0;
  6212.  
  6213.    /****************************************************************************
  6214.       Possible output is:
  6215.  
  6216.       Header information of object 0x00073890 was overwritten at 0x0007388c.
  6217.       The first eight bytes of the memory block (in hex) are: AAAAAAAAAAAAAAAA.
  6218.       This memory block was (re)allocated at line number 8 in _debug_mallo.c.
  6219.       Heap state was valid at line 8 of _debug_mallo.c.
  6220.       Memory error detected at line 13 of _debug_mallo.c.
  6221.    ****************************************************************************/
  6222. }
  6223.  
  6224.  
  6225. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6226.  
  6227. Example of _debug_malloc 
  6228.  
  6229.      Memory Management in the Programming Guide 
  6230.      Debugging Your Heaps in the Programming Guide 
  6231.      Differentiating between Memory Management Functions 
  6232.      _debug_calloc - Allocate and Initialize Memory 
  6233.      _debug_free - Release Memory 
  6234.      _debug_realloc - Reallocate Memory Block 
  6235.      _debug_umalloc - Reserve Memory Blocks from User Heap 
  6236.      _dump_allocated - Get Information about Allocated Memory 
  6237.      _dump_allocated_delta - Get Information about Allocated Memory 
  6238.      _heap_check - Validate Default Memory Heap 
  6239.      malloc - Reserve Storage Block 
  6240.      <malloc.h> 
  6241.      <stdlib.h> 
  6242.  
  6243.  
  6244. ΓòÉΓòÉΓòÉ 4.49. _debug_realloc - Reallocate Memory Block ΓòÉΓòÉΓòÉ
  6245.  
  6246.  
  6247. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6248.  
  6249. #include <stdlib.h>  /* also in <malloc.h> */
  6250. void *_debug_realloc(void *ptr, size_t size,
  6251.                      const char *file, size_t line);
  6252.  
  6253.  
  6254. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6255.  
  6256. Language Level:  Extension 
  6257.  
  6258. _debug_realloc is the debug version of realloc. Like realloc, it reallocates 
  6259. the block of memory pointed to by ptr to a new size, specified in bytes. It 
  6260. also sets any new memory  it allocates to 0xAA, so you can easily locate 
  6261. instances where your program tries to use the data in that memory without 
  6262. initializing it first. 
  6263.  
  6264. In addition, _debug_realloc makes an implicit call to _heap_check, and stores 
  6265. the file name file and the line number line where the storage is reallocated. 
  6266. This information can be used later by the _heap_check and _dump_allocated or 
  6267. _dump_allocated_delta functions. 
  6268.  
  6269. If ptr is NULL, _debug_realloc behaves like _debug_malloc (or malloc) and 
  6270. allocates the block of memory. 
  6271.  
  6272. To use _debug_realloc, you must compile with the debug memory (/Tm) compiler 
  6273. option. This option maps all realloc calls to _debug_realloc (you can also call 
  6274. _debug_realloc explicitly). 
  6275.  
  6276. Note:  The /Tm option maps all calls to memory management functions (including 
  6277. a heap-specific version) to their debug counterparts. To prevent a call from 
  6278. being mapped, parenthesize the function name. 
  6279.  
  6280. Because _debug_realloc always checks what heap the memory was allocated from, 
  6281. you can use _debug_realloc to reallocate memory blocks allocated by the 
  6282. regular, or debug versions of the memory management functions.  However, if the 
  6283. memory was not allocated by the memory management functions, or was previously 
  6284. freed, _debug_realloc generates an error message and the program ends. 
  6285.  
  6286. Return Value 
  6287. _debug_realloc returns a pointer to the reallocated memory block. The ptr 
  6288. argument to _debug_realloc is not the same as the return value; _debug_realloc 
  6289. always changes the memory location to help you locate references to the memory 
  6290. that were not freed before the memory was reallocated. 
  6291.  
  6292. If size is 0, _debug_realloc returns NULL. If not enough memory is available to 
  6293. expand the block to the given size, the original block is unchanged and NULL is 
  6294. returned. 
  6295.  
  6296.  
  6297. ΓòÉΓòÉΓòÉ <hidden> Example of _debug_realloc ΓòÉΓòÉΓòÉ
  6298.  
  6299. /************************************************************************
  6300.  
  6301. This example uses _debug_realloc to allocate 100 bytes of storage. It then 
  6302. attempts to write to storage that was not allocated. When _debug_realloc is 
  6303. called again, _heap_check detects the error, generates several messages, and 
  6304. stops the program. 
  6305.  
  6306. Note:  You must compile this example with the /Tm option to map the realloc 
  6307. calls to _debug_realloc. 
  6308.  
  6309. ************************************************************************/
  6310.  
  6311. #include <stdlib.h>
  6312. #include <stdio.h>
  6313. #include <string.h>
  6314.  
  6315. int main(void)
  6316. {
  6317.    char *ptr;
  6318.  
  6319.    if (NULL == (ptr = (char*)realloc(NULL, 100))) {
  6320.       puts("Could not allocate memory block.");
  6321.       exit(EXIT_FAILURE);
  6322.    }
  6323.    memset(ptr, 'a', 105);     /* overwrites storage that was not allocated    */
  6324.    ptr = (char*)realloc(ptr, 200);        /*  realloc invokes _heap_check     */
  6325.    puts("_debug_realloc did not detect that a memory block was overwritten." );
  6326.    return 0;
  6327.  
  6328.    /****************************************************************************
  6329.       The output should be similar to:
  6330.  
  6331.       End of allocated object 0x00073890 was overwritten at 0x000738f4.
  6332.       The first eight bytes of the memory block (in hex) are: 6161616161616161.
  6333.       This memory block was (re)allocated at line number 8 in _debug_reall.c.
  6334.       Heap state was valid at line 8 of _debug_reall.c.
  6335.       Memory error detected at line 13 of _debug_reall.c.
  6336.    ****************************************************************************/
  6337. }
  6338.  
  6339.  
  6340. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6341.  
  6342. Example of _debug_realloc 
  6343.  
  6344.      Memory Management in the Programming Guide 
  6345.      Debugging Your Heaps in the Programming Guide 
  6346.      Differentiating between Memory Management Functions 
  6347.      _debug_calloc - Allocate and Initialize Memory 
  6348.      _debug_free - Release Memory 
  6349.      _debug_malloc - Allocate Memory 
  6350.      _dump_allocated - Get Information about Allocated Memory 
  6351.      _dump_allocated_delta - Get Information about Allocated Memory 
  6352.      _heap_check - Validate Default Memory Heap 
  6353.      realloc - Change Reserved Storage Block Size 
  6354.      <malloc.h> 
  6355.      <stdlib.h> 
  6356.  
  6357.  
  6358. ΓòÉΓòÉΓòÉ 4.50. _debug_ucalloc - Reserve and Initialize Memory from User Heap ΓòÉΓòÉΓòÉ
  6359.  
  6360.  
  6361. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6362.  
  6363. #include <umalloc.h>
  6364. void *_debug_ucalloc(Heap_t heap, size_t num, size_t size,
  6365.                      const char *file, size_t line);
  6366.  
  6367.  
  6368. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6369.  
  6370. Language Level:  Extension 
  6371.  
  6372. _debug_ucalloc is the debug version of _ucalloc. Like _ucalloc, it allocates 
  6373. memory from the heap you specify for an array of num elements, each of length 
  6374. size bytes. It then initializes all bits of each element to 0. 
  6375.  
  6376. In addition, _debug_ucalloc makes an implicit call to _uheap_check, and stores 
  6377. the name of the file file and the line number line where the storage is 
  6378. allocated. This information can be used later by the _uheap_check and 
  6379. _udump_allocated or _udump_allocated_delta functions. 
  6380.  
  6381. To use _debug_ucalloc, you must compile with the debug memory (/Tm) compiler 
  6382. option. the /Tm compiler option. This option maps all _ucalloc calls to 
  6383. _debug_ucalloc (you can also call _debug_ucalloc explicitly). 
  6384.  
  6385. Note:  The /Tm option maps all calls to memory management functions (including 
  6386. heap-specific versions) to their debug counterparts. To prevent a call from 
  6387. being mapped, parenthesize the function name. 
  6388.  
  6389. _debug_ucalloc works just like _debug_calloc except that you specify the heap 
  6390. to use; _debug_calloc always allocates from the default heap. 
  6391.  
  6392. If the heap does not have enough memory for the request, _debug_ucalloc calls 
  6393. the getmore_fn that you specified when you created the heap with _ucreate. 
  6394.  
  6395. To reallocate or free memory allocated with _debug_ucalloc, use the 
  6396. non-heap-specific _debug_realloc and _debug_free. These functions always check 
  6397. what heap the memory was allocated from. 
  6398.  
  6399. Return Value 
  6400. _debug_ucalloc returns a pointer to the reserved space. If size or num was 
  6401. specified as zero, or if your getmore_fn cannot provide enough memory, 
  6402. _debug_ucalloc returns NULL. Passing _debug_ucalloc a heap that is not valid 
  6403. results in undefined behavior. 
  6404.  
  6405.  
  6406. ΓòÉΓòÉΓòÉ <hidden> Example of _debug_ucalloc ΓòÉΓòÉΓòÉ
  6407.  
  6408. /************************************************************************
  6409.  
  6410. This example creates a user heap and allocates memory from it with 
  6411. _debug_ucalloc.  It then attempts to write to memory that was not allocated. 
  6412. When _debug_free is called, _uheap_check detects the error, generates several 
  6413. messages, and stops the program. 
  6414.  
  6415. Note:  You must compile this example with the /Tm option to map the _ucalloc 
  6416. calls to _debug_ucalloc and free to _debug_free. 
  6417.  
  6418. *********************************************************************** /
  6419.  
  6420. #include <stdlib.h>
  6421. #include <stdio.h>
  6422. #include <umalloc.h>
  6423. #include <string.h>
  6424.  
  6425. int main(void)
  6426. {
  6427.    Heap_t  myheap;
  6428.    char    *ptr;
  6429.  
  6430.    /* Use default heap as user heap */
  6431.    myheap = _udefault(NULL);
  6432.  
  6433.    if (NULL == (ptr = (char*)_ucalloc(myheap, 100, 1))) {
  6434.       puts("Cannot allocate memory from user heap.");
  6435.       exit(EXIT_FAILURE);
  6436.    }
  6437.    memset(ptr, 'x', 105);   /* Overwrites storage that was not allocated */
  6438.    free(ptr);
  6439.    return 0;
  6440.  
  6441.    /****************************************************************************
  6442.       The output should be similar to :
  6443.  
  6444.       End of allocated object 0x00073890 was overwritten at 0x000738f4.
  6445.       The first eight bytes of the memory block (in hex) are: 7878787878787878.
  6446.       This memory block was (re)allocated at line number 14 in _debug_ucallo.c.
  6447.       Heap state was valid at line 14 of _debug_ucallo.c.
  6448.       Memory error detected at line 19 of _debug_ucallo.c.
  6449.    ****************************************************************************/
  6450. }
  6451.  
  6452.  
  6453. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6454.  
  6455. Example of _debug_ucalloc 
  6456.  
  6457.      "Managing Memory" in the Programming Guide 
  6458.      "Debugging Your Heaps" in the Programming Guide 
  6459.      Differentiating between Memory Management Functions 
  6460.      calloc - Reserve and Initialize Storage 
  6461.      _debug_calloc - Allocate and Initialize Memory 
  6462.      _debug_free - Release Memory 
  6463.      _debug_umalloc - Reserve Memory Blocks from User Heap 
  6464.      _ucalloc - Reserve and Initialize Memory from User Heap 
  6465.      _ucreate - Create a Memory Heap 
  6466.      _udump_allocated - Get Information about Allocated Memory in Heap 
  6467.      _uheap_check - Validate User Memory Heap 
  6468.      <umalloc.h> 
  6469.  
  6470.  
  6471. ΓòÉΓòÉΓòÉ 4.51. _debug_uheapmin - Release Unused Memory in User Heap ΓòÉΓòÉΓòÉ
  6472.  
  6473.  
  6474. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6475.  
  6476. #include <umalloc.h>
  6477. int _debug_uheapmin(Heap_t heap, const char *file, size_t line);
  6478.  
  6479.  
  6480. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6481.  
  6482. Language Level:  Extension 
  6483.  
  6484. _debug_uheapmin is the debug version of _uheapmin. Like _uheapmin, it returns 
  6485. all unused memory blocks from the specified heap to the operating system. 
  6486.  
  6487. To return the memory, _debug_uheapmin calls the release_fn you supplied when 
  6488. you created the heap with _ucreate. If you do not supply a release_fn, 
  6489. _debug_uheapmin has no effect and returns 0. 
  6490.  
  6491. In addition, _debug_uheapmin makes an implicit call to _uheap_check to validate 
  6492. the heap. 
  6493.  
  6494. _debug_uheapmin works just like _debug_heapmin except that you specify the heap 
  6495. to use; _debug_heapmin always uses the default heap. 
  6496.  
  6497. To use _debug_uheapmin, you must compile with the debug memory (/Tm) compiler 
  6498. option. This option maps all _uheapmin calls to _debug_uheapmin (you can also 
  6499. call _debug_uheapmin explicitly). 
  6500.  
  6501. Note:  The /Tm option maps all calls to memory management functions (including 
  6502. heap-specific versions) to their debug counterparts. To prevent a call from 
  6503. being mapped, parenthesize the function name. 
  6504.  
  6505. Return Value 
  6506. If successful, _debug_uheapmin returns 0. A nonzero return value indicates 
  6507. failure. If the heap specified is not valid, _debug_uheapmin generates an error 
  6508. message with the file name and line number where the call to _debug_uheapmin 
  6509. was made. 
  6510.  
  6511.  
  6512. ΓòÉΓòÉΓòÉ <hidden> Example of _debug_uheapmin ΓòÉΓòÉΓòÉ
  6513.  
  6514. /************************************************************************
  6515.  
  6516. This example creates a heap and allocates memory from it, then uses 
  6517. _debug_heapmin to release the memory. 
  6518.  
  6519. Note:  You must compile this example with the /Tm option to map the _uheapmin 
  6520. calls to _debug_uheapmin. 
  6521.  
  6522. *********************************************************************** /
  6523.  
  6524. #include <stdlib.h>
  6525. #include <stdio.h>
  6526. #include <string.h>
  6527. #include <umalloc.h>
  6528.  
  6529. int main(void)
  6530. {
  6531.    Heap_t  myheap;
  6532.    char    *ptr;
  6533.  
  6534.    /* Use default heap as user heap */
  6535.    myheap = _udefault(NULL);
  6536.  
  6537.    /* Allocate a large object */
  6538.    if (NULL == (ptr = (char*)_umalloc(myheap, 60000))) {
  6539.       puts("Cannot allocate memory from user heap.\n");
  6540.       exit(EXIT_FAILURE);
  6541.    }
  6542.    memset(ptr, 'x', 60000);
  6543.    free(ptr);
  6544.  
  6545.    /* _debug_uheapmin will attempt to return the freed object to the system */
  6546.    if (0 != _uheapmin(myheap)) {
  6547.       puts("_debug_uheapmin returns failed.\n");
  6548.       exit(EXIT_FAILURE);
  6549.    }
  6550.    return 0;
  6551. }
  6552.  
  6553.  
  6554. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6555.  
  6556. Example of _debug_uheapmin 
  6557.  
  6558.      "Managing Memory" in the Programming Guide 
  6559.      "Debugging Your Heaps" in the Programming Guide 
  6560.      Differentiating between Memory Management Functions 
  6561.      _heapmin - Release Unused Memory from Default Heap 
  6562.      _ucreate - Create a Memory Heap 
  6563.      _udump_allocated - Get Information about Allocated Memory in Heap 
  6564.      _uheap_check - Validate User Memory Heap 
  6565.      _uheapmin - Release Unused Memory in User Heap 
  6566.      <umalloc.h> 
  6567.  
  6568.  
  6569. ΓòÉΓòÉΓòÉ 4.52. _debug_umalloc - Reserve Memory Blocks from User Heap ΓòÉΓòÉΓòÉ
  6570.  
  6571.  
  6572. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6573.  
  6574. #include <umalloc.h>
  6575. void *_debug_umalloc(Heap_t heap, size_t size,
  6576.                      const char *file, size_t line);
  6577.  
  6578.  
  6579. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6580.  
  6581. Language Level:  Extension 
  6582.  
  6583. _debug_umalloc is the debug version of _umalloc. Like _umalloc, it reserves 
  6584. storage space from the heap you specify for a block of size bytes. 
  6585. _debug_umalloc also sets all the memory it allocates to 0xAA, so you can easily 
  6586. locate instances where your program uses the data in the memory without 
  6587. initializing it first. 
  6588.  
  6589. In addition, _debug_umalloc makes an implicit call to _uheap_check, and stores 
  6590. the name of the file file and the line number line where the storage is 
  6591. allocated. This information can be used later by the _uheap_check and 
  6592. _udump_allocated or _udump_allocated_delta functions. _debug_umalloc also sets 
  6593. all the memory it allocates to 0xAA; this can help you debug problems where 
  6594. your program uses the data in the memory without initializing it. 
  6595.  
  6596. _debug_umalloc works just like _debug_malloc except that you specify the heap 
  6597. to use; _debug_malloc always allocates from the default heap. 
  6598.  
  6599. If the heap does not have enough memory for the request, _debug_umalloc calls 
  6600. the getmore_fn that you specified when you created the heap with _ucreate. 
  6601.  
  6602. To use _debug_umalloc, you must compile with the debug memory (/Tm) compiler 
  6603. option. This option maps all _umalloc calls to _debug_umalloc (you can also 
  6604. call _debug_umalloc explicitly). 
  6605.  
  6606. Note:  The /Tm option maps all calls to memory management functions (including 
  6607. heap-specific versions) to their debug counterparts. To prevent a call from 
  6608. being mapped, parenthesize the function name. 
  6609.  
  6610. To reallocate or free memory allocated with _debug_umalloc, use the 
  6611. non-heap-specific _debug_realloc and _debug_free. These functions always check 
  6612. what heap the memory was allocated from. 
  6613.  
  6614. Return Value: 
  6615. _debug_umalloc returns a pointer to the reserved space. If size was specified 
  6616. as zero, or the getmore_fn cannot provide enough memory, _debug_umalloc returns 
  6617. NULL. Passing _debug_umalloc a heap that is not valid results in undefined 
  6618. behavior. 
  6619.  
  6620.  
  6621. ΓòÉΓòÉΓòÉ <hidden> Example of _debug_umalloc ΓòÉΓòÉΓòÉ
  6622.  
  6623. /************************************************************************
  6624.  
  6625. This example creates a heap myheap and uses _debug_umalloc to allocate 100 
  6626. bytes from it. It then attempts to overwrite storage that was not allocated. 
  6627. The call to _debug_free invokes _uheap_check, which detects the error, 
  6628. generates messages, and ends the program. 
  6629.  
  6630. Note:  You must compile this example with the /Tm option to map _umalloc to 
  6631. _debug_umalloc and free to _debug_free. 
  6632.  
  6633.  ***********************************************************************
  6634.  
  6635. #include <stdlib.h>
  6636. #include <stdio.h>
  6637. #include <umalloc.h>
  6638. #include <string.h>
  6639.  
  6640. int main(void)
  6641. {
  6642.    Heap_t  myheap;
  6643.    char    *ptr;
  6644.  
  6645.    /* Use default heap as user heap */
  6646.    myheap = _udefault(NULL);
  6647.  
  6648.    if (NULL == (ptr = (char*)_umalloc(myheap, 100))) {
  6649.       puts("Cannot allocate memory from user heap.\n");
  6650.       exit(EXIT_FAILURE);
  6651.    }
  6652.    memset(ptr, 'x', 105);   /* Overwrites storage that was not allocated */
  6653.    free(ptr);
  6654.    return 0;
  6655.  
  6656.    /****************************************************************************
  6657.       The output should be similar to :
  6658.  
  6659.       End of allocated object 0x00073890 was overwritten at 0x000738f4.
  6660.       The first eight bytes of the memory block (in hex) are: 7878787878787878.
  6661.       This memory block was (re)allocated at line number 14 in _debug_umallo.c.
  6662.       Heap state was valid at line 14 of _debug_umallo.c.
  6663.       Memory error detected at line 19 of _debug_umallo.c.
  6664.    ****************************************************************************/
  6665. }
  6666.  
  6667.  
  6668. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6669.  
  6670. Example of _debug_umalloc 
  6671.  
  6672.      "Managing Memory" in the Programming Guide 
  6673.      "Debugging Your Heaps" in the Programming Guide 
  6674.      Differentiating between Memory Management Functions 
  6675.      _debug_free - Release Memory 
  6676.      _debug_malloc - Allocate Memory 
  6677.      _debug_ucalloc - Reserve and Initialize Memory from User Heap 
  6678.      malloc - Reserve Storage Block 
  6679.      _ucreate - Create a Memory Heap 
  6680.      _udump_allocated - Get Information about Allocated Memory in Heap 
  6681.      _umalloc - Reserve Memory Blocks from User Heap 
  6682.      _uheap_check - Validate User Memory Heap 
  6683.      <umalloc.h> 
  6684.  
  6685.  
  6686. ΓòÉΓòÉΓòÉ 4.53. difftime - Compute Time Difference ΓòÉΓòÉΓòÉ
  6687.  
  6688.  
  6689. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6690.  
  6691. #include <time.h>
  6692. double difftime(time_t time2, time_t time1);
  6693.  
  6694.  
  6695. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6696.  
  6697. Language Level: ANSI, SAA, POSIX, XPG4 
  6698.  
  6699. difftime computes the difference in seconds between time2 and time1. 
  6700.  
  6701. Return Value 
  6702. The difftime function returns the elapsed time in seconds from time1 to time2 
  6703. as a double precision number.  Type time_t is defined in <time.h>. 
  6704.  
  6705.  
  6706. ΓòÉΓòÉΓòÉ <hidden> Example of difftime ΓòÉΓòÉΓòÉ
  6707.  
  6708. /************************************************************************
  6709.  
  6710. This example shows a timing application using difftime.  The example calculates 
  6711. how long, on average, it takes to find the prime numbers from 2 to 10000. 
  6712.  
  6713. ************************************************************************/
  6714.  
  6715. #include <time.h>
  6716. #include <stdio.h>
  6717.  
  6718. #define  RUNS          1000
  6719. #define  SIZE          10000
  6720.  
  6721. int mark[SIZE];
  6722.  
  6723. int main(void)
  6724. {
  6725.    time_t start,finish;
  6726.    int i,loop,n,num;
  6727.  
  6728.    time(&start);
  6729.  
  6730.    /*  This loop finds the prime numbers between 2 and SIZE                   */
  6731.  
  6732.    for (loop = 0; loop < RUNS; ++loop) {
  6733.       for (n = 0; n < SIZE; ++n)
  6734.          mark[n] = 0;
  6735.  
  6736.       /*  This loops marks all the composite numbers with -1                  */
  6737.  
  6738.       for (num = 0, n = 2; n < SIZE; ++n)
  6739.          if (!mark[n]) {
  6740.             for (i = 2*n; i < SIZE; i += n)
  6741.                mark[i] = -1;
  6742.             ++num;
  6743.          }
  6744.    }
  6745.    time(&finish);
  6746.    printf("Program takes an average of %f seconds to find %d primes.\n",
  6747.       difftime(finish, start)/RUNS, num);
  6748.    return 0;
  6749.  
  6750.    /****************************************************************************
  6751.       The output should be similar to :
  6752.  
  6753.       Program takes an average of 0.106000 seconds to find 1229 primes.
  6754.    ****************************************************************************/
  6755. }
  6756.  
  6757.  
  6758. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6759.  
  6760. Example of difftime 
  6761.  
  6762.      asctime - Convert Time to Character String 
  6763.      ctime - Convert Time to Character String 
  6764.      gmtime - Convert Time 
  6765.      localtime - Convert Time 
  6766.      mktime - Convert Local Time 
  6767.      strftime - Convert to Formatted Time 
  6768.      time - Determine Current Time 
  6769.      <time.h> 
  6770.  
  6771.  
  6772. ΓòÉΓòÉΓòÉ 4.54. _disable - Disable Interrupts ΓòÉΓòÉΓòÉ
  6773.  
  6774.  
  6775. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6776.  
  6777. #include <builtin.h>
  6778. void _disable( void );
  6779.  
  6780.  
  6781. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6782.  
  6783. Language Level:  Extension 
  6784.  
  6785. _disable disables interrupts by executing the CLI machine instruction. It 
  6786. disables interrupts until the instruction after a call to _enable has been 
  6787. executed. 
  6788.  
  6789. Note:  _disable is a built-in function, which means it is implemented as an 
  6790. inline instruction and has no backing code in the library.  For this reason: 
  6791.  
  6792.      You cannot take the address of _disable. 
  6793.      You cannot parenthesize a call to _disable. (Parentheses specify a call 
  6794.       to the function's backing code, and _disable has none.) 
  6795.  
  6796.  You can run code containing this function only at ring zero. Otherwise, an 
  6797.  invalid instruction exception is generated. 
  6798.  
  6799.  Return Value 
  6800.  This function has no return value. 
  6801.  
  6802.  
  6803. ΓòÉΓòÉΓòÉ <hidden> Example of _disable ΓòÉΓòÉΓòÉ
  6804.  
  6805. /************************************************************************
  6806.  
  6807. In this example, _disable disables interrupts by executing a CLI instruction. 
  6808.  
  6809. ************************************************************************/
  6810.  
  6811. #include <builtin.h>
  6812.  
  6813. int main(void)
  6814. {
  6815.    /* ------------------------------------------------------ */
  6816.    /* The expected assembler instruction looks like this :   */
  6817.    /*       CLI                                              */
  6818.    /* -------------------------------------------------------*/
  6819.    _disable();
  6820.    return 0;
  6821. }
  6822.  
  6823.  
  6824. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6825.  
  6826. Example of disable 
  6827.  
  6828.      _enable - Enable Interrupts 
  6829.      _interrupt - Call Interrupt  Procedure 
  6830.      <builtin.h> 
  6831.  
  6832.  
  6833. ΓòÉΓòÉΓòÉ 4.55. div  - Calculate Quotient and Remainder ΓòÉΓòÉΓòÉ
  6834.  
  6835.  
  6836. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6837.  
  6838. #include <stdlib.h>
  6839. div_t div(int numerator, int denominator);
  6840.  
  6841.  
  6842. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6843.  
  6844. Language Level: ANSI, SAA, POSIX, XPG4 
  6845.  
  6846. div calculates the quotient and remainder of the division of numerator by 
  6847. denominator. 
  6848.  
  6849. Return Value 
  6850. div returns a structure of type div_t, containing both the quotient int quot 
  6851. and the remainder int rem.  If the return value cannot be represented, its 
  6852. value is undefined. If denominator is 0, an exception will be raised. 
  6853.  
  6854.  
  6855. ΓòÉΓòÉΓòÉ <hidden> Example of div ΓòÉΓòÉΓòÉ
  6856.  
  6857. /************************************************************************
  6858.  
  6859. This example uses div to calculate the quotients and remainders for a set of 
  6860. two dividends and two divisors. 
  6861.  
  6862. ************************************************************************/
  6863.  
  6864. #include <stdlib.h>
  6865. #include <stdio.h>
  6866.  
  6867. int main(void)
  6868. {
  6869.    int num[2] =  { 45,-45 };
  6870.    int den[2] =  { 7,-7 };
  6871.    div_t ans;              /* div_t is a struct type containing two ints:
  6872.                               'quot' stores quotient; 'rem' stores remainder */
  6873.    short i,j;
  6874.  
  6875.    printf("Results of division:\n");
  6876.    for (i = 0; i < 2; i++)
  6877.       for (j = 0; j < 2; j++) {
  6878.          ans = div(num[i], den[j]);
  6879.          printf("Dividend: %6ld  Divisor: %6ld", num[i], den[j]);
  6880.          printf("  Quotient: %6ld  Remainder: %6ld\n", ans.quot, ans.rem);
  6881.       }
  6882.    return 0;
  6883.  
  6884.    /****************************************************************************
  6885.       The output should be:
  6886.  
  6887.       Results of division:
  6888.       Dividend:  45  Divisor:   7  Quotient:   6  Remainder:   3
  6889.       Dividend:  45  Divisor:  -7  Quotient:  -6  Remainder:   3
  6890.       Dividend: -45  Divisor:   7  Quotient:  -6  Remainder:  -3
  6891.       Dividend: -45  Divisor:  -7  Quotient:   6  Remainder:  -3
  6892.    ****************************************************************************/
  6893. }
  6894.  
  6895.  
  6896. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6897.  
  6898. Example of div 
  6899.  
  6900.      ldiv - Perform Long Division 
  6901.      <stdlib.h> 
  6902.  
  6903.  
  6904. ΓòÉΓòÉΓòÉ 4.56. _DLL_InitTerm - Initialize and Terminate DLL Environment ΓòÉΓòÉΓòÉ
  6905.  
  6906.  
  6907. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6908.  
  6909. unsigned long __stdcall
  6910. _DLL_InitTerm(HINSTANCE modhandle,
  6911.                               DWORD flag, LPVOID dummy);
  6912. /* no header file - defined in runtime startup code */
  6913.  
  6914.  
  6915. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6916.  
  6917. Language Level:  Extension 
  6918.  
  6919. _DLL_InitTerm is the initialization and termination entry point for a DLL. When 
  6920. each new process or thread gains access to the DLL, _DLL_InitTerm initializes 
  6921. the necessary environment for the DLL, including storage, semaphores, and 
  6922. variables. When each process or thread frees its access to the DLL, 
  6923. _DLL_InitTerm terminates the DLL environment created for that process or 
  6924. thread. 
  6925.  
  6926. The default _DLL_InitTerm function supplied by VisualAge for C++ performs the 
  6927. actions required to initialize and terminate the runtime environment, or for 
  6928. subsystem DLLs, to initialize and terminate memory functions. It is called 
  6929. automatically when you link to the DLL. If your DLL requires initialization or 
  6930. termination actions in addition to the actions performed in the default 
  6931. function, you will need to create your own _DLL_InitTerm function. The flag 
  6932. parameter has four values defined in windows.h. If the value of the flag 
  6933. parameter is: 
  6934.  
  6935.  DLL_PROCESS_ATTACH  The DLL environment is initialized 
  6936.  
  6937.  DLL_PROCESS_DETACH  The DLL environment is ended 
  6938.  
  6939.  DLL_THREAD_ATTACH   A new thread that can access the DLL has been created in 
  6940.                      the process. 
  6941.  
  6942.  DLL_THREAD_DETACH   A thread has terminated 
  6943.  
  6944.  The modhandle parameter is the module handle assigned by the operating system 
  6945.  for this DLL. You can use the module handle as a parameter to various Win32 
  6946.  API calls. For example, you can call GetModuleFileName with the module handle 
  6947.  to return the fully-qualified path name of the DLL, which tells you where the 
  6948.  DLL was loaded from. 
  6949.  
  6950.  Because it is called by the operating system loader, you must compile your 
  6951.  _DLL_InitTerm function with __stdcall linkage. 
  6952.  
  6953.  For more information on creating your own _DLL_InitTerm function, see the 
  6954.  chapter Building Dynamic Link Libraries in the Programming Guide. 
  6955.  
  6956.  Note:  A _DLL_InitTerm function for a subsystem DLL has the same prototype, 
  6957.  but the content of the function is different because there is no runtime 
  6958.  environment to initialize or terminate. For more information on building 
  6959.  subsystem DLLs, see the section Building a Subsystem DLL in the Programming 
  6960.  Guide. 
  6961.  
  6962.  Return Value 
  6963.  The return code is significant only when the value of the flag parameter is 
  6964.  DLL_PROCESS_ATTACH. The return code from _DLL_InitTerm tells the loader if the 
  6965.  initialization was performed successfully. If the call was successful, 
  6966.  _DLL_InitTerm returns a nonzero value. A return code of 0 indicates that the 
  6967.  function failed. If a failure is indicated, the loader will not load the 
  6968.  program that is accessing the DLL. 
  6969.  
  6970.  This function is also called by the operating system in thread creation and 
  6971.  termination. When the value of the flag parameter is DLL_THREAD_ATTACH, a new 
  6972.  THREAD has been created in the process. When the value of the flag parameter 
  6973.  is DLL_THREAD_DETACH, a thread has terminated. 
  6974.  
  6975.  
  6976. ΓòÉΓòÉΓòÉ <hidden> Example of _DLL_Initterm ΓòÉΓòÉΓòÉ
  6977.  
  6978. /************************************************************************
  6979.  
  6980. This example shows the _DLL_InitTerm function from the VisualAge for C++ sample 
  6981. program for building DLLs. 
  6982.  
  6983. ************************************************************************/
  6984.  
  6985. #include <windows.h>
  6986. #include <stdlib.h>
  6987. #include <stdio.h>
  6988. #include <string.h>
  6989. #define  CCHMAXPATH  255
  6990. /* _CRT_init is the C run-time environment initialization function.         */
  6991. /* It will return 0 to indicate success and -1 to indicate failure.         */
  6992.  
  6993. int _CRT_init(void);
  6994. #ifdef   STATIC_LINK
  6995.  
  6996. /* _CRT_term is the C run-time environment termination function.            */
  6997. /* It only needs to be called when the C run-time functions are statically  */
  6998. /* linked.                                                                  */
  6999. void _CRT_term(void);
  7000. #else
  7001.  
  7002.  
  7003. static void  cleanup(void);
  7004. #endif
  7005. size_t nSize;
  7006. int *pArray;
  7007.  
  7008. /* _DLL_InitTerm is the function that gets called by the operating system   */
  7009. /* loader when it loads and frees this DLL for each process that accesses   */
  7010. /* this DLL.  However, it only gets called the first time the DLL is loaded */
  7011. /* and the last time it is freed for a particular process.  The system      */
  7012. /* linkage convention MUST be used because the operating system loader is   */
  7013. /* calling this function.                                                   */
  7014.  
  7015. unsigned long _System _DLL_InitTerm(unsigned long hModule, unsigned long
  7016.                                     ulFlag, long * dummy)
  7017. {
  7018.    size_t i;
  7019.    int  rc;
  7020.    char namebuf╤ìCCHMAXPATHΓêÖ;
  7021.  
  7022.    /* If ulFlag is one then the DLL is being loaded so initialization should*/
  7023.    /* be performed.  If ulFlag is zero then the DLL is being freed so       */
  7024.    /* termination should be performed.                                      */
  7025.  
  7026.    switch (ulFlag) {
  7027.       case 1 :
  7028.  
  7029.          /*******************************************************************/
  7030.          /* The C run-time environment initialization function must be      */
  7031.          /* called before any calls to C run-time functions that are not    */
  7032.          /* inlined.                                                        */
  7033.          /*******************************************************************/
  7034.  
  7035.          if (_CRT_init() == -1)
  7036.             return 0UL;
  7037. #ifndef  STATIC_LINK
  7038.  
  7039.          /*******************************************************************/
  7040.          /* Cleanup routine is registered by atexit function to clean up    */
  7041.          /* if the runtime is dynamically linked.                           */
  7042.          /*******************************************************************/
  7043.  
  7044.             if (atexit(cleanup))
  7045.                printf("atexit for cleanup failed\n");
  7046. #endif
  7047.          if ((rc = GetModuleFileName((void *)hModule, namebuf, CCHMAXPATH)) == 0)
  7048.             printf("GetModuleFileName returned %lu\n", GetLastError());
  7049.          else
  7050.             printf("The name of this DLL is %s\n", namebuf);
  7051.          srand(17);
  7052.          nSize = (rand()%128)+32;
  7053.          printf("The array size for this process is %u\n", nSize);
  7054.          if ((pArray = malloc(nSize *sizeof(int))) == NULL) {
  7055.             printf("Could not allocate space for unsorted array.\n");
  7056.             return 0UL;
  7057.          }
  7058.          for (i = 0; i < nSize; ++i)
  7059.             pArray╤ìiΓêÖ = rand();
  7060.          break;
  7061.       case 0 :
  7062. #ifdef   STATIC_LINK
  7063.          printf("The array will now be freed.\n");
  7064.          free(pArray);
  7065.          _CRT_term();
  7066. #endif
  7067.          break;
  7068.       default  :
  7069.          printf("ulFlag = %lu\n", ulFlag);
  7070.          return 0UL;
  7071.    }
  7072.  
  7073.    /* A non-zero value must be returned to indicate success. */
  7074.  
  7075.    return 1UL;
  7076. }
  7077. #ifndef  STATIC_LINK
  7078. static void cleanup(void)
  7079. {
  7080.    printf("The array will now be freed.\n");
  7081.    free(pArray);
  7082.    return ;
  7083. }
  7084. #endif
  7085.  
  7086.  
  7087. ΓòÉΓòÉΓòÉ <hidden> Example of _DLL_InitTerm for a Subsystem ΓòÉΓòÉΓòÉ
  7088.  
  7089. /************************************************************************
  7090.  
  7091. The following example shows the _DLL_InitTerm function from the VisualAge for 
  7092. C++ sample for building subsystem DLLs. 
  7093.  
  7094. ************************************************************************/
  7095.  
  7096. #pragma strings( readonly )
  7097. /* This example provides 5 external entrypoints of which 2 are exported for   */
  7098. /* use by client processes.  The entrypoints are:                             */
  7099. /*                                                                            */
  7100. /* _DLL_InitTerm - Initialization/Termination function for the DLL that is    */
  7101. /*                 invoked by the loader.  When the /Ge- compile option is    */
  7102. /*                 used the linker is told that this is the function to       */
  7103. /*                 execute when the DLL is first loaded and last freed for    */
  7104. /*                 each process.                                              */
  7105. /*                                                                            */
  7106. /* DLLREGISTER  - Called by _DLL_InitTerm for each process that loads the     */
  7107. /*                DLL.                                                        */
  7108. /*                                                                            */
  7109. /* DLLINCREMENT - Accepts a count from its client and adds this value to      */
  7110. /*                the process and system totals.                              */
  7111. /*                                                                            */
  7112. /* DLLSTATS     - Dumps process and system totals on behalf of its client.    */
  7113. /*                                                                            */
  7114. /* DLLDEREGISTER- Called by _DLL_InitTerm for each process that frees the     */
  7115. /*                DLL.                                                        */
  7116. /*                                                                            */
  7117. /******************************************************************************/
  7118.  
  7119. #include <windows.h>
  7120. #include <stdio.h>
  7121. #include "sample05.h"
  7122.  
  7123. unsigned long _System _DLL_InitTerm( unsigned long hModule, \
  7124.                                      unsigned long ulFlag, LPVOID dummy);
  7125.  
  7126. static unsigned long DLLREGISTER( void );
  7127. static unsigned long DLLDEREGISTER( void );
  7128.  
  7129. #define SHARED_SEMAPHORE_NAME "DLL.LCK"
  7130.  
  7131. /* The following data will be per-process data.  It will not be shared among  */
  7132. /* different processes.                                                       */
  7133.  
  7134. static HANDLE hmtxSharedSem;    /* Shared semaphore top                       */
  7135. static ULONG ulProcessTotal;   /* Total of increments for a process           */
  7136. static DWORD pid;              /* Process identifier                          */
  7137.  
  7138. /* This is the global data segment that is shared by every process.           */
  7139.  
  7140. #pragma data_seg( GLOBAL_SEG )
  7141.  
  7142. static ULONG ulProcessCount;                /* total number of processes      */
  7143. static ULONG ulGrandTotal;                  /* Grand total of increments      */
  7144.  
  7145. /* _DLL_InitTerm() - called by the loader for DLL initialization/termination  */
  7146. /* This function must return a non-zero value if successful and a zero value  */
  7147. /* if unsuccessful.                                                           */
  7148.  
  7149. unsigned long _DLL_InitTerm( unsigned long hModule, unsigned long ulFlag,
  7150.                                     LPVOID dummy)
  7151.    {
  7152.    ULONG rc;
  7153.  
  7154.    /* If ulFlag is one  then initialization is required:                      */
  7155.    /*    If the shared memory pointer is NULL then the DLL is being loaded    */
  7156.    /*    for the first time so acquire the named shared storage for the       */
  7157.    /*    process control structures.  A linked list of process control        */
  7158.    /*    structures will be maintained.  Each time a new process loads this   */
  7159.    /*    DLL, a new process control structure is created and it is inserted   */
  7160.    /*    at the end of the list by calling DLLREGISTER.                       */
  7161.    /*                                                                         */
  7162.    /* If ulFlag is zero then termination is required:                         */
  7163.    /*    Call DLLDEREGISTER which will remove the process control structure   */
  7164.    /*    and free the shared memory block from its virtual address space.     */
  7165.  
  7166.    switch( ulFlag )
  7167.       {
  7168.    case 1:
  7169.          if ( !ulProcessCount )
  7170.             {
  7171.             _rmem_init();
  7172.             /* Create the shared mutex semaphore.                             */
  7173.  
  7174.             if (( hmtxSharedSem = CreateMutex(NULL,
  7175.                                              TRUE,
  7176.                                               SHARED_SEMAPHORE_NAME)) == NULL)
  7177.                {
  7178.                printf( "CreateMutex  rc = %lu\n", GetLastError() );
  7179.                return 0;
  7180.                }
  7181.             }
  7182.  
  7183.          /* Register the current process.                                     */
  7184.  
  7185.          if ( DLLREGISTER( ) )
  7186.             return 0;
  7187.  
  7188.          break;
  7189.  
  7190.       case 0:
  7191.          /* De-register the current process.                                  */
  7192.  
  7193.          if ( DLLDEREGISTER( ) )
  7194.             return 0;
  7195.  
  7196.          _rmem_term();
  7197.  
  7198.          break;
  7199.  
  7200.       default:
  7201.          return 0;
  7202.       }
  7203.  
  7204.    /* Indicate success.  Non-zero means success!!!                            */
  7205.  
  7206.    return 1;
  7207.    }
  7208.  
  7209. /* DLLREGISTER - Registers the current process so that it can use this        */
  7210. /*               subsystem.  Called by _DLL_InitTerm when the DLL is first    */
  7211. /*               loaded for the current process.                              */
  7212.  
  7213. static unsigned long DLLREGISTER( void )
  7214.    {
  7215.    ULONG rc;
  7216.  
  7217.    /* Get the process id       */
  7218.  
  7219.     pid = GetCurrentProcessId();
  7220.  
  7221.    /* Open the shared mutex semaphore for this process.                       */
  7222.  
  7223.    if ( ( hmtxSharedSem = OpenMutex(SYNCHRONIZE,
  7224.                                     TRUE,
  7225.                                     SHARED_SEMAPHORE_NAME ) ) == NULL)
  7226.       {
  7227.       printf( "OpenMutex rc = %lu\n", rc = GetLastError() );
  7228.       return rc;
  7229.       }
  7230.  
  7231.    /* Acquire the shared mutex semaphore.                                     */
  7232.  
  7233.    if ( WaitForSingleObject( hmtxSharedSem,
  7234.                                    INFINITE )  == 0xFFFFFFFF )
  7235.       {
  7236.       printf( "WaitFor SingleObject rc = %lu\n", rc = GetLastError() );
  7237.       CloseHandle( hmtxSharedSem );
  7238.       return rc;
  7239.       }
  7240.  
  7241.    /* Increment the count of processes registered.                            */
  7242.  
  7243.    ++ulProcessCount;
  7244.  
  7245.    /* Initialize the per-process data.                                        */
  7246.  
  7247.    ulProcessTotal = 0;
  7248.  
  7249.    /* Tell the user that the current process has been registered.             */
  7250.  
  7251.    printf( "\nProcess %lu has been registered.\n\n", pid );
  7252.  
  7253.    /* Release the shared mutex semaphore.                                     */
  7254.  
  7255.    if ( ReleaseMutex( hmtxSharedSem ) == FALSE )
  7256.       {
  7257.       printf( "ReleaseMutex rc = %lu\n", rc = GetLastError() );
  7258.       return rc;
  7259.       }
  7260.  
  7261.    return 0;
  7262.    }
  7263.  
  7264. /* DLLINCREMENT - Increments the process and global totals on behalf of the   */
  7265. /*                calling program.                                            */
  7266.  
  7267. int DLLINCREMENT( int incount )
  7268.    {
  7269.    ULONG            rc;                     /* return code from DOS APIs      */
  7270.  
  7271.    /* Acquire the shared mutex semaphore.                                     */
  7272.  
  7273.    if ( WaitForSingleObject( hmtxSharedSem,
  7274.                                 INFINITE )  == 0xFFFFFFFF )
  7275.       {
  7276.       printf( "WaitForSingleObject rc = %lu\n", rc = GetLastError());
  7277.       return rc;
  7278.       }
  7279.  
  7280.    /* Increment the counts the process and grand totals.                      */
  7281.  
  7282.    ulProcessTotal += incount;
  7283.    ulGrandTotal += incount;
  7284.  
  7285.    /* Tell the user that the increment was successful.                        */
  7286.  
  7287.    printf( "\nThe increment for process %lu was successful.\n\n", pid );
  7288.  
  7289.    /* Release the shared mutex semaphore.                                     */
  7290.  
  7291.    if ( ReleaseMutex( hmtxSharedSem )  == FALSE )
  7292.       {
  7293.       printf( "ReleaseMutex rc = %lu\n", rc = GetLastError() );
  7294.       return rc;
  7295.       }
  7296.  
  7297.    return 0;
  7298.    }
  7299.  
  7300. /* DLLSTATS  - Prints process and grand totals.                               */
  7301.  
  7302. int DLLSTATS( void )
  7303.    {
  7304.    ULONG          rc;
  7305.  
  7306.    /* Acquire the shared mutex semaphore.                                     */
  7307.  
  7308.    if ( WaitForSingleObject( hmtxSharedSem,
  7309.                                    INFINITE )  == 0xFFFFFFFF )
  7310.       {
  7311.       printf( "WaitForSingleObject rc = %lu\n", rc = GetLastError());
  7312.       return rc;
  7313.       }
  7314.  
  7315.    /* Print out per-process and global information.                           */
  7316.  
  7317.    printf( "\nCurrent process identifier     = %lu\n", pid );
  7318.    printf( "Current process total          = %lu\n", ulProcessTotal );
  7319.    printf( "Number of processes registered = %lu\n", ulProcessCount );
  7320.    printf( "Grand Total                    = %lu\n\n", ulGrandTotal );
  7321.  
  7322.    /* Release the shared mutex semaphore.                                     */
  7323.  
  7324.    if ( ReleaseMutex( hmtxSharedSem ) == FALSE )
  7325.       {
  7326.       printf( "ReleaseMutex rc = %lu\n", rc = GetLastError() );
  7327.       return rc;
  7328.       }
  7329.  
  7330.    return 0;
  7331.    }
  7332.  
  7333. /* DLLDEREGISTER - Deregisters the current process from this subsystem.       */
  7334. /*                 Called by _DLL_InitTerm when the DLL is freed for the      */
  7335. /*                 last time by the current process.                          */
  7336.  
  7337. static unsigned long DLLDEREGISTER( void )
  7338.    {
  7339.    ULONG rc;
  7340.  
  7341.    /* Acquire the shared mutex semaphore.                                     */
  7342.  
  7343.    if ( ( rc = WaitForSingleObject( hmtxSharedSem,
  7344.                                    INFINITE ) ) == 0xFFFFFFFF )
  7345.       {
  7346.       printf( "WaitForSingleObject rc = %lu\n", GetLastError());
  7347.       return rc;
  7348.       }
  7349.  
  7350.    /* Decrement the count of processes registered.                            */
  7351.  
  7352.    --ulProcessCount;
  7353.  
  7354.    /* Tell the user that the current process has been deregistered.           */
  7355.  
  7356.    printf( "\nProcess %lu has been deregistered.\n\n", pid );
  7357.  
  7358.    /* Release the shared mutex semaphore.                                     */
  7359.  
  7360.    if ( ReleaseMutex( hmtxSharedSem ) == FALSE )
  7361.       {
  7362.       printf( "ReleaseMutex rc = %lu\n", rc= GetLastError() );
  7363.       return rc;
  7364.       }
  7365.  
  7366.    /* Close the shared mutex semaphore for this process.                      */
  7367.  
  7368.    if ( CloseHandle( hmtxSharedSem )  == FALSE )
  7369.       {
  7370.       printf( "CloseHandle   rc = %lu\n", rc = GetLastError() );
  7371.       return rc;
  7372.       }
  7373.  
  7374.    return 0;
  7375.    }
  7376.  
  7377.  
  7378. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7379.  
  7380. Example of _DLL_Initterm 
  7381.  
  7382. Example of _DLL_Initterm for a Subsystem 
  7383.  
  7384.      Building a Dynamic Link Library in the Programming Guide 
  7385.      Building a Subsystem DLL in the Programming Guide 
  7386.      _CRT_init - Initialize DLL Runtime Environment 
  7387.      _CRT_term - Terminate DLL Runtime Environment 
  7388.      _rmem_init - Initialize Memory Functions for Subsystem DLL 
  7389.      _rmem_term - Terminate Memory Functions for Subsystem DLL 
  7390.  
  7391.  
  7392. ΓòÉΓòÉΓòÉ 4.57. _dump_allocated - Get Information about Allocated Memory ΓòÉΓòÉΓòÉ
  7393.  
  7394.  
  7395. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7396.  
  7397. #include <stdlib.h>   /* also in <malloc.h> */
  7398. void _dump_allocated(int nbytes);
  7399.  
  7400.  
  7401. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7402.  
  7403. Language Level:  Extension 
  7404.  
  7405. _dump_allocated prints information to stderr about each memory block that is 
  7406. currently allocated and was allocated using the debug memory management 
  7407. functions (_debug_calloc, _debug_malloc, and so on). 
  7408.  
  7409. Use nbytes to specify how many bytes of each memory block are to be printed. If 
  7410. nbytes is a: 
  7411.  
  7412.  Negative value Prints all bytes of each block. 
  7413.  
  7414.  0             Prints no bytes. 
  7415.  
  7416.  Positive value Prints the specified number of bytes or the entire block, 
  7417.                whichever is smaller. 
  7418.  
  7419.  Call _dump_allocated at points in your code where you want a report of the 
  7420.  currently allocated memory. For example, a good place to call _dump_allocated 
  7421.  is a point where most of the memory is already freed and you want to find a 
  7422.  memory leak, such as at the end of a program. 
  7423.  
  7424.  _dump_allocated prints the information to stderr, but you can change the 
  7425.  destination with the _set_crt_msg_handle function. You can also use 
  7426.  _dump_allocated_delta to display information only about the memory that was 
  7427.  allocated since the previous call to _dump_allocated or _dump_allocated_delta. 
  7428.  
  7429.  To use _dump_allocated and the debug memory management functions, you must 
  7430.  compile with the debug memory (/Tm) compiler option. 
  7431.  
  7432.  Note:  The /Tm option maps all calls to memory management functions (including 
  7433.  a heap-specific version) to their debug counterparts. To prevent a call from 
  7434.  being mapped, parenthesize the function name. 
  7435.  
  7436.  A heap-specific version of this function (_udump_allocated) is also available. 
  7437.  _dump_allocated always prints information about memory allocated from the 
  7438.  default heap. 
  7439.  
  7440.  Return Value 
  7441.  There is no return value. 
  7442.  
  7443.  
  7444. ΓòÉΓòÉΓòÉ <hidden> Example of _dump_allocated ΓòÉΓòÉΓòÉ
  7445.  
  7446. /************************************************************************
  7447.  
  7448. This example allocates three memory blocks, and then calls _dump_allocated to 
  7449. dump information and the first 8 bytes for each memory block. 
  7450.  
  7451. Note:  You must compile this example with the /Tm option to map the memory 
  7452. management functions to their debug versions. 
  7453.  
  7454. ************************************************************************/
  7455.  
  7456. rules=none.
  7457.  
  7458. #include <stdlib.h>
  7459. #include <string.h>
  7460. #include <stdio.h>
  7461.  
  7462. #define  INIT_STR      "It\0works"
  7463. #define  INIT_STR_LEN  (sizeof(INIT_STR) - 1)
  7464.  
  7465. int main(void) {
  7466.    char *pBlock1;
  7467.    char *pBlock2;
  7468.    char *pBlock3;
  7469.  
  7470.    if (NULL == (pBlock1 = (char*)malloc(35))) { /* allocate first memory block*/
  7471.       printf("Could not allocate first memory block.\n");
  7472.       return  EXIT_FAILURE;
  7473.    }
  7474.  
  7475.    memcpy(pBlock1, INIT_STR, INIT_STR_LEN); /* initialize first memory block  */
  7476.    if (NULL == (pBlock2 = (char*)calloc(2, 120))) { /* allocate second
  7477.                                                                 memory block  */
  7478.       printf("Could not allocate second memory block.\n");
  7479.       return  EXIT_FAILURE;
  7480.    }
  7481.  
  7482.    memcpy(pBlock2, INIT_STR, INIT_STR_LEN); /* initialize second memory block */
  7483.    if (NULL == (pBlock3 = (char*)realloc(NULL, 2235))) {  /* allocate third
  7484.                                                              memory block     */
  7485.       printf("Could not allocate third memory block.\n");
  7486.       return  EXIT_FAILURE;
  7487.    }
  7488.  
  7489.    memcpy(pBlock3, INIT_STR, INIT_STR_LEN); /* initialize third memory block  */
  7490.    if (NULL == (pBlock3 = (char*)realloc(pBlock3, 300))) {/* reallocate third */
  7491.                                       /* memory block to different size       */
  7492.  
  7493.       printf("Could not reallocate third memory block.\n");
  7494.       return  EXIT_FAILURE;
  7495.    }
  7496.  
  7497.    _dump_allocated(8);    /* show first eight bytes of each memory block      */
  7498.    return 0;
  7499.  
  7500.    /****************************************************************************
  7501.       The output should be similar to:
  7502.  
  7503.       -------------------------------------------------------------------------------
  7504.                        START OF DUMP OF ALLOCATED MEMORY BLOCKS
  7505.       -------------------------------------------------------------------------------
  7506.       Address: 0x00074310      Size: 0x0000012C (300)
  7507.       This memory block was (re)allocated at line number 32 in _dump_alloc.c.
  7508.       Memory contents:  49740077 6F726B73                      [It.works        ]
  7509.       -------------------------------------------------------------------------------
  7510.       Address: 0x000738F0      Size: 0x000000F0 (240)
  7511.       This memory block was (re)allocated at line number 19 in _dump_alloc.c.
  7512.       Memory contents:  49740077 6F726B73                      [It.works        ]
  7513.       -------------------------------------------------------------------------------
  7514.       Address: 0x00073890      Size: 0x00000023 (35)
  7515.       This memory block was (re)allocated at line number 13 in _dump_alloc.c.
  7516.       Memory contents:  49740077 6F726B73                      [It.works        ]
  7517.       -------------------------------------------------------------------------------
  7518.                        END OF DUMP OF ALLOCATED MEMORY BLOCKS
  7519.       -------------------------------------------------------------------------------
  7520.    ****************************************************************************/
  7521. }
  7522.  
  7523.  
  7524. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7525.  
  7526. Example of _dump_allocated 
  7527.  
  7528.      Memory Management in the Programming Guide 
  7529.      Debugging Your Heaps in the Programming Guide 
  7530.      Differentiating between Memory Management Functions 
  7531.      _debug_calloc - Allocate and Initialize Memory 
  7532.      _debug_free - Release Memory 
  7533.      _debug_malloc - Allocate Memory 
  7534.      _debug_realloc - Reallocate Memory Block 
  7535.      _dump_allocated_delta - Get Information about Allocated Memory 
  7536.      _heap_check - Validate Default Memory Heap 
  7537.      _udump_allocated - Get Information about Allocated Memory in Heap 
  7538.      <malloc.h> 
  7539.      <stdlib.h> 
  7540.  
  7541.  
  7542. ΓòÉΓòÉΓòÉ 4.58. _dump_allocated_delta - Get Information about Allocated Memory ΓòÉΓòÉΓòÉ
  7543.  
  7544.  
  7545. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7546.  
  7547. #include <stdlib.h>     /* also in <malloc.h> */
  7548. void _dump_allocated_delta(int nbytes);
  7549.  
  7550.  
  7551. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7552.  
  7553. Language Level:  Extension 
  7554.  
  7555. _dump_allocated_delta prints information to stderr about each memory block 
  7556. allocated by a debug memory management function (_debug_malloc and so on) since 
  7557. the last call to _dump_allocated_delta or _dump_allocated. 
  7558.  
  7559. _dump_allocated_delta and _dump_allocated print the same type of information to 
  7560. stderr, but _dump_allocated displays information about all blocks that have 
  7561. been allocated since the start of your program. 
  7562.  
  7563. Use nbytes to specify how many bytes of each memory block are to be printed. If 
  7564. nbytes is a: 
  7565.  
  7566.  Negative value  Prints all bytes of each block. 
  7567.  0               Prints no bytes. 
  7568.  Positive value  Prints the specified number of bytes or the entire block, 
  7569.                  whichever is smaller. 
  7570.  
  7571.  _dump_allocated_delta prints the information to stderr, but you can change the 
  7572.  destination with the _set_crt_msg_handle function. 
  7573.  
  7574.  A heap-specific version of this function, _udump_allocated_delta, is also 
  7575.  available. _dump_allocated_delta always displays information about the default 
  7576.  heap. 
  7577.  
  7578.  To use _dump_allocated_delta and the debug versions of the memory management 
  7579.  functions, specify the debug memory (/Tm) compiler option. 
  7580.  
  7581.  Note:  The /Tm option maps all calls to memory management functions (including 
  7582.  heap-specific versions) are mapped to their debug counterparts. To prevent a 
  7583.  call from being mapped, parenthesize the function name. 
  7584.  
  7585.  Return Value: 
  7586.  There is no return value. 
  7587.  
  7588.  
  7589. ΓòÉΓòÉΓòÉ <hidden> Example of _dump_allocated_delta ΓòÉΓòÉΓòÉ
  7590.  
  7591. /************************************************************************
  7592.  
  7593. This example allocates some memory and calls _dump_allocated to print 
  7594. information about the allocated blocks.  It then allocates more memory, and 
  7595. calls _dump_allocated_delta again to print information about the allocations 
  7596. since the previous call. 
  7597.  
  7598. Note:  You must compile this example with the /Tm option to map the memory 
  7599. management functions to their debug versions. 
  7600.  
  7601. ************************************************************************/
  7602.  
  7603. #include <stdlib.h>
  7604. #include <stdio.h>
  7605. #include <string.h>
  7606.  
  7607. int main(void)
  7608. {
  7609.    char *ptr1, *ptr2;
  7610.  
  7611.    if (NULL == (ptr1 = (char*)malloc(10))) {
  7612.       puts("Could not allocate memory block.");
  7613.       exit(EXIT_FAILURE);
  7614.    }
  7615.    memset(ptr1, 'a', 5);
  7616.    _dump_allocated(10);
  7617.  
  7618.    if (NULL == (ptr2 = (char*)malloc(20))) {
  7619.       puts("Could not allocate memory block.");
  7620.       exit(EXIT_FAILURE);
  7621.    }
  7622.    memset(ptr2, 'b', 5);
  7623.    _dump_allocated_delta(10);
  7624.  
  7625.    free(ptr1);
  7626.    free(ptr2);
  7627.    return 0;
  7628.  
  7629.    /****************************************************************************
  7630.       The output should be similar to :
  7631.  
  7632.       -------------------------------------------------------------------------------
  7633.                        START OF DUMP OF ALLOCATED MEMORY BLOCKS
  7634.       -------------------------------------------------------------------------------
  7635.       Address: 0x00073890      Size: 0x0000000A (10)
  7636.       This memory block was (re)allocated at line number 9 in _dump_alloc_d.c.
  7637.       Memory contents:  61616161 61AAAAAA AAAA                 [aaaaa╨ÿ╨ÿ╨ÿ╨ÿ╨ÿ      ]
  7638.       -------------------------------------------------------------------------------
  7639.                        END OF DUMP OF ALLOCATED MEMORY BLOCKS
  7640.       -------------------------------------------------------------------------------
  7641.       -------------------------------------------------------------------------------
  7642.                        START OF DUMP OF ALLOCATED MEMORY BLOCKS
  7643.       -------------------------------------------------------------------------------
  7644.       Address: 0x000738D0      Size: 0x00000014 (20)
  7645.       This memory block was (re)allocated at line number 16 in _dump_alloc_d.c.
  7646.       Memory contents:  62626262 62AAAAAA AAAA                 [bbbbb╨ÿ╨ÿ╨ÿ╨ÿ╨ÿ      ]
  7647.       -------------------------------------------------------------------------------
  7648.                        END OF DUMP OF ALLOCATED MEMORY BLOCKS
  7649.       -------------------------------------------------------------------------------
  7650.    ****************************************************************************/
  7651. }
  7652.  
  7653.  
  7654. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7655.  
  7656. Example of _dump_allocated_delta 
  7657.  
  7658.      Differentiating between Memory Management Functions 
  7659.      _debug_calloc - Allocate and Initialize Memory 
  7660.      _debug_malloc - Allocate Memory 
  7661.      _dump_allocated - Get Information about Allocated Memory 
  7662.      _debug_realloc - Reallocate Memory Block 
  7663.      _set_crt_msg_handle - Change Runtime Message Output Destination 
  7664.      _udump_allocated_delta - Get Information about Allocated Memory in Heap 
  7665.      <stdlib.h> 
  7666.      <malloc.h> 
  7667.  
  7668.  
  7669. ΓòÉΓòÉΓòÉ 4.59. dup - Associate Second Handle with Open File ΓòÉΓòÉΓòÉ
  7670.  
  7671.  
  7672. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7673.  
  7674. #include <io.h>
  7675. int dup(int handle);
  7676.  
  7677.  
  7678. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7679.  
  7680. Language Level:  XPG4, Extension 
  7681.  
  7682. dup associates a second file handle with a currently open file. You can carry 
  7683. out operations on the file using either file handle because all handles 
  7684. associated with a given file use the same file pointer. Creation of a new 
  7685. handle does not affect the type of access allowed for the file. 
  7686.  
  7687. For example, given: 
  7688.  
  7689.    handle2 = dup(handle1)
  7690. handle2 will have the same file access mode (text or binary) as handle1. In 
  7691. addition, if handle1 was originally opened with the O_APPEND flag (described in 
  7692. open - Open File), handle2 will also have that attribute. 
  7693.  
  7694. Warning: Both handles share a single file pointer. If you reposition a file 
  7695. using handle1, the position in the file returned by handle2 will also change. 
  7696.  
  7697. If you duplicate a file handle for an open stream, the resulting file handle 
  7698. has the same restrictions as the original file handle. 
  7699.  
  7700. Note:  In earlier releases of VisualAge C++, dup began with an underscore 
  7701. (_dup). Because it is defined by the X/Open standard, the underscore has been 
  7702. removed. For compatibility, VisualAge for C++ will map _dup to dup for you. 
  7703.  
  7704. Return Value 
  7705. dup returns the next available file handle for the given file. It returns -1 if 
  7706. an error occurs and sets errno to one of the following values: 
  7707.  
  7708.  Value          Meaning 
  7709.  EBADF          The file handle is not valid. 
  7710.  EMFILE         No more file handles are available. 
  7711.  EOS2ERR        The call to the operating system was not successful. 
  7712.  
  7713.  
  7714. ΓòÉΓòÉΓòÉ <hidden> Example of dup ΓòÉΓòÉΓòÉ
  7715.  
  7716. /************************************************************************
  7717.  
  7718. This example makes a second file handle, fh3, refer to the same file as the 
  7719. file handle fh1 using dup. The file handle fh2 is then associated with the file 
  7720. edopen.da2, and finally fh2 is forced to associate with edopen.da1 dup2. 
  7721.  
  7722. ************************************************************************/
  7723.  
  7724. #include <io.h>
  7725. #include <stdio.h>
  7726. #include <stdlib.h>
  7727. #include <fcntl.h>
  7728. #include <sys\stat.h>
  7729.  
  7730. int main(void)
  7731. {
  7732.    int fh1,fh2,fh3;
  7733.  
  7734.    if (-1 == (fh1 = open("edopen.da1", O_CREAT|O_TRUNC|O_RDWR, S_IREAD|S_IWRITE)
  7735.       )) {
  7736.       perror("Unable to open edopen.da1");
  7737.       return EXIT_FAILURE;
  7738.    }
  7739.    if (-1 == (fh3 = dup(fh1))) {     /* fh3 refers to the sample file as fh1  */
  7740.       perror("Unable to dup");
  7741.       close(fh1);
  7742.       return EXIT_FAILURE;
  7743.    }
  7744.    else
  7745.       printf("Successfully performed dup handle.\n");
  7746.    if (-1 == (fh2 = open("edopen.da2", O_CREAT|O_TRUNC|O_RDWR, S_IREAD|S_IWRITE)
  7747.       )) {
  7748.       perror("Unable to open edopen.da2");
  7749.       close(fh1);
  7750.       close(fh3);
  7751.       return EXIT_FAILURE;
  7752.    }
  7753.    if (-1 == dup2(fh1, fh2)) {  /* Force fh2 to the refer to the same file    */
  7754.                                 /* as fh1.                                    */
  7755.       perror("Unable to dup2");
  7756.    }
  7757.    else
  7758.       printf("Successfully performed dup2 handle.\n");
  7759.    close(fh1);
  7760.    close(fh2);
  7761.    close(fh3);
  7762.    return 0;
  7763.  
  7764.    /****************************************************************************
  7765.       The output should be:
  7766.  
  7767.        Successfully performed dup handle.
  7768.        Successfully performed dup2 handle.
  7769.    ****************************************************************************/
  7770. }
  7771.  
  7772.  
  7773. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7774.  
  7775. Example of dup 
  7776.  
  7777.      close - Close File Associated with Handle 
  7778.      creat - Create New File 
  7779.      dup2 - Associate Second Handle with Open File 
  7780.      open - Open File 
  7781.      _sopen - Open Shared File 
  7782.      <io.h> 
  7783.  
  7784.  
  7785. ΓòÉΓòÉΓòÉ 4.60. dup2 - Associate Second Handle with Open File ΓòÉΓòÉΓòÉ
  7786.  
  7787.  
  7788. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7789.  
  7790. #include <io.h>
  7791. int dup2(int handle1, int handle2);
  7792.  
  7793.  
  7794. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7795.  
  7796. Language Level:  XPG4, Extension 
  7797.  
  7798. dup2 makes handle2 refer to the currently open file associated with handle1. 
  7799. You can carry out operations on the file using either file handle because all 
  7800. handles associated with a given file use the same file pointer. 
  7801.  
  7802. handle2 will point to the same file as handle1, but will retain the file access 
  7803. mode (text or binary) that it had before duplication. In addition, if handle2 
  7804. was originally opened with the O_APPEND flag, it will also retain that 
  7805. attribute. If handle2 is associated with an open file at the time of the call, 
  7806. that file is closed. 
  7807.  
  7808. Warning: Both handles share a single file position. If you reposition a file 
  7809. using handle1, the position in the file returned by handle2 will also change. 
  7810.  
  7811. If you duplicate a file handle for an open stream (using fileno), the resulting 
  7812. file handle has the same restrictions as the original file handle. 
  7813.  
  7814. Note:  In earlier releases of VisualAge C++, dup2 began with an underscore 
  7815. (_dup2). Because it is defined by the X/Open standard, the underscore has been 
  7816. removed. For compatibility, VisualAge for C++ will map _dup2 to dup2 for you. 
  7817.  
  7818. Return Value 
  7819. dup2 returns 0 to indicate success. It returns -1 if an error occurs and sets 
  7820. errno to one of the following values: 
  7821.  
  7822.  Value          Meaning 
  7823.  EBADF          The file handle is not valid. 
  7824.  EMFILE         No more file handles are available. 
  7825.  EOS2ERR        The call to the operating system was not successful. 
  7826.  
  7827.  
  7828. ΓòÉΓòÉΓòÉ <hidden> Example of dup2 ΓòÉΓòÉΓòÉ
  7829.  
  7830. /************************************************************************
  7831.  
  7832. This example makes a second file handle, fh3, refer to the same file as the 
  7833. file handle fh1 using dup. The file handle fh2 is then associated with the file 
  7834. edopen.da2, and finally fh2 is forced to associate with edopen.da1 by the dup2 
  7835. function. 
  7836.  
  7837. ************************************************************************/
  7838.  
  7839. #include <io.h>
  7840. #include <stdio.h>
  7841. #include <stdlib.h>
  7842. #include <fcntl.h>
  7843. #include <sys\stat.h>
  7844.  
  7845. int main(void)
  7846. {
  7847.    int fh1,fh2,fh3;
  7848.  
  7849.    if (-1 == (fh1 = open("edopen.da1", O_CREAT|O_TRUNC|O_RDWR, S_IREAD|S_IWRITE)
  7850.       )) {
  7851.       perror("Unable to open edopen.da1");
  7852.       return EXIT_FAILURE;
  7853.    }
  7854.    if (-1 == (fh3 = dup(fh1))) {     /* fh3 refers to the sample file as fh1  */
  7855.       perror("Unable to dup");
  7856.       close(fh1);
  7857.       return EXIT_FAILURE;
  7858.    }
  7859.    else
  7860.       printf("Successfully performed dup handle.\n");
  7861.    if (-1 == (fh2 = open("edopen.da2", O_CREAT|O_TRUNC|O_RDWR, S_IREAD|S_IWRITE)
  7862.       )) {
  7863.       perror("Unable to open edopen.da2");
  7864.       close(fh1);
  7865.       close(fh3);
  7866.       return EXIT_FAILURE;
  7867.    }
  7868.    if (-1 == dup2(fh1, fh2)) {  /* Force fh2 to the refer to the same file    */
  7869.                                 /* as fh1.                                    */
  7870.       perror("Unable to dup2");
  7871.    }
  7872.    else
  7873.       printf("Successfully performed dup2 handle.\n");
  7874.    close(fh1);
  7875.    close(fh2);
  7876.    close(fh3);
  7877.    return 0;
  7878.  
  7879.    /****************************************************************************
  7880.       The output should be:
  7881.  
  7882.        Successfully performed dup handle.
  7883.        Successfully performed dup2 handle.
  7884.    ****************************************************************************/
  7885. }
  7886.  
  7887.  
  7888. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7889.  
  7890. Example of dup2 
  7891.  
  7892.      close - Close File Associated with Handle 
  7893.      creat - Create New File 
  7894.      dup - Associate Second Handle with Open File 
  7895.      open - Open File 
  7896.      _sopen - Open Shared File 
  7897.      <io.h> 
  7898.  
  7899.  
  7900. ΓòÉΓòÉΓòÉ 4.61. _ecvt - Convert Floating-Point to Character ΓòÉΓòÉΓòÉ
  7901.  
  7902.  
  7903. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7904.  
  7905. #include <stdlib.h>
  7906. char *_ecvt(double value, int ndigits, int *decptr, int *signptr);
  7907.  
  7908.  
  7909. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7910.  
  7911. Language Level:  Extension 
  7912.  
  7913. _ecvt converts the floating-point number value to a character string. _ecvt 
  7914. stores ndigits digits of value as a string and adds a null character (\0). If 
  7915. the number of digits in value exceeds ndigits, the low-order digit is rounded. 
  7916. If there are fewer than ndigits digits, the string is padded with zeros. Only 
  7917. digits are stored in the string. 
  7918.  
  7919. You can obtain the position of the decimal point and the sign of value after 
  7920. the call from decptr and signptr. decptr points to an integer value that gives 
  7921. the position of the decimal point with respect to the beginning of the string. 
  7922. A 0 or a negative integer value indicates that the decimal point lies to the 
  7923. left of the first digit. 
  7924.  
  7925. signptr points to an integer that indicates the sign of the converted number. 
  7926. If the integer value is 0, the number is positive. If it is not 0, the number 
  7927. is negative. 
  7928.  
  7929. _ecvt also converts NaN and infinity values to the strings NAN and INFINITY, 
  7930. respectively. For more information on NaN and infinity values, see Infinity and 
  7931. NaN Support. 
  7932.  
  7933. Warning: For each thread, the _ecvt, _fcvt and _gcvt functions use a single, 
  7934. dynamically allocated buffer for the conversion. Any subsequent call that the 
  7935. same thread makes to these functions destroys the result of the previous call. 
  7936.  
  7937. Return Value 
  7938. _ecvt returns a pointer to the string of digits. Because of the limited 
  7939. precision of the double type, no more than 16 decimal digits are significant in 
  7940. any conversion. If it cannot allocate memory to perform the conversion. _ecvt 
  7941. returns NULL and sets errno to ENOMEM. 
  7942.  
  7943.  
  7944. ΓòÉΓòÉΓòÉ <hidden> Example of _ecvt ΓòÉΓòÉΓòÉ
  7945.  
  7946. /************************************************************************
  7947.  
  7948. This example reads in two floating-point numbers, calculates their product, and 
  7949. prints out only the billions digit of its character representation. At most, 16 
  7950. decimal digits of significance can be expected. The output assumes the user 
  7951. enters the numbers 1000000 and 3000. 
  7952.  
  7953. ************************************************************************/
  7954.  
  7955. #include <stdio.h>
  7956. #include <stdlib.h>
  7957. #include <math.h>
  7958.  
  7959. int main(void)
  7960. {
  7961.    float x,y;
  7962.    double z;
  7963.    int w,b,decimal,sign;
  7964.    char *buffer;
  7965.  
  7966.    printf("Enter two floating-point numbers:\n");
  7967.    if (2 != scanf("%e %e", &x, &y)) {
  7968.       printf("input error...\n");
  7969.       return EXIT_FAILURE;
  7970.    }
  7971.    z = x *y;
  7972.    printf("Their product is %g\n", z);
  7973.    w = log10(fabs(z))+1.;
  7974.    buffer = _ecvt(z, w, &decimal, &sign);
  7975.    b = decimal-10;
  7976.    if (b < 0)
  7977.       printf("Their product does not exceed one billion.\n");
  7978.    else
  7979.       if (b > 15)
  7980.          printf("The billions digit of their product is insignificant.\n");
  7981.       else
  7982.          printf("The billions digit of their product is %c.\n", buffer[b]);
  7983.    return 0;
  7984.  
  7985.    /****************************************************************************
  7986.       For the following input:
  7987.  
  7988.       1000000 3000
  7989.  
  7990.       The output should be:
  7991.  
  7992.       Enter two floating-point numbers:
  7993.       1000000 3000
  7994.       Their product is 3e+09
  7995.       The billions digit of their product is 3.
  7996.    ****************************************************************************/
  7997. }
  7998.  
  7999.  
  8000. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8001.  
  8002. Example of _ecvt 
  8003.  
  8004.      _fcvt - Convert Floating-Point to String 
  8005.      _gcvt - Convert Floating-Point to String 
  8006.      Infinity and NaN Support 
  8007.      <stdlib.h> 
  8008.  
  8009.  
  8010. ΓòÉΓòÉΓòÉ 4.62. _enable - Enable Interrupts ΓòÉΓòÉΓòÉ
  8011.  
  8012.  
  8013. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8014.  
  8015. #include <builtin.h>  /* also defined in <stdlib.h> */
  8016. void _enable( void );
  8017.  
  8018.  
  8019. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8020.  
  8021. Language Level:  Extension 
  8022.  
  8023. _enable enables interrupts by generating the STI machine instruction. 
  8024. Interrupts are enabled after the instruction following STI has been executed. 
  8025. If interrupts are disabled and you call _enable followed immediately by a call 
  8026. to _disable, interrupts remain disabled. 
  8027.  
  8028. Because it is a built-in function and has no backing code in the library: 
  8029.  
  8030.      You cannot take the address of _enable. 
  8031.      You cannot parenthesize an _enable function call because parentheses 
  8032.       specify a call to the backing code for the function in the library. 
  8033.  
  8034.  You can run code containing this function only at ring zero. Otherwise, an 
  8035.  invalid instruction exception will be generated. 
  8036.  
  8037.  Return Value 
  8038.  There is no return value. 
  8039.  
  8040.  
  8041. ΓòÉΓòÉΓòÉ <hidden> Example of _enable ΓòÉΓòÉΓòÉ
  8042.  
  8043. /************************************************************************
  8044.  
  8045. In this example, _enable enables interrupts by executing an STI instruction. 
  8046.  
  8047. ************************************************************************/
  8048.  
  8049. #include <builtin.h>
  8050.  
  8051. int main(void)
  8052. {
  8053.    /* ------------------------------------------------------ */
  8054.    /* The expected assembler instruction looks like this :   */
  8055.    /*       STI                                              */
  8056.    /* ------------------------------------------------------ */
  8057.    _enable();
  8058.    return 0;
  8059. }
  8060.  
  8061.  
  8062. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8063.  
  8064. Example of _enable 
  8065.  
  8066.      _disable - Disable Interrupts 
  8067.      _interrupt - Call Interrupt  Procedure 
  8068.      <builtin.h> 
  8069.  
  8070.  
  8071. ΓòÉΓòÉΓòÉ 4.63. _endthread - Terminate Current Thread ΓòÉΓòÉΓòÉ
  8072.  
  8073.  
  8074. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8075.  
  8076. #include <stdlib.h>  /* also in <process.h> */
  8077. void _endthread(void);
  8078.  
  8079.  
  8080. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8081.  
  8082. Language Level:  Extension 
  8083.  
  8084. _endthread ends a thread that you previously created with _beginthread. When 
  8085. the thread has finished, it automatically ends itself with an implicit call to 
  8086. _endthread. You can also call _endthread explicitly to end the thread before it 
  8087. has completed its function, for example, if some error condition occurs. 
  8088.  
  8089. Note:  When using the _beginthread and _endthread functions, you must specify 
  8090. the /Gm+ compiler option to use the multithread libraries. 
  8091.  
  8092. Return Value 
  8093. There is no return value. 
  8094.  
  8095.  
  8096. ΓòÉΓòÉΓòÉ <hidden> Example of _endthread ΓòÉΓòÉΓòÉ
  8097.  
  8098. /************************************************************************
  8099.  
  8100. In this example, the main program creates two threads, bonjour and au_revoir. 
  8101.  
  8102. Note:  You must compile this example with the /Gm+ option. 
  8103.  
  8104. ************************************************************************/
  8105.  
  8106. /************************************************************************
  8107.  Note:  To run this example, you must compile it using
  8108.  the /Gm+ compile-time option.
  8109.  ***********************************************************************      */
  8110.  
  8111. #if (1 == __TOS_OS2__)
  8112.     #define  INCL_DOS                          /*  OS/2  */
  8113.     #include <os2.h>
  8114. #else
  8115.     #include <windows.h>                       /*  Windows  */
  8116. #endif
  8117.  
  8118. #include <stdio.h>
  8119. #include <stdlib.h>
  8120. #include <process.h>
  8121.  
  8122. void _Optlink bonjour(void *arg)
  8123. {
  8124.    int i = 0;
  8125.  
  8126.    while (i++ < 5)
  8127.       printf("Bonjour!\n");
  8128.    _endthread();                        /* This thread ends itself explicitly */
  8129.    puts("thread should terminate before printing this");
  8130. }
  8131.  
  8132. void _Optlink au_revoir(void *arg)
  8133. {
  8134.    int i = 0;
  8135.  
  8136.    while (i++ < 5)                         /* This thread makes an implicit   */
  8137.       printf("Au revoir!\n");              /*  call to _endthread             */
  8138. }
  8139.  
  8140. int main(void)
  8141. {
  8142.    unsigned long tid1;
  8143.    unsigned long tid2;
  8144.  
  8145.    tid1 = _beginthread(bonjour, NULL, 8192, NULL);
  8146.    tid2 = _beginthread(au_revoir, NULL, 8192, NULL);
  8147.    if (-1 == tid1 || -1 == tid2) {
  8148.       printf("Unable to start threads.\n");
  8149.       return EXIT_FAILURE;
  8150.    }
  8151. #if (1 == __TOS_OS2__)
  8152.    DosWaitThread(&tid2, DCWW_WAIT);            /*  wait until threads 1 and 2 */
  8153.    DosWaitThread(&tid1, DCWW_WAIT);            /*  have been completed        */
  8154. #else
  8155.    WaitForSingleObject((HANDLE)tid2, INFINITE);  /* wait until threads 1 and 2 */
  8156.    WaitForSingleObject((HANDLE)tid1, INFINITE);  /* have been completed        */
  8157. #endif
  8158.  
  8159.    return 0;
  8160.  
  8161. }
  8162.  
  8163.  
  8164. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8165.  
  8166. Example of _endthread 
  8167.  
  8168.      _beginthread - Create New Thread 
  8169.      /Gm+ option. in the User's Guide 
  8170.      <stdlib.h> 
  8171.      <process.h> 
  8172.  
  8173.  
  8174. ΓòÉΓòÉΓòÉ 4.64. __eof - Determine End of File ΓòÉΓòÉΓòÉ
  8175.  
  8176.  
  8177. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8178.  
  8179. #include <io.h>
  8180. int __eof (int handle);
  8181.  
  8182.  
  8183. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8184.  
  8185. Language Level:  Extension 
  8186.  
  8187. __eof determines whether the file pointer has reached the end-of-file for the 
  8188. file associated with handle. You cannot use __eof on a nonseekable file; it 
  8189. will fail. 
  8190.  
  8191. Return Value 
  8192. __eof returns the value 1 if the current position is the end of the file or 0 
  8193. if it is not. A return value of -1 shows an error, and the system sets errno to 
  8194. the following values: 
  8195.  
  8196.  Value          Meaning 
  8197.  EBADF          File handle is not valid. 
  8198.  EOS2ERR        The call to the operating system was not successful. 
  8199.  
  8200.  
  8201. ΓòÉΓòÉΓòÉ <hidden> Example of __eof ΓòÉΓòÉΓòÉ
  8202.  
  8203. /************************************************************************
  8204.  
  8205. This example creates the file sample.dat and then checks if the file pointer is 
  8206. at the end of that file using the __eof function. 
  8207.  
  8208. ************************************************************************/
  8209.  
  8210. #include <sys\stat.h>
  8211. #include <io.h>
  8212. #include <stdio.h>
  8213. #include <stdlib.h>
  8214.  
  8215. int main(void)
  8216. {
  8217.    int fh,returnValue;
  8218.  
  8219.    fh = creat("sample.dat", S_IREAD|S_IWRITE);
  8220.    if (-1 == fh) {
  8221.       perror("Error creating sample.dat");
  8222.       return EXIT_FAILURE;
  8223.    }
  8224.    if (-1 == (returnValue = __eof(fh))) {
  8225.       perror("eof function error");
  8226.       return EXIT_FAILURE;
  8227.    }
  8228.    if (1 == returnValue)
  8229.       printf("File pointer is at end-of-file position.\n");
  8230.    else
  8231.       printf("File pointer is not at end-of-file position.\n");
  8232.    close(fh);
  8233.    return 0;
  8234.  
  8235.    /****************************************************************************
  8236.       The output should be:
  8237.  
  8238.       File pointer is at end-of-file position.
  8239.    ****************************************************************************/
  8240. }
  8241.  
  8242.  
  8243. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8244.  
  8245. Example of __eof 
  8246.  
  8247.      _chsize - Alter Length of File 
  8248.      creat - Create New File 
  8249.      _filelength - Determine File Length 
  8250.      _sopen - Open Shared File 
  8251.      open - Open File 
  8252.      <io.h> 
  8253.  
  8254.  
  8255. ΓòÉΓòÉΓòÉ 4.65. erf - erfc - Calculate Error Functions ΓòÉΓòÉΓòÉ
  8256.  
  8257.  
  8258. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8259.  
  8260. #include <math.h>
  8261. double erf(double x);
  8262. double erfc(double x);
  8263.  
  8264.  
  8265. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8266.  
  8267. Language Level: SAA, XPG4 
  8268.  
  8269. erf calculates the error function. 
  8270.  
  8271. erfc computes the value of 1.0 - erf(x). erfc is used in place of erf for large 
  8272. values of x. 
  8273.  
  8274. Return Value 
  8275. erf returns a double value that represents the error function. erfc returns a 
  8276. double value representing 1.0 - erf. 
  8277.  
  8278.  
  8279. ΓòÉΓòÉΓòÉ <hidden> Example of erf - erfc ΓòÉΓòÉΓòÉ
  8280.  
  8281. /************************************************************************
  8282.  
  8283. This example uses erf and erfc to compute the error function of two numbers. 
  8284.  
  8285. ************************************************************************/
  8286.  
  8287.  #include <stdio.h>
  8288.  #include <math.h>
  8289.  
  8290.  double smallx, largex, value;
  8291.  
  8292.  int main(void)
  8293.  {
  8294.     smallx = 0.1;
  8295.     largex = 10.0;
  8296.     value = erf(smallx);         /* value = 0.112463 */
  8297.     printf("Error value for 0.1: %lf\n", value);
  8298.     value = erfc(largex);        /* value = 2.088488e-45 */
  8299.     printf("Error value for 10.0: %le\n", value);
  8300.     return 0;
  8301.  
  8302.  
  8303.  /************************************************************************
  8304.  *
  8305.  Output should be:
  8306.  
  8307.  Error value for 0.1: 0.112463
  8308.  Error value for 10.0: 2.088488e-45
  8309.  
  8310.  
  8311.                                                                          *
  8312.  ************************************************************************/
  8313.  }
  8314.  
  8315.  
  8316. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8317.  
  8318. Example of erf - erfc 
  8319.  
  8320.      Bessel Functions - Solve Differential Equations 
  8321.      gamma - Gamma Function 
  8322.      <math.h> 
  8323.  
  8324.  
  8325. ΓòÉΓòÉΓòÉ 4.66. execl - _execvpe - Load and Run Child Process ΓòÉΓòÉΓòÉ
  8326.  
  8327.  
  8328. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8329.  
  8330. #include <process.h>
  8331. int execl(char *pathname, char *arg0, char *arg1,...,
  8332.              char *argn, NULL);
  8333. int execle(char *pathname, char *arg0, char *arg1,...,
  8334.              char *argn, NULL, char *envp[ ]);
  8335. int execlp(char *pathname, char *arg0, char *arg1,...,
  8336.              char *argn, NULL);
  8337. int _execlpe(char *pathname, char *arg0, char *arg1,...,
  8338.              char *argn, NULL, char *envp[ ]);
  8339. int execv(char *pathname, char *argv[ ]);
  8340. int execve(char *pathname, char *argv[ ],char *envp[ ]);
  8341. int execvp(char *pathname, char *argv[ ]);
  8342. int _execvpe(char *pathname, char *argv[ ], char *envp[ ]);
  8343.  
  8344.  
  8345. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8346.  
  8347. Language Level:  XPG4 (except _execlpe and _execvpe), Extension 
  8348.  
  8349. The exec functions load and run new child processes. The parent process is 
  8350. ended after the child process has started.  Sufficient storage must be 
  8351. available for loading and running the child process. 
  8352.  
  8353. All of the exec functions are versions of the same routine;  the letters at the 
  8354. end determine the specific variation: 
  8355.  
  8356.  Letter    Variation 
  8357.   p        Uses PATH environment variable to find the file to be run. 
  8358.   l        Passes a list of command line arguments separately. 
  8359.   v        Passes to the child process an array of pointers to command-line 
  8360.            arguments. 
  8361.   e        Passes to the child process an array of pointers to environment 
  8362.            strings. 
  8363.  
  8364.  Note:  In earlier releases of VisualAge C++, all of the exec functions began 
  8365.  with an underscore (_execl). Because they are defined by the X/Open standard, 
  8366.  the underscore has been removed. _execlpe and _execvpe retain the initial 
  8367.  underscore because they are not included in the X/Open standard. For 
  8368.  compatibility, VisualAge for C++ will map the _exec functions to the correct 
  8369.  exec function. 
  8370.  
  8371.  The pathname argument specifies the file to run as the child process.  The 
  8372.  pathname can specify a full path from the root, a partial path from the 
  8373.  current working directory, or a file name.  If pathname does not have a file 
  8374.  name extension or does not end with a period, the exec functions will add the 
  8375.  .EXE extension and search for the file.  If pathname has an extension, the 
  8376.  exec function uses only that extension. If pathname ends with a period, the 
  8377.  exec functions search for pathname with no extension.  The execlp, _execlpe, 
  8378.  execvp, and _execvpe functions search for the pathname in the directories that 
  8379.  the PATH environment variable specifies. 
  8380.  
  8381.  You pass arguments to the new process by giving one or more pointers to 
  8382.  character strings as arguments in the exec call.  These character strings form 
  8383.  the argument list for the child process. 
  8384.  
  8385.  The compiler can pass the argument pointers as separate arguments (execl, 
  8386.  execle, execlp, and _execlpe) or as an array of pointers (execv, execve, 
  8387.  execvp, and _execvpe).  You should pass at least one argument, either arg0 or 
  8388.  argv[0], to the child process. If you do not, an argument will be returned 
  8389.  that points to the same file as the path name argument you specified. This 
  8390.  argument may not be exactly identical to the path name argument you specified. 
  8391.  A different value does not produce an error. 
  8392.  
  8393.  Use the execl, execle, execlp, and _execlpe functions for the cases where you 
  8394.  know the number of arguments in advance. The arg0 argument is usually a 
  8395.  pointer to pathname. The arg1 through argn arguments are pointers to the 
  8396.  character strings forming the new argument list. There must be a NULL pointer 
  8397.  following argn to mark the end of the argument list. 
  8398.  
  8399.  Use the execv, execve, execvp, and _execvpe functions when the number of 
  8400.  arguments to the new process is variable.  Pass pointers to the arguments of 
  8401.  these functions as an array, argv[ ]. The argv[0] argument is usually a 
  8402.  pointer to pathname. The argv[1] through argv[n] arguments are pointers to the 
  8403.  character strings forming the new argument list.  If argv[n] is the last 
  8404.  parameter, then argv[n+1] must be NULL. 
  8405.  
  8406.  Files that are open when you make an exec call remain open in the new process. 
  8407.  In the execl, execlp, execv, and execvp calls, the child process receives the 
  8408.  environment of the parent.  The execle, _execlpe, execve, and _execvpe 
  8409.  functions let you change the environment for the child process by passing a 
  8410.  list of environment settings through the envp argument.  The envp argument is 
  8411.  an array of character pointers, each element of which points to a string 
  8412.  ending with a null character that defines an environment variable.  Such a 
  8413.  string usually has the following form: 
  8414.  
  8415.      NAME=value
  8416.  
  8417.  where NAME is the name of an environment variable, and value is the string 
  8418.  value to which the exec function sets that variable. 
  8419.  
  8420.  Note:  Do not enclose the value in double quotation marks. 
  8421.  
  8422.  The final element of the envp array should be NULL. When envp itself is NULL, 
  8423.  the child process receives the environment settings of the parent process. 
  8424.  
  8425.  The exec functions do not preserve signal settings in child processes created 
  8426.  by calls to exec functions.  Calls to exec functions reset the signal settings 
  8427.  to the default in the child process. 
  8428.  
  8429.  Return Value 
  8430.  The exec functions do not normally return control to the calling process. 
  8431.  They are equivalent to the corresponding _spawn functions with P_OVERLAY as 
  8432.  the value of modeflag.  If an error occurs, the exec functions return -1 and 
  8433.  set errno to one of the following values: 
  8434.  
  8435.  Value          Meaning 
  8436.  EACCESS        The specified file has a locking or sharing violation. 
  8437.  EMFILE         There are too many open files.  The system must open the 
  8438.                 specified file to tell whether it is an executable file. 
  8439.  ENOENT         The file or pathname was not found or was specified 
  8440.                 incorrectly. 
  8441.  ENOEXEC        The specified file cannot run or has an incorrect executable 
  8442.                 file format. 
  8443.  ENOMEM         One of the following conditions exists: 
  8444.                     Not enough storage is available to run the child process. 
  8445.                     Not enough storage is available for the argument or 
  8446.                      environment strings. 
  8447.  
  8448.  
  8449. ΓòÉΓòÉΓòÉ <hidden> Example of exec Functions ΓòÉΓòÉΓòÉ
  8450.  
  8451. /************************************************************************
  8452.  
  8453. This example calls four of the eight exec routines.  When invoked without 
  8454. arguments, the program first runs the code for case PARENT.  It then calls 
  8455. execle() to load and run a copy of itself.  The instructions for the child are 
  8456. blocked to run only if argv[0] and one parameter were passed (case CHILD).  In 
  8457. its turn, the child runs its own child as a copy of the same program.  This 
  8458. sequence is continued until four generations of child processes have run.  Each 
  8459. of the processes prints a message identifying itself. 
  8460.  
  8461. ************************************************************************/
  8462.  
  8463. #include <stdio.h>
  8464. #include <stdlib.h>
  8465. #include <process.h>
  8466.  
  8467. #define  PARENT       1
  8468. #define  CHILD        2
  8469.  
  8470. char *args[3];
  8471.  
  8472. int main(int argc, char **argv, char **envp) {
  8473.    switch(argc) {
  8474.       case PARENT: {                   /* No argument: run a child */
  8475.          printf("Parent process began.\n");
  8476.          execle(argv[0],argv[0],"1",NULL,envp);
  8477.          abort();     /* Not executed because parent was overlaid. */
  8478.       }
  8479.       case CHILD: {           /* One argument: run a child's child */
  8480.          printf("Child process %s began.\n", argv[1]);
  8481.          if ('1' == *argv[1]) {   /* generation one */
  8482.             execl(argv[0], argv[0], "2", NULL);
  8483.             abort();    /* Not executed because child was overlaid */
  8484.         }
  8485.         if('2' == *argv[1]) {                    /* generation two */
  8486.             args[0] = argv[0];
  8487.             args[1] = "3";
  8488.             args[2] = NULL;
  8489.             execv(argv[0],args);
  8490.             abort();    /* Not executed because child was overlaid */
  8491.          }
  8492.          if ('3' == *argv[1]) {                /* generation three */
  8493.             args[0] = argv[0];
  8494.             args[1] = "4";
  8495.             args[2] = NULL;
  8496.             execve(argv[0], args, _environ);
  8497.             abort();    /* Not executed because child was overlaid */
  8498.         }
  8499.          if ('4' == *argv[1])                   /* generation four */
  8500.             printf("Child process %s", argv[1]);
  8501.       }
  8502.    }
  8503.    printf(" ended.\n");
  8504.    return 55;
  8505.    /* The output should be similar to:
  8506.       Parent process began.
  8507.       Child process 1 began.
  8508.       Child process 2 began.
  8509.       Child process 3 began.
  8510.       Child process 4 began.
  8511.       Child process 4 ended.                                        */
  8512. }
  8513.  
  8514.  
  8515. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8516.  
  8517. Example of exec Functions 
  8518.  
  8519.      abort - Stop a Program 
  8520.      _cwait - Wait for Child Process 
  8521.      exit - End Program 
  8522.      _exit - End Process 
  8523.      _spawnl - _spawnvpe - Start and Run Child Processes 
  8524.      system - Invoke the Command Processor 
  8525.      "Arguments to main" in the Language Reference 
  8526.      <process.h> 
  8527.  
  8528.  
  8529. ΓòÉΓòÉΓòÉ 4.67. exit - End Program ΓòÉΓòÉΓòÉ
  8530.  
  8531.  
  8532. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8533.  
  8534. #include <stdlib.h>  /* also in <process.h> */
  8535. void exit(int status);
  8536.  
  8537.  
  8538. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8539.  
  8540. Language Level: ANSI, SAA, POSIX, XPG4, Extension 
  8541.  
  8542. exit returns control to the host environment from the program. It first calls 
  8543. all functions registered with the atexit function, in reverse order;  that is, 
  8544. the last one registered is the first one called. It flushes all buffers and 
  8545. closes all open files before ending the program. All files opened with tmpfile 
  8546. are deleted. 
  8547.  
  8548. The argument status can have a value from 0 to 255 inclusive or be one of the 
  8549. macros EXIT_SUCCESS or EXIT_FAILURE. A status value of EXIT_SUCCESS or 0 
  8550. indicates a normal exit; otherwise, another status value is returned. 
  8551.  
  8552. Return Value 
  8553. exit returns both control and the value of status to the operating system. 
  8554.  
  8555.  
  8556. ΓòÉΓòÉΓòÉ <hidden> Example of exit ΓòÉΓòÉΓòÉ
  8557.  
  8558. /************************************************************************
  8559.  
  8560. This example ends the program after flushing buffers and closing any open files 
  8561. if it cannot open the file myfile.mjq. 
  8562.  
  8563. ************************************************************************/
  8564.  
  8565. #include <stdio.h>
  8566. #include <stdlib.h>
  8567.  
  8568. FILE *stream;
  8569.  
  8570. int main(void)
  8571. {
  8572.    if (NULL == (stream = fopen("myfile.mjq", "r"))) {
  8573.       perror("Could not open data file");
  8574.       exit(EXIT_FAILURE);
  8575.    }
  8576.    return 0;
  8577.  
  8578.    /****************************************************************************
  8579.       The output should be:
  8580.  
  8581.       Could not open data file: The file cannot be found.
  8582.    ****************************************************************************/
  8583. }
  8584.  
  8585.  
  8586. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8587.  
  8588. Example of exit 
  8589.  
  8590.      abort - Stop a Program 
  8591.      atexit - Record Program Termination Function 
  8592.      _onexit - Record Termination Function 
  8593.      _exit - End Process 
  8594.      signal - Handle Interrupt Signals 
  8595.      tmpfile - Create Temporary File 
  8596.      <stdlib.h> 
  8597.  
  8598.  
  8599. ΓòÉΓòÉΓòÉ 4.68. _exit - End Process ΓòÉΓòÉΓòÉ
  8600.  
  8601.  
  8602. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8603.  
  8604. #include <stdlib.h>  /* also in <process.h> */
  8605. void _exit(int status);
  8606.  
  8607.  
  8608. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8609.  
  8610. Language Level:  Extension 
  8611.  
  8612. _exit ends the calling process without calling functions registered by _onexit 
  8613. or atexit. It also does not flush stream buffers or delete temporary files. You 
  8614. supply the status value as a parameter; the value 0 typically means a normal 
  8615. exit. 
  8616.  
  8617. Return Value 
  8618. Although _exit does not return a value, the value is available to the waiting 
  8619. parent process, if there is one, after the child process ends.  If no parent 
  8620. process waits for the exiting process, the status value is lost.  The status 
  8621. value is available through the operating system batch command IF ERRORLEVEL. 
  8622.  
  8623.  
  8624. ΓòÉΓòÉΓòÉ <hidden> Example of _exit ΓòÉΓòÉΓòÉ
  8625.  
  8626. /************************************************************************
  8627.  
  8628. This example calls _exit to end the process. Because _exit does not flush the 
  8629. buffer first, the output from the second printf statement will not appear. 
  8630.  
  8631. ************************************************************************/
  8632.  
  8633. #include <stdio.h>
  8634. #include <stdlib.h>                      /* You can also use <process.h>      */
  8635.  
  8636. char buf[51];
  8637.  
  8638. int main(void)
  8639. {
  8640.  
  8641.    /* Make sure the standard output stream is line-buffered even if the       */
  8642.    /* output is redirected to a file.                                         */
  8643.  
  8644.    if (0 != setvbuf(stdout, buf, _IOLBF, 50))
  8645.       printf("The buffering was not set correctly.\n");
  8646.    printf("This will print out but ...\n");
  8647.    printf("this will not!");
  8648.    _exit(EXIT_FAILURE);
  8649.    return 0;
  8650.  
  8651.    /****************************************************************************
  8652.       The output should be:
  8653.  
  8654.       This will print out but ...
  8655.    ****************************************************************************/
  8656. }
  8657.  
  8658.  
  8659. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8660.  
  8661. Example of _exit 
  8662.  
  8663.      abort - Stop a Program 
  8664.      atexit - Record Program Termination Function 
  8665.      execl - _execvpe - Load and Run Child Process 
  8666.      exit - End Program 
  8667.      _onexit - Record Termination Function 
  8668.      <process.h> 
  8669.      <stdlib.h> 
  8670.  
  8671.  
  8672. ΓòÉΓòÉΓòÉ 4.69. exp - Calculate Exponential Function ΓòÉΓòÉΓòÉ
  8673.  
  8674.  
  8675. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8676.  
  8677. #include <math.h>
  8678. double exp(double x);
  8679.  
  8680.  
  8681. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8682.  
  8683. Language Level: ANSI, SAA, POSIX, XPG4 
  8684.  
  8685. exp calculates the exponential function of a floating-point argument x (e to 
  8686. the exponent x, where e equals 2.17128128...). 
  8687.  
  8688. Return Value 
  8689. If an overflow occurs, exp returns HUGE_VAL. If an underflow occurs, it returns 
  8690. 0. Both overflow and underflow set errno to ERANGE. 
  8691.  
  8692.  
  8693. ΓòÉΓòÉΓòÉ <hidden> Example of exp ΓòÉΓòÉΓòÉ
  8694.  
  8695. /************************************************************************
  8696.  
  8697. This example calculates y as the exponential function of x: 
  8698.  
  8699. ************************************************************************/
  8700.  
  8701. #include <stdio.h>
  8702. #include <math.h>
  8703.  
  8704. int main(void)
  8705. {
  8706.    double x,y;
  8707.  
  8708.    x = 5.0;
  8709.    y = exp(x);
  8710.    printf("exp( %lf ) = %lf\n", x, y);
  8711.    return 0;
  8712.  
  8713.    /****************************************************************************
  8714.       The output should be:
  8715.  
  8716.       exp( 5.000000 ) = 148.413159
  8717.    ****************************************************************************/
  8718. }
  8719.  
  8720.  
  8721. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8722.  
  8723. Example of exp 
  8724.  
  8725.      log - Calculate Natural Logarithm 
  8726.      log10 - Calculate Base 10 Logarithm 
  8727.      <math.h> 
  8728.  
  8729.  
  8730. ΓòÉΓòÉΓòÉ 4.70. fabs - Calculate Floating-Point Absolute Value ΓòÉΓòÉΓòÉ
  8731.  
  8732.  
  8733. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8734.  
  8735. #include <math.h>
  8736. double fabs(double x);
  8737.  
  8738.  
  8739. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8740.  
  8741. Language Level: ANSI, SAA, POSIX, XPG4 
  8742.  
  8743. fabs calculates the absolute value of the floating-point argument x. 
  8744.  
  8745. Return Value 
  8746. fabs returns the absolute value. There is no error return value. 
  8747.  
  8748.  
  8749. ΓòÉΓòÉΓòÉ <hidden> Example of fabs ΓòÉΓòÉΓòÉ
  8750.  
  8751. /************************************************************************
  8752.  
  8753. This example calculates y as the absolute value of x: 
  8754.  
  8755. ************************************************************************/
  8756.  
  8757. #include <stdio.h>
  8758. #include <math.h>
  8759.  
  8760. int main(void)
  8761. {
  8762.    double x,y;
  8763.  
  8764.    x = -5.6798;
  8765.    y = fabs(x);
  8766.    printf("fabs( %lf ) = %lf\n", x, y);
  8767.    return 0;
  8768.  
  8769.    /****************************************************************************
  8770.       The output should be similar to :
  8771.  
  8772.       fabs( -5.679800 ) = 5.679800
  8773.    ****************************************************************************/
  8774. }
  8775.  
  8776.  
  8777. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8778.  
  8779. Example of fabs 
  8780.  
  8781.      abs - Calculate Integer Absolute Value 
  8782.      _cabs - Calculate Absolute Value of Complex Number 
  8783.      labs - Calculate Absolute Value of Long Integer 
  8784.      <math.h> 
  8785.  
  8786.  
  8787. ΓòÉΓòÉΓòÉ 4.71. _facos - Calculate Arccosine ΓòÉΓòÉΓòÉ
  8788.  
  8789.  
  8790. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8791.  
  8792. #include <builtin.h>
  8793. double _facos(double x);
  8794.  
  8795.  
  8796. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8797.  
  8798. Language Level:  Extension 
  8799.  
  8800. _facos calculates the arccosine of x. This function causes the compiler to emit 
  8801. the appropriate 80387 instructions for the calculation of the arccosine. 
  8802.  
  8803. Because it is a built-in function and has no backing code in the library: 
  8804.  
  8805.      You cannot take the address of _facos. 
  8806.      You cannot parenthesize a _facos function call, because parentheses 
  8807.       specify a call to the backing code for the function. 
  8808.  
  8809.  Return Value 
  8810.  _facos returns the arccosine of x. 
  8811.  
  8812.  
  8813. ΓòÉΓòÉΓòÉ <hidden> Example of _facos ΓòÉΓòÉΓòÉ
  8814.  
  8815. /************************************************************************
  8816.  
  8817. This example prompts for a value for x. It prints an error message if x is 
  8818. greater than 1 or less than -1. Otherwise, it assigns the arccosine of x to y. 
  8819.  
  8820. ************************************************************************/
  8821.  
  8822. #include <builtin.h>
  8823. #include <stdio.h>
  8824.  
  8825. #define MAX  1.0
  8826. #define MIN -1.0
  8827.  
  8828. int main(void)
  8829. {
  8830.    double x;
  8831.  
  8832.    printf("Enter x:\n");
  8833.    scanf("%lf", &x);
  8834.  
  8835.    /* Output error if not in range */
  8836.    if (MAX < x)
  8837.       printf("Error: %lf too large for acos.\n", x);
  8838.    else if (MIN > x)
  8839.            printf("Error: %lf too small for acos.\n", x);
  8840.         else
  8841.            printf("The arccosine of %lf is %lf.\n", x, _facos(x));
  8842.    return 0;
  8843.  
  8844.    /****************************************************************************
  8845.       Assuming you enter: -1.0
  8846.  
  8847.       The output should be:
  8848.  
  8849.       The arccossine of -1.000000 is 3.141593.
  8850.    ****************************************************************************/
  8851. }
  8852.  
  8853.  
  8854. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8855.  
  8856. Example of _facos 
  8857.  
  8858.      acos - Calculate Arccosine 
  8859.      cos - Calculate Cosine 
  8860.      cosh - Calculate Hyperbolic Cosine 
  8861.      _fcos - Calculate Cosine 
  8862.      _fcossin - Calculate Cosine and Sine 
  8863.      _fsincos - Calculate Sine and Cosine 
  8864.      <builtin.h> 
  8865.  
  8866.  
  8867. ΓòÉΓòÉΓòÉ 4.72. _fasin - Calculate Arcsine ΓòÉΓòÉΓòÉ
  8868.  
  8869.  
  8870. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8871.  
  8872. #include <builtin.h>
  8873. double _fasin(double x);
  8874.  
  8875.  
  8876. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8877.  
  8878. Language Level:  Extension 
  8879.  
  8880. _fasin calculates the arcsine of x. This function causes the compiler to emit 
  8881. the appropriate 80387 instructions for the calculation of arcsine. 
  8882.  
  8883. Because it is a built-in function and has no backing code in the library: 
  8884.  
  8885.      You cannot take the address of _fasin. 
  8886.      You cannot parenthesize a _fasin function call, because parentheses 
  8887.       specify a call to the backing code for the function. 
  8888.  
  8889.  Return Value 
  8890.  _fasin returns the arcsine of x. 
  8891.  
  8892.  
  8893. ΓòÉΓòÉΓòÉ <hidden> Example of _fasin ΓòÉΓòÉΓòÉ
  8894.  
  8895. /************************************************************************
  8896.  
  8897. This example prompts for a value of x. It prints an error message if x is 
  8898. greater than 1 or less than -1. Otherwise, it assigns the arcsine of x to y. 
  8899.  
  8900. ************************************************************************/
  8901.  
  8902. #include <builtin.h>
  8903. #include <stdio.h>
  8904.  
  8905. #define MAX  1.0
  8906. #define MIN -1.0
  8907.  
  8908. int main(void)
  8909. {
  8910.    double x;
  8911.  
  8912.    printf("Enter x:\n");
  8913.    scanf("%lf", &x);
  8914.  
  8915.    /* Output error if not in range */
  8916.    if (MAX < x)
  8917.       printf("Error: %lf too large for asin.\n", x);
  8918.    else if (MIN > x)
  8919.            printf("Error: %lf too small for asin.\n", x);
  8920.         else
  8921.            printf("The arcsine of %lf is %lf.\n", x, _fasin(x));
  8922.    return 0;
  8923.  
  8924.    /****************************************************************************
  8925.       Assuming you enter: 1.0
  8926.  
  8927.       The ouput should be:
  8928.  
  8929.       The arcsine of 1.000000 is 1.570796.
  8930.    ****************************************************************************/
  8931. }
  8932.  
  8933.  
  8934. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8935.  
  8936. Example of _fasin 
  8937.  
  8938.      asin - Calculate Arcsine 
  8939.      _fcossin - Calculate Cosine and Sine 
  8940.      _fsin - Calculate Sine 
  8941.      _fsincos - Calculate Sine and Cosine 
  8942.      sin - Calculate Sine 
  8943.      sinh - Calculate Hyperbolic Sine 
  8944.      <builtin.h> 
  8945.  
  8946.  
  8947. ΓòÉΓòÉΓòÉ 4.73. fclose - Close Stream ΓòÉΓòÉΓòÉ
  8948.  
  8949.  
  8950. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8951.  
  8952. #include <stdio.h>
  8953. int fclose(FILE *stream);
  8954.  
  8955.  
  8956. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8957.  
  8958. Language Level: ANSI, SAA, POSIX, XPG4 
  8959.  
  8960. fclose closes a stream pointed to by stream.  This function flushes all buffers 
  8961. associated with the stream before closing it.  When it closes the stream, the 
  8962. function releases any buffers that the system reserved. When a binary stream is 
  8963. closed, the last record in the file is padded with null characters (\0) to the 
  8964. end of the record. 
  8965.  
  8966. Return Value 
  8967. fclose returns 0 if it successfully closes the stream, or EOF if any errors 
  8968. were detected. 
  8969.  
  8970. Note:  Once you close a stream with fclose, you must open it again before you 
  8971. can use it. 
  8972.  
  8973.  
  8974. ΓòÉΓòÉΓòÉ <hidden> Example of fclose ΓòÉΓòÉΓòÉ
  8975.  
  8976. /************************************************************************
  8977.  
  8978. This example opens a file fclose.dat for reading as a stream; then it closes 
  8979. this file. 
  8980.  
  8981. ************************************************************************/
  8982.  
  8983. #include <stdio.h>
  8984.  
  8985. int main(void)
  8986. {
  8987.    FILE *stream;
  8988.  
  8989.    stream = fopen("fclose.dat", "r");
  8990.    if (0 != fclose(stream))                               /* Close the stream.*/
  8991.       perror("fclose error");
  8992.    else
  8993.       printf("File closed successfully.\n");
  8994.    return 0;
  8995.  
  8996.    /****************************************************************************
  8997.       The output should be:
  8998.  
  8999.       File closed successfully.
  9000.    ****************************************************************************/
  9001. }
  9002.  
  9003.  
  9004. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9005.  
  9006. Example of fclose 
  9007.  
  9008.      close - Close File Associated with Handle 
  9009.      _fcloseall - Close All Open Streams 
  9010.      fflush - Write Buffer to File 
  9011.      fopen - Open Files 
  9012.      freopen - Redirect Open Files 
  9013.      <stdio.h> 
  9014.  
  9015.  
  9016. ΓòÉΓòÉΓòÉ 4.74. _fcloseall - Close All Open Streams ΓòÉΓòÉΓòÉ
  9017.  
  9018.  
  9019. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9020.  
  9021. #include <stdio.h>
  9022. int _fcloseall(void);
  9023.  
  9024.  
  9025. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9026.  
  9027. Language Level:  Extension 
  9028.  
  9029. _fcloseall closes all open streams, except stdin, stdout, and stderr. It also 
  9030. closes and deletes any temporary files created by tmpfile. 
  9031.  
  9032. _fcloseall flushes all buffers associated with the streams before closing them. 
  9033. When it closes streams, it releases the buffers that the system reserved, but 
  9034. does not release user-allocated buffers. 
  9035.  
  9036. Return Value 
  9037. _fcloseall returns the total number of streams closed, or EOF if an error 
  9038. occurs. 
  9039.  
  9040.  
  9041. ΓòÉΓòÉΓòÉ <hidden> Example of _fcloseall ΓòÉΓòÉΓòÉ
  9042.  
  9043. /************************************************************************
  9044.  
  9045. This example opens a file john for reading as a data stream, and then closes 
  9046. the file. It closes all other streams except stdin, stdout, and stderr. 
  9047.  
  9048. ************************************************************************/
  9049.  
  9050. #include <stdio.h>
  9051.  
  9052. #define OUTFILE "temp.out"
  9053.  
  9054. int main(void)
  9055. {
  9056.    FILE *stream;
  9057.    int numclosed;
  9058.  
  9059.    stream = fopen(OUTFILE, "w");
  9060.    numclosed = _fcloseall();
  9061.    printf("Number of files closed = %d\n", numclosed);
  9062.    remove(OUTFILE);
  9063.    return 0;
  9064.  
  9065.    /****************************************************************************
  9066.       The output should be:
  9067.  
  9068.       Number of files closed = 1
  9069.    ****************************************************************************/
  9070. }
  9071.  
  9072.  
  9073. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9074.  
  9075. Example of _fcloseall 
  9076.  
  9077.      close - Close File Associated with Handle 
  9078.      fclose - Close Stream 
  9079.      fflush - Write Buffer to File 
  9080.      fopen - Open Files 
  9081.      freopen - Redirect Open Files 
  9082.      tmpfile - Create Temporary File 
  9083.      <stdio.h> 
  9084.  
  9085.  
  9086. ΓòÉΓòÉΓòÉ 4.75. _fcos - Calculate Cosine ΓòÉΓòÉΓòÉ
  9087.  
  9088.  
  9089. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9090.  
  9091. #include <builtin.h>
  9092. double _fcos( double x);
  9093.  
  9094.  
  9095. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9096.  
  9097. Language Level:  Extension 
  9098.  
  9099. _fcos calculates the cosine of x, where x is expressed in radians. The value of 
  9100. x must be less than 2**63. This function causes the compiler to emit the 
  9101. appropriate 80387 instruction and return only the cosine. 
  9102.  
  9103. Because it is a built-in function and has no backing code in the library: 
  9104.  
  9105.      You cannot take the address of _fcos. 
  9106.      You cannot parenthesize a _fcos function call, because parentheses 
  9107.       specify a call to the backing code for the function in the library. 
  9108.  
  9109.  Return Value 
  9110.  _fcos returns the cosine expressed in radians. 
  9111.  
  9112.  
  9113. ΓòÉΓòÉΓòÉ <hidden> Example of _fcos ΓòÉΓòÉΓòÉ
  9114.  
  9115. /************************************************************************
  9116.  
  9117. This example calculates y to be the cosine of x. 
  9118.  
  9119. ************************************************************************/
  9120.  
  9121. #include <builtin.h>
  9122. #include <stdio.h>
  9123.  
  9124. int main(void)
  9125. {
  9126.    double x;
  9127.  
  9128.    x = 7.2;
  9129.    printf("The cosine of %lf is %lf.\n", x, _fcos(x));
  9130.    return 0;
  9131.  
  9132.    /****************************************************************************
  9133.       The output should be similar to :
  9134.  
  9135.       The cosine of 7.200000 is 0.608351.
  9136.    ****************************************************************************/
  9137. }
  9138.  
  9139.  
  9140. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9141.  
  9142. Example of _fcos 
  9143.  
  9144.      cos - Calculate Cosine 
  9145.      cosh - Calculate Hyperbolic Cosine 
  9146.      _facos - Calculate Arccosine 
  9147.      _fcossin - Calculate Cosine and Sine 
  9148.      _fsincos - Calculate Sine and Cosine 
  9149.      <builtin.h> 
  9150.  
  9151.  
  9152. ΓòÉΓòÉΓòÉ 4.76. _fcossin - Calculate Cosine and Sine ΓòÉΓòÉΓòÉ
  9153.  
  9154.  
  9155. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9156.  
  9157. #include <builtin.h>
  9158. double _fcossin(double x, double *y);
  9159.  
  9160.  
  9161. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9162.  
  9163. Language Level:  Extension 
  9164.  
  9165. _fcossin calculates the cosine of x, and stores the sine of x in *y. This is 
  9166. faster than separately calculating the sine and cosine. Use _fcossin instead of 
  9167. _fsincos when you will be using the cosine first, and then the sine. This 
  9168. function causes the compiler to emit the FSINCOS 80387 instruction. 
  9169.  
  9170. Because it is a built-in function and has no backing code in the library: 
  9171.  
  9172.      You cannot take the address of _fcossin. 
  9173.      You cannot parenthesize a _fcossin function call, because parentheses 
  9174.       specify a call to the backing code for the function in the library. 
  9175.  
  9176.  Return Value 
  9177.  _fcossin returns the cosine of x. 
  9178.  
  9179.  
  9180. ΓòÉΓòÉΓòÉ <hidden> Example of _fcossin ΓòÉΓòÉΓòÉ
  9181.  
  9182. /************************************************************************
  9183.  
  9184. This example calculates the cosine of x and stores it in z, and stores the sine 
  9185. of x in *y. 
  9186.  
  9187. ************************************************************************/
  9188.  
  9189. #include <builtin.h>
  9190. #include <stdio.h>
  9191.  
  9192. int main(void)
  9193. {
  9194.    double x, y, z;
  9195.  
  9196.    printf("Enter x:\n");
  9197.    scanf("%lf", &x);
  9198.  
  9199.    z = _fcossin(x, &y);
  9200.    printf("The cosine of %lf is %lf.\n", x, z);
  9201.    printf("The sine of %lf is %lf.\n", x, y);
  9202.    return 0;
  9203.  
  9204.    /****************************************************************************
  9205.       Assuming you enter : 1.0
  9206.  
  9207.       The output should be :
  9208.  
  9209.       The cosine of 1.000000 is 0.540302.
  9210.       The sine of 1.000000 is 0.841471.
  9211.    ****************************************************************************/
  9212. }
  9213.  
  9214.  
  9215. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9216.  
  9217. Example of _fcossin 
  9218.  
  9219.      acos - Calculate Arccosine 
  9220.      asin - Calculate Arcsine 
  9221.      cos - Calculate Cosine 
  9222.      cosh - Calculate Hyperbolic Cosine 
  9223.      _facos - Calculate Arccosine 
  9224.      _fasin - Calculate Arcsine 
  9225.      _fcos - Calculate Cosine 
  9226.      sin - Calculate Sine 
  9227.      sinh - Calculate Hyperbolic Sine 
  9228.      _fsin - Calculate Sine 
  9229.      _fsincos - Calculate Sine and Cosine 
  9230.      <builtin.h> 
  9231.  
  9232.  
  9233. ΓòÉΓòÉΓòÉ 4.77. _fcvt - Convert Floating-Point to String ΓòÉΓòÉΓòÉ
  9234.  
  9235.  
  9236. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9237.  
  9238. #include <stdlib.h>
  9239. char *_fcvt(double value, int ndec, int *decptr, int *signptr);
  9240.  
  9241.  
  9242. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9243.  
  9244. Language Level:  Extension 
  9245.  
  9246. _fcvt converts the floating-point number value to a character string. _fcvt 
  9247. stores the digits of value as a string and adds a null character (\0). The ndec 
  9248. variable specifies the number of digits to be stored after the decimal point. 
  9249.  
  9250. If the number of digits after the decimal point in value exceeds ndec, _fcvt 
  9251. rounds the correct digit according to the FORTRAN F format.  If there are fewer 
  9252. than ndec digits of precision, _fcvt pads the string with zeros. 
  9253.  
  9254. A FORTRAN F number has the following format: 
  9255.  
  9256. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  9257. Γöé                                        Γöé
  9258. Γöé       ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ                    Γöé
  9259. Γöé           Γöé         Γöé                    Γöé
  9260. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇdigitΓöÇΓö┤ΓöÇΓöÇ.ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö┤ΓöÇΓöÇ><                  Γöé
  9261. Γöé   Γö£ΓöÇ+ΓöÇΓöñ          ΓööΓöÇdigitΓöÇΓöÿ                     Γöé
  9262. Γöé   ΓööΓöÇΓö┤ΓöÇΓöÿ                                   Γöé
  9263. Γöé                                        Γöé
  9264. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  9265.  
  9266. _fcvt stores only digits in the string. You can obtain the position of the 
  9267. decimal point and the sign of value after the call from decptr and signptr. 
  9268. decptr points to an integer value giving the position of the decimal point with 
  9269. respect to the beginning of the string.  A 0 or negative integer value shows 
  9270. that the decimal point lies to the left of the first digit. 
  9271.  
  9272. signptr points to an integer showing the sign of value. _fcvt sets the integer 
  9273. to 0 if value is positive and to a nonzero number if value is negative. 
  9274.  
  9275. _fcvt also converts NaN and infinity values to the strings NAN and INFINITY, 
  9276. respectively. For more information on NaN and infinity values, see Infinity and 
  9277. NaN Support. 
  9278.  
  9279. Warning: For each thread, the _ecvt, _fcvt, and _gcvt functions use a single, 
  9280. dynamically allocated buffer for the conversion. Any subsequent call that the 
  9281. same thread makes to these functions destroys the result of the previous call. 
  9282.  
  9283. Return Value 
  9284. _fcvt returns a pointer to the string of digits. Because of the limited 
  9285. precision of the double type, no more than 16 decimal digits are significant in 
  9286. any conversion. If it cannot allocate memory to perform the conversion, _fcvt 
  9287. returns NULL and sets errno to ENOMEM. 
  9288.  
  9289.  
  9290. ΓòÉΓòÉΓòÉ <hidden> Example of _fcvt ΓòÉΓòÉΓòÉ
  9291.  
  9292. /************************************************************************
  9293.  
  9294. This example reads in two floating-point numbers, computes their product, and 
  9295. prints out only the billions digit of its character representation.  At most, 
  9296. 16 decimal digits of significance can be expected. The output given assumes the 
  9297. user enters the values 2000000 and 3000. 
  9298.  
  9299. ************************************************************************/
  9300.  
  9301. #include <stdio.h>
  9302. #include <stdlib.h>
  9303. #include <math.h>
  9304.  
  9305. int main(void)
  9306. {
  9307.    float x = 2000000;
  9308.    float y = 3000;
  9309.    double z;
  9310.    int w,b,decimal,sign;
  9311.    char *buffer;
  9312.  
  9313.    z = x *y;
  9314.    printf("The product of %e and %e is %g.\n", x, y, z);
  9315.    w = log10(fabs(z))+1.;
  9316.    buffer = _fcvt(z, w, &decimal, &sign);
  9317.    b = decimal-10;
  9318.    if (b < 0)
  9319.       printf("Their product does not exceed one billion.\n");
  9320.    if (b > 15)
  9321.       printf("The billions digit of their product is insignificant.\n");
  9322.    if ((b > -1) && (b < 16))
  9323.       printf("The billions digit of their product is %c.\n", buffer[b]);
  9324.    return 0;
  9325.  
  9326.    /****************************************************************************
  9327.       The output should be:
  9328.  
  9329.       The product of 2.000000e+06 and 3.000000e+03 is 6e+09.
  9330.       The billions digit of their product is 6.
  9331.    ****************************************************************************/
  9332. }
  9333.  
  9334.  
  9335. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9336.  
  9337. Example of _fcvt 
  9338.  
  9339.      _ecvt - Convert Floating-Point to Character 
  9340.      _gcvt - Convert Floating-Point to String 
  9341.      Infinity and NaN Support 
  9342.      <stdlib.h> 
  9343.  
  9344.  
  9345. ΓòÉΓòÉΓòÉ 4.78. fdopen - Associates Input Or Output With File ΓòÉΓòÉΓòÉ
  9346.  
  9347.  
  9348. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9349.  
  9350. #include <stdio.h>
  9351. FILE *fdopen(int handle, char *type);
  9352.  
  9353.  
  9354. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9355.  
  9356. Language Level:  XPG4, Extension 
  9357.  
  9358. fdopen associates an input or output stream with the file identified by handle. 
  9359. The type variable is a character string specifying the type of access requested 
  9360. for the stream. 
  9361.  
  9362.  Mode Description 
  9363.  r 
  9364.       Create a stream to read a text file. The file pointer is set to the 
  9365.       beginning of the file. 
  9366.  w 
  9367.       Create a stream to write to a text file. The file pointer is set to the 
  9368.       beginning of the file. 
  9369.  a 
  9370.       Create a stream to write, in append mode, at the end of the text file. 
  9371.       The file pointer is set to the end of the file. 
  9372.  r+ 
  9373.       Create a stream for reading and writing a text file. The file pointer is 
  9374.       set to the beginning of the file. 
  9375.  w+ 
  9376.       Create a stream for reading and writing a text file. The file pointer is 
  9377.       set to the beginning of the file. 
  9378.  a+ 
  9379.       Create a stream for reading or writing, in append mode, at the end of the 
  9380.       text file. The file pointer is set to the end of the file. 
  9381.  rb 
  9382.       Create a stream to read a binary file. The file pointer is set to the 
  9383.       beginning of the file. 
  9384.  wb 
  9385.       Create a stream to write to a binary file. The file pointer is set to the 
  9386.       beginning of the file. 
  9387.  ab 
  9388.       Create a stream to write to a binary file in append mode. The file 
  9389.       pointer is set to the end of the file. 
  9390.  r+b or rb+ 
  9391.       Create a stream for reading and writing a binary file. The file pointer 
  9392.       is set to the beginning of the file. 
  9393.  w+b or wb+ 
  9394.       Create a stream for reading and writing a binary file. The file pointer 
  9395.       is set to the beginning of the file. 
  9396.  a+b or ab+ 
  9397.       Create a stream for reading and writing to a binary file in append mode. 
  9398.       The file pointer is set to the end of the file. 
  9399.  
  9400.  Warning: Use the w, w+, wb, wb+, and w+b modes with care; they can destroy 
  9401.  existing files. 
  9402.  
  9403.  The specified type must be compatible with the access mode you used to open 
  9404.  the file. If the file was opened with the O_APPEND FLAG, the stream mode must 
  9405.  be r, a, a+, rb, ab, a+b, or ab+. 
  9406.  
  9407.  When you open a file with a, a+, ab, a+b, or ab+ as the value of type, all 
  9408.  write operations take place at the end of the file. Although you can 
  9409.  reposition the file pointer using fseek or rewind, the file pointer always 
  9410.  moves back to the end of the file before the system carries out any write 
  9411.  operation. This action prevents you from writing over existing data. 
  9412.  
  9413.  When you specify any of the types containing +, you can read from and write to 
  9414.  the file, and the file is open for update. However, when switching from 
  9415.  reading to writing or from writing to reading, you must include an intervening 
  9416.  fseek, fsetpos, or rewind operation. You can specify the current file position 
  9417.  with fseek. 
  9418.  
  9419.  In accessing text files, carriage-return line-feed (CR-LF) combinations are 
  9420.  translated into a single line feed (LF) on input; LF characters are translated 
  9421.  to CR-LF combinations on output. Accesses to binary files suppress all of 
  9422.  these translations. (See "Stream Processing" in the Programming Guide for the 
  9423.  differences between text and binary streams.) 
  9424.  
  9425.  If fdopen returns NULL, use close to close the file. If fdopen is successful, 
  9426.  you must use fclose to close the stream and file. 
  9427.  
  9428.  Note:  In earlier releases of VisualAge C++, fdopen began with an underscore 
  9429.  (_fdopen). Because it is defined by the X/Open standard, the underscore has 
  9430.  been removed. For compatibility, VisualAge for C++ will map _fdopen to fdopen 
  9431.  for you. 
  9432.  
  9433.  Return Value 
  9434.  fdopen returns a pointer to a file structure that can be used to access the 
  9435.  open file. A NULL pointer return value indicates an error. 
  9436.  
  9437.  
  9438. ΓòÉΓòÉΓòÉ <hidden> Example of fdopen ΓòÉΓòÉΓòÉ
  9439.  
  9440. /************************************************************************
  9441.  
  9442. This example opens the file sample.dat and associates a stream with the file 
  9443. using fdopen. It then reads from the stream into the buffer. 
  9444.  
  9445. ************************************************************************/
  9446.  
  9447. #include <io.h>
  9448. #include <stdio.h>
  9449. #include <stdlib.h>
  9450. #include <fcntl.h>
  9451. #include <string.h>
  9452.  
  9453. int main(void)
  9454. {
  9455.    long length;
  9456.    int fh;
  9457.    char buffer[20];
  9458.    FILE *fp;
  9459.  
  9460.    memset(buffer, '\0', 20);                              /* Initialize buffer*/
  9461.    printf("\nCreating sample.dat.\n");
  9462.    system("echo Sample Program > sample.dat");
  9463.    if (-1 == (fh = open("sample.dat", O_RDWR|O_APPEND))) {
  9464.       perror("Unable to open sample.dat");
  9465.       return EXIT_FAILURE;
  9466.    }
  9467.    if (NULL == (fp = fdopen(fh, "r"))) {
  9468.       perror("fdopen failed");
  9469.       close(fh);
  9470.       return EXIT_FAILURE;
  9471.    }
  9472.    if (7 != fread(buffer, 1, 7, fp)) {
  9473.       perror("fread failed");
  9474.       fclose(fp);
  9475.       return EXIT_FAILURE;
  9476.    }
  9477.    printf("Successfully read from the stream the following:\n%s.\n", buffer);
  9478.    fclose(fp);
  9479.    return 0;
  9480.  
  9481.    /****************************************************************************
  9482.       The output should be:
  9483.  
  9484.       Creating sample.dat.
  9485.       Successfully read from the stream the following:
  9486.       Sample .
  9487.    ****************************************************************************/
  9488. }
  9489.  
  9490.  
  9491. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9492.  
  9493. Example of fdopen 
  9494.  
  9495.      close - Close File Associated with Handle 
  9496.      creat - Create New File 
  9497.      fclose - Close Stream 
  9498.      fopen - Open Files 
  9499.      fseek - Reposition File Position 
  9500.      fsetpos - Set File Position 
  9501.      open - Open File 
  9502.      rewind - Adjust Current File Position 
  9503.      _sopen - Open Shared File 
  9504.      <stdio.h> 
  9505.  
  9506.  
  9507. ΓòÉΓòÉΓòÉ 4.79. feof - Test End-of-File Indicator ΓòÉΓòÉΓòÉ
  9508.  
  9509.  
  9510. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9511.  
  9512. #include <stdio.h>
  9513. int feof(FILE *stream);
  9514.  
  9515.  
  9516. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9517.  
  9518. Language Level: ANSI, SAA, POSIX, XPG4 
  9519.  
  9520. feof indicates whether the end-of-file flag is set for the given stream.  The 
  9521. end-of-file flag is set by several functions to indicate the end of the file. 
  9522. The end-of-file flag is cleared by calling rewind, fsetpos, fseek, or clearerr 
  9523. for this stream. 
  9524.  
  9525. Return Value 
  9526. feof returns a nonzero value if and only if the EOF flag is set;  otherwise, it 
  9527. returns 0. 
  9528.  
  9529.  
  9530. ΓòÉΓòÉΓòÉ <hidden> Example of feof ΓòÉΓòÉΓòÉ
  9531.  
  9532. /************************************************************************
  9533.  
  9534. This example scans the input stream until it reads an end-of-file character. 
  9535.  
  9536. ************************************************************************/
  9537.  
  9538. #include <stdio.h>
  9539.  
  9540. int main(void)
  9541. {
  9542.    char inp_char;
  9543.    FILE *stream;
  9544.  
  9545.    stream = fopen("feof.dat", "r");
  9546.  
  9547.    /* scan an input stream until an end-of-file character is read             */
  9548.  
  9549.    while (0 == feof(stream)) {
  9550.       fscanf(stream, "%c", &inp_char);
  9551.       printf("<x%x> ", inp_char);
  9552.    }
  9553.    fclose(stream);
  9554.    return 0;
  9555.  
  9556.    /****************************************************************************
  9557.       If feof.dat contains : abc defgh
  9558.  
  9559.       The output should be:
  9560.  
  9561.       <x61> <x62> <x63> <x20> <x64> <x65> <x66> <x67> <x68>
  9562.    ****************************************************************************/
  9563. }
  9564.  
  9565.  
  9566. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9567.  
  9568. Example of feof 
  9569.  
  9570.      clearerr - Reset Error Indicators 
  9571.      ferror - Test for Read/Write Errors 
  9572.      fseek - Reposition File Position 
  9573.      fsetpos - Set File Position 
  9574.      perror - Print Error Message 
  9575.      rewind - Adjust Current File Position 
  9576.      <stdio.h> 
  9577.  
  9578.  
  9579. ΓòÉΓòÉΓòÉ 4.80. ferror - Test for Read/Write Errors ΓòÉΓòÉΓòÉ
  9580.  
  9581.  
  9582. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9583.  
  9584. #include <stdio.h>
  9585. int ferror(FILE *stream);
  9586.  
  9587.  
  9588. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9589.  
  9590. Language Level: ANSI, SAA, POSIX, XPG4 
  9591.  
  9592. ferror tests for an error in reading from or writing to the given stream.  If 
  9593. an error occurs, the error indicator for the stream remains set until you close 
  9594. stream, call rewind, or call clearerr. 
  9595.  
  9596. Return Value 
  9597. The ferror function returns a nonzero value to indicate an error on the given 
  9598. stream.  A return value of 0 means no error has occurred. 
  9599.  
  9600.  
  9601. ΓòÉΓòÉΓòÉ <hidden> Example of ferror ΓòÉΓòÉΓòÉ
  9602.  
  9603. /************************************************************************
  9604.  
  9605. This example puts data out to a stream and then checks that a write error has 
  9606. not occurred. 
  9607.  
  9608. ************************************************************************/
  9609.  
  9610. #include <stdio.h>
  9611. #include <stdlib.h>
  9612.  
  9613. int main(void)
  9614. {
  9615.    FILE *stream;
  9616.    char *string = "Important information";
  9617.  
  9618.    stream = fopen("ferror.dat", "w");
  9619.    fprintf(stream, "%s\n", string);
  9620.    if (ferror(stream)) {
  9621.       printf("write error\n");
  9622.       clearerr(stream);
  9623.       return EXIT_FAILURE;
  9624.    }
  9625.    else
  9626.       printf("Data written to a file successfully.\n");
  9627.    if (fclose(stream))
  9628.       perror("fclose error");
  9629.    return 0;
  9630.  
  9631.    /****************************************************************************
  9632.       The output should be:
  9633.  
  9634.       Data written to a file successfully.
  9635.    ****************************************************************************/
  9636. }
  9637.  
  9638.  
  9639. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9640.  
  9641. Example of ferror 
  9642.  
  9643.      clearerr - Reset Error Indicators 
  9644.      feof - Test End-of-File Indicator 
  9645.      fopen - Open Files 
  9646.      perror - Print Error Message 
  9647.      strerror - Set Pointer to Runtime Error Message 
  9648.      _strerror - Set Pointer to System Error String 
  9649.      <stdio.h> 
  9650.  
  9651.  
  9652. ΓòÉΓòÉΓòÉ 4.81. fflush - Write Buffer to File ΓòÉΓòÉΓòÉ
  9653.  
  9654.  
  9655. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9656.  
  9657. #include <stdio.h>
  9658. int fflush(FILE *stream);
  9659.  
  9660.  
  9661. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9662.  
  9663. Language Level: ANSI, SAA, POSIX, XPG4 
  9664.  
  9665. fflush causes the system to empty the buffer associated with the specified 
  9666. output stream, if possible. If the stream is open for input, fflush undoes the 
  9667. effect of any ungetc function. The stream remains open after the call. 
  9668.  
  9669. If stream is NULL, the system flushes all open streams. 
  9670.  
  9671. Note:  The system automatically flushes buffers when you close the stream, or 
  9672. when a program ends normally without closing the stream. 
  9673.  
  9674. Return Value 
  9675. fflush returns the value 0 if it successfully flushes the buffer. It returns 
  9676. EOF if an error occurs. 
  9677.  
  9678.  
  9679. ΓòÉΓòÉΓòÉ <hidden> Example of fflush ΓòÉΓòÉΓòÉ
  9680.  
  9681. /************************************************************************
  9682.  
  9683. This example flushes a stream buffer. 
  9684.  
  9685. ************************************************************************/
  9686.  
  9687. #include <stdio.h>
  9688.  
  9689. int main(void)
  9690. {
  9691.    FILE *stream;
  9692.  
  9693.    stream = fopen("myfile.dat", "w");
  9694.    fprintf(stream, "Hello world");
  9695.    fflush(stream);
  9696.    fclose(stream);
  9697.    return 0;
  9698. }
  9699.  
  9700.  
  9701. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9702.  
  9703. Example of fflush 
  9704.  
  9705.      fclose - Close Stream 
  9706.      _flushall - Write Buffers to Files 
  9707.      setbuf - Control Buffering 
  9708.      ungetc - Push Character onto Input Stream 
  9709.      <stdio.h> 
  9710.  
  9711.  
  9712. ΓòÉΓòÉΓòÉ 4.82. fgetc - Read a Character ΓòÉΓòÉΓòÉ
  9713.  
  9714.  
  9715. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9716.  
  9717. #include <stdio.h>
  9718. int fgetc(FILE *stream);
  9719.  
  9720.  
  9721. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9722.  
  9723. Language Level: ANSI, SAA, POSIX, XPG4 
  9724.  
  9725. fgetc reads a single unsigned character from the input stream at the current 
  9726. position and increases the associated file pointer, if any, so that it points 
  9727. to the next character. 
  9728.  
  9729. Note:  fgetc is identical to getc but is always implemented as a function call; 
  9730. it is never replaced by a macro. 
  9731.  
  9732. Return Value 
  9733. fgetc returns the character read as an integer. An EOF return value indicates 
  9734. an error or an end-of-file condition.  Use feof or ferror to determine whether 
  9735. the EOF value indicates an error or the end of the file. 
  9736.  
  9737.  
  9738. ΓòÉΓòÉΓòÉ <hidden> Example of fgetc ΓòÉΓòÉΓòÉ
  9739.  
  9740. /************************************************************************
  9741.  
  9742. This example gathers a line of input from a stream. 
  9743.  
  9744. ************************************************************************/
  9745.  
  9746. #include <stdio.h>
  9747.  
  9748. #define  MAX_LEN       80
  9749.  
  9750. int main(void)
  9751. {
  9752.    FILE *stream;
  9753.    char buffer[MAX_LEN+1];
  9754.    int i,ch;
  9755.  
  9756.    stream = fopen("myfile.dat", "r");
  9757.    for (i = 0; (i < (sizeof(buffer)-1) && ((ch = fgetc(stream)) != EOF) &&
  9758.                (ch != '\n')); i++)
  9759.       buffer[i] = ch;
  9760.    buffer[i] = '\0';
  9761.    if (fclose(stream))
  9762.       perror("fclose error");
  9763.    printf("The input line was : %s\n", buffer);
  9764.    return 0;
  9765.  
  9766.    /****************************************************************************
  9767.       If myfile.dat contains: one two three
  9768.  
  9769.       The output should be:
  9770.  
  9771.       The input line was : one two three
  9772.    ****************************************************************************/
  9773. }
  9774.  
  9775.  
  9776. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9777.  
  9778. Example of fgetc 
  9779.  
  9780.      _fgetchar - Read Single Character from stdin 
  9781.      feof - Test End-of-File Indicator 
  9782.      ferror - Test for Read/Write Errors 
  9783.      fputc - Write Character 
  9784.      getc - getchar - Read a Character 
  9785.      _getch - _getche - Read Character from Keyboard 
  9786.      <stdio.h> 
  9787.  
  9788.  
  9789. ΓòÉΓòÉΓòÉ 4.83. _fgetchar - Read Single Character from stdin ΓòÉΓòÉΓòÉ
  9790.  
  9791.  
  9792. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9793.  
  9794. #include <stdio.h>
  9795. int _fgetchar(void);
  9796.  
  9797.  
  9798. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9799.  
  9800. Language Level:  Extension 
  9801.  
  9802. _fgetchar reads a single character from the stdin stream. It is equivalent to 
  9803. the following fgetc call: 
  9804.  
  9805.    fgetc(c, stdin);
  9806.  
  9807. For portability, use the ANSI/ISO fgetc function instead of _fgetchar. 
  9808.  
  9809. Return Value 
  9810. _fgetchar returns the character read.  A return value of EOF indicates an error 
  9811. or end-of-file position. Use feof or ferror to tell whether the return value 
  9812. indicates an error or an end-of-file position. 
  9813.  
  9814.  
  9815. ΓòÉΓòÉΓòÉ <hidden> Example of _fgetchar ΓòÉΓòÉΓòÉ
  9816.  
  9817. /************************************************************************
  9818.  
  9819. This example gathers a line of input from stdin using _fgetchar: 
  9820.  
  9821. ************************************************************************/
  9822.  
  9823. #include <stdio.h>
  9824.  
  9825. int main(void)
  9826. {
  9827.    char buffer[81];
  9828.    int i,ch;
  9829.  
  9830.    printf("Please input a line of characters...\n");
  9831.    for (i = 0; (i < 80) && ((ch = _fgetchar()) != EOF) && (ch != '\n'); i++)
  9832.       buffer[i] = ch;
  9833.    buffer[i] = '\0';
  9834.    printf("The input line was : %s\n", buffer);
  9835.    return 0;
  9836.  
  9837.    /****************************************************************************
  9838.       The output should be:
  9839.  
  9840.       Please input a line of characters...
  9841.       This is a simple program.
  9842.       The input line was : This is a simple program.
  9843.    ****************************************************************************/
  9844. }
  9845.  
  9846.  
  9847. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9848.  
  9849. Example of _fgetchar 
  9850.  
  9851.      feof - Test End-of-File Indicator 
  9852.      ferror - Test for Read/Write Errors 
  9853.      fgetc - Read a Character 
  9854.      _fputchar - Write Character 
  9855.      getc - getchar - Read a Character 
  9856.      _getch - _getche - Read Character from Keyboard 
  9857.      <stdio.h> 
  9858.  
  9859.  
  9860. ΓòÉΓòÉΓòÉ 4.84. fgetpos - Get File Position ΓòÉΓòÉΓòÉ
  9861.  
  9862.  
  9863. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9864.  
  9865. #include <stdio.h>
  9866. int fgetpos(FILE *stream, fpos_t *pos);
  9867.  
  9868.  
  9869. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9870.  
  9871. Language Level: ANSI, SAA, XPG4 
  9872.  
  9873. fgetpos stores the current position of the file pointer associated with stream 
  9874. into the object pointed to by pos.  The value pointed to by pos can be used 
  9875. later in a call to fsetpos to reposition the stream. 
  9876.  
  9877. Note:  For buffered text streams, fgetpos returns an incorrect file position if 
  9878. the file contains new-line characters instead of carriage-return line-feed 
  9879. combinations.  Your file would only contain new-line characters if you 
  9880. previously used it as a binary stream.  To avoid this problem, either continue 
  9881. to process the file as a binary stream, or use unbuffered I/O operations. 
  9882.  
  9883. Return Value 
  9884. fgetpos returns 0 if successful. On error, fgetpos returns nonzero and sets 
  9885. errno to a nonzero value. 
  9886.  
  9887.  
  9888. ΓòÉΓòÉΓòÉ <hidden> Example of fgetpos ΓòÉΓòÉΓòÉ
  9889.  
  9890. /************************************************************************
  9891.  
  9892. This example opens the file myfile.dat for reading and stores the current file 
  9893. pointer position into the variable pos. 
  9894.  
  9895. ************************************************************************/
  9896.  
  9897. #include <stdio.h>
  9898.  
  9899. FILE *stream;
  9900.  
  9901. int main(void)
  9902. {
  9903.    int retcode;
  9904.    fpos_t pos;
  9905.  
  9906.    stream = fopen("myfile.dat", "rb");
  9907.  
  9908.     /* The value returned by fgetpos can be used by fsetpos                   */
  9909.     /* to set the file pointer if 'retcode' is 0                              */
  9910.  
  9911.    if ( 0 == (retcode = fgetpos(stream, &pos)) )
  9912.       printf("Current position of file pointer found.\n");
  9913.    fclose(stream);
  9914.    return 0;
  9915.  
  9916.    /****************************************************************************
  9917.       If myfile.dat exists, the output should be:
  9918.  
  9919.       Current position of file pointer found.
  9920.    ****************************************************************************/
  9921. }
  9922.  
  9923.  
  9924. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9925.  
  9926. Example of fgetpos 
  9927.  
  9928.      fseek - Reposition File Position 
  9929.      fsetpos - Set File Position 
  9930.      ftell - Get Current Position 
  9931.      <stdio.h> 
  9932.  
  9933.  
  9934. ΓòÉΓòÉΓòÉ 4.85. fgets - Read a String ΓòÉΓòÉΓòÉ
  9935.  
  9936.  
  9937. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9938.  
  9939. #include <stdio.h>
  9940. char *fgets (char *string, int n, FILE *stream);
  9941.  
  9942.  
  9943. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9944.  
  9945. Language Level: ANSI, SAA, POSIX, XPG4 
  9946.  
  9947. fgets reads characters from the current stream position up to and including the 
  9948. first new-line character (\n), up to the end of the stream, or until the number 
  9949. of characters read is equal to n-1, whichever comes first.  fgets stores the 
  9950. result in string and adds a null character (\0) to the end of the string.  The 
  9951. string includes the new-line character, if read.  If n is equal to 1, the 
  9952. string is empty. 
  9953.  
  9954. Return Value 
  9955. fgets returns a pointer to the string buffer if successful.  A NULL return 
  9956. value indicates an error or an end-of-file condition.  Use feof or ferror to 
  9957. determine whether the NULL value indicates an error or the end of the file. In 
  9958. either case, the value of the string is unchanged. 
  9959.  
  9960.  
  9961. ΓòÉΓòÉΓòÉ <hidden> Example of fgets ΓòÉΓòÉΓòÉ
  9962.  
  9963. /************************************************************************
  9964.  
  9965. This example gets a line of input from a data stream.  The example reads no 
  9966. more than MAX_LEN - 1 characters, or up to a new-line character, from the 
  9967. stream. 
  9968.  
  9969. ************************************************************************/
  9970.  
  9971. #include <stdio.h>
  9972.  
  9973. #define  MAX_LEN       100
  9974.  
  9975. int main(void)
  9976. {
  9977.    FILE *stream;
  9978.    char line[MAX_LEN],*result;
  9979.  
  9980.    stream = fopen("myfile.dat", "rb");
  9981.    if ((result = fgets(line, MAX_LEN, stream)) != NULL)
  9982.       printf("The string is %s\n", result);
  9983.    if (fclose(stream))
  9984.       perror("fclose error");
  9985.    return 0;
  9986.  
  9987.    /****************************************************************************
  9988.       If myfile.dat contains: This is my data file.
  9989.  
  9990.       The output should be:
  9991.  
  9992.       The string is This is my data file.
  9993.    ****************************************************************************/
  9994. }
  9995.  
  9996.  
  9997. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9998.  
  9999. Example of fgets 
  10000.  
  10001.      feof - Test End-of-File Indicator 
  10002.      ferror - Test for Read/Write Errors 
  10003.      fputs - Write String 
  10004.      gets - Read a Line 
  10005.      puts - Write a String 
  10006.      <stdio.h> 
  10007.  
  10008.  
  10009. ΓòÉΓòÉΓòÉ 4.86. fgetwc - Read Wide Character from Stream ΓòÉΓòÉΓòÉ
  10010.  
  10011.  
  10012. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10013.  
  10014. #include <wchar.h>
  10015. wint_t fgetwc(FILE *stream);
  10016.  
  10017.  
  10018. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10019.  
  10020. Language Level:  ANSI 93 
  10021.  
  10022. fgetwc reads the next multibyte character from the input stream pointed to by 
  10023. stream, converts it to a wide character, and advances the associated file 
  10024. position indicator for the stream (if defined). 
  10025.  
  10026. The behavior of fgetwc is affected by the LC_CTYPE category of the current 
  10027. locale. If you change the category between subsequent read operations on the 
  10028. same stream, undefined results can occur. 
  10029.  
  10030. Using non-wide-character functions with fgetwc on the same stream results in 
  10031. undefined behavior. 
  10032.  
  10033. After calling fgetwc, flush the buffer or reposition the stream pointer before 
  10034. calling a write function for the stream, unless EOF has been reached. After a 
  10035. write operation on the stream, flush the buffer or reposition the stream 
  10036. pointer before calling fgetwc. 
  10037.  
  10038. Return Value 
  10039. fgetwc returns the next wide character that corresponds to the multibyte 
  10040. character from the input stream pointed to by stream. If the stream is at EOF, 
  10041. the EOF indicator for the stream is set and fgetwc returns WEOF. 
  10042.  
  10043. If a read error occurs, the error indicator for the stream is set and fgetwc 
  10044. returns WEOF. If an encoding error occurs (an error converting the multibyte 
  10045. character into a wide character), fgetwc sets errno to EILSEQ and returns WEOF. 
  10046.  
  10047. Use ferror and feof to distinguish between a read error and an EOF. EOF is only 
  10048. reached when an attempt is made to read past the last byte of data. Reading up 
  10049. to and including the last byte of data does not turn on the EOF indicator. 
  10050.  
  10051.  
  10052. ΓòÉΓòÉΓòÉ <hidden> Example of fgetwc ΓòÉΓòÉΓòÉ
  10053.  
  10054. /************************************************************************
  10055.  
  10056. This example opens a file, reads in each wide character using fgetwc, and 
  10057. prints out the characters. 
  10058.  
  10059. ************************************************************************/
  10060.  
  10061. #include <stdio.h>
  10062. #include <stdlib.h>
  10063. #include <wchar.h>
  10064. #include <errno.h>
  10065.  
  10066. int main(void)
  10067. {
  10068.    FILE   *stream;
  10069.    wint_t wc;
  10070.  
  10071.    if (NULL == (stream = fopen("fgetwc.dat", "r"))) {
  10072.       printf("Unable to open: \"fgetwc.dat\"\n");
  10073.       exit(1);
  10074.    }
  10075.  
  10076.    errno = 0;
  10077.    while (WEOF != (wc = fgetwc(stream)))
  10078.       printf("wc = %lc\n", wc);
  10079.  
  10080.    if (EILSEQ == errno) {
  10081.       printf("An invalid wide character was encountered.\n");
  10082.       exit(1);
  10083.    }
  10084.    fclose(stream);
  10085.    return 0;
  10086.  
  10087.    /****************************************************************************
  10088.       Assuming the file fgetwc.dat contains:
  10089.  
  10090.       Hello world!
  10091.  
  10092.       The output should be similar to:
  10093.  
  10094.       wc = H
  10095.       wc = e
  10096.       wc = l
  10097.       wc = l
  10098.       wc = o
  10099.       :
  10100.    ****************************************************************************/
  10101. }
  10102.  
  10103.  
  10104. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10105.  
  10106. Example of fgetwc 
  10107.  
  10108.      fgetc - Read a Character 
  10109.      _fgetchar - Read Single Character from stdin 
  10110.      fgetws - Read Wide-Character String from Stream 
  10111.      fputwc - Write Wide Character 
  10112.      _getch - _getche - Read Character from Keyboard 
  10113.      <stdio.h> 
  10114.      <wchar.h> 
  10115.  
  10116.  
  10117. ΓòÉΓòÉΓòÉ 4.87. fgetws - Read Wide-Character String from Stream ΓòÉΓòÉΓòÉ
  10118.  
  10119.  
  10120. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10121.  
  10122. #include <wchar.h>
  10123. wchar_t *fgetws(wchar_t *wcs, int n, FILE *stream);
  10124.  
  10125.  
  10126. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10127.  
  10128. Language Level:  ANSI 93, XPG4 
  10129.  
  10130. fgetws reads wide characters from the stream into the array pointed to by wcs. 
  10131. At most, n - 1 wide characters are read. fgetws stops reading characters after 
  10132. WEOF, or after it reads a new-line wide character (which is retained). It adds 
  10133. a null wide character immediately after the last wide character read into the 
  10134. array. 
  10135.  
  10136. fgetws advances the file position unless there is an error. If an error occurs, 
  10137. the file position is undefined. 
  10138.  
  10139. The behavior of fgetws is affected by the LC_CTYPE category of the current 
  10140. locale. If you change the category between subsequent read operations on the 
  10141. same stream, undefined results can occur. 
  10142.  
  10143. Using non-wide-character functions with fgetws on the same stream results in 
  10144. undefined behavior. 
  10145.  
  10146. After calling fgetws, flush the buffer or reposition the stream pointer before 
  10147. calling a write function for the stream, unless WEOF has been reached. After a 
  10148. write operation on the stream, flush the buffer or reposition the stream 
  10149. pointer before calling fgetws. 
  10150.  
  10151. Return Value 
  10152. If successful, fgetws returns a pointer to the wide-character string wcs. If 
  10153. WEOF is encountered before any wide characters have been read into wcs, the 
  10154. contents of wcs remain unchanged and fgetws returns a null pointer. If WEOF is 
  10155. reached after data has already been read into the string buffer, fgetws returns 
  10156. a pointer to the string buffer to indicate success. A subsequent call would 
  10157. return NULL because WEOF would be reached without any data being read. 
  10158.  
  10159. If a read error occurs, the contents of wcs are indeterminate and fgetws 
  10160. returns NULL. If an encoding error occurs (in converting a wide character to a 
  10161. multibyte character), fgetws sets errno to EILSEQ and returns NULL. 
  10162.  
  10163. If n equals 1, the wcs buffer has only room for the terminating null character 
  10164. and nothing is read from the stream. (Such an operation is still considered a 
  10165. read operation, so it cannot immediately follow a write operation unless the 
  10166. buffer is flushed or the stream pointer repositioned first.) 
  10167.  
  10168. If n is greater than 1, fgetws fails only if an I/O error occurs or if WEOF is 
  10169. reached before data is read from the stream. Use ferror and feof to distinguish 
  10170. between a read error and a WEOF. WEOF is only reached when an attempt is made 
  10171. to read past the last byte of data. Reading up to and including the last byte 
  10172. of data does not turn on the WEOF indicator. 
  10173.  
  10174.  
  10175. ΓòÉΓòÉΓòÉ <hidden> Example of fgetws ΓòÉΓòÉΓòÉ
  10176.  
  10177. /************************************************************************
  10178.  
  10179. This example opens a file, reads in the file contents using fgetws, then prints 
  10180. the file contents. 
  10181.  
  10182. ************************************************************************/
  10183.  
  10184. #include <errno.h>
  10185. #include <stdio.h>
  10186. #include <stdlib.h>
  10187. #include <wchar.h>
  10188.  
  10189. int main(void)
  10190. {
  10191.    FILE    *stream;
  10192.    wchar_t  wcs[100];
  10193.  
  10194.    if (NULL == (stream = fopen("fgetws.dat", "r"))) {
  10195.       printf("Unable to open: \"fgetws.dat\"\n");
  10196.       exit(1);
  10197.    }
  10198.  
  10199.    errno = 0;
  10200.    if (NULL == fgetws(wcs, 100, stream)) {
  10201.       if (EILSEQ == errno) {
  10202.          printf("An invalid wide character was encountered.\n");
  10203.          exit(1);
  10204.       }
  10205.       else if (feof(stream))
  10206.               printf("End of file reached.\n");
  10207.            else
  10208.               perror("Read error.\n");
  10209.    }
  10210.    printf("wcs = \"%ls\"\n", wcs);
  10211.    fclose(stream);
  10212.    return 0;
  10213.  
  10214.    /****************************************************************************
  10215.       Assuming the file fgetws.dat contains:
  10216.  
  10217.       This test string should not return -1
  10218.  
  10219.       The output should be similar to:
  10220.  
  10221.       wcs = "This test string should not return -1"
  10222.    ****************************************************************************/
  10223. }
  10224.  
  10225.  
  10226. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10227.  
  10228. Example of fgetws 
  10229.  
  10230.      fgets - Read a String 
  10231.      fgetwc - Read Wide Character from Stream 
  10232.      fputws - Write Wide-Character String. 
  10233.      <stdio.h> 
  10234.      <wchar.h> 
  10235.  
  10236.  
  10237. ΓòÉΓòÉΓòÉ 4.88. _filelength - Determine File Length ΓòÉΓòÉΓòÉ
  10238.  
  10239.  
  10240. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10241.  
  10242. #include <io.h>
  10243. long _filelength(int handle);
  10244.  
  10245.  
  10246. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10247.  
  10248. Language Level:  Extension 
  10249.  
  10250. _filelength returns the length, in bytes, of the file associated with handle. 
  10251. The length of the file will be correct even if you have the handle opened and 
  10252. have appended data to the file. 
  10253.  
  10254. Return Value 
  10255. A return value of -1L indicates an error, and errno is set to one of the 
  10256. following values: 
  10257.  
  10258.  Value        Meaning 
  10259.  EBADF        The file handle is incorrect or the mode specified does not match 
  10260.               the mode you opened the file with. 
  10261.  EOS2ERR      The call to the operating system was not successful. 
  10262.  
  10263.  
  10264. ΓòÉΓòÉΓòÉ <hidden> Example of _filelength ΓòÉΓòÉΓòÉ
  10265.  
  10266. /************************************************************************
  10267.  
  10268. This example opens a file and tries to determine the current length of the file 
  10269. using _filelength. 
  10270.  
  10271. ************************************************************************/
  10272.  
  10273. #include <io.h>
  10274. #include <stdio.h>
  10275. #include <stdlib.h>
  10276. #include <fcntl.h>
  10277.  
  10278. int main(void)
  10279. {
  10280.    long length;
  10281.    int fh;
  10282.  
  10283.    printf("\nCreating sample.dat.\n");
  10284.    system("echo Sample Program > sample.dat");
  10285.    if (-1 == (fh = open("sample.dat", O_RDWR|O_APPEND))) {
  10286.       printf("Unable to open sample.dat.\n");
  10287.       return EXIT_FAILURE;
  10288.    }
  10289.    if (-1 == (length = _filelength(fh))) {
  10290.       printf("Unable to determine length of sample.dat.\n");
  10291.       return EXIT_FAILURE;
  10292.    }
  10293.    printf("Current length of sample.dat is %d.\n", length);
  10294.    close(fh);
  10295.    return 0;
  10296.  
  10297.    /****************************************************************************
  10298.       The output should be:
  10299.  
  10300.       Creating sample.dat.
  10301.       Current length of sample.dat is 17.
  10302.    ****************************************************************************/
  10303. }
  10304.  
  10305.  
  10306. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10307.  
  10308. Example of _filelength 
  10309.  
  10310.      _chsize - Alter Length of File 
  10311.      __eof - Determine End of File 
  10312.      <io.h> 
  10313.  
  10314.  
  10315. ΓòÉΓòÉΓòÉ 4.89. fileno - Determine File Handle ΓòÉΓòÉΓòÉ
  10316.  
  10317.  
  10318. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10319.  
  10320. #include <stdio.h>
  10321. int fileno(FILE *stream);
  10322.  
  10323.  
  10324. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10325.  
  10326. Language Level:  XPG4, Extension 
  10327.  
  10328. fileno determines the file handle currently associated with stream. 
  10329.  
  10330. Note:  In earlier releases of VisualAge C++, fileno began with an underscore 
  10331. (_fileno). Because it is defined by the X/Open standard, the underscore has 
  10332. been removed. For compatibility, VisualAge for C++ will map _fileno to fileno 
  10333. for you. 
  10334.  
  10335. Return Value 
  10336. fileno returns the file handle. If the function fails, the return value is -1 
  10337. and the errno variable may be set to one of the following values: 
  10338.  
  10339.  Value          Meaning 
  10340.  ENULLFCB       The input stream is NULL. 
  10341.  EBADTYPE       The input stream file is not a stream file. 
  10342.  
  10343.  The result is undefined if stream does not specify an open file. 
  10344.  
  10345.  
  10346. ΓòÉΓòÉΓòÉ <hidden> Example of fileno ΓòÉΓòÉΓòÉ
  10347.  
  10348. /************************************************************************
  10349.  
  10350. This example determines the file handle of the stderr data stream. 
  10351.  
  10352. ************************************************************************/
  10353.  
  10354. #include <stdio.h>
  10355.  
  10356. int main(void)
  10357. {
  10358.    int result;
  10359.  
  10360.    result = 0xFFFF&fileno(stderr);
  10361.    printf("The file handle associated with stderr is %d.\n", result);
  10362.    return 0;
  10363.  
  10364.    /****************************************************************************
  10365.       The output should be similar to:
  10366.  
  10367.       The file handle associated with stderr is 2.
  10368.    ****************************************************************************/
  10369. }
  10370.  
  10371.  
  10372. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10373.  
  10374. Example of fileno 
  10375.  
  10376.      dup - Associate Second Handle with Open File 
  10377.      dup2 - Associate Second Handle with Open File 
  10378.      fopen - Open Files 
  10379.      freopen - Redirect Open Files 
  10380.      isatty - Test Handle for Character Device 
  10381.      open - Open File 
  10382.      <stdio.h> 
  10383.  
  10384.  
  10385. ΓòÉΓòÉΓòÉ 4.90. floor - Integer <= Argument ΓòÉΓòÉΓòÉ
  10386.  
  10387.  
  10388. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10389.  
  10390. #include <math.h>
  10391. double floor(double x);
  10392.  
  10393.  
  10394. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10395.  
  10396. Language Level: ANSI, SAA, POSIX, XPG4 
  10397.  
  10398. floor calculates the largest integer that is less than or equal to x. 
  10399.  
  10400. Return Value 
  10401. floor returns the floating-point result as a double value. 
  10402.  
  10403. The result of floor cannot have a range error. 
  10404.  
  10405.  
  10406. ΓòÉΓòÉΓòÉ <hidden> Example of floor ΓòÉΓòÉΓòÉ
  10407.  
  10408. /************************************************************************
  10409.  
  10410. This example assigns y value of the largest integer less than or equal to 2.8 
  10411. and z the value of the largest integer less than or equal to -2.8. 
  10412.  
  10413. ************************************************************************/
  10414.  
  10415. #include <stdio.h>
  10416. #include <math.h>
  10417.  
  10418. int main(void)
  10419. {
  10420.    double y,z;
  10421.  
  10422.    y = floor(2.8);
  10423.    z = floor(-2.8);
  10424.    printf("floor(  2.8 ) = %lf\n", y);
  10425.    printf("floor( -2.8 ) = %lf\n", z);
  10426.    return 0;
  10427.  
  10428.    /****************************************************************************
  10429.       The output should be:
  10430.  
  10431.       floor(  2.8 ) = 2.000000
  10432.       floor( -2.8 ) = -3.000000
  10433.    ****************************************************************************/
  10434. }
  10435.  
  10436.  
  10437. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10438.  
  10439. Example of floor 
  10440.  
  10441.      ceil - Find Integer >= Argument 
  10442.      fmod - Calculate Floating-Point Remainder 
  10443.      <math.h> 
  10444.  
  10445.  
  10446. ΓòÉΓòÉΓòÉ 4.91. _flushall - Write Buffers to Files ΓòÉΓòÉΓòÉ
  10447.  
  10448.  
  10449. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10450.  
  10451. #include <stdio.h>
  10452. int _flushall(void);
  10453.  
  10454.  
  10455. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10456.  
  10457. Language Level:  Extension 
  10458.  
  10459. _flushall causes the system to write to file the contents of all buffers 
  10460. associated with open output streams (including stdin, stdout, and stderr). It 
  10461. clears all buffers associated with open input streams of their current 
  10462. contents. The next read operation, if there is one, reads new data from the 
  10463. input files into the buffers. All streams remain open after the call. 
  10464.  
  10465. For portability, use the ANSI/ISO function fflush instead of _flushall. 
  10466.  
  10467. Return Value 
  10468. _flushall returns the number of open streams of input and output. If an error 
  10469. occurs, _flushall returns EOF. 
  10470.  
  10471.  
  10472. ΓòÉΓòÉΓòÉ <hidden> Example of _flushall ΓòÉΓòÉΓòÉ
  10473.  
  10474. /************************************************************************
  10475.  
  10476. In this example, _flushall completes any pending input or output on all streams 
  10477. by flushing all buffers. 
  10478.  
  10479. ************************************************************************/
  10480.  
  10481. #include <stdio.h>
  10482.  
  10483. int main(void)
  10484. {
  10485.    int i,numflushed;
  10486.    char buffer1[5] =  { 1,2,3,4 };
  10487.    char buffer2[5] =  { 5,6,7,8 };
  10488.    char *file1 = "file1.dat";
  10489.    char *file2 = "file2.dat";
  10490.    FILE *stream1,*stream2;
  10491.  
  10492.    stream1 = fopen(file1, "a+");
  10493.    stream2 = fopen(file2, "a+");
  10494.    for (i = 0; i <= sizeof(buffer1); i++) {
  10495.       fputc(buffer1[i], stream1);
  10496.       fputc(buffer2[i], stream2);
  10497.    }
  10498.    numflushed = _flushall();                   /* all streams flushed          */
  10499.    printf("Number of files flushed = %d\n", numflushed);
  10500.    fclose(stream1);
  10501.    fclose(stream2);
  10502.    return 0;
  10503.  
  10504.    /****************************************************************************
  10505.       The output should be:
  10506.  
  10507.       Number of files flushed = 5
  10508.    ****************************************************************************/
  10509. }
  10510.  
  10511.  
  10512. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10513.  
  10514. Example of _flushall 
  10515.  
  10516.      close - Close File Associated with Handle 
  10517.      fclose - Close Stream 
  10518.      fflush - Write Buffer to File 
  10519.      <stdio.h> 
  10520.  
  10521.  
  10522. ΓòÉΓòÉΓòÉ 4.92. fmod - Calculate Floating-Point Remainder ΓòÉΓòÉΓòÉ
  10523.  
  10524.  
  10525. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10526.  
  10527. #include <math.h>
  10528. double fmod(double x, double y);
  10529.  
  10530.  
  10531. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10532.  
  10533. Language Level: ANSI, SAA, POSIX, XPG4 
  10534.  
  10535. fmod calculates the floating-point remainder of x/y. The absolute value of the 
  10536. result is always less than the absolute value of y. The result will have the 
  10537. same sign as x. 
  10538.  
  10539. Return Value 
  10540.  
  10541. fmod returns the floating-point remainder of x/y. If y is zero or if x/y causes 
  10542. an overflow, fmod returns 0. 
  10543.  
  10544.  
  10545. ΓòÉΓòÉΓòÉ <hidden> Example of fmod ΓòÉΓòÉΓòÉ
  10546.  
  10547. /************************************************************************
  10548.  
  10549. This example computes z as the remainder of x/y; here, x/y is -3 with a 
  10550. remainder of -1. 
  10551.  
  10552. ************************************************************************/
  10553.  
  10554. #include <stdio.h>
  10555. #include <math.h>
  10556.  
  10557. int main(void)
  10558. {
  10559.    double x,y,z;
  10560.  
  10561.    x = -10.0;
  10562.    y = 3.0;
  10563.    z = fmod(x, y);                                        /* z = -1.0         */
  10564.    printf("fmod( %lf, %lf) = %lf\n", x, y, z);
  10565.    return 0;
  10566.  
  10567.    /****************************************************************************
  10568.       The output should be:
  10569.  
  10570.       fmod( -10.000000, 3.000000) = -1.000000
  10571.    ****************************************************************************/
  10572. }
  10573.  
  10574.  
  10575. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10576.  
  10577. Example of fmod 
  10578.  
  10579.      ceil - Find Integer >= Argument 
  10580.      fabs - Calculate Floating-Point Absolute Value 
  10581.      floor - Integer <= Argument 
  10582.      <math.h> 
  10583.  
  10584.  
  10585. ΓòÉΓòÉΓòÉ 4.93. fopen - Open Files ΓòÉΓòÉΓòÉ
  10586.  
  10587.  
  10588. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10589.  
  10590. #include <stdio.h>
  10591. FILE *fopen(const char *filename, const char *mode);
  10592.  
  10593.  
  10594. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10595.  
  10596. Language Level: ANSI, SAA, POSIX, XPG4 
  10597.  
  10598. fopen opens the file specified by filename. mode is a character string 
  10599. specifying the type of access requested for the file. The mode variable 
  10600. contains one positional parameter followed by optional keyword parameters. 
  10601.  
  10602. The possible values for the positional parameters are: 
  10603.  
  10604.  Mode Description 
  10605.  r 
  10606.    Open a text file for reading.  The file must exist. 
  10607.  w 
  10608.    Create a text file for writing. If the given file exists, its contents are 
  10609.    destroyed. 
  10610.  a 
  10611.    Open a text file in append mode for writing at the end of the file. fopen 
  10612.    creates the file if it does not exist. 
  10613.  r+ 
  10614.    Open a text file for both reading and writing.  The file must exist. 
  10615.  w+ 
  10616.    Create a text file for both reading and writing. If the given file exists, 
  10617.    its contents are destroyed. 
  10618.  a+ 
  10619.    Open a text file in append mode for reading or updating at the end of the 
  10620.    file.  fopen creates the file if it does not exist. 
  10621.  rb 
  10622.    Open a binary file for reading.  The file must exist. 
  10623.  wb 
  10624.    Create an empty binary file for writing. If the file exists, its contents 
  10625.    are destroyed. 
  10626.  ab 
  10627.    Open a binary file in append mode for writing at the end of the file. fopen 
  10628.    creates the file if it does not exist. 
  10629.  r+b or rb+ 
  10630.    Open a binary file for both reading and writing. The file must exist. 
  10631.  w+b or wb+ 
  10632.    Create an empty binary file for both reading and writing. If the file 
  10633.    exists, its contents will be destroyed. 
  10634.  a+b or ab+ 
  10635.    Open a binary file in append mode for writing at the end of the file.  fopen 
  10636.    creates the file if it does not exist. 
  10637.  
  10638.  Warning: Use the w, w+, wb, w+b, and wb+ parameters with care;  data in 
  10639.  existing files of the same name will be lost. 
  10640.  
  10641.  Text files contain printable characters and control characters organized into 
  10642.  lines. Each line ends with a new-line character, except for the last line, 
  10643.  which does not require one. The system may insert or convert control 
  10644.  characters in an output text stream. 
  10645.  
  10646.  Note:  Data output to a text stream may not compare as equal to the same data 
  10647.  on input. 
  10648.  
  10649.  Binary files contain a series of characters.  For binary files, the system 
  10650.  does not translate control characters on input or output. 
  10651.  
  10652.  When you open a file with a, a+, ab, a+b or ab+ mode, all write operations 
  10653.  take place at the end of the file.  Although you can reposition the file 
  10654.  pointer using fseek or rewind, the write functions move the file pointer back 
  10655.  to the end of the file before they carry out any operation. This action 
  10656.  prevents you from overwriting existing data. 
  10657.  
  10658.  When you specify the update mode (using + in the second or third position), 
  10659.  you can both read from and write to the file.  However, when switching between 
  10660.  reading and writing, you must include an intervening positioning function such 
  10661.  as fseek, fsetpos, rewind, or fflush.  Output may immediately follow input if 
  10662.  the end-of-file was detected. 
  10663.  
  10664.  The keyword parameters are: 
  10665.  
  10666.  blksize=value 
  10667.    Specifies the maximum length, in bytes, of a physical block of records. For 
  10668.    fixed-length records, the maximum size is 32760 bytes.  For variable-length 
  10669.    records, the maximum is 32756. The default buffer size is 4096 bytes. 
  10670.  lrecl=value 
  10671.    Specifies the length, in bytes, for fixed-length records and the maximum 
  10672.    length for variable-length records. For fixed-length records, the maximum 
  10673.    length is 32760 bytes.  For variable-length records, the maximum is 32756. 
  10674.    If the value of LRECL is larger than the value of BLKSIZE, the LRECL value 
  10675.    is ignored. 
  10676.  recfm=value 
  10677.    value can be: 
  10678.    F         fixed-length, unblocked records 
  10679.    V         variable-length, unblocked records The default for the VisualAge 
  10680.    for C++ compiler is fixed-length record format. 
  10681.  type=value 
  10682.    value can be: 
  10683.  
  10684.    memory  This parameter identifies this file as a memory file that is 
  10685.    accessible only from C programs. If you want to use a memory file, you must 
  10686.    compile with the /Sv option. 
  10687.  
  10688.  The VisualAge for C++ compiler does not support record I/O. 
  10689.  
  10690.  fopen generally fails if parameters are mismatched. 
  10691.  
  10692.  The file attributes can be altered only if the open mode specified with the 
  10693.  fopen function is one of the write modes (w, w+, wb, or wb+). The system 
  10694.  deletes the existing file and creates a new file with the attributes specified 
  10695.  in fopen. 
  10696.  
  10697.  Return Value 
  10698.  fopen returns a pointer to a file structure that can be used to access the 
  10699.  open file. A NULL pointer return value indicates an error. 
  10700.  
  10701.  
  10702. ΓòÉΓòÉΓòÉ <hidden> Example of fopen ΓòÉΓòÉΓòÉ
  10703.  
  10704. /************************************************************************
  10705.  
  10706. This example attempts to open a file for reading. 
  10707.  
  10708. ************************************************************************/
  10709.  
  10710. #include <stdio.h>
  10711.  
  10712. int main(void)
  10713. {
  10714.    FILE *stream;
  10715.  
  10716.    if (NULL == (stream = fopen("myfile.dat", "r")))
  10717.       printf("Could not open data file\n");
  10718.    else
  10719.       fclose(stream);
  10720.  
  10721.     /* The following call opens a fixed record length file                    */
  10722.     /* for reading and writing in record mode.                                */
  10723.  
  10724.    if (NULL == (stream = fopen("myfile.dat",
  10725.                         "rb+, lrecl=80, blksize=240, recfm=f, type=record")))
  10726.       printf("Could not open data file\n");
  10727.    else
  10728.       fclose(stream);
  10729.    return 0;
  10730.  
  10731.    /****************************************************************************
  10732.       The output should be:
  10733.  
  10734.       Could not open data file
  10735.    ****************************************************************************/
  10736. }
  10737.  
  10738.  
  10739. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10740.  
  10741. Example of fopen 
  10742.  
  10743.      creat - Create New File 
  10744.      fclose - Close Stream 
  10745.      fflush - Write Buffer to File 
  10746.      fread - Read Items 
  10747.      freopen - Redirect Open Files 
  10748.      open - Open File 
  10749.      _sopen - Open Shared File 
  10750.      fseek - Reposition File Position 
  10751.      fsetpos - Set File Position 
  10752.      fwrite - Write Items 
  10753.      rewind - Adjust Current File Position 
  10754.      <stdio.h> 
  10755.  
  10756.  
  10757. ΓòÉΓòÉΓòÉ 4.94. _fpatan - Calculate Arctangent ΓòÉΓòÉΓòÉ
  10758.  
  10759.  
  10760. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10761.  
  10762. #include <builtin.h>
  10763. double _fpatan(double x);
  10764.  
  10765.  
  10766. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10767.  
  10768. Language Level:  Extension 
  10769.  
  10770. _fpatan calculates the arctangent of x, which is a value in radians between 
  10771. -pi/2 and pi/2. This function causes the compiler to emit the appropriate 80387 
  10772. instruction for the calculation of arctangent. 
  10773.  
  10774. Because it is a built-in function and has no backing code in the library: 
  10775.  
  10776.      You cannot take the address of _fpatan. 
  10777.      You cannot parenthesize a _fpatan function call, because parentheses 
  10778.       specify a call to the backing code for the function. 
  10779.  
  10780.  Return Value 
  10781.  This function returns the arctangent of x. 
  10782.  
  10783.  
  10784. ΓòÉΓòÉΓòÉ <hidden> Example of _fpatan ΓòÉΓòÉΓòÉ
  10785.  
  10786. /************************************************************************
  10787.  
  10788. This example calculates the arctangent of x. 
  10789.  
  10790. ************************************************************************/
  10791.  
  10792. #include <builtin.h>
  10793. #include <stdio.h>
  10794.  
  10795. int main(void)
  10796. {
  10797.    double x;
  10798.  
  10799.    x = 0.45;
  10800.    printf("The arctangent of %lf is %lf.\n", x, _fpatan(x));
  10801.    return 0;
  10802.  
  10803.    /****************************************************************************
  10804.       The output should be :
  10805.  
  10806.       The arctangent of 0.450000 is 0.422854.
  10807.    ****************************************************************************/
  10808. }
  10809.  
  10810.  
  10811. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10812.  
  10813. Example of _fpatan 
  10814.  
  10815.      atan - atan2 - Calculate Arctangent 
  10816.      _fptan - Calculate Tangent 
  10817.      tan - Calculate Tangent 
  10818.      tanh - Calculate Hyperbolic Tangent 
  10819.      <builtin.h> 
  10820.  
  10821.  
  10822. ΓòÉΓòÉΓòÉ 4.95. _fpreset - Reset Floating-Point Unit ΓòÉΓòÉΓòÉ
  10823.  
  10824.  
  10825. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10826.  
  10827. #include <float.h>
  10828. void _fpreset(void);
  10829.  
  10830.  
  10831. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10832.  
  10833. Language Level:  Extension 
  10834.  
  10835. _fpreset resets the floating-point unit to the default state that the math 
  10836. library requires to function correctly. The value of this default state may 
  10837. change between releases of VisualAge for C++. You can determine the default 
  10838. state by calling _fpreset and then calling _control87 with 0 as the parameter. 
  10839.  
  10840. This function is often used within signal handlers. If a program traps 
  10841. floating-point error signals (SIGFPE) with signal, the program can safely 
  10842. recover from floating-point errors by calling longjmp. For more information on 
  10843. signal handlers, see "Signal and Windows Exception Handling" the Programming 
  10844. Guide. 
  10845.  
  10846. _fpreset resets the floating-point unit of the current thread only.  It does 
  10847. not affect any other threads that may be processing. 
  10848.  
  10849. Return Value 
  10850. There is no return value. 
  10851.  
  10852.  
  10853. ΓòÉΓòÉΓòÉ <hidden> Example of _fpreset ΓòÉΓòÉΓòÉ
  10854.  
  10855. /************************************************************************
  10856.  
  10857. This example establishes the function fphandler as a floating-point error 
  10858. handler. The main program produces a floating-point error, which causes control 
  10859. to be passed to fphandler. The fphandler function calls _fpreset to reset the 
  10860. floating-point unit, and then returns to main. 
  10861.  
  10862. ************************************************************************/
  10863.  
  10864. #include <stdio.h>
  10865. #include <stdlib.h>
  10866. #include <signal.h>
  10867. #include <setjmp.h>
  10868. #include <float.h>
  10869.  
  10870. jmp_buf mark;
  10871.  
  10872. void fphandler(int sig)
  10873. {
  10874.    printf("Floating point signal = %d\n", sig);
  10875.    _fpreset();                /* Reinitialize floating-point package          */
  10876.    longjmp(mark, -1);
  10877. }
  10878.  
  10879. int main(void)
  10880. {
  10881.    double a = 1.0,b = 0.0,c;
  10882.  
  10883.    if (SIG_ERR == signal(SIGFPE, (_SigFunc)fphandler))
  10884.       return EXIT_FAILURE;
  10885.    if (0 == setjmp(mark)) {
  10886.       c = a/b;                    /* generate floating-point error            */
  10887.       printf("Should never get here\n");
  10888.    }
  10889.    printf("Recovered from floating-point error\n");
  10890.    return 0;
  10891.  
  10892.    /****************************************************************************
  10893.       The output should be:
  10894.  
  10895.       Floating point signal = 3
  10896.       Recovered from floating-point error
  10897.    ****************************************************************************/
  10898. }
  10899.  
  10900.  
  10901. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10902.  
  10903. Example of _fpreset 
  10904.  
  10905.      _clear87 - Clear Floating-Point Status Word 
  10906.      _control87 - Set Floating-Point Control Word 
  10907.      longjmp - Restore Stack Environment 
  10908.      signal - Handle Interrupt Signals 
  10909.      _status87 - Get Floating-Point Status Word 
  10910.      <float.h> 
  10911.  
  10912.  
  10913. ΓòÉΓòÉΓòÉ 4.96. fprintf - Write Formatted Data to a Stream ΓòÉΓòÉΓòÉ
  10914.  
  10915.  
  10916. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10917.  
  10918. #include <stdio.h>
  10919. int fprintf(FILE *stream, const char *format-string, argument-list);
  10920.  
  10921.  
  10922. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10923.  
  10924. Language Level: ANSI, SAA, POSIX, XPG4, Extension 
  10925.  
  10926. fprintf formats and writes a series of characters and values to the output 
  10927. stream. fprintf converts each entry in argument-list, if any, and writes to the 
  10928. stream according to the corresponding format specification in the 
  10929. format-string. 
  10930.  
  10931. The format-string has the same form and function as the format-string argument 
  10932. for printf. See printf - Print Formatted Characters for a description of the 
  10933. format-string and the argument list. 
  10934.  
  10935. In extended mode, fprintf also converts floating-point values of NaN and 
  10936. infinity to the strings "NAN" or "nan" and "INFINITY" or "infinity". The case 
  10937. and sign of the string is determined by the format specifiers.  See Infinity 
  10938. and NaN Support for more information on infinity and NaN values. 
  10939.  
  10940. If you specify a null string for the %s or %ls format specifier, fprintf prints 
  10941. (null). (In previous releases of VisualAge C++, printf produced no output for a 
  10942. null string.) 
  10943.  
  10944. Return Value 
  10945. fprintf returns the number of bytes printed or a negative value if an output 
  10946. error occurs. 
  10947.  
  10948.  
  10949. ΓòÉΓòÉΓòÉ <hidden> Example of fprintf ΓòÉΓòÉΓòÉ
  10950.  
  10951. /************************************************************************
  10952.  
  10953. This example sends a line of asterisks for each integer in the array count to 
  10954. the file myfile.  The number of asterisks printed on each line corresponds to 
  10955. an integer in the array. 
  10956.  
  10957. ************************************************************************/
  10958.  
  10959. #include <stdio.h>
  10960.  
  10961. int count[10] =  { 1, 5, 8, 3, 0, 3, 5, 6, 8, 10 } ;
  10962.  
  10963. int main(void)
  10964. {
  10965.    int i,j;
  10966.    FILE *stream;
  10967.  
  10968.    stream = fopen("myfile.dat", "w");
  10969.  
  10970.                    /* Open the stream for writing                             */
  10971.  
  10972.    for (i = 0; i < sizeof(count)/sizeof(count[0]); i++) {
  10973.       for (j = 0; j < count[i]; j++)
  10974.          fprintf(stream, "*");
  10975.  
  10976.                    /* Print asterisk                                          */
  10977.  
  10978.       fprintf(stream, "\n");
  10979.  
  10980.                    /* Move to the next line                                   */
  10981.  
  10982.    }
  10983.    fclose(stream);
  10984.    return 0;
  10985.  
  10986.    /****************************************************************************
  10987.       The output data file myfile.dat should contain:
  10988.  
  10989.       *
  10990.       *****
  10991.       ********
  10992.       ***
  10993.  
  10994.       ***
  10995.       *****
  10996.       ******
  10997.       ********
  10998.       **********
  10999.    ****************************************************************************/
  11000. }
  11001.  
  11002.  
  11003. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11004.  
  11005. Example of fprintf 
  11006.  
  11007.      _cprintf - Print Characters to Screen 
  11008.      fscanf - Read Formatted Data 
  11009.      printf - Print Formatted Characters 
  11010.      sprintf - Print Formatted Data to Buffer 
  11011.      vfprintf - Print Argument Data to Stream 
  11012.      vprintf - Print Argument Data 
  11013.      vsprintf - Print Argument Data to Buffer 
  11014.      vswprintf - Format and Write Wide Characters to Buffer 
  11015.      Infinity and NaN Support 
  11016.      <stdio.h> 
  11017.  
  11018.  
  11019. ΓòÉΓòÉΓòÉ 4.97. _fptan - Calculate Tangent ΓòÉΓòÉΓòÉ
  11020.  
  11021.  
  11022. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11023.  
  11024. #include <builtin.h>
  11025. double _fptan(double x);
  11026.  
  11027.  
  11028. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11029.  
  11030. Language Level:  Extension 
  11031.  
  11032. _fptan calculates the tangent of x, where x is expressed in radians. The value 
  11033. of x must be less than 2**63. This function causes the compiler to emit the 
  11034. appropriate 80387 instruction for the calculation of tangent. 
  11035.  
  11036. Because it is a built-in function and has no backing code in the library: 
  11037.  
  11038.      You cannot take the address of _fptan. 
  11039.      You cannot parenthesize a _fptan function call, because parentheses 
  11040.       specify a call to the backing code for the function in the library. 
  11041.  
  11042.  Return Value 
  11043.  _fptan returns the tangent of x expressed in radians. 
  11044.  
  11045.  
  11046. ΓòÉΓòÉΓòÉ <hidden> Example of _fptan ΓòÉΓòÉΓòÉ
  11047.  
  11048. /************************************************************************
  11049.  
  11050. This example calculates the tangent of pi/4. 
  11051.  
  11052. ************************************************************************/
  11053.  
  11054. #include <builtin.h>
  11055. #include <stdio.h>
  11056.  
  11057. int main(void)
  11058. {
  11059.    double pi;
  11060.  
  11061.    pi = 3.1415926;
  11062.    printf("The tangent of %lf is %lf.\n", pi/4.0, _fptan(pi/4.0));
  11063.    return 0;
  11064.  
  11065.    /****************************************************************************
  11066.       The output should be :
  11067.  
  11068.       The tangent of 0.785398 is 1.000000.
  11069.    ****************************************************************************/
  11070. }
  11071.  
  11072.  
  11073. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11074.  
  11075. Example of _fptan 
  11076.  
  11077.      atan - atan2 - Calculate Arctangent 
  11078.      _fpatan - Calculate Arctangent 
  11079.      tan - Calculate Tangent 
  11080.      tanh - Calculate Hyperbolic Tangent 
  11081.      <builtin.h> 
  11082.  
  11083.  
  11084. ΓòÉΓòÉΓòÉ 4.98. fputc - Write Character ΓòÉΓòÉΓòÉ
  11085.  
  11086.  
  11087. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11088.  
  11089. #include <stdio.h>
  11090. int fputc(int c, FILE *stream);
  11091.  
  11092.  
  11093. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11094.  
  11095. Language Level: ANSI, SAA, POSIX, XPG4 
  11096.  
  11097. fputc converts c to an unsigned char and then writes c to the output stream at 
  11098. the current position and advances the file position appropriately. If the 
  11099. stream is opened with one of the append modes, the character is appended to the 
  11100. end of the stream. 
  11101.  
  11102. fputc is identical to putc except that it is never replaced by a macro. 
  11103.  
  11104. Return Value 
  11105. fputc returns the character written.  A return value of EOF indicates an error. 
  11106.  
  11107.  
  11108. ΓòÉΓòÉΓòÉ <hidden> Example of fputc ΓòÉΓòÉΓòÉ
  11109.  
  11110. /************************************************************************
  11111.  
  11112. This example writes the contents of buffer to a file called myfile.dat. 
  11113.  
  11114. Note:  Because the output occurs as a side effect within the second expression 
  11115. of the for statement, the statement body is null. 
  11116.  
  11117. ************************************************************************/
  11118.  
  11119. #include <stdio.h>
  11120. #include <stdlib.h>
  11121.  
  11122. #define  NUM_ALPHA     26
  11123.  
  11124. int main(void)
  11125. {
  11126.    FILE *stream;
  11127.    int i;
  11128.    int ch;
  11129.  
  11130.    /* Don't forget the NULL char at the end of the string!                    */
  11131.  
  11132.    char buffer[NUM_ALPHA+1] = "abcdefghijklmnopqrstuvwxyz";
  11133.  
  11134.    if ((stream = fopen("myfile.dat", "w")) != NULL) {
  11135.  
  11136.      /* Put buffer into file                                                  */
  11137.  
  11138.       for (i = 0; (i < sizeof(buffer)) && ((ch = fputc(buffer[i], stream)) !=
  11139.          EOF); ++i)
  11140.          ;
  11141. #ifdef _M_PPC
  11142.       fputc( '\n', stream );
  11143. #endif
  11144.       fclose(stream);
  11145.       return 0;
  11146.    }
  11147.    else
  11148.       perror("Error opening myfile.dat");
  11149.    return EXIT_FAILURE;
  11150.  
  11151.    /****************************************************************************
  11152.       The output data file myfile.dat should contain:
  11153.  
  11154.       abcdefghijklmnopqrstuvwxyz
  11155.    ****************************************************************************/
  11156. }
  11157.  
  11158.  
  11159. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11160.  
  11161. Example of fputc 
  11162.  
  11163.      fgetc - Read a Character 
  11164.      _fputchar - Write Character 
  11165.      putc - putchar - Write a Character 
  11166.      _putch - Write Character to Screen 
  11167.      <stdio.h> 
  11168.  
  11169.  
  11170. ΓòÉΓòÉΓòÉ 4.99. _fputchar - Write Character ΓòÉΓòÉΓòÉ
  11171.  
  11172.  
  11173. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11174.  
  11175. #include <stdio.h>
  11176. int _fputchar(int c);
  11177.  
  11178.  
  11179. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11180.  
  11181. Language Level:  Extension 
  11182.  
  11183. _fputchar writes the single character c to the stdout stream at the current 
  11184. position. It is equivalent to the following fputc call: 
  11185.  
  11186.    fputc(c, stdout);
  11187.  
  11188. For portability, use the ANSI/ISO fputc function instead of _fputchar. 
  11189.  
  11190. Return Value 
  11191. _fputchar returns the character written.  A return value of EOF indicates that 
  11192. a write error has occurred. Use ferror and feof to tell whether this is an 
  11193. error condition or the end of the file. 
  11194.  
  11195.  
  11196. ΓòÉΓòÉΓòÉ <hidden> Example of _fputchar ΓòÉΓòÉΓòÉ
  11197.  
  11198. /************************************************************************
  11199.  
  11200. This example writes the contents of buffer to stdout: 
  11201.  
  11202. ************************************************************************/
  11203.  
  11204. #include <stdio.h>
  11205.  
  11206. int main(void)
  11207. {
  11208.    char buffer[80];
  11209.    int i,ch = 1;
  11210.  
  11211.    for (i = 0; i < 80; i++)
  11212.       buffer[i] = 'c';
  11213.    for (i = 0; (i < 80) && (ch != EOF); i++)
  11214.       ch = _fputchar(buffer[i]);
  11215.    printf("\n");
  11216.    return 0;
  11217.  
  11218.    /****************************************************************************
  11219.       The output should be similar to:
  11220.  
  11221.    ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
  11222.    ****************************************************************************/
  11223. }
  11224.  
  11225.  
  11226. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11227.  
  11228. Example of _fputchar 
  11229.  
  11230.      _fgetchar - Read Single Character from stdin 
  11231.      fputc - Write Character 
  11232.      putc - putchar - Write a Character 
  11233.      _putch - Write Character to Screen 
  11234.      <stdio.h> 
  11235.  
  11236.  
  11237. ΓòÉΓòÉΓòÉ 4.100. fputs - Write String ΓòÉΓòÉΓòÉ
  11238.  
  11239.  
  11240. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11241.  
  11242. #include <stdio.h>
  11243. int fputs(const char *string, FILE *stream);
  11244.  
  11245.  
  11246. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11247.  
  11248. Language Level: ANSI, SAA, POSIX, XPG4 
  11249.  
  11250. fputs copies string to the output stream at the current position.  It does not 
  11251. copy the null character (\0) at the end of the string. 
  11252.  
  11253. Return Value 
  11254. fputs returns EOF if an error occurs; otherwise, it returns a non-negative 
  11255. value. 
  11256.  
  11257.  
  11258. ΓòÉΓòÉΓòÉ <hidden> Example of fputs ΓòÉΓòÉΓòÉ
  11259.  
  11260. /************************************************************************
  11261.  
  11262. This example writes a string to a stream. 
  11263.  
  11264. ************************************************************************/
  11265.  
  11266. #include <stdio.h>
  11267.  
  11268. #define  NUM_ALPHA     26
  11269.  
  11270. int main(void)
  11271. {
  11272.    FILE *stream;
  11273.    int num;
  11274.  
  11275.    /* Do not forget that the '\0' char occupies one character                 */
  11276.  
  11277.    static char buffer[NUM_ALPHA+1] = "abcdefghijklmnopqrstuvwxyz";
  11278.  
  11279.    if ((stream = fopen("myfile.dat", "w")) != NULL) {
  11280.  
  11281.       /* Put buffer into file                                                 */
  11282.  
  11283.       if ((num = fputs(buffer, stream)) != EOF) {
  11284.  
  11285.         /* Note that fputs() does not copy the \0 character                   */
  11286.  
  11287.          printf("Total number of characters written to file = %i\n", num);
  11288.          fclose(stream);
  11289.       }
  11290.       else                                                /* fputs failed     */
  11291.          perror("fputs failed");
  11292.    }
  11293.    else
  11294.       perror("Error opening myfile.dat");
  11295.    return 0;
  11296.  
  11297.    /****************************************************************************
  11298.       The output should be:
  11299.  
  11300.       Total number of characters written to file = 26
  11301.    ****************************************************************************/
  11302. }
  11303.  
  11304.  
  11305. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11306.  
  11307. Example of fputs 
  11308.  
  11309.      _cputs - Write String to Screen 
  11310.      fgets - Read a String 
  11311.      gets - Read a Line 
  11312.      puts - Write a String 
  11313.      <stdio.h> 
  11314.  
  11315.  
  11316. ΓòÉΓòÉΓòÉ 4.101. fputwc - Write Wide Character ΓòÉΓòÉΓòÉ
  11317.  
  11318.  
  11319. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11320.  
  11321. #include <wchar.h>
  11322. wint_t fputwc(wint_t wc, FILE *stream);
  11323.  
  11324.  
  11325. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11326.  
  11327. Language Level:  ANSI 93, XPG4 
  11328.  
  11329. fputwc converts the wide character wc to a multibyte character and writes it to 
  11330. the output stream pointed to by stream at the current position. It also 
  11331. advances the file position indicator appropriately. If the file cannot support 
  11332. positioning requests, or if the stream was opened with append mode, the 
  11333. character is appended to the stream. 
  11334.  
  11335. The behavior of fputwc is affected by the LC_CTYPE category of the current 
  11336. locale. If you change the category between subsequent operations on the same 
  11337. stream, undefined results can occur. Using non-wide-character functions with 
  11338. fputwc on the same stream results in undefined behavior. 
  11339.  
  11340. After calling fputwc, flush the buffer or reposition the stream pointer before 
  11341. calling a read function for the stream. After reading from the stream, flush 
  11342. the buffer or reposition the stream pointer before calling fputwc, unless EOF 
  11343. has been reached. 
  11344.  
  11345. Return Value 
  11346. fputwc returns the wide character written. If a write error occurs, the error 
  11347. indicator for the stream is set and fputwc returns WEOF. If an encoding error 
  11348. occurs during conversion from wide character to a multibyte character, fputwc 
  11349. sets errno to EILSEQ and returns WEOF. 
  11350.  
  11351.  
  11352. ΓòÉΓòÉΓòÉ <hidden> Example of fputwc ΓòÉΓòÉΓòÉ
  11353.  
  11354. /************************************************************************
  11355.  
  11356. This example opens a file and uses fputwc to write wide characters to the file. 
  11357.  
  11358. ************************************************************************/
  11359.  
  11360. #include <stdio.h>
  11361. #include <stdlib.h>
  11362. #include <wchar.h>
  11363. #include <errno.h>
  11364.  
  11365. int main(void)
  11366. {
  11367.    FILE    *stream;
  11368.    wchar_t *wcs = L"A character string.";
  11369.    int     i;
  11370.  
  11371.    if (NULL == (stream = fopen("fputwc.out", "w"))) {
  11372.       printf("Unable to open: \"fputwc.out\".\n");
  11373.       exit(1);
  11374.    }
  11375.  
  11376.    for (i = 0; wcs[i] != L'\0'; i++) {
  11377.       errno = 0;
  11378.       if (WEOF == fputwc(wcs[i], stream)) {
  11379.          printf("Unable to fputwc() the wide character.\n"
  11380.                 "wcs[%d] = 0x%lx\n", i, wcs[i]);
  11381.          if (EILSEQ == errno)
  11382.             printf("An invalid wide character was encountered.\n");
  11383.          exit(1);
  11384.       }
  11385.    }
  11386.    fclose(stream);
  11387.    return 0;
  11388.  
  11389.    /****************************************************************************
  11390.       The output file fputwc.out should contain :
  11391.  
  11392.       A character string.
  11393.    ****************************************************************************/
  11394. }
  11395.  
  11396.  
  11397. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11398.  
  11399. Example of fputwc 
  11400.  
  11401.      fgetwc - Read Wide Character from Stream 
  11402.      fputc - Write Character 
  11403.      _fputchar - Write Character 
  11404.      fputws - Write Wide-Character String 
  11405.      _putch - Write Character to Screen 
  11406.      <stdio.h> 
  11407.      <wchar.h> 
  11408.  
  11409.  
  11410. ΓòÉΓòÉΓòÉ 4.102. fputws - Write Wide-Character String ΓòÉΓòÉΓòÉ
  11411.  
  11412.  
  11413. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11414.  
  11415. #include <wchar.h>
  11416. int fputws(const wchar_t *wcs, FILE *stream);
  11417.  
  11418.  
  11419. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11420.  
  11421. Language Level:  ANSI, SAA, XPG4 
  11422.  
  11423. fputws converts the wide-character string wcs to a multibyte-character string 
  11424. and writes it to stream as a multibyte character string. It does not write the 
  11425. terminating null byte. 
  11426.  
  11427. The behavior of fputws is affected by the LC_CTYPE category of the current 
  11428. locale. If you change the category between subsequent operations on the same 
  11429. stream, undefined results can occur. Using non-wide-character functions with 
  11430. fputws on the same stream results in undefined behavior. 
  11431.  
  11432. After calling fputws, flush the buffer or reposition the stream pointer before 
  11433. calling a read function for the stream. After a read operation, flush the 
  11434. buffer or reposition the stream pointer before calling fputws, unless EOF has 
  11435. been reached. 
  11436.  
  11437. Return Value 
  11438. fputws returns a non-negative value if successful. If a write error occurs, the 
  11439. error indicator for the stream is set and fputws returns -1. If an encoding 
  11440. error occurs in converting the wide characters to multibyte characters, fputws 
  11441. sets errno to EILSEQ and returns -1. 
  11442.  
  11443.  
  11444. ΓòÉΓòÉΓòÉ <hidden> Example of fputws ΓòÉΓòÉΓòÉ
  11445.  
  11446. /************************************************************************
  11447.  
  11448. This example opens a file and writes a wide-character string to the file using 
  11449. fgetws. 
  11450.  
  11451. ************************************************************************/
  11452.  
  11453. #include <stdio.h>
  11454. #include <stdlib.h>
  11455. #include <wchar.h>
  11456. #include <errno.h>
  11457.  
  11458. int main(void)
  11459. {
  11460.    FILE    *stream;
  11461.    wchar_t *wcs = L"This test string should not return -1";
  11462.  
  11463.    if (NULL == (stream = fopen("fputws.out", "w"))) {
  11464.       printf("Unable to open: \"fputws.out\".\n");
  11465.       exit(1);
  11466.    }
  11467.  
  11468.    errno = 0;
  11469.    if (EOF == fputws(wcs, stream)) {
  11470.       printf("Unable to complete fputws() function.\n");
  11471.       if (EILSEQ == errno)
  11472.          printf("An invalid wide character was encountered.\n");
  11473.       exit(1);
  11474.    }
  11475.    fclose(stream);
  11476.    return 0;
  11477.  
  11478.    /****************************************************************************
  11479.       The output file fputws.out should contain :
  11480.  
  11481.       This test string should not return -1
  11482.    ****************************************************************************/
  11483. }
  11484.  
  11485.  
  11486. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11487.  
  11488. Example of fputws 
  11489.  
  11490.      fgetws - Read Wide-Character String from Stream 
  11491.      fputs - Write String 
  11492.      fputwc - Write Wide Character 
  11493.      <stdio.h> 
  11494.      <wchar.h> 
  11495.  
  11496.  
  11497. ΓòÉΓòÉΓòÉ 4.103. fread - Read Items ΓòÉΓòÉΓòÉ
  11498.  
  11499.  
  11500. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11501.  
  11502. #include <stdio.h>
  11503. size_t fread(void *buffer, size_t size, size_t count,
  11504.                 FILE *stream);
  11505.  
  11506.  
  11507. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11508.  
  11509. Language Level: ANSI, SAA, POSIX, XPG4 
  11510.  
  11511. fread reads up to count items of size length from the input stream and stores 
  11512. them in the given buffer.  The position in the file increases by the number of 
  11513. bytes read. 
  11514.  
  11515. Return Value 
  11516. fread returns the number of full items successfully read, which can be less 
  11517. than count if an error occurs or if the end-of-file is met before reaching 
  11518. count.  If size or count is 0, fread returns zero and the contents of the array 
  11519. and the state of the stream remain unchanged. 
  11520.  
  11521. Use ferror and feof to distinguish between a read error and an end-of-file. 
  11522.  
  11523.  
  11524. ΓòÉΓòÉΓòÉ <hidden> Example of fread ΓòÉΓòÉΓòÉ
  11525.  
  11526. /************************************************************************
  11527.  
  11528. This example attempts to read NUM_ALPHA characters from the file myfile.dat. If 
  11529. there are any errors with either fread or fopen, a message is printed. 
  11530.  
  11531. ************************************************************************/
  11532.  
  11533. #include <stdio.h>
  11534.  
  11535. #define  NUM_ALPHA     26
  11536.  
  11537. int main(void)
  11538. {
  11539.    FILE *stream;
  11540.    int num;                     /* number of characters read from stream      */
  11541.  
  11542.    /* Do not forget that the '\0' char occupies one character too!            */
  11543.  
  11544.    char buffer[NUM_ALPHA+1];
  11545.  
  11546.    if ((stream = fopen("myfile.dat", "r")) != NULL) {
  11547.       num = fread(buffer, sizeof(char), NUM_ALPHA, stream);
  11548.       if (num) {                                          /* fread success    */
  11549.          printf("Number of characters has been read = %i\n", num);
  11550.          buffer[num] = '\0';
  11551.          printf("buffer = %s\n", buffer);
  11552.          fclose(stream);
  11553.       }
  11554.       else {                                              /* fread failed     */
  11555.          if (ferror(stream))                              /* possibility 1    */
  11556.             perror("Error reading myfile.dat");
  11557.          else
  11558.             if (feof(stream))                             /* possibility 2    */
  11559.  
  11560.                perror("EOF found");
  11561.       }
  11562.    }
  11563.    else
  11564.       perror("Error opening myfile.dat");
  11565.    return 0;
  11566.  
  11567.    /****************************************************************************
  11568.       The output should be:
  11569.  
  11570.       Number of characters has been read = 26
  11571.       buffer = abcdefghijklmnopqrstuvwxyz
  11572.    ****************************************************************************/
  11573. }
  11574.  
  11575.  
  11576. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11577.  
  11578. Example of fread 
  11579.  
  11580.      feof - Test End-of-File Indicator 
  11581.      ferror - Test for Read/Write Errors 
  11582.      fopen - Open Files 
  11583.      fwrite - Write Items 
  11584.      read - Read Into Buffer 
  11585.      <stdio.h> 
  11586.  
  11587.  
  11588. ΓòÉΓòÉΓòÉ 4.104. free - Release Storage Blocks ΓòÉΓòÉΓòÉ
  11589.  
  11590.  
  11591. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11592.  
  11593. #include <stdlib.h>  /* also in <malloc.h> */
  11594. void free(void *ptr);
  11595.  
  11596.  
  11597. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11598.  
  11599. Language Level: ANSI, SAA, POSIX, XPG4, Extension 
  11600.  
  11601. free frees a block of storage. ptr points to a block previously reserved with a 
  11602. call to one of the memory allocation functions (such as calloc, _umalloc, or 
  11603. _trealloc). The number of bytes freed is the number of bytes specified when you 
  11604. reserved (or reallocated, in the case of realloc) the block of storage.  If ptr 
  11605. is NULL, free simply returns. 
  11606.  
  11607. Note:  Attempting to free a block of storage not allocated with a C memory 
  11608. management function or a block that was previously freed can affect the 
  11609. subsequent reserving of storage and lead to undefined results. 
  11610.  
  11611. Return Value 
  11612. There is no return value. 
  11613.  
  11614.  
  11615. ΓòÉΓòÉΓòÉ <hidden> Example of free ΓòÉΓòÉΓòÉ
  11616.  
  11617. /************************************************************************
  11618.  
  11619. This example uses calloc to allocate storage for x array elements and then 
  11620. calls free to free them. 
  11621.  
  11622. ************************************************************************/
  11623.  
  11624. #include <stdio.h>
  11625. #include <stdlib.h>
  11626.  
  11627. int main(void)
  11628. {
  11629.    long *array;                         /* start of the array                 */
  11630.    int num = 100;                       /* number of entries of the array     */
  11631.  
  11632.    printf("Allocating memory for %d long integers.\n", num);
  11633.  
  11634.    /* allocate num entries                                                    */
  11635.  
  11636.    if (NULL != (array = (long *)calloc(num, sizeof(long)))) {
  11637.  
  11638.      /*.......................................................................*/
  11639.      /*  do something with the array                                          */
  11640.      /*.......................................................................*/
  11641.  
  11642.       free(array);                                        /* deallocates array*/
  11643.    }
  11644.    else {                                                 /* Out of storage   */
  11645.       perror("Error: out of storage");
  11646.       abort();
  11647.    }
  11648.    return 0;
  11649.  
  11650.    /****************************************************************************
  11651.       The output should be:
  11652.  
  11653.       Allocating memory for 100 long integers.
  11654.    ****************************************************************************/
  11655. }
  11656.  
  11657.  
  11658. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11659.  
  11660. Example of free 
  11661.  
  11662.      Managing Memory in the Programming Guide 
  11663.      _alloca - Temporarily Reserve Storage Block 
  11664.      calloc - Reserve and Initialize Storage 
  11665.      _debug_free - Release Memory 
  11666.      malloc - Reserve Storage Block 
  11667.      realloc - Change Reserved Storage Block Size 
  11668.      <malloc.h> 
  11669.      <stdlib.h> 
  11670.  
  11671.  
  11672. ΓòÉΓòÉΓòÉ 4.105. _freemod - Free User DLL ΓòÉΓòÉΓòÉ
  11673.  
  11674.  
  11675. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11676.  
  11677. #include <stdlib.h>
  11678. int _freemod(unsigned long module_handle);
  11679.  
  11680.  
  11681. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11682.  
  11683. Language Level:  Extension 
  11684.  
  11685. _freemod frees all references to a dynamic link library (DLL) for the calling 
  11686. process. It is the counterpart of the _loadmod function, which loads a DLL for 
  11687. the process. The module_handle is the module handle of the DLL, which was 
  11688. returned by _loadmod. 
  11689.  
  11690. Note:  _loadmod and _freemod perform exactly the same function as the Windows 
  11691. APIs LoadLibrary and FreeLibrary. They are provided for compatibility with 
  11692. earlier VisualAge for C++ releases only, and will not be supported in future 
  11693. versions. Use LoadLibrary and FreeLibrary instead. For more details on these 
  11694. APIs, see the Win32 Programmer's Reference. 
  11695.  
  11696. Return Value 
  11697. _freemod returns 0 if successful. If not, _freemod returns -1 and sets errno to 
  11698. EOS2ERR. 
  11699.  
  11700.  
  11701. ΓòÉΓòÉΓòÉ <hidden> Example of _freemod ΓòÉΓòÉΓòÉ
  11702.  
  11703. /************************************************************************
  11704.  
  11705. This example loads the DLL mark with _loadmod, and uses the API GetProcAddress 
  11706. to get the address of the function dor from within the DLL. It then calls that 
  11707. function, which multiplies two integers passed to it. When the function and DLL 
  11708. are no longer needed, the program frees the DLL module. The types HMODULE and 
  11709. FARPROC are defined by including <windows.h>. 
  11710.  
  11711. Note:  To run this program, you must first create mark.dll. Copy the code for 
  11712. the PLUS function into a file called mark.c, and the code for the .DEF file 
  11713. into mark.def.  Eliminate the comments from these two files. Compile with the 
  11714. command: 
  11715.  
  11716.    icc /Ge- mark.c mark.def
  11717. You can then run the example. 
  11718.  
  11719. ************************************************************************/
  11720.  
  11721. #include <windows.h>
  11722. #include <stdio.h>
  11723. #include <stdlib.h>
  11724.  
  11725. typedef (_Optlink *fptr)(int, int);
  11726.  
  11727. int main(void) {
  11728.  
  11729.    int x = 4, y = 7;
  11730.    unsigned long handle;
  11731.    char *modname = "MARK";                          /* DLL name             */
  11732.    char *fname = "PLUS";                            /* function name        */
  11733.    fptr faddr;                                      /* pointer to function  */
  11734.  
  11735.    /*  dynamically load the 'mark' DLL                        */
  11736.  
  11737.    if (_loadmod(modname, &handle)) {
  11738.       printf("Error loading module %s\n", modname);
  11739.       return EXIT_FAILURE;
  11740.    }
  11741.  
  11742.    /* get function address from DLL                 */
  11743.  
  11744.    faddr = (fptr)GetProcAddress((HMODULE)handle, fname);
  11745.    if (NULL != faddr) {
  11746.       printf("Calling the function from the %s DLL to add %d and %d\n",
  11747.              modname, x, y);
  11748.       printf("The result from the function call is %d\n", faddr(x, y));
  11749.    }
  11750.    else {
  11751.       DWORD rc = GetLastError();
  11752.       printf("Error locating address of function %s, rc=%d\n", fname, rc);
  11753.       _freemod(handle);
  11754.       return EXIT_FAILURE;
  11755.    }
  11756.  
  11757.    if (_freemod(handle)) {
  11758.       printf("Error in freeing the %s DLL module\n", modname);
  11759.       return EXIT_FAILURE;
  11760.    }
  11761.  
  11762.    printf("Reference to the %s DLL module has been freed\n", modname);
  11763.  
  11764.    /****************************************************************************
  11765.         The output should be:
  11766.  
  11767.         Calling the function from MARK DLL to add 4 and 7
  11768.         The result of the function call is 11
  11769.         Reference to the MARK DLL module has been freed
  11770.    *****************************************************************************/
  11771. }
  11772.  
  11773.  
  11774. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11775.  
  11776. Example of _freemod 
  11777.  
  11778.      "Building Dynamic Link Libraries" in the Programming Guide 
  11779.      _loadmod - Load DLL 
  11780.      <stdlib.h> 
  11781.  
  11782.  
  11783. ΓòÉΓòÉΓòÉ 4.106. freopen - Redirect Open Files ΓòÉΓòÉΓòÉ
  11784.  
  11785.  
  11786. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11787.  
  11788. #include <stdio.h>
  11789. FILE *freopen(const char *filename, const char *mode, FILE *stream);
  11790.  
  11791.  
  11792. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11793.  
  11794. Language Level: ANSI, SAA, POSIX, XPG4 
  11795.  
  11796. freopen closes the file currently associated with stream and reassigns stream 
  11797. to the file specified by filename. The freopen function opens the new file 
  11798. associated with stream with the given mode, which is a character string 
  11799. specifying the type of access requested for the file. You can also use the 
  11800. freopen function to redirect the standard stream files stdin, stdout, and 
  11801. stderr to files that you specify. 
  11802.  
  11803. If filename is an empty string, freopen closes and reopens the stream to the 
  11804. new open mode, rather than reassigning it to a new file or device. You can use 
  11805. freopen with no file name specified to change the mode of a standard stream 
  11806. from text to binary without redirecting the stream, for example: 
  11807.  
  11808.    fp = freopen("", "rb", stdin);
  11809. You can use the same method to change the mode from binary back to text. 
  11810.  
  11811. Portability Note  This method is included in the SAA C definition, but not in 
  11812. the ANSI/ISO C standard. 
  11813.  
  11814. See fopen. for a description of the mode parameter. 
  11815.  
  11816. Return Value 
  11817. freopen returns a pointer to the newly opened stream. If an error occurs, 
  11818. freopen closes the original file and returns a NULL pointer value. 
  11819.  
  11820.  
  11821. ΓòÉΓòÉΓòÉ <hidden> Example of freopen ΓòÉΓòÉΓòÉ
  11822.  
  11823. /************************************************************************
  11824.  
  11825. This example closes the stream1 data stream and reassigns its stream pointer. 
  11826. Note that stream1 and stream2 will have the same value, but they will not 
  11827. necessarily have the same value as stream. 
  11828.  
  11829. ************************************************************************/
  11830.  
  11831. #include <stdio.h>
  11832. #include <stdlib.h>
  11833.  
  11834. int main(void)
  11835. {
  11836.    FILE *stream,*stream1,*stream2;
  11837.  
  11838.    stream = fopen("myfile.dat", "r");
  11839.    stream1 = stream;
  11840.    if (NULL == (stream2 = freopen("", "w+", stream1)))
  11841.       return EXIT_FAILURE;
  11842.    fclose(stream2);
  11843.    return 0;
  11844. }
  11845.  
  11846.  
  11847. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11848.  
  11849. Example of freopen 
  11850.  
  11851.      close - Close File Associated with Handle 
  11852.      fclose - Close Stream 
  11853.      _fcloseall - Close All Open Streams 
  11854.      fopen - Open Files 
  11855.      open - Open File 
  11856.      _sopen - Open Shared File 
  11857.      <stdio.h> 
  11858.  
  11859.  
  11860. ΓòÉΓòÉΓòÉ 4.107. frexp - Separate Floating-Point Value ΓòÉΓòÉΓòÉ
  11861.  
  11862.  
  11863. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11864.  
  11865. #include <math.h>
  11866. double frexp(double x, int *expptr);
  11867.  
  11868.  
  11869. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11870.  
  11871. Language Level: ANSI, SAA, POSIX, XPG4 
  11872.  
  11873. frexp breaks down the floating-point value x into a term m for the mantissa and 
  11874. another term n for the exponent, such that x = m * (2**n), and the absolute 
  11875. value of m is greater than or equal to 0.5 and less than 1.0 or equal to 0. 
  11876. frexp stores the integer exponent n at the location to which expptr points. 
  11877.  
  11878. Return Value 
  11879. frexp returns the mantissa term m.  If x is 0, frexp returns 0 for both the 
  11880. mantissa and exponent.  The mantissa has the same sign as the argument x.  The 
  11881. result of the frexp function cannot have a range error. 
  11882.  
  11883.  
  11884. ΓòÉΓòÉΓòÉ <hidden> Example of frexp ΓòÉΓòÉΓòÉ
  11885.  
  11886. /************************************************************************
  11887.  
  11888. This example decomposes the floating-point value of x, 16.4, into its mantissa 
  11889. 0.5125, and its exponent 5.  It stores the mantissa in y and the exponent in n. 
  11890.  
  11891. ************************************************************************/
  11892.  
  11893. #include <stdio.h>
  11894. #include <math.h>
  11895.  
  11896. int main(void)
  11897. {
  11898.    double x,m;
  11899.    int n;
  11900.  
  11901.    x = 16.4;
  11902.    m = frexp(x, &n);
  11903.    printf("The mantissa is %lf and the exponent is %d\n", m, n);
  11904.    return 0;
  11905.  
  11906.    /****************************************************************************
  11907.       The output should be:
  11908.  
  11909.       The mantissa is 0.512500 and the exponent is 5
  11910.    ****************************************************************************/
  11911. }
  11912.  
  11913.  
  11914. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11915.  
  11916. Example of frexp 
  11917.  
  11918.      ldexp - Multiply by a Power of Two 
  11919.      modf - Separate Floating-Point Value 
  11920.      <math.h> 
  11921.  
  11922.  
  11923. ΓòÉΓòÉΓòÉ 4.108. fscanf - Read Formatted Data ΓòÉΓòÉΓòÉ
  11924.  
  11925.  
  11926. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11927.  
  11928. #include <stdio.h>
  11929. int fscanf (FILE *stream, const char *format-string, argument-list);
  11930.  
  11931.  
  11932. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11933.  
  11934. Language Level: ANSI, SAA, POSIX, XPG4, Extension 
  11935.  
  11936. fscanf reads data from the current position of the specified stream into the 
  11937. locations given by the entries in argument-list, if any.  Each entry in 
  11938. argument-list must be a pointer to a variable with a type that corresponds to a 
  11939. type specifier in format-string. 
  11940.  
  11941. The format-string controls the interpretation of the input fields and has the 
  11942. same form and function as the format-string argument for the scanf function. 
  11943. See scanf for a description of format-string. 
  11944.  
  11945. In extended mode, the fscanf function also reads in the strings "INFINITY", 
  11946. "INF", and "NAN" (in upper or lowercase) and converts them to the corresponding 
  11947. floating-point value.  The sign of the value is determined by the format 
  11948. specification. See Infinity and NaN Support for more information on infinity 
  11949. and NaN values. 
  11950.  
  11951. Return Value 
  11952. fscanf returns the number of fields that it successfully converted and 
  11953. assigned.  The return value does not include fields that fscanf read but did 
  11954. not assign. 
  11955.  
  11956. The return value is EOF if an input failure occurs before any conversion, or 
  11957. the number of input items assigned if successful. 
  11958.  
  11959.  
  11960. ΓòÉΓòÉΓòÉ <hidden> Example of fscanf ΓòÉΓòÉΓòÉ
  11961.  
  11962. /************************************************************************
  11963.  
  11964. This example opens the file myfile.dat for reading and then scans this file for 
  11965. a string, a long integer value, a character, and a floating-point value. 
  11966.  
  11967. ************************************************************************/
  11968.  
  11969. #include <stdio.h>
  11970.  
  11971. #define  MAX_LEN       80
  11972.  
  11973. int main(void)
  11974. {
  11975.    FILE *stream;
  11976.    long l;
  11977.    float fp;
  11978.    char s[MAX_LEN+1];
  11979.    char c;
  11980.  
  11981.    stream = fopen("myfile.dat", "r");
  11982.  
  11983.     /* Put in various data.                                                   */
  11984.  
  11985.    fscanf(stream, "%s", &s[0]);
  11986.    fscanf(stream, "%ld", &l);
  11987.    fscanf(stream, "%c", &c);
  11988.    fscanf(stream, "%f", &fp);
  11989.    printf("string = %s\n", s);
  11990.    printf("long double = %ld\n", l);
  11991.    printf("char = %c\n", c);
  11992.    printf("float = %f\n", fp);
  11993.    return 0;
  11994.  
  11995.    /****************************************************************************
  11996.       If myfile.dat contains:
  11997.       abcdefghijklmnopqrstuvwxyz 343.2.
  11998.  
  11999.       The output should be:
  12000.  
  12001.       string = abcdefghijklmnopqrstuvwxyz
  12002.       long double = 343
  12003.       char = .
  12004.       float = 2.000000
  12005.    ****************************************************************************/
  12006. }
  12007.  
  12008.  
  12009. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12010.  
  12011. Example of fscanf 
  12012.  
  12013.      Infinity and NaN Support 
  12014.      _cscanf - Read Data from Keyboard 
  12015.      fprintf - Write Formatted Data to a Stream 
  12016.      scanf - Read Data 
  12017.      sscanf - Read Data 
  12018.      <stdio.h> 
  12019.  
  12020.  
  12021. ΓòÉΓòÉΓòÉ 4.109. fseek - Reposition File Position ΓòÉΓòÉΓòÉ
  12022.  
  12023.  
  12024. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12025.  
  12026. #include <stdio.h>
  12027. int fseek(FILE *stream, long int offset, int origin);
  12028.  
  12029.  
  12030. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12031.  
  12032. Language Level: ANSI, SAA, POSIX, XPG4 
  12033.  
  12034. fseek changes the current file position associated with stream to a new 
  12035. location within the file. The next operation on the stream takes place at the 
  12036. new location.  On a stream open for update, the next operation can be either a 
  12037. reading or a writing operation. 
  12038.  
  12039. The origin must be one of the following constants defined in <stdio.h>: 
  12040.  
  12041.  Origin            Definition 
  12042.  SEEK_SET          Beginning of file 
  12043.  SEEK_CUR          Current position of file pointer 
  12044.  SEEK_END          End of file 
  12045.  
  12046.  For a binary stream, you can also change the position beyond the end of the 
  12047.  file.  An attempt to position before the beginning of the file causes an 
  12048.  error. If successful, fseek clears the end-of-file indicator, even when origin 
  12049.  is SEEK_END, and undoes the effect of any preceding ungetc function on the 
  12050.  same stream. 
  12051.  
  12052.  Note:  For streams opened in text mode, fseek has limited use because some 
  12053.  system translations (such as those between carriage-return-line-feed and new 
  12054.  line) can produce unexpected results.  The only fseek operations that can be 
  12055.  relied upon to work on streams opened in text mode are seeking with an offset 
  12056.  of zero relative to any of the origin values or seeking from the beginning of 
  12057.  the file with an offset value returned from a call to ftell. See the chapter 
  12058.  "Performing I/O Operations" in the Programming Guide for more information. 
  12059.  
  12060.  Return Value 
  12061.  fseek returns 0 if it successfully moves the pointer.  A nonzero return value 
  12062.  indicates an error.  On devices that cannot seek, such as terminals and 
  12063.  printers, the return value is nonzero. 
  12064.  
  12065.  
  12066. ΓòÉΓòÉΓòÉ <hidden> Example of fseek ΓòÉΓòÉΓòÉ
  12067.  
  12068. /************************************************************************
  12069.  
  12070. This example opens a file myfile.dat for reading. After performing input 
  12071. operations (not shown), fseek moves the file pointer to the beginning of the 
  12072. file. 
  12073.  
  12074. ************************************************************************/
  12075.  
  12076. #include <stdio.h>
  12077. #include <stdlib.h>
  12078.  
  12079. int main(void)
  12080. {
  12081.    FILE *stream;
  12082.    int result;
  12083.  
  12084.    stream = fopen("myfile.dat", "r");
  12085.  
  12086.    result = fseek(stream, 0L, SEEK_SET);   /* moves the pointer to the
  12087.                                               beginning of the file           */
  12088.  
  12089.    if (result)                           /* fail to move the pointer to the   */
  12090.       return EXIT_FAILURE;               /* beginning of the file             */
  12091.    fclose(stream);
  12092.    return 0;
  12093. }
  12094.  
  12095.  
  12096. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12097.  
  12098. Example of fseek 
  12099.  
  12100.      fgetpos - Get File Position 
  12101.      fsetpos - Set File Position 
  12102.      ftell - Get Current Position 
  12103.      rewind - Adjust Current File Position 
  12104.      ungetc - Push Character onto Input Stream 
  12105.      <stdio.h> 
  12106.  
  12107.  
  12108. ΓòÉΓòÉΓòÉ 4.110. fsetpos - Set File Position ΓòÉΓòÉΓòÉ
  12109.  
  12110.  
  12111. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12112.  
  12113. #include <stdio.h>
  12114. int fsetpos(FILE *stream, const fpos_t *pos);
  12115.  
  12116.  
  12117. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12118.  
  12119. Language Level: ANSI, SAA, XPG4 
  12120.  
  12121. fsetpos moves any file position associated with stream to a new location within 
  12122. the file according to the value pointed to by pos.  The value of pos was 
  12123. obtained by a previous call to the fgetpos library function. 
  12124.  
  12125. If successful, fsetpos clears the end-of-file indicator, and undoes the effect 
  12126. of any previous ungetc function on the same stream. 
  12127.  
  12128. After the fsetpos call, the next operation on a stream in update mode may be 
  12129. input or output. 
  12130.  
  12131. Return Value 
  12132. If fsetpos successfully changes the current position of the file, it returns 0. 
  12133. A nonzero return value indicates an error. 
  12134.  
  12135.  
  12136. ΓòÉΓòÉΓòÉ <hidden> Example of fsetpos ΓòÉΓòÉΓòÉ
  12137.  
  12138. /************************************************************************
  12139.  
  12140. This example opens a file myfile.dat for reading. After performing input 
  12141. operations (not shown), fsetpos moves the file pointer to the beginning of the 
  12142. file and rereads the first byte. 
  12143.  
  12144. ************************************************************************/
  12145.  
  12146. #include <stdio.h>
  12147.  
  12148. FILE *stream;
  12149.  
  12150. int main(void)
  12151. {
  12152.    int retcode;
  12153.    fpos_t pos,pos1,pos2,pos3;
  12154.    char ptr[20];           /* existing file 'myfile.dat' has 20 byte records  */
  12155.  
  12156.     /* Open file, get position of file pointer, and read first record         */
  12157.  
  12158.    stream = fopen("myfile.dat", "rb");
  12159.    fgetpos(stream, &pos);
  12160.    pos1 = pos;
  12161.    if (!fread(ptr, sizeof(ptr), 1, stream))
  12162.       perror("fread error");
  12163.  
  12164.     /* Perform a number of read operations - the value of 'pos' changes       */
  12165.     /* Re-set pointer to start of file and re-read first record               */
  12166.  
  12167.    fsetpos(stream, &pos1);
  12168.    if (!fread(ptr, sizeof(ptr), 1, stream))
  12169.       perror("fread error");
  12170.    fclose(stream);
  12171.    return 0;
  12172. }
  12173.  
  12174.  
  12175. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12176.  
  12177. Example of fsetpos 
  12178.  
  12179.      fgetpos - Get File Position 
  12180.      fseek - Reposition File Position 
  12181.      ftell - Get Current Position 
  12182.      rewind - Adjust Current File Position 
  12183.      ungetc - Push Character onto Input Stream 
  12184.      <stdio.h> 
  12185.  
  12186.  
  12187. ΓòÉΓòÉΓòÉ 4.111. _fsin - Calculate Sine ΓòÉΓòÉΓòÉ
  12188.  
  12189.  
  12190. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12191.  
  12192. #include <builtin.h>
  12193. double _fsin( double x);
  12194.  
  12195.  
  12196. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12197.  
  12198. Language Level:  Extension 
  12199.  
  12200. _fsin calculates the sine of x, where x is expressed in radians. The value of x 
  12201. must be less than 2**63. This function causes the compiler to emit the 
  12202. appropriate 80387 instruction for the calculation of sine. 
  12203.  
  12204. Because it is a built-in function and has no backing code in the library: 
  12205.  
  12206.      You cannot take the address of _fsin. 
  12207.      You cannot parenthesize a _fsin function call, because parentheses 
  12208.       specify a call to the backing code for the function in the library. 
  12209.  
  12210.  Return Value 
  12211.  This function returns the sine of a variable x expressed in radians. 
  12212.  
  12213.  
  12214. ΓòÉΓòÉΓòÉ <hidden> Example of _fsin ΓòÉΓòÉΓòÉ
  12215.  
  12216. /************************************************************************
  12217.  
  12218. This example calculates y as the sine of pi/2. 
  12219.  
  12220. ************************************************************************/
  12221.  
  12222. #include <builtin.h>
  12223. #include <stdio.h>
  12224.  
  12225. int main(void)
  12226. {
  12227.    double pi;
  12228.  
  12229.    pi = 3.1415926535;
  12230.    printf("The sine of %lf is %lf.\n", pi/2.0, _fsin(pi/2.0));
  12231.    return 0;
  12232.  
  12233.    /****************************************************************************
  12234.       The output should be :
  12235.  
  12236.       The sine of 1.570796 is 1.000000.
  12237.    ****************************************************************************/
  12238. }
  12239.  
  12240.  
  12241. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12242.  
  12243. Example of _fsin 
  12244.  
  12245.      _fasin - Calculate Arcsine 
  12246.      _fcossin - Calculate Cosine and Sine 
  12247.      _fsincos - Calculate Sine and Cosine 
  12248.      sin - Calculate Sine 
  12249.      sinh - Calculate Hyperbolic Sine 
  12250.      <builtin.h> 
  12251.  
  12252.  
  12253. ΓòÉΓòÉΓòÉ 4.112. _fsincos - Calculate Sine and Cosine ΓòÉΓòÉΓòÉ
  12254.  
  12255.  
  12256. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12257.  
  12258. #include <builtin.h>
  12259. double _fsincos(double x, double *y);
  12260.  
  12261.  
  12262. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12263.  
  12264. Language Level:  Extension 
  12265.  
  12266. _fsincos calculates the sine of x, and stores the cosine in *y. This operation 
  12267. is faster than separately calculating the sine and cosine. Use _fsincos instead 
  12268. of _fcossin when you will be using the sine first, and then the cosine. 
  12269.  
  12270. Because it is a built-in function and has no backing code in the library: 
  12271.  
  12272.      You cannot take the address of _fsincos. 
  12273.      You cannot parenthesize a _fsincos function call because parentheses 
  12274.       specify a call to the backing code for the function. 
  12275.  
  12276.  Return Value 
  12277.  This function returns the sine of x. 
  12278.  
  12279.  
  12280. ΓòÉΓòÉΓòÉ <hidden> Example of _fsincos ΓòÉΓòÉΓòÉ
  12281.  
  12282. /************************************************************************
  12283.  
  12284. This example calculates the sine of x and stores it in z, and stores the cosine 
  12285. of x in y. 
  12286.  
  12287. ************************************************************************/
  12288.  
  12289. #include <builtin.h>
  12290. #include <stdio.h>
  12291.  
  12292. int main(void)
  12293. {
  12294.    double x, y, z;
  12295.  
  12296.    printf("Enter x:\n");
  12297.    scanf("%lf", &x);
  12298.  
  12299.    z = _fsincos(x, &y);
  12300.    printf("The sine of %lf is %lf.\n", x, z);
  12301.    printf("The cosine of %lf is %lf.\n", x, y);
  12302.    return 0;
  12303.  
  12304.    /****************************************************************************
  12305.       Assuming you enter : 1.0
  12306.  
  12307.       The output should be :
  12308.  
  12309.       The sine of 1.000000 is 0.841471.
  12310.       The cosine of 1.000000 is 0.540302.
  12311.    ****************************************************************************/
  12312. }
  12313.  
  12314.  
  12315. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12316.  
  12317. Example of _fsincos 
  12318.  
  12319.      acos - Calculate Arccosine 
  12320.      asin - Calculate Arcsine 
  12321.      cos - Calculate Cosine 
  12322.      cosh - Calculate Hyperbolic Cosine 
  12323.      _facos - Calculate Arccosine 
  12324.      _fasin - Calculate Arcsine 
  12325.      _fcos - Calculate Cosine 
  12326.      _fcossin - Calculate Cosine and Sine 
  12327.      _fsin - Calculate Sine 
  12328.      sin - Calculate Sine 
  12329.      sinh - Calculate Hyperbolic Sine 
  12330.      <builtin.h> 
  12331.  
  12332.  
  12333. ΓòÉΓòÉΓòÉ 4.113. _fsqrt -  Calculate Square Root ΓòÉΓòÉΓòÉ
  12334.  
  12335.  
  12336. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12337.  
  12338. #include <builtin.h>
  12339. double _fsqrt(double x);
  12340.  
  12341.  
  12342. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12343.  
  12344. Language Level:  Extension 
  12345.  
  12346. _fsqrt computes the square root of x using the FSQRT 80387 instruction. Note 
  12347. that this function does not set errno as the sqrt function does. If you pass a 
  12348. negative value to this function, an exception is generated. 
  12349.  
  12350. Note:  _fsqrt is a built-in function, which means it is implemented as an 
  12351. inline instruction and has no backing code in the library. For this reason: 
  12352.  
  12353.      You cannot take the address of _fsqrt. 
  12354.      You cannot parenthesize a call to _fsqrt. (Parentheses specify a call to 
  12355.       the function's backing code, and _fsqrt has none.) 
  12356.  
  12357.  Return Value 
  12358.  _fsqrt returns the value of the square root of x. 
  12359.  
  12360.  
  12361. ΓòÉΓòÉΓòÉ <hidden> Example of _fsqrt ΓòÉΓòÉΓòÉ
  12362.  
  12363. /************************************************************************
  12364.  
  12365. This example calculates the square root of 4. 
  12366.  
  12367. ************************************************************************/
  12368.  
  12369. #include <builtin.h>
  12370. #include <stdio.h>
  12371.  
  12372. int main(void)
  12373. {
  12374.    double x;
  12375.  
  12376.    x = 4.0;
  12377.    printf("The square root of %lf is %lf.\n", x, _fsqrt(x));
  12378.    return 0;
  12379.  
  12380.    /****************************************************************************
  12381.       The output should be :
  12382.  
  12383.       The square root of 4.000000 is 2.000000.
  12384.    ****************************************************************************/
  12385. }
  12386.  
  12387.  
  12388. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12389.  
  12390. Example of _fsqrt 
  12391.  
  12392.      sqrt - Calculate Square Root 
  12393.      <math.h> 
  12394.  
  12395.  
  12396. ΓòÉΓòÉΓòÉ 4.114. fstat - Information about Open File ΓòÉΓòÉΓòÉ
  12397.  
  12398.  
  12399. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12400.  
  12401. #include <sys\stat.h>
  12402. #include <sys\types.h>
  12403. int fstat(int handle, struct stat *buffer);
  12404.  
  12405.  
  12406. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12407.  
  12408. Language Level:  XPG4, Extension 
  12409.  
  12410. fstat obtains information about the open file associated with the given handle 
  12411. and stores it in the structure to which buffer points.  The <sys\stat.h> 
  12412. include file defines the stat structure.  The stat structure contains the 
  12413. following fields: 
  12414.  
  12415.  Field       Value 
  12416.  
  12417.  st_mode     Bit mask for file mode information. fstat sets the S_IFCHR bit if 
  12418.              handle refers to a device. The S_IFDIR bit is set if pathname 
  12419.              specifies a directory. It sets the S_IFREG bit if handle refers to 
  12420.              an ordinary file.  It sets user read/write bits according to the 
  12421.              permission mode of the file. The other bits have undefined values. 
  12422.  
  12423.  st_dev      Drive number of the disk containing the file. 
  12424.  
  12425.  st_rdev     Drive number of the disk containing the file (same as st_dev). 
  12426.  
  12427.  st_nlink    Always 1. 
  12428.  
  12429.  st_size     Size of the file in bytes. 
  12430.  
  12431.  st_atime    Time of last access of file. 
  12432.  
  12433.  st_mtime    Time of last modification of file. 
  12434.  
  12435.  st_ctime    Time of file creation. 
  12436.  
  12437.  There are three additional fields in the stat structure for portability to 
  12438.  other operating systems; they have no meaning under Windows. 
  12439.  
  12440.  Note: 
  12441.  
  12442.    1. If the given handle refers to a device, the size and time fields in the 
  12443.       stat structure are not meaningful. 
  12444.  
  12445.    2. In earlier releases of VisualAge C++, fstat began with an underscore 
  12446.       (_fstat). Because it is defined by the X/Open standard, the underscore 
  12447.       has been removed. For compatibility, VisualAge for C++ will map _fstat to 
  12448.       fstat for you. 
  12449.  
  12450.  Return Value 
  12451.  If it obtains the file status information, fstat returns 0. A return value of 
  12452.  -1 indicates an error, and fstat sets errno to EBADF, showing an incorrect 
  12453.  file handle. 
  12454.  
  12455.  
  12456. ΓòÉΓòÉΓòÉ <hidden> Example of fstat ΓòÉΓòÉΓòÉ
  12457.  
  12458. /************************************************************************
  12459.  
  12460. This example uses fstat to report the size of a file named data. 
  12461.  
  12462. ***********************************************************************(/
  12463.  
  12464. #include <time.h>
  12465. #include <sys\types.h>
  12466. #include <sys\stat.h>
  12467. #include <stdio.h>
  12468.  
  12469. int main(void)
  12470. {
  12471.    struct stat buf;
  12472.    FILE *fp;
  12473.    int fh,result;
  12474.    char *buffer = "A line to output";
  12475.  
  12476.    fp = fopen("data", "w+");
  12477.    fprintf(fp, "%s", buffer);
  12478.    fflush(fp);
  12479.    fclose(fp);
  12480.    fp = fopen("data", "r");
  12481.    if (0 == fstat(fileno(fp), &buf)) {
  12482.       printf("file size is %ld\n", buf.st_size);
  12483.       printf("time modified is %s\n", ctime(&buf.st_atime));
  12484.    }
  12485.    else
  12486.       printf("Bad file handle\n");
  12487.    fclose(fp);
  12488.    return 0;
  12489.  
  12490.    /****************************************************************************
  12491.       The output should be similar to:
  12492.  
  12493.       file size is 16
  12494.       time modified is Thu May 16 16:14 1995
  12495.    ****************************************************************************/
  12496. }
  12497.  
  12498.  
  12499. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12500.  
  12501. Example of fstat 
  12502.  
  12503.      stat - Get Information about File or Directory 
  12504.      <sys\stat.h> 
  12505.      <sys\types.h> 
  12506.  
  12507.  
  12508. ΓòÉΓòÉΓòÉ 4.115. ftell - Get Current Position ΓòÉΓòÉΓòÉ
  12509.  
  12510.  
  12511. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12512.  
  12513. #include <stdio.h>
  12514. long int ftell(FILE *stream);
  12515.  
  12516.  
  12517. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12518.  
  12519. Language Level: ANSI, SAA, POSIX, XPG4 
  12520.  
  12521. ftell finds the current position of the file associated with stream. For a 
  12522. fixed-length binary file, the value returned by ftell is an offset relative to 
  12523. the beginning of the stream. 
  12524.  
  12525. Note:  For buffered text streams, ftell returns an incorrect file position if 
  12526. the file contains new-line characters instead of carriage-return line-feed 
  12527. combinations.  Your file would only contain new-line characters if you 
  12528. previously used it as a binary stream.  To avoid this problem, either continue 
  12529. to process the file as a binary stream, or use unbuffered I/O operations. 
  12530.  
  12531. Return Value 
  12532.  
  12533. ftell returns the current file position. On error, ftell returns -1L and sets 
  12534. errno to a nonzero value. 
  12535.  
  12536.  
  12537. ΓòÉΓòÉΓòÉ <hidden> Example of ftell ΓòÉΓòÉΓòÉ
  12538.  
  12539. /************************************************************************
  12540.  
  12541. This example opens the file myfile.dat for reading. It reads enough characters 
  12542. to fill half of the buffer and prints out the position in the stream and the 
  12543. buffer. 
  12544.  
  12545. ************************************************************************/
  12546.  
  12547. #include <stdio.h>
  12548.  
  12549. #define  NUM_ALPHA     26
  12550. #define  NUM_CHAR      6
  12551.  
  12552. int main(void)
  12553. {
  12554.    FILE *stream;
  12555.    int i;
  12556.    char ch;
  12557.    char buffer[NUM_ALPHA];
  12558.    long position;
  12559.  
  12560.    if ((stream = fopen("myfile.dat", "r")) != NULL) {
  12561.  
  12562.      /* read into buffer                                                      */
  12563.  
  12564.       for (i = 0; (i < NUM_ALPHA/2) && ((buffer[i] = fgetc(stream)) != EOF);
  12565.            ++i)
  12566.          if (i == NUM_CHAR-1) { /* We want to be able to position the
  12567.                                    file pointer to the character in
  12568.                                    position NUM_CHAR                          */
  12569.  
  12570.             position = ftell(stream);
  12571.             printf("Current position of the file is stored.\n");
  12572.          }
  12573.       buffer[i] = '\0';
  12574.       fseek(stream, position, SEEK_SET);
  12575.       ch = fgetc(stream);       /* get the character at position NUM_CHAR     */
  12576.       fclose(stream);
  12577.    }
  12578.    else
  12579.       perror("Error opening myfile.dat");
  12580.    return 0;
  12581. }
  12582.  
  12583.  
  12584. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12585.  
  12586. Example of ftell 
  12587.  
  12588.      fseek - Reposition File Position 
  12589.      fgetpos - Get File Position 
  12590.      fopen - Open Files 
  12591.      fsetpos - Set File Position 
  12592.      <stdio.h> 
  12593.  
  12594.  
  12595. ΓòÉΓòÉΓòÉ 4.116. _ftime - Store Current Time ΓòÉΓòÉΓòÉ
  12596.  
  12597.  
  12598. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12599.  
  12600. #include <sys\timeb.h>
  12601. #include <sys\types.h>
  12602. void _ftime(struct timeb *timeptr);
  12603.  
  12604.  
  12605. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12606.  
  12607. Language Level:  Extension 
  12608.  
  12609. _ftime gets the current time and stores it in the structure to which timeptr 
  12610. points.  The <sys\timeb.h> include file contains the definition of the timeb 
  12611. structure.  It contains four fields: 
  12612.  
  12613.  time      The time in seconds since 00:00:00 Coordinated Universal Time, 
  12614.            January 1, 1970. 
  12615.  millitm   The fraction of a second, in milliseconds. 
  12616.  timezone  The difference in minutes between Coordinated Universal Time and 
  12617.            local time, going from east to west. _ftime sets the value of 
  12618.            timezone from the value of the global variable _timezone. 
  12619.  dstflag   Nonzero if daylight saving time is currently in effect for the local 
  12620.            time zone. For an explanation of how daylight saving time is 
  12621.            determined, see tzset - Assign Values to Locale Information. 
  12622.  
  12623.  Return Value 
  12624.  There is no return value. 
  12625.  
  12626.  
  12627. ΓòÉΓòÉΓòÉ <hidden> Example of _ftime ΓòÉΓòÉΓòÉ
  12628.  
  12629. /************************************************************************
  12630.  
  12631. This example polls the system clock, converts the current time to a character 
  12632. string, prints the string, and saves the time data in the structure timebuffer. 
  12633.  
  12634. ************************************************************************/
  12635.  
  12636. #include <sys\types.h>
  12637. #include <sys\timeb.h>
  12638. #include <stdio.h>
  12639. #include <time.h>
  12640.  
  12641. int main(void)
  12642. {
  12643.    struct timeb timebuffer;
  12644.  
  12645.    _ftime(&timebuffer);
  12646.    printf("the time is %s\n", ctime(&(timebuffer.time)));
  12647.    return 0;
  12648.  
  12649.    /****************************************************************************
  12650.       The output should be similar to:
  12651.  
  12652.       the time is Thu May 16 16:17 1995
  12653.    ****************************************************************************/
  12654. }
  12655.  
  12656.  
  12657. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12658.  
  12659. Example of _ftime 
  12660.  
  12661.      asctime - Convert Time to Character String 
  12662.      ctime - Convert Time to Character String 
  12663.      gmtime - Convert Time 
  12664.      localtime - Convert Time 
  12665.      mktime - Convert Local Time 
  12666.      time - Determine Current Time 
  12667.      tzset - Assign Values to Locale Information 
  12668.      <sys\timeb.h> 
  12669.      <sys\types.h> 
  12670.  
  12671.  
  12672. ΓòÉΓòÉΓòÉ 4.117. _fullpath - Get Full Path Name of Partial Path ΓòÉΓòÉΓòÉ
  12673.  
  12674.  
  12675. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12676.  
  12677. #include <stdlib.h>
  12678. char *_fullpath(char *pathbuf, char *partialpath, size_t n);
  12679.  
  12680.  
  12681. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12682.  
  12683. Language Level:  Extension 
  12684.  
  12685. _fullpath gets the full path name of the given partial path name partialpath, 
  12686. and stores it in pathbuf. The integer argument n specifies the maximum length 
  12687. for the path name.  An error occurs if the length of the path name, including 
  12688. the terminating null character, exceeds n characters. 
  12689.  
  12690. If pathbuf is NULL, _fullpath uses malloc to allocate a buffer of size 
  12691. _MAX_PATH bytes to store the path name. 
  12692.  
  12693. Return Value 
  12694. _fullpath returns a pointer to pathbuf.  If an error occurs, _fullpath returns 
  12695. NULL and sets errno to one of the following values: 
  12696.  
  12697.  Value          Meaning 
  12698.  ENOMEM         Unable to allocate storage for the buffer. 
  12699.  ERANGE         The path name is longer than n characters. 
  12700.  EOS2ERR        A system error occurred.  Check _doserrno for the specific 
  12701.                 Windows code. 
  12702.  
  12703.  
  12704. ΓòÉΓòÉΓòÉ <hidden> Example of _fullpath ΓòÉΓòÉΓòÉ
  12705.  
  12706. /************************************************************************
  12707. This example uses _fullpath to get and store the full path name of the current 
  12708. directory. 
  12709.  
  12710. ************************************************************************/
  12711.  
  12712. #include <stdio.h>
  12713. #include <stdlib.h>
  12714. #include <errno.h>
  12715.  
  12716. int main(void)
  12717. {
  12718.    char *retBuffer;
  12719.  
  12720.    retBuffer = _fullpath(NULL, ".", 0);
  12721.    if (NULL == retBuffer) {
  12722.       printf("An error has occurred, errno is set to %d.\n", errno);
  12723.    }
  12724.    else
  12725.       printf("Full path name of current directory is %s.\n", retBuffer);
  12726.    return 0;
  12727.  
  12728.    /****************************************************************************
  12729.       The output should be similar to:
  12730.  
  12731.         Full path name of current directory is D:\BIN.
  12732.    ****************************************************************************/
  12733. }
  12734.  
  12735.  
  12736. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12737.  
  12738. Example of _fullpath 
  12739.  
  12740.      _getcwd - Get Path Name of Current Directory 
  12741.      _getdcwd - Get Full Path Name of Current Directory 
  12742.      _makepath - Create Path 
  12743.      malloc - Reserve Storage Block 
  12744.      _splitpath - Decompose Path Name 
  12745.      <stdlib.h> 
  12746.  
  12747.  
  12748. ΓòÉΓòÉΓòÉ 4.118. fwrite - Write Items ΓòÉΓòÉΓòÉ
  12749.  
  12750.  
  12751. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12752.  
  12753. #include <stdio.h>
  12754. size_t fwrite(const void *buffer, size_t size, size_t count,
  12755.                  FILE *stream);
  12756.  
  12757.  
  12758. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12759.  
  12760. Language Level: ANSI, SAA, POSIX, XPG4 
  12761.  
  12762. fwrite writes up to count items, each of size bytes in length, from buffer to 
  12763. the output stream. 
  12764.  
  12765. Return Value 
  12766. fwrite returns the number of full items successfully written, which can be 
  12767. fewer than count if an error occurs. 
  12768.  
  12769.  
  12770. ΓòÉΓòÉΓòÉ <hidden> Example of fwrite ΓòÉΓòÉΓòÉ
  12771.  
  12772. /************************************************************************
  12773.  
  12774. This example writes NUM long integers to a stream in binary format. 
  12775.  
  12776. ************************************************************************/
  12777.  
  12778. #include <stdio.h>
  12779.  
  12780. #define  NUM           100
  12781.  
  12782. int main(void)
  12783. {
  12784.    FILE *stream;
  12785.    long list[NUM];
  12786.    int numwritten;
  12787.  
  12788.    stream = fopen("myfile.dat", "w+b");
  12789.  
  12790.               /* assign values to list[]                                      */
  12791.  
  12792.    numwritten = fwrite(list, sizeof(long), NUM, stream);
  12793.    printf("Number of items successfully written : %d\n", numwritten);
  12794.    return 0;
  12795.  
  12796.    /****************************************************************************
  12797.       The output should be:
  12798.  
  12799.       Number of items successfully written : 100
  12800.    ****************************************************************************/
  12801. }
  12802.  
  12803.  
  12804. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12805.  
  12806. Example of fwrite 
  12807.  
  12808.      fopen - Open Files 
  12809.      fread - Read Items 
  12810.      read - Read Into Buffer 
  12811.      write - Writes from Buffer to File 
  12812.      <stdio.h> 
  12813.  
  12814.  
  12815. ΓòÉΓòÉΓòÉ 4.119. _fyl2x - Calculate y * log2(x) ΓòÉΓòÉΓòÉ
  12816.  
  12817.  
  12818. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12819.  
  12820. #include <builtin.h>
  12821. double _fyl2x(double x, double y);
  12822.  
  12823.  
  12824. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12825.  
  12826. Language Level:  Extension 
  12827.  
  12828. _fyl2x computes the base-2 logarithm of x and multiplies it by y (y * log2(x)). 
  12829. The variable x cannot be negative. This instruction is designed with built-in 
  12830. multiplication to optimize the calculation of logarithms with arbitrary 
  12831. positive base: log b (x) = (log2(b)**-1) * log2(x) 
  12832.  
  12833. Because it is a built-in function and has no backing code in the library: 
  12834.  
  12835.      You cannot take the address of _fyl2x. 
  12836.      You cannot parenthesize a _fyl2x function call, because parentheses 
  12837.       specify a call to the backing code for the function in the library. 
  12838.  
  12839.  Return Value 
  12840.  _fyl2x returns the result of the formula y * log2(x). 
  12841.  
  12842.  
  12843. ΓòÉΓòÉΓòÉ <hidden> Example of _fyl2x ΓòÉΓòÉΓòÉ
  12844.  
  12845. /************************************************************************
  12846.  
  12847. This example calculates (y * log2(x)), after prompting the user for values of x 
  12848. and y. 
  12849.  
  12850. ************************************************************************/
  12851.  
  12852. #include <builtin.h>
  12853. #include <stdio.h>
  12854.  
  12855. int main(void)
  12856. {
  12857.    double x, y;
  12858.  
  12859.    printf("Enter a value for x:\n");
  12860.    scanf("%lf", &x);
  12861.    printf("Enter a value for y:\n");
  12862.    scanf("%lf", &y);
  12863.    printf("%lf * log2(%lf) is %lf.\n", y, x, _fyl2x(x, y));
  12864.    return 0;
  12865.  
  12866.    /****************************************************************************
  12867.       Assuming you enter 4.0 for x and 3.0 for y.
  12868.  
  12869.       The output should be :
  12870.  
  12871.       3.000000 * log2(4.000000) is 6.000000.
  12872.    ****************************************************************************/
  12873. }
  12874.  
  12875.  
  12876. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12877.  
  12878. Example of _fyl2x 
  12879.  
  12880.      _fyl2xp1 -  Calculate y * log2(x + 1) 
  12881.      _f2xm1 -  Calculate (2**x) - 1 
  12882.      <builtin.h> 
  12883.  
  12884.  
  12885. ΓòÉΓòÉΓòÉ 4.120. _fyl2xp1 -  Calculate y * log2(x + 1) ΓòÉΓòÉΓòÉ
  12886.  
  12887.  
  12888. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12889.  
  12890. #include <builtin.h>
  12891. double _fyl2xp1(double x, double y);
  12892.  
  12893.  
  12894. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12895.  
  12896. Language Level:  Extension 
  12897.  
  12898. _fyl2xp1 computes the base-2 logarithm of x+1 and multiplies it by y (y * 
  12899. log2(x+1)). The variable x must be in the range -(1-(sqrt(2)/2)) to (sqrt(2) - 
  12900. 1). _fyl2xp1 provides improved accuracy over _fyl2x when logarithms of numbers 
  12901. very close to 1 are computed. When x is small, you can retain more significant 
  12902. digits by providing x to the _fyl2xp1 function than by providing x+1 as an 
  12903. argument to the _fyl2x function. 
  12904.  
  12905. Because it is a built-in function and has no backing code in the library: 
  12906.  
  12907.      You cannot take the address of _fyl2xp1. 
  12908.      You cannot parenthesize a _fyl2xp1 function call, because parentheses 
  12909.       specify a call to the backing code for the function in the library. 
  12910.  
  12911.  Return Value 
  12912.  _fyl2xp1 returns the result of the formula y * log2(x+1). 
  12913.  
  12914.  
  12915. ΓòÉΓòÉΓòÉ <hidden> Example of _fyl2xp1 ΓòÉΓòÉΓòÉ
  12916.  
  12917. /************************************************************************
  12918.  
  12919. This example calculates (y * log2(x + 1)), after prompting the user for values 
  12920. of x and y. 
  12921.  
  12922. ************************************************************************/
  12923.  
  12924. #include <builtin.h>
  12925. #include <stdio.h>
  12926.  
  12927. int main(void)
  12928. {
  12929.    double x, y;
  12930.  
  12931.    printf("Enter a value for x:\n");
  12932.    scanf("%lf", &x);
  12933.    printf("Enter a value for y:\n");
  12934.    scanf("%lf", &y);
  12935.    printf("%lf * log2(%lf + 1) is %lf.\n", y, x, _fyl2xp1(x, y));
  12936.    return 0;
  12937.  
  12938.    /****************************************************************************
  12939.       Assuming you enter 0.001 for x and 2.0 for y.
  12940.  
  12941.       The output should be :
  12942.  
  12943.       2.000000 * log2(0.001000 + 1) is 0.002884.
  12944.    ****************************************************************************/
  12945. }
  12946.  
  12947.  
  12948. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12949.  
  12950. Example of _fyl2xp1 
  12951.  
  12952.      _fyl2x - Calculate y * log2(x) 
  12953.      _f2xm1 -  Calculate (2**x) - 1 
  12954.      <builtin.h> 
  12955.  
  12956.  
  12957. ΓòÉΓòÉΓòÉ 4.121. _f2xm1 -  Calculate (2**x) - 1 ΓòÉΓòÉΓòÉ
  12958.  
  12959.  
  12960. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12961.  
  12962. #include <builtin.h>
  12963. double _f2xm1(double x);
  12964.  
  12965.  
  12966. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12967.  
  12968. Language Level:  Extension 
  12969.  
  12970. _f2xm1 calculates 2 raised to the power of x, minus 1 ((2**x)-1). The variable 
  12971. x must be in the range -1 to 1. This instruction is designed to produce very 
  12972. accurate results when x is close to 0. Large errors may occur for operands with 
  12973. magnitudes close to 1. You can exponentiate values other than 2 by using the 
  12974. formula x**y = 2**(y * log2(x)). 
  12975.  
  12976. Because it is a built-in function and has no backing code in the library: 
  12977.  
  12978.      You cannot take the address of _f2xm1. 
  12979.      You cannot parenthesize a _f2xm1 function call, because parentheses 
  12980.       specify a call to the backing code for the function in the library. 
  12981.  
  12982.  Return Value 
  12983.  This function returns the value of the formula (2**x)-1. 
  12984.  
  12985.  
  12986. ΓòÉΓòÉΓòÉ <hidden> Example of _f2xm1 ΓòÉΓòÉΓòÉ
  12987.  
  12988. /************************************************************************
  12989.  
  12990. This example calculates (2**x)-1 after prompting the user for a value for x. 
  12991.  
  12992. ************************************************************************/
  12993.  
  12994. #include <builtin.h>
  12995. #include <stdio.h>
  12996.  
  12997. int main(void)
  12998. {
  12999.    double x;
  13000.  
  13001.    printf("Enter a value for x:\n");
  13002.    scanf("%lf", &x);
  13003.    printf("(2**(%lf)) - 1 is %lf.\n", x, _f2xm1(x));
  13004.    return 0;
  13005.  
  13006.    /****************************************************************************
  13007.       Assuming you enter : 0.001
  13008.  
  13009.       The output should be :
  13010.  
  13011.       (2**(0.001000)) - 1 is 0.000693.
  13012.    ****************************************************************************/
  13013. }
  13014.  
  13015.  
  13016. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13017.  
  13018. Example of _f2xm1 
  13019.  
  13020.      _fyl2x - Calculate y * log2(x) 
  13021.      _fyl2xp1 -  Calculate y * log2(x + 1) 
  13022.      <builtin.h> 
  13023.  
  13024.  
  13025. ΓòÉΓòÉΓòÉ 4.122. gamma - Gamma Function ΓòÉΓòÉΓòÉ
  13026.  
  13027.  
  13028. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13029.  
  13030. #include <math.h> /* SAA extension to ANSI */
  13031. double gamma(double x);
  13032.  
  13033.  
  13034. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13035.  
  13036. Language Level: SAA 
  13037.  
  13038. gamma computes ln( |G(x)| ). 
  13039.  
  13040. Portability Note  According to the SAA standard, x must be a positive real 
  13041. value.  Under the VisualAge for C++ compiler, x can also be a negative integer. 
  13042.  
  13043. Return Value 
  13044. gamma returns the value of ln(|G(x)|). If x is a negative value, errno is set 
  13045. to EDOM. If the result causes an overflow, gamma returns HUGE_VAL and sets 
  13046. errno to ERANGE. 
  13047.  
  13048.  
  13049. ΓòÉΓòÉΓòÉ <hidden> Example of gamma ΓòÉΓòÉΓòÉ
  13050.  
  13051. /************************************************************************
  13052.  
  13053. This example uses gamma to calculate ln(|G(x)|), where x = 42. 
  13054.  
  13055. ************************************************************************/
  13056.  
  13057. #include <math.h>
  13058. #include <stdio.h>
  13059.  
  13060. int main(void)
  13061. {
  13062.    double x = 42,g_at_x;
  13063.  
  13064.    g_at_x = exp(gamma(x));                       /* g_at_x = 3.345253e+49     */
  13065.    printf("The value of G(%4.2f) is %7.2e\n", x, g_at_x);
  13066.    return 0;
  13067.  
  13068.    /****************************************************************************
  13069.       The output should be:
  13070.  
  13071.       The value of G(42.00) is 3.35e+49
  13072.    ****************************************************************************/
  13073. }
  13074.  
  13075.  
  13076. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13077.  
  13078. Example of gamma 
  13079.  
  13080.      Bessel Functions - Solve Differential Equations 
  13081.      erf - erfc - Calculate Error Functions 
  13082.      <math.h> 
  13083.  
  13084.  
  13085. ΓòÉΓòÉΓòÉ 4.123. _gcvt - Convert Floating-Point to String ΓòÉΓòÉΓòÉ
  13086.  
  13087.  
  13088. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13089.  
  13090. #include <stdlib.h>
  13091. char *_gcvt(double value, int ndec, char *buffer);
  13092.  
  13093.  
  13094. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13095.  
  13096. Language Level:  Extension 
  13097.  
  13098. _gcvt converts a floating-point value to a character string pointed to by 
  13099. buffer. The buffer should be large enough to hold the converted value and a 
  13100. null character (\0) that _gcvt automatically adds to the end of the string. 
  13101. There is no provision for overflow. 
  13102.  
  13103. _gcvt tries to produce ndec significant digits in FORTRAN F format. Failing 
  13104. that, it produces ndec significant digits in FORTRAN E format. Trailing zeros 
  13105. might be suppressed in the conversion if they are insignificant. 
  13106.  
  13107. A FORTRAN F number has the following format: 
  13108.  
  13109.  
  13110.  
  13111. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13112. Γöé                                        Γöé
  13113. Γöé        ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ                            Γöé
  13114. Γöé             Γöé                            Γöé
  13115. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇdigitsΓöÇΓö┤ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö¼ΓöÇΓöÇ><             Γöé
  13116. Γöé   Γö£ΓöÇ+ΓöÇΓöñ  Γöé       Γöé   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ Γöé Γöé               Γöé
  13117. Γöé   Γöé Γöé Γöé  Γöé       Γöé          Γöé Γöé Γöé               Γöé
  13118. Γöé   ΓööΓöÇΓö┤ΓöÇΓöÿ  Γöé       ΓööΓöÇ.ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö┤ΓöÇΓöÿ Γöé               Γöé
  13119. Γöé       Γöé           ΓööΓöÇdigitsΓöÇΓöÿ   Γöé               Γöé
  13120. Γöé       Γöé   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ           Γöé               Γöé
  13121. Γöé       Γöé        Γöé           Γöé               Γöé
  13122. Γöé       ΓööΓöÇ.ΓöÇΓöÇΓöÇΓöÇdigitsΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ               Γöé
  13123. Γöé                                        Γöé
  13124. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  13125.  
  13126. A FORTRAN E number has the following format: 
  13127.  
  13128.  
  13129.  
  13130. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13131. Γöé                                        Γöé
  13132. Γöé       ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ                    ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ     Γöé
  13133. Γöé           Γöé                        Γöé     Γöé
  13134. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇdigitΓöÇΓö┤ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇEΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇdigitΓöÇΓö┤ΓöÇΓöÇ><   Γöé
  13135. Γöé   Γö£ΓöÇ+ΓöÇΓöñ       Γöé   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ Γöé  ΓööΓöÇeΓöÇΓöÿ  Γö£ΓöÇ+ΓöÇΓöñ           Γöé
  13136. Γöé   Γöé Γöé Γöé       Γöé          Γöé Γöé     Γöé Γöé Γöé           Γöé
  13137. Γöé   ΓööΓöÇΓö┤ΓöÇΓöÿ       ΓööΓöÇ.ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö┤ΓöÇΓöÿ     ΓööΓöÇΓö┤ΓöÇΓöÿ           Γöé
  13138. Γöé                ΓööΓöÇdigitsΓöÇΓöÿ                    Γöé
  13139. Γöé                                        Γöé
  13140. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  13141.  
  13142. _gcvt also converts NaN and infinity values to the strings NAN and INFINITY, 
  13143. respectively. For more information on NaN and infinity values, see Infinity and 
  13144. NaN Support. 
  13145.  
  13146. Warning: For each thread, _ecvt, _fcvt and _gcvt use a single, dynamically 
  13147. allocated buffer for the conversion. Any subsequent call that the same thread 
  13148. makes to these functions destroys the result of the previous call. 
  13149.  
  13150. Return Value 
  13151. _gcvt returns a pointer to the string of digits. If it cannot allocate memory 
  13152. to perform the conversion, _gcvt returns an empty string and sets errno to 
  13153. ENOMEM. 
  13154.  
  13155.  
  13156. ΓòÉΓòÉΓòÉ <hidden> Example of _gcvt ΓòÉΓòÉΓòÉ
  13157.  
  13158. /************************************************************************
  13159.  
  13160. This example converts the value -3.1415e3 to a character string and places it 
  13161. in the character array buffer1. It then converts the macro value _INF to a 
  13162. character string and places it in buffer2. 
  13163.  
  13164. ************************************************************************/
  13165.  
  13166. #include <stdio.h>
  13167. #include <stdlib.h>
  13168. #include <float.h>                  /* for the definition of _INF             */
  13169.  
  13170. int main(void)
  13171. {
  13172.    char buffer1[10],buffer2[10];
  13173.  
  13174.    _gcvt(-3.1415e3, 7, buffer1);
  13175.    printf("The first result is %s \n", buffer1);
  13176.    _gcvt(_INF, 5, buffer2);
  13177.    printf("The second result is %s \n", buffer2);
  13178.    return 0;
  13179.  
  13180.    /****************************************************************************
  13181.       The output should be:
  13182.  
  13183.       The first result is -3141.5
  13184.       The second result is INFINITY
  13185.    ****************************************************************************/
  13186. }
  13187.  
  13188.  
  13189. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13190.  
  13191. Example of _gcvt 
  13192.  
  13193.      _ecvt - Convert Floating-Point to Character 
  13194.      _fcvt - Convert Floating-Point to String 
  13195.      Infinity and NaN Support 
  13196.      <stdlib.h> 
  13197.  
  13198.  
  13199. ΓòÉΓòÉΓòÉ 4.124. getc - getchar - Read a Character ΓòÉΓòÉΓòÉ
  13200.  
  13201.  
  13202. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13203.  
  13204. #include <stdio.h>
  13205. int getc(FILE *stream);
  13206. int getchar(void);
  13207.  
  13208.  
  13209. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13210.  
  13211. Language Level: ANSI, SAA, POSIX, XPG4 
  13212.  
  13213. getc reads a single character from the current stream position and advances the 
  13214. stream position to the next character. getchar is identical to getc(stdin). 
  13215.  
  13216. getc is equivalent to fgetc except that, if it is implemented as a macro, getc 
  13217. can evaluate stream more than once. Therefore, the stream argument to getc 
  13218. should not be an expression with side effects. 
  13219.  
  13220. Return Value 
  13221. getc and getchar return the character read.  A return value of EOF indicates an 
  13222. error or end-of-file condition. Use ferror or feof to determine whether an 
  13223. error or an end-of-file condition occurred. 
  13224.  
  13225.  
  13226. ΓòÉΓòÉΓòÉ <hidden> Example of getc - getchar ΓòÉΓòÉΓòÉ
  13227.  
  13228. /************************************************************************
  13229.  
  13230. This example gets a line of input from the stdin stream.  You can also use 
  13231. getc(stdin) instead of getchar() in the for statement to get a line of input 
  13232. from stdin. 
  13233.  
  13234. ************************************************************************/
  13235.  
  13236.  
  13237.  #include <stdio.h>
  13238.  #define LINE 80
  13239.  
  13240.  int main(void) {
  13241.  
  13242.    char buffer[LINE+1];
  13243.    int i;
  13244.    int ch;
  13245.    printf( "Please enter string\n" );
  13246.  
  13247.    /* Keep reading until either:
  13248.       1. the length of LINE is exceeded  or
  13249.       2. the input character is EOF  or
  13250.       3. the input character is a newline character
  13251.     */
  13252.    for ( i = 0; ( i < LINE ) && (( ch = getchar()) != EOF) &&
  13253.                 ( ch !='\n' ); ++i )
  13254.      buffer[i] = ch;
  13255.    buffer[i] = '\0';  /* a string should always end with '\0' ! */
  13256.    printf( "The string is %s\n", buffer );
  13257.    return 0;
  13258.  
  13259.  /************************************************************************
  13260.  Output should be:
  13261.  
  13262.  Please enter string
  13263.  hello world
  13264.  The string is hello world
  13265.  ************************************************************************/
  13266.  }
  13267.  
  13268.  
  13269. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13270.  
  13271. Example of getc - getchar 
  13272.  
  13273.      fgetc - Read a Character 
  13274.      _fgetchar - Read Single Character from stdin 
  13275.      _getch - _getche - Read Character from Keyboard 
  13276.      putc - putchar - Write a Character 
  13277.      ungetc - Push Character onto Input Stream 
  13278.      gets - Read a Line 
  13279.      <stdio.h> 
  13280.  
  13281.  
  13282. ΓòÉΓòÉΓòÉ 4.125. _getch - _getche - Read Character from Keyboard ΓòÉΓòÉΓòÉ
  13283.  
  13284.  
  13285. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13286.  
  13287. #include <conio.h>
  13288. int _getch(void);
  13289. int _getche(void);
  13290.  
  13291.  
  13292. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13293.  
  13294. Language Level:  Extension 
  13295.  
  13296. _getch reads a single character from the keyboard, without echoing.  _getche 
  13297. reads a single character from the keyboard and displays the character read. 
  13298. Neither function can be used to read Ctrl-Break. 
  13299.  
  13300. You can use _kbhit to test if a keystroke is waiting in the buffer. If you call 
  13301. _getch or _getche without first calling _kbhit, the program waits for a key to 
  13302. be pressed. 
  13303.  
  13304. Return Value 
  13305. _getch and _getche return the character read. To read a function key or 
  13306. cursor-moving key, you must call _getch and _getche twice; the first call 
  13307. returns 0 or 0xE0, and the second call returns the particular extended key 
  13308. code. 
  13309.  
  13310.  
  13311. ΓòÉΓòÉΓòÉ <hidden> Example of _getch - _getche ΓòÉΓòÉΓòÉ
  13312.  
  13313. /************************************************************************
  13314.  
  13315. This example gets characters from the keyboard until it finds the character 
  13316. 'x'. 
  13317.  
  13318. ************************************************************************/
  13319.  
  13320. #include <conio.h>
  13321. #include <stdio.h>
  13322.  
  13323. int main(void)
  13324. {
  13325.    int ch;
  13326.    printf("\nType in some letters.\n");
  13327.    printf("If you type in an 'x', the program ends.\n");
  13328.    for(;;) {
  13329.       ch = _getch();
  13330.       if ('x' == ch) {
  13331.          _ungetch(ch);
  13332.          break;
  13333.       }
  13334.       _putch(ch);
  13335.    }
  13336.    ch = _getch();
  13337.    printf("\n");
  13338.    printf("\nThe last character was '%c'.", ch);
  13339.    return 0;
  13340.  
  13341.    /*****************************************************************
  13342.       Here is the output from a sample run:
  13343.  
  13344.       Type in some letters.
  13345.       If you type in an 'x', the program ends.
  13346.       One Two Three Four Five Si
  13347.       The last character was 'x'.
  13348.    *****************************************************************/
  13349. }
  13350.  
  13351.  
  13352. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13353.  
  13354. Example of _getch - _getche 
  13355.  
  13356.      _cgets - Read String of Characters from Keyboard 
  13357.      fgetc - Read a Character 
  13358.      getc - getchar - Read a Character 
  13359.      _kbhit - Test for Keystroke 
  13360.      _putch - Write Character to Screen 
  13361.      _ungetch - Push Character Back to Keyboard 
  13362.      <conio.h> 
  13363.  
  13364.  
  13365. ΓòÉΓòÉΓòÉ 4.126. _getcwd - Get Path Name of Current Directory ΓòÉΓòÉΓòÉ
  13366.  
  13367.  
  13368. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13369.  
  13370. #include <direct.h>
  13371. char *_getcwd(char *pathbuf, int n);
  13372.  
  13373.  
  13374. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13375.  
  13376. Language Level:  Extension 
  13377.  
  13378. _getcwd gets the full path name of the current working directory and stores it 
  13379. in the buffer pointed to by pathbuf.  The integer argument n specifies the 
  13380. maximum length for the path name.  An error occurs if the length of the path 
  13381. name, including the terminating null character, exceeds n characters. 
  13382.  
  13383. If the pathbuf argument is NULL, _getcwd uses malloc to reserve a buffer of at 
  13384. least n bytes to store the path name.  If the current working directory string 
  13385. is more than n bytes, a large enough buffer will be allocated to contain the 
  13386. string.  You can later free this buffer using the _getcwd return value as the 
  13387. argument to free. 
  13388.  
  13389. Return Value 
  13390. _getcwd returns pathbuf. If an error occurs, _getcwd returns NULL and sets 
  13391. errno to one of the following values: 
  13392.  
  13393.  Value       Meaning 
  13394.  ENOMEM      Not enough storage space available to reserve n bytes (when 
  13395.              pathbuf is NULL). 
  13396.  ERANGE      The path name is longer than n characters. 
  13397.  EOS2ERR     A Windows system call failed. Use _doserrno to obtain more 
  13398.              information about the return code. 
  13399.  
  13400.  
  13401. ΓòÉΓòÉΓòÉ <hidden> Example of _getcwd ΓòÉΓòÉΓòÉ
  13402.  
  13403. /************************************************************************
  13404.  
  13405. This example stores the name of the current working directory (up to _MAX_PATH 
  13406. characters) in a buffer.  The value of _MAX_PATH is defined in <stdlib.h>. 
  13407.  
  13408. ************************************************************************/
  13409.  
  13410. #include <direct.h>
  13411. #include <stdio.h>
  13412. #include <stdlib.h>
  13413.  
  13414. int main(void)
  13415. {
  13416.    char buffer[_MAX_PATH];
  13417.  
  13418.    if (NULL == getcwd(buffer, _MAX_PATH))
  13419.       perror("getcwd error");
  13420.    printf("The current directory is %s\n", buffer);
  13421.    return 0;
  13422.  
  13423.    /****************************************************************************
  13424.       The output should be similar to:
  13425.  
  13426.       The current directory is E:\MIG_XMPS
  13427.    ****************************************************************************/
  13428. }
  13429.  
  13430.  
  13431. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13432.  
  13433. Example of _getcwd 
  13434.  
  13435.      chdir - Change Current Working Directory 
  13436.      _fullpath - Get Full Path Name of Partial Path 
  13437.      _getdcwd - Get Full Path Name of Current Directory 
  13438.      _getdrive - Get Current Working Drive 
  13439.      malloc - Reserve Storage Block 
  13440.      <direct.h> 
  13441.  
  13442.  
  13443. ΓòÉΓòÉΓòÉ 4.127. _getdcwd - Get Full Path Name of Current Directory ΓòÉΓòÉΓòÉ
  13444.  
  13445.  
  13446. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13447.  
  13448. #include <direct.h>
  13449. char *_getdcwd(int drive, char *pathbuf, int n);
  13450.  
  13451.  
  13452. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13453.  
  13454. Language Level:  Extension 
  13455.  
  13456. _getdcwd gets the full path name for the current directory of the specified 
  13457. drive, and stores it in the location pointed to by pathbuf. The drive argument 
  13458. is an integer value representing the drive (A: is 1, B: is 2, and so on). 
  13459.  
  13460. The integer argument n specifies the maximum length for the path name. An error 
  13461. occurs if the length of the path name, including the terminating null 
  13462. character, exceeds n characters. 
  13463.  
  13464. If the pathbuf argument is NULL, _getdcwd uses malloc to reserve a buffer of at 
  13465. least n bytes to store the path name.  If the current working directory string 
  13466. is more than n bytes, a large enough buffer will be allocated to contain the 
  13467. string. You can later free this buffer using the _getdcwd return value as the 
  13468. argument to free. 
  13469.  
  13470. The alternative to this function is the GetCurrentDirectory API call. 
  13471.  
  13472. Return Value 
  13473. _getdcwd returns pathbuf. If an error occurs, _getdcwd returns NULL and sets 
  13474. errno to one of the following values: 
  13475.  
  13476.  Value          Meaning 
  13477.  ENOMEM         Not enough storage space available to reserve n bytes (when 
  13478.                 pathbuf is NULL). 
  13479.  ERANGE         The path name is longer than n characters. 
  13480.  EOS2ERR        A Windows system call failed. Use _doserrno to obtain more 
  13481.                 information about the return code. 
  13482.  
  13483.  
  13484. ΓòÉΓòÉΓòÉ <hidden> Example of _getdcwd ΓòÉΓòÉΓòÉ
  13485.  
  13486. /************************************************************************
  13487.  
  13488. This example uses _getdcwd to obtain the current working directory of drive C. 
  13489.  
  13490. ************************************************************************/
  13491.  
  13492. #include <stdio.h>
  13493. #include <direct.h>
  13494. #include <errno.h>
  13495.  
  13496. int main(void)
  13497. {
  13498.    char *retBuffer;
  13499.  
  13500.    retBuffer = _getdcwd(3, NULL, 0);
  13501.    if (NULL == retBuffer)
  13502.       printf("An error has occurred, errno is set to %d.\n", errno);
  13503.    else
  13504.       printf("%s is the current working directory in drive C.\n", retBuffer);
  13505.    return 0;
  13506.  
  13507.    /****************************************************************************
  13508.       The output should be similar to:
  13509.  
  13510.       C:\ is the current working directory in drive C.
  13511.    ****************************************************************************/
  13512. }
  13513.  
  13514.  
  13515. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13516.  
  13517. Example of _getdcwd 
  13518.  
  13519.      chdir - Change Current Working Directory 
  13520.      _chdrive - Change Current Working Drive 
  13521.      _fullpath - Get Full Path Name of Partial Path 
  13522.      _getcwd - Get Path Name of Current Directory 
  13523.      _getdrive - Get Current Working Drive 
  13524.      malloc - Reserve Storage Block 
  13525.      <direct.h> 
  13526.  
  13527.  
  13528. ΓòÉΓòÉΓòÉ 4.128. _getdrive - Get Current Working Drive ΓòÉΓòÉΓòÉ
  13529.  
  13530.  
  13531. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13532.  
  13533. #include <direct.h>
  13534. int _getdrive(void);
  13535.  
  13536.  
  13537. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13538.  
  13539. Language Level:  Extension 
  13540.  
  13541. _getdrive gets the drive number for the current working drive. 
  13542.  
  13543. An alternative to this function is the GetCurrrentDirectory API call. 
  13544.  
  13545. Return Value 
  13546. _getdrive returns an integer corresponding to alphabetical position of the 
  13547. letter representing the current working drive. For example, A: is 1, B: is 2, 
  13548. J: is 10, and so on. 
  13549.  
  13550.  
  13551. ΓòÉΓòÉΓòÉ <hidden> Example of _getdrive ΓòÉΓòÉΓòÉ
  13552.  
  13553. /************************************************************************
  13554.  
  13555. This example gets and prints the current working drive number. 
  13556.  
  13557. ************************************************************************/
  13558.  
  13559. #include <stdio.h>
  13560. #include <direct.h>
  13561.  
  13562. int main(void)
  13563. {
  13564.    printf("Current working drive is %d.\n", _getdrive());
  13565.    return 0;
  13566.  
  13567.    /****************************************************************************
  13568.       The output should be similar to:
  13569.  
  13570.       Current working drive is 5.
  13571.    ****************************************************************************/
  13572. }
  13573.  
  13574.  
  13575. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13576.  
  13577. Example of _getdrive 
  13578.  
  13579.      chdir - Change Current Working Directory 
  13580.      _chdrive - Change Current Working Drive 
  13581.      _getcwd - Get Path Name of Current Directory 
  13582.      _getdcwd - Get Full Path Name of Current Directory 
  13583.      <direct.h> 
  13584.  
  13585.  
  13586. ΓòÉΓòÉΓòÉ 4.129. getenv - Search for Environment Variables ΓòÉΓòÉΓòÉ
  13587.  
  13588.  
  13589. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13590.  
  13591. #include <stdlib.h>
  13592. char *getenv(const char *varname);
  13593.  
  13594.  
  13595. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13596.  
  13597. Language Level: ANSI, SAA, POSIX, XPG4 
  13598.  
  13599. getenv searches the list of environment variables for an entry corresponding to 
  13600. varname. 
  13601.  
  13602. Return Value 
  13603. getenv returns a pointer to the environment table entry containing the current 
  13604. string value of varname.  The return value is NULL if the given variable is not 
  13605. currently defined or if the system does not support environment variables. 
  13606.  
  13607. You should copy the string that is returned because it may be written over by a 
  13608. subsequent call to getenv. 
  13609.  
  13610.  
  13611. ΓòÉΓòÉΓòÉ <hidden> Example of getenv ΓòÉΓòÉΓòÉ
  13612.  
  13613. /************************************************************************
  13614.  
  13615. In this example, pathvar points to the value of the PATH environment variable. 
  13616.  
  13617. ************************************************************************/
  13618.  
  13619. #include <stdio.h>
  13620. #include <stdlib.h>
  13621.  
  13622. int main(void)
  13623. {
  13624.    char *pathvar;
  13625.  
  13626.    pathvar = getenv("PATH");
  13627.    if (NULL == pathvar)
  13628.       printf("Environment variable PATH is not defined.\n");
  13629.    else
  13630.       printf("Path set by environment variable PATH is successfully stored.\n");
  13631.    return 0;
  13632.  
  13633.    /****************************************************************************
  13634.       The output should be:
  13635.  
  13636.       Path set by environment variable PATH is successfully stored.
  13637.    ****************************************************************************/
  13638. }
  13639.  
  13640.  
  13641. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13642.  
  13643. Example of getenv 
  13644.  
  13645.      putenv - Modify Environment Variables 
  13646.      <stdlib.h> 
  13647.  
  13648.  
  13649. ΓòÉΓòÉΓòÉ 4.130. getpid - Get Process Identifier ΓòÉΓòÉΓòÉ
  13650.  
  13651.  
  13652. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13653.  
  13654. #include <process.h>
  13655. int getpid(void);
  13656.  
  13657.  
  13658. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13659.  
  13660. Language Level:  XPG4, Extension 
  13661.  
  13662. getpid gets the process identifier that uniquely identifies the calling 
  13663. process. 
  13664.  
  13665. Note:  In earlier releases of VisualAge C++, getpid began with an underscore 
  13666. (_getpid). Because it is defined by the X/Open standard, the underscore has 
  13667. been removed. For compatibility, VisualAge for C++ will map _getpid to getpid 
  13668. for you. 
  13669.  
  13670. Return Value 
  13671. getpid function gets the process identifier as an integer value.  There is no 
  13672. error return value. 
  13673.  
  13674.  
  13675. ΓòÉΓòÉΓòÉ <hidden> Example of getpid ΓòÉΓòÉΓòÉ
  13676.  
  13677. /************************************************************************
  13678.  
  13679. This example prints the process identifier: 
  13680.  
  13681. ************************************************************************/
  13682.  
  13683. #include <process.h>
  13684. #include <string.h>
  13685. #include <stdio.h>
  13686. #include <stdlib.h>
  13687.  
  13688. int main(void)
  13689. {
  13690.    printf("Process identifier is %05d\n", getpid());
  13691.    return 0;
  13692.  
  13693.    /****************************************************************************
  13694.       The output should be similar to:
  13695.  
  13696.       Process identifier is 00242
  13697.    ****************************************************************************/
  13698. }
  13699.  
  13700.  
  13701. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13702.  
  13703. Example of getpid 
  13704.  
  13705.      _cwait - Wait for Child Process 
  13706.      execl - _execvpe - Load and Run Child Process 
  13707.      _spawnl - _spawnvpe - Start and Run Child Processes 
  13708.      wait - Wait for Child Process 
  13709.      <process.h> 
  13710.  
  13711.  
  13712. ΓòÉΓòÉΓòÉ 4.131. gets - Read a Line ΓòÉΓòÉΓòÉ
  13713.  
  13714.  
  13715. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13716.  
  13717. #include <stdio.h>
  13718. char *gets(char *buffer);
  13719.  
  13720.  
  13721. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13722.  
  13723. Language Level: ANSI, SAA, POSIX, XPG4 
  13724.  
  13725. gets reads a line from the standard input stream stdin and stores it in buffer. 
  13726. The line consists of all characters up to and including the first new-line 
  13727. character (\n) or EOF. gets then replaces the new-line character, if read, with 
  13728. a null character (\0) before returning the line. 
  13729.  
  13730. Return Value 
  13731. If successful, gets returns its argument.  A NULL pointer return value 
  13732. indicates an error or an end-of-file condition with no characters read. Use 
  13733. ferror or feof to determine which of these conditions occurred. If there is an 
  13734. error, the value stored in buffer is undefined.  If an end-of-file condition 
  13735. occurs, buffer is not changed. 
  13736.  
  13737.  
  13738. ΓòÉΓòÉΓòÉ <hidden> Example of gets ΓòÉΓòÉΓòÉ
  13739.  
  13740. /************************************************************************
  13741.  
  13742. This example gets a line of input from stdin. 
  13743.  
  13744. ************************************************************************/
  13745.  
  13746. #include <stdio.h>
  13747.  
  13748. #define  MAX_LINE      100
  13749.  
  13750. int main(void)
  13751. {
  13752.    char line[MAX_LINE];
  13753.    char *result;
  13754.  
  13755.    if ((result = gets(line)) != NULL) {
  13756.       if (ferror(stdin))
  13757.          perror("Error");
  13758.       printf("Input line : %s\n", result);
  13759.    }
  13760.    return 0;
  13761.  
  13762.    /****************************************************************************
  13763.       For the following input:
  13764.       This is a test for function gets.
  13765.  
  13766.       The output should be:
  13767.       Input line : This a test for function gets.
  13768.    ****************************************************************************/
  13769. }
  13770.  
  13771.  
  13772. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13773.  
  13774. Example of gets 
  13775.  
  13776.      _cgets - Read String of Characters from Keyboard 
  13777.      fgets - Read a String 
  13778.      feof - Test End-of-File Indicator 
  13779.      ferror - Test for Read/Write Errors 
  13780.      fputs - Write String 
  13781.      getc - getchar - Read a Character 
  13782.      puts - Write a String 
  13783.      <stdio.h> 
  13784.  
  13785.  
  13786. ΓòÉΓòÉΓòÉ 4.132. getsyntx - Return LC_SYNTAX Characters ΓòÉΓòÉΓòÉ
  13787.  
  13788.  
  13789. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13790.  
  13791. #include <variant.h>
  13792. struct variant *getsyntx(void);
  13793.  
  13794.  
  13795. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13796.  
  13797. Language Level:  Extension 
  13798.  
  13799. getsyntx determines the encoding of the special characters defined in the 
  13800. LC_SYNTAX category of the current locale, and stores the encoding values in the 
  13801. structure of type struct variant. For details of the structure type, see 
  13802. <variant.h>. 
  13803.  
  13804. Your program cannot modify the returned structure. The structure can be 
  13805. overwritten by a call to setlocale with the argument LC_ALL or LC_SYNTAX. 
  13806.  
  13807. Return Value 
  13808. getsyntx returns the pointer to the structure containing the values of the 
  13809. special characters. If the information about the special characters is not 
  13810. available in the current locale, getsyntx returns a null pointer. 
  13811.  
  13812.  
  13813. ΓòÉΓòÉΓòÉ <hidden> Example of getsyntx ΓòÉΓòÉΓòÉ
  13814.  
  13815. /************************************************************************
  13816.  
  13817. This example uses getsyntx to show the value of various special characters. 
  13818.  
  13819. ************************************************************************/
  13820.  
  13821. #include <stdio.h>
  13822. #include <stdlib.h>
  13823. #include <variant.h>
  13824. #include <locale.h>
  13825.  
  13826. #if (1 == __TOS_OS2__)
  13827.    #define LOCNAME "en_us.ibm-850"     /* OS/2 name        */
  13828. #else
  13829.    #define LOCNAME "fr_fr.ibm-1252"    /* Windows name     */
  13830. #endif
  13831.  
  13832. int main(void)
  13833. {
  13834.    struct variant *var;
  13835.  
  13836.    if (NULL == setlocale(LC_ALL, LOCNAME)) {
  13837.       printf("Locale \"%s\" could not be loaded\n", LOCNAME);
  13838.       exit(1);
  13839.    }
  13840.    var = getsyntx();
  13841.    printf("codeset         : %s\n", var->codeset         );
  13842.    printf("backslash       : %c\n", var->backslash       );
  13843.    printf("right_bracket   : %c\n", var->right_bracket   );
  13844.    printf("left_bracket    : %c\n", var->left_bracket    );
  13845.    printf("right_brace     : %c\n", var->right_brace     );
  13846.    printf("left_brace      : %c\n", var->left_brace      );
  13847.    printf("circumflex      : %c\n", var->circumflex      );
  13848.    printf("tilde           : %c\n", var->tilde           );
  13849.    printf("exclamation_mark: %c\n", var->exclamation_mark);
  13850.    printf("number_sign     : %c\n", var->number_sign     );
  13851.    printf("vertical_line   : %c\n", var->vertical_line   );
  13852.    printf("dollar_sign     : %c\n", var->dollar_sign     );
  13853.    printf("commercial_at   : %c\n", var->commercial_at   );
  13854.    printf("grave_accent    : %c\n", var->grave_accent    );
  13855.    return 0;
  13856.  
  13857.    /****************************************************************************
  13858.       The OS/2 output should be similar to :
  13859.  
  13860.       codeset         : IBM-850
  13861.       backslash       : \
  13862.       right_bracket   : ]
  13863.       left_bracket    : [
  13864.       right_brace     : }
  13865.       left_brace      : {
  13866.       circumflex      : ╨║
  13867.       tilde           : ~
  13868.       exclamation_mark: !
  13869.       number_sign     : #
  13870.       vertical_line   : |
  13871.       dollar_sign     : $
  13872.       commercial_at   : @
  13873.       grave_accent    : `
  13874.    ****************************************************************************/
  13875. }
  13876.  
  13877.  
  13878. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13879.  
  13880. Example of getsyntx 
  13881.  
  13882.      setlocale - Set Locale 
  13883.      <locale.h> 
  13884.      <variant.h> 
  13885.  
  13886.  
  13887. ΓòÉΓòÉΓòÉ 4.133. getwc - Read Wide Character from Stream ΓòÉΓòÉΓòÉ
  13888.  
  13889.  
  13890. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13891.  
  13892. #include <stdio.h>
  13893. #include <wchar.h>
  13894. wint_t getwc(FILE *stream);
  13895.  
  13896.  
  13897. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13898.  
  13899. Language Level:  ANSI 93, XPG4 
  13900.  
  13901. getwc reads the next multibyte character from stream, converts it to a wide 
  13902. character, and advances the associated file position indicator for stream. 
  13903.  
  13904. getwc is equivalent to fgetwc except that, if it is implemented as a macro, it 
  13905. can evaluate stream more than once. Therefore, the argument should never be an 
  13906. expression with side effects. 
  13907.  
  13908. The behavior of getwc is affected by the LC_CTYPE category of the current 
  13909. locale. If you change the category between subsequent read operations on the 
  13910. same stream, undefined results can occur. 
  13911.  
  13912. Using non-wide-character functions with getwc on the same stream results in 
  13913. undefined behavior. 
  13914.  
  13915. After calling getwc, flush the buffer or reposition the stream pointer before 
  13916. calling a write function for the stream, unless EOF has been reached. After a 
  13917. write operation on the stream, flush the buffer or reposition the stream 
  13918. pointer before calling getwc. 
  13919.  
  13920. Return Value 
  13921. getwc returns the next wide character from the input stream, or WEOF. If an 
  13922. error occurs, getwc sets the error indicator. If getwc encounters the 
  13923. end-of-file, it sets the EOF indicator. If an encoding error occurs during 
  13924. conversion of the multibyte character, getwc sets errno to EILSEQ. 
  13925.  
  13926. Use ferror or feof to determine whether an error or an EOF condition occurred. 
  13927. EOF is only reached when an attempt is made to read past the last byte of data. 
  13928. Reading up to and including the last byte of data does not turn on the EOF 
  13929. indicator. 
  13930.  
  13931.  
  13932. ΓòÉΓòÉΓòÉ <hidden> Example of getwc ΓòÉΓòÉΓòÉ
  13933.  
  13934. /************************************************************************
  13935.  
  13936. This example opens a file and uses getwc to read wide characters from the file. 
  13937.  
  13938. ************************************************************************/
  13939.  
  13940. #include <errno.h>
  13941. #include <stdio.h>
  13942. #include <stdlib.h>
  13943. #include <wchar.h>
  13944.  
  13945. int main(void)
  13946. {
  13947.    FILE    *stream;
  13948.    wint_t  wc;
  13949.  
  13950.    if (NULL == (stream = fopen("getwc.dat", "r"))) {
  13951.       printf("Unable to open: \"getwc.dat\".\n");
  13952.       exit(1);
  13953.    }
  13954.  
  13955.    errno = 0;
  13956.    while (WEOF !=(wc = getwc(stream)))
  13957.       printf("wc = %lc\n", wc);
  13958.  
  13959.    if (EILSEQ == errno) {
  13960.       printf("An invalid wide character was encountered.\n");
  13961.       exit(1);
  13962.    }
  13963.    fclose(stream);
  13964.    return 0;
  13965.  
  13966.    /****************************************************************************
  13967.       Assuming the file getwc.dat contains:
  13968.  
  13969.       Hello world!
  13970.  
  13971.       The output should be:
  13972.  
  13973.       wc = H
  13974.       wc = e
  13975.       wc = l
  13976.       wc = l
  13977.       wc = o
  13978.       :
  13979.    ****************************************************************************/
  13980. }
  13981.  
  13982.  
  13983. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13984.  
  13985. Example of getwc 
  13986.  
  13987.      fgetwc - Read Wide Character from Stream 
  13988.      getwchar - Get Wide Character from stdin 
  13989.      getc - getchar - Read a Character 
  13990.      _getch - _getche - Read Character from Keyboard 
  13991.      putwc - Write Wide Character 
  13992.      <stdio.h> 
  13993.      <wchar.h> 
  13994.  
  13995.  
  13996. ΓòÉΓòÉΓòÉ 4.134. getwchar - Get Wide Character from stdin ΓòÉΓòÉΓòÉ
  13997.  
  13998.  
  13999. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14000.  
  14001. #include <wchar.h>
  14002. wint_t getwchar(void);
  14003.  
  14004.  
  14005. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14006.  
  14007. Language Level: ANSI, SAA, XPG4 
  14008.  
  14009. getwchar reads the next multibyte character from stdin, converts it to a wide 
  14010. character, and advances the associated file position indicator for stdin. A 
  14011. call to  getwchar is equivalent to a call to getwc(stdin). 
  14012.  
  14013. The behavior of getwchar is affected by the LC_CTYPE category of the current 
  14014. locale. If you change the category between subsequent read operations on the 
  14015. same stream, undefined results can occur. 
  14016.  
  14017. Using non-wide-character functions with getwchar on STDIN results in undefined 
  14018. behavior. 
  14019.  
  14020. Return Value 
  14021. getwchar returns the next wide character from stdin or WEOF. If getwchar 
  14022. encounters EOF, it sets the EOF indicator for the stream and returns WEOF. If a 
  14023. read error occurs, the error indicator for the stream is set and getwchar 
  14024. returns WEOF. If an encoding error occurs during the conversion of the 
  14025. multibyte character to a wide character, getwchar sets errno to EILSEQ and 
  14026. returns WEOF. 
  14027.  
  14028. Use ferror or feof to determine whether an error or an EOF condition occurred. 
  14029. EOF is only reached when an attempt is made to read past the last byte of data. 
  14030. Reading up to and including the last byte of data does not turn on the EOF 
  14031. indicator. 
  14032.  
  14033.  
  14034. ΓòÉΓòÉΓòÉ <hidden> Example of getwchar ΓòÉΓòÉΓòÉ
  14035.  
  14036. /************************************************************************
  14037.  
  14038. This example uses getwchar to read wide characters from the keyboard, then 
  14039. prints the wide characters. 
  14040.  
  14041. ************************************************************************/
  14042.  
  14043. #include <errno.h>
  14044. #include <stdio.h>
  14045. #include <stdlib.h>
  14046. #include <wchar.h>
  14047.  
  14048. int main(void)
  14049. {
  14050.    wint_t  wc;
  14051.  
  14052.    errno = 0;
  14053.    while (WEOF != (wc = getwchar()))
  14054.       printf("wc = %lc\n", wc);
  14055.  
  14056.    if (EILSEQ == errno) {
  14057.       printf("An invalid wide character was encountered.\n");
  14058.       exit(1);
  14059.    }
  14060.    return 0;
  14061.  
  14062.    /****************************************************************************
  14063.       Assuming you enter: abcde^Z            (note: ^Z is CNTRL-Z)
  14064.  
  14065.       The output should be:
  14066.  
  14067.       wc = a
  14068.       wc = b
  14069.       wc = c
  14070.       wc = d
  14071.       wc = e
  14072.    ****************************************************************************/
  14073. }
  14074.  
  14075.  
  14076. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14077.  
  14078. Example of getwchar 
  14079.  
  14080.      fgetc - Read a Character 
  14081.      _fgetchar - Read Single Character from stdin 
  14082.      getc - getchar - Read a Character 
  14083.      _getch - _getche - Read Character from Keyboard 
  14084.      getwc - Read Wide Character from Stream 
  14085.      <wchar.h> 
  14086.  
  14087.  
  14088. ΓòÉΓòÉΓòÉ 4.135. gmtime - Convert Time ΓòÉΓòÉΓòÉ
  14089.  
  14090.  
  14091. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14092.  
  14093. #include <time.h>
  14094. struct tm *gmtime(const time_t *time);
  14095.  
  14096.  
  14097. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14098.  
  14099. Language Level: ANSI, SAA, POSIX, XPG4 
  14100.  
  14101. The gmtime function breaks down the time value and stores it in a tm structure, 
  14102. defined in time.h.  The structure pointed to by the return value reflects 
  14103. Coordinated Universal Time, not local time. The value time is usually obtained 
  14104. from a call to time. 
  14105.  
  14106. The fields of the tm structure include: 
  14107.  
  14108.  tm_sec         Seconds (0-61) 
  14109.  tm_min         Minutes (0-59) 
  14110.  tm_hour        Hours (0-23) 
  14111.  tm_mday        Day of month (1-31) 
  14112.  tm_mon         Month (0-11;  January = 0) 
  14113.  tm_year        Year (current year minus 1900) 
  14114.  tm_wday        Day of week (0-6;  Sunday = 0) 
  14115.  tm_yday        Day of year (0-365;  January 1 = 0) 
  14116.  tm_isdst       Zero if Daylight Saving Time is not in effect;  positive if 
  14117.                 Daylight Saving Time is in effect;  negative if the information 
  14118.                 is not available. 
  14119.  
  14120.  Return Value 
  14121.  gmtime returns a pointer to the resulting tm structure. It returns NULL if 
  14122.  Coordinated Universal Time is not available. 
  14123.  
  14124.  Note: 
  14125.  
  14126.    1. The range (0-61) for tm_sec allows for as many as two leap seconds. 
  14127.  
  14128.    2. The gmtime and localtime functions may use a common, statically allocated 
  14129.       buffer for the conversion. Each call to one of these functions may alter 
  14130.       the result of the previous call. 
  14131.  
  14132.    3. The time and date functions begin at 00:00:00 Coordinated Universal Time, 
  14133.       January 1, 1970. 
  14134.  
  14135.  
  14136. ΓòÉΓòÉΓòÉ <hidden> Example of gmtime ΓòÉΓòÉΓòÉ
  14137.  
  14138. /************************************************************************
  14139.  
  14140. This example uses gmtime to adjust a time_t representation to a Coordinated 
  14141. Universal Time character string, and then converts it to a printable string 
  14142. using asctime. 
  14143.  
  14144. ************************************************************************/
  14145.  
  14146. #include <stdio.h>
  14147. #include <time.h>
  14148.  
  14149. int main(void)
  14150. {
  14151.    time_t ltime;
  14152.  
  14153.    time(<ime);
  14154.    printf("Coordinated Universal Time is %s\n", asctime(gmtime(<ime)));
  14155.    return 0;
  14156.  
  14157.    /****************************************************************************
  14158.       The output should be similar to:
  14159.  
  14160.       Coordinated Universal Time is Mon Sep 16 21:44 1995
  14161.    ****************************************************************************/
  14162. }
  14163.  
  14164.  
  14165. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14166.  
  14167. Example of gmtime 
  14168.  
  14169.      asctime - Convert Time to Character String 
  14170.      ctime - Convert Time to Character String 
  14171.      localtime - Convert Time 
  14172.      mktime - Convert Local Time 
  14173.      time - Determine Current Time 
  14174.      <time.h> 
  14175.  
  14176.  
  14177. ΓòÉΓòÉΓòÉ 4.136. _heap_check - Validate Default Memory Heap ΓòÉΓòÉΓòÉ
  14178.  
  14179.  
  14180. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14181.  
  14182. #include <stdlib.h>    /* also in <malloc.h> */
  14183. void _heap_check(void);
  14184.  
  14185.  
  14186. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14187.  
  14188. Language Level:  Extension 
  14189.  
  14190. _heap_check checks all memory blocks in the default heap that have been 
  14191. allocated or freed using the debug memory management functions (_debug_calloc, 
  14192. _debug_malloc, and so on). _heap_check checks that your program has not 
  14193. overwritten freed memory blocks or memory outside the bounds of allocated 
  14194. blocks. 
  14195.  
  14196. When you call a debug memory management function (such as _debug_malloc), it 
  14197. calls _heap_check automatically. You can also call _heap_check explicitly. 
  14198. Place calls to _heap_check throughout your code, especially in areas that you 
  14199. suspect have memory problems. 
  14200.  
  14201. Calling _heap_check frequently (explicitly or through the debug memory 
  14202. functions) can increase your program's memory requirements and decrease its 
  14203. execution speed.  To reduce the overhead of heap-checking, you can use the 
  14204. CPP_HEAP_SKIP environment variable to control how often the functions check the 
  14205. heap. For example: 
  14206.  
  14207.   SET CPP_HEAP_SKIP=10
  14208. specifies that every tenth call to any debug memory function (regardless of the 
  14209. type of heap) checks the heap. Explicit calls to _heap_check are always 
  14210. performed. For more details on CPP_HEAP_SKIP, see "Skipping Heap Checks" in the 
  14211. Programming Guide. 
  14212.  
  14213. To use _heap_check and the debug memory management functions, you must compile 
  14214. with the debug memory (/Tm) compiler option. 
  14215.  
  14216. Note:  The /Tm option maps all calls to memory management functions (including 
  14217. heap-specific versions) to their debug counterparts. To prevent a call from 
  14218. being mapped, parenthesize the function name. 
  14219.  
  14220. _heap_check always checks the default heap. 
  14221.  
  14222. Return Value 
  14223. There is no return value. 
  14224.  
  14225.  
  14226. ΓòÉΓòÉΓòÉ <hidden> Example of _heap_check ΓòÉΓòÉΓòÉ
  14227.  
  14228. /************************************************************************
  14229.  
  14230. This example allocates 5000 bytes of storage, and then attempts to write to 
  14231. storage that was not allocated.  The call to _heap_check detects the error, 
  14232. generates several messages, and stops the program. 
  14233.  
  14234. ************************************************************************/
  14235.  
  14236. #include <stdlib.h>
  14237. #include <stdio.h>
  14238.  
  14239. int main(void)
  14240. {
  14241.    char *ptr;
  14242.  
  14243.    if (NULL == (ptr = (char*)malloc(5000))) {
  14244.       puts("Could not allocate memory block.");
  14245.       return EXIT_FAILURE;
  14246.    }
  14247.  
  14248.    *(ptr-1) = 'a';            /* overwrites storage that was not allocated    */
  14249.    _heap_check();
  14250.    puts("_heap_check did not detect that a memory block was overwritten.");
  14251.    return 0;
  14252.  
  14253.    /****************************************************************************
  14254.       The output should be similar to:
  14255.  
  14256.       Header information of object 0x00073890 was overwritten at 0x0007388c.
  14257.       The first eight bytes of the memory block (in hex) are: AAAAAAAAAAAAAAAA.
  14258.       This memory block was (re)allocated at line number 8 in _heap_check.c.
  14259.       Heap state was valid at line 8 of _heap_check.c.
  14260.       Memory error detected at line 14 of _heap_check.c.
  14261.    ****************************************************************************/
  14262. }
  14263.  
  14264.  
  14265. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14266.  
  14267. Example of _heap_check 
  14268.  
  14269.      Memory Management in the Programming Guide 
  14270.      Debugging Your Heaps in the Programming Guide 
  14271.      Differentiating between Memory Management Functions 
  14272.      _debug_calloc - Allocate and Initialize Memory 
  14273.      _debug_free - Release Memory 
  14274.      _debug_heapmin - Release Unused Memory in the Default Heap 
  14275.      _debug_malloc - Allocate Memory 
  14276.      _debug_realloc - Reallocate Memory Block 
  14277.      _dump_allocated - Get Information about Allocated Memory 
  14278.      _dump_allocated_delta - Get Information about Allocated Memory 
  14279.      _heapchk - Validate Default Memory Heap 
  14280.      _uheap_check - Validate User Memory Heap 
  14281.      <malloc.h> 
  14282.      <stdlib.h> 
  14283.  
  14284.  
  14285. ΓòÉΓòÉΓòÉ 4.137. _heapchk - Validate Default Memory Heap ΓòÉΓòÉΓòÉ
  14286.  
  14287.  
  14288. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14289.  
  14290. #include <malloc.h>
  14291. int _heapchk(void);
  14292.  
  14293.  
  14294. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14295.  
  14296. Language Level:  Extension 
  14297.  
  14298. _heapchk checks the default storage heap for minimal consistency by checking 
  14299. all allocated and freed objects on the heap. 
  14300.  
  14301. A heap-specific version of this function, _uheapchk, is also available. 
  14302.  
  14303. Note:  Using the _heapchk, _heapset, and _heap_walk functions (and their 
  14304. heap-specific equivalents) may add overhead to each object allocated from the 
  14305. heap. 
  14306.  
  14307. Return Value 
  14308. _heapchk returns one of the following values, defined in <malloc.h>: 
  14309.  
  14310.  _HEAPBADBEGIN     The heap specified is not valid. (Only occurs if you changed 
  14311.                    the default heap and then later closed or destroyed it.) 
  14312.  _HEAPBADNODE      A memory node is corrupted, or the heap is damaged. 
  14313.  _HEAPEMPTY        The heap has not been initialized. 
  14314.  _HEAPOK           The heap appears to be consistent. 
  14315.  
  14316.  
  14317. ΓòÉΓòÉΓòÉ <hidden> Example of _heapchk ΓòÉΓòÉΓòÉ
  14318.  
  14319. /************************************************************************
  14320.  
  14321. This example performs some memory allocations, then calls _heapchk to check the 
  14322. heap. 
  14323.  
  14324. ***********************************************************************/
  14325.  
  14326. #include <stdlib.h>
  14327. #include <stdio.h>
  14328. #include <malloc.h>
  14329.  
  14330. int main(void)
  14331. {
  14332.    char *ptr;
  14333.    int  rc;
  14334.  
  14335.    if (NULL == (ptr = (char*)malloc(10))) {
  14336.       puts("Could not allocate memory block.");
  14337.       exit(EXIT_FAILURE);
  14338.    }
  14339.    *(ptr - 1) = 'x';      /* overwrites storage that was not allocated */
  14340.  
  14341.    if (_HEAPOK != (rc = _heapchk())) {
  14342.       switch(rc) {
  14343.          case _HEAPEMPTY:
  14344.             puts("The heap has not been initialized.");
  14345.             break;
  14346.          case _HEAPBADNODE:
  14347.             puts("A memory node is corrupted or the heap is damaged.");
  14348.             break;
  14349.          case _HEAPBADBEGIN:
  14350.             puts("The heap specified is not valid.");
  14351.             break;
  14352.       }
  14353.       exit(rc);
  14354.    }
  14355.    free(ptr);
  14356.    return 0;
  14357.  
  14358.    /****************************************************************************
  14359.       The output should be similar to :
  14360.  
  14361.       A memory node is corrupted or the heap is damaged.
  14362.    ****************************************************************************/
  14363. }
  14364.  
  14365.  
  14366. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14367.  
  14368. Example of _heapchk 
  14369.  
  14370.      "Managing Memory" in the Programming Guide 
  14371.      _uheapchk - Validate Memory Heap 
  14372.      _heapmin - Release Unused Memory from Default Heap 
  14373.      _heapset - Validate and Set Default Heap 
  14374.      _heap_walk - Return Information about Default Heap 
  14375.      <malloc.h> 
  14376.      <umalloc.h> 
  14377.  
  14378.  
  14379. ΓòÉΓòÉΓòÉ 4.138. _heapmin - Release Unused Memory from Default Heap ΓòÉΓòÉΓòÉ
  14380.  
  14381.  
  14382. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14383.  
  14384. #include <stdlib.h>  /* also in <malloc.h> */
  14385. int _heapmin(void);
  14386.  
  14387.  
  14388. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14389.  
  14390. Language Level:  Extension 
  14391.  
  14392. _heapmin returns all unused memory from the default runtime heap to the 
  14393. operating system. 
  14394.  
  14395. Heap-specific, debug versions of this function (_uheapmin, and _debug_heapmin) 
  14396. are also available. _heapmin always operates on the default heap. 
  14397.  
  14398. Note:  If you create your own heap and make it the default heap, _heapmin calls 
  14399. the release function that you provide to return the memory. 
  14400.  
  14401. Return Value 
  14402. _heapmin returns 0 if successful; if not, it returns -1. 
  14403.  
  14404.  
  14405. ΓòÉΓòÉΓòÉ <hidden> Example of _heapmin ΓòÉΓòÉΓòÉ
  14406.  
  14407. /************************************************************************
  14408.  
  14409. This example shows how to use the _heapmin function. 
  14410.  
  14411. ************************************************************************/
  14412.  
  14413. #include <stdio.h>
  14414. #include <stdlib.h>
  14415.  
  14416. int main(void)
  14417. {
  14418.    if (_heapmin())
  14419.       printf("_heapmin failed.\n");
  14420.    else
  14421.       printf("_heapmin was successful.\n");
  14422.    return 0;
  14423.  
  14424.    /****************************************************************************
  14425.       The output should be:
  14426.  
  14427.      _heapmin was successful.
  14428.    ****************************************************************************/
  14429. }
  14430.  
  14431.  
  14432. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14433.  
  14434. Example of _heapmin 
  14435.  
  14436.      Managing Memory in the Programming Guide 
  14437.      _debug_heapmin - Release Unused Memory in the Default Heap 
  14438.      _debug_uheapmin - Release Unused Memory in User Heap 
  14439.      _uheapmin - Release Unused Memory in User Heap 
  14440.      <malloc.h> 
  14441.      <stdlib.h> 
  14442.  
  14443.  
  14444. ΓòÉΓòÉΓòÉ 4.139. _heapset - Validate and Set Default Heap ΓòÉΓòÉΓòÉ
  14445.  
  14446.  
  14447. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14448.  
  14449. #include <malloc.h>
  14450. int _heapset(unsigned int fill);
  14451.  
  14452.  
  14453. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14454.  
  14455. Language Level:  Extension 
  14456.  
  14457. _heapset checks the default storage heap for minimal consistency by checking 
  14458. all allocated and freed objects on the heap (similar to _heapchk). It then sets 
  14459. each byte of the heap's free objects to the value of fill. 
  14460.  
  14461. Using _heapset can help you locate problems where your program continues to use 
  14462. a freed pointer to an object. After you set the free heap to a specific value, 
  14463. when your program tries to interpret the set values in the freed object as 
  14464. data, unexpected results occur, indicating a problem. 
  14465.  
  14466. A heap-specific version of this function, _uheapset, is also available. 
  14467.  
  14468. Note:  Using the _heapchk, _heapset, and _heap_walk functions (and their 
  14469. heap-specific equivalents) may add overhead to each object allocated from the 
  14470. heap. 
  14471.  
  14472. Return Value 
  14473. _heapset returns one of the following values, defined in <malloc.h>: 
  14474.  
  14475.  _HEAPBADBEGIN     The heap specified is not valid; it may have been closed or 
  14476.                    destroyed. 
  14477.  _HEAPBADNODE      A memory node is corrupted, or the heap is damaged. 
  14478.  _HEAPEMPTY        The heap has not been initialized. 
  14479.  _HEAPOK           The heap appears to be consistent. 
  14480.  
  14481.  
  14482. ΓòÉΓòÉΓòÉ <hidden> Example of _heapset ΓòÉΓòÉΓòÉ
  14483.  
  14484. /************************************************************************
  14485.  
  14486. This example allocates and frees memory, then uses _heapset to set the free 
  14487. heap to X. It checks the return code from _heapset to ensure the heap is still 
  14488. valid. 
  14489.  
  14490. *********************************************************************** /
  14491.  
  14492. #include <stdlib.h>
  14493. #include <stdio.h>
  14494. #include <string.h>
  14495. #include <malloc.h>
  14496.  
  14497. int main (void)
  14498. {
  14499.    char  *ptr;
  14500.    int   rc;
  14501.  
  14502.    if (NULL == (ptr = (char*)malloc(10))) {
  14503.       puts("Could not allocate memory block.");
  14504.       exit(EXIT_FAILURE);
  14505.    }
  14506.    memset(ptr,'A',5);
  14507.    free(ptr);
  14508.  
  14509.    if (_HEAPOK != (rc = _heapset('X'))) {
  14510.       switch(rc) {
  14511.          case _HEAPEMPTY:
  14512.             puts("The heap has not been initialized.");
  14513.             break;
  14514.          case _HEAPBADNODE:
  14515.             puts("A memory node is corrupted or the heap is damaged.");
  14516.             break;
  14517.          case _HEAPBADBEGIN:
  14518.             puts("The heap specified is not valid.");
  14519.             break;
  14520.       }
  14521.       exit(rc);
  14522.    }
  14523.    return 0;
  14524. }
  14525.  
  14526.  
  14527. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14528.  
  14529. Example of _heapset 
  14530.  
  14531.      "Managing Memory" in the Programming Guide 
  14532.      _heapchk - Validate Default Memory Heap 
  14533.      _heapmin - Release Unused Memory from Default Heap 
  14534.      _heap_walk - Return Information about Default Heap 
  14535.      _uheapset - Validate and Set Memory Heap 
  14536.      <malloc.h> 
  14537.      <umalloc.h> 
  14538.  
  14539.  
  14540. ΓòÉΓòÉΓòÉ 4.140. _heap_walk - Return Information about Default Heap ΓòÉΓòÉΓòÉ
  14541.  
  14542.  
  14543. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14544.  
  14545. #include <malloc.h>
  14546. int _heap_walk(int (*callback_fn)(const void *object, size_t size,
  14547.                                               int flag, int status,
  14548.                                               const char* file, int line) );
  14549.  
  14550.  
  14551. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14552.  
  14553. Language Level:  Extension 
  14554.  
  14555. _heap_walk traverses the default heap, and for each allocated or freed object, 
  14556. it calls the callback_fn function that you provide. For each object, it passes 
  14557. your function: 
  14558.  
  14559.  object    A pointer to the object. 
  14560.  size      The size of the object. 
  14561.  flag      The value _USEDENTRY if the object is currently allocated, or 
  14562.            _FREEENTRY if the object has been freed.  (Both values are defined 
  14563.            in <malloc.h>.) 
  14564.  status    One of the following values, defined in <malloc.h>, depending on the 
  14565.            status of the object: 
  14566.            _HEAPBADBEGIN          The heap specified is not valid; it may have 
  14567.                                   been closed or destroyed. 
  14568.            _HEAPBADNODE           A memory node is corrupted, or the heap is 
  14569.                                   damaged. 
  14570.            _HEAPEMPTY             The heap has not been initialized. 
  14571.            _HEAPOK                The heap appears to be consistent. 
  14572.  file      The name of the file where the object was allocated. 
  14573.  line      The line where the object was allocated. 
  14574.  
  14575.  _heap_walk provides information about all objects, regardless of which memory 
  14576.  management functions were used to allocate them. However, the file and line 
  14577.  information are only available if the object was allocated and freed using the 
  14578.  debug versions of the memory management functions. Otherwise, file is NULL and 
  14579.  line is 0. 
  14580.  
  14581.  _heap_walk calls callback_fn for each object until one of the following 
  14582.  occurs: 
  14583.  
  14584.      All objects have been traversed. 
  14585.      callback_fn returns a nonzero value to _heap_walk. 
  14586.      It cannot continue because of a problem with the heap. 
  14587.  
  14588.  You may want to code your callback_fn to return a nonzero value if the status 
  14589.  of the object is not _HEAPOK. Even if callback_fn returns 0 for an object that 
  14590.  is corrupted, _heap_walk cannot continue because of the state of the heap and 
  14591.  returns to its caller. 
  14592.  
  14593.  You can use callback_fn to process the information from _heap_walk in various 
  14594.  ways. For example, you may want to print the information to a file or use it 
  14595.  to generate your own error messages. You can use the information to look for 
  14596.  memory leaks and objects incorrectly allocated or freed from the heap. It can 
  14597.  be especially useful to call _heap_walk when _heapchk returns an error. 
  14598.  
  14599.  A heap-specific version of this function, _uheap_walk, is also available. 
  14600.  
  14601.  Note: 
  14602.  
  14603.    1. Using the _heapchk, _heapset, and _heap_walk functions (and their 
  14604.       heap-specific equivalents) may add overhead to each object allocated from 
  14605.       the heap. 
  14606.  
  14607.    2. _heap_walk locks the heap while it traverses it, to ensure that no other 
  14608.       operations use the heap until _heap_walk finishes. As a result, in your 
  14609.       callback_fn, you cannot call any critical functions in the runtime 
  14610.       library, either explicitly or by calling another function that calls a 
  14611.       critical function. See the Programming Guide for a list of critical 
  14612.       functions. 
  14613.  
  14614.  Return Value 
  14615.  _heap_walk returns the last value of status to the caller. 
  14616.  
  14617.  
  14618. ΓòÉΓòÉΓòÉ <hidden> Example of _heap_walk ΓòÉΓòÉΓòÉ
  14619.  
  14620. /************************************************************************
  14621.  
  14622. This example allocates some memory, then uses _heap_walk to walk the heap and 
  14623. pass information about allocated objects to the callback function 
  14624. callback_function. callback_function then checks the information and keeps 
  14625. track of the number of allocated objects. 
  14626.  
  14627. *********************************************************************** /
  14628.  
  14629. #include <stdlib.h>
  14630. #include <stdio.h>
  14631. #include <malloc.h>
  14632.  
  14633. int _Optlink callback_function(const void *pentry, size_t sz, int useflag,
  14634.                                int status, const char *filename, size_t line)
  14635. {
  14636.    if (_HEAPOK != status) {
  14637.       puts("status is not _HEAPOK.");
  14638.       exit(status);
  14639.    }
  14640.    if (_USEDENTRY == useflag)
  14641.       printf("allocated  %p     %u\n", pentry, sz);
  14642.    else
  14643.       printf("freed      %p     %u\n", pentry, sz);
  14644.    return 0;
  14645. }
  14646.  
  14647. int main(void)
  14648. {
  14649.    char  *p1, *p2, *p3;
  14650.  
  14651.    if (NULL == (p1 = (char*)malloc(100)) ||
  14652.        NULL == (p2 = (char*)malloc(200)) ||
  14653.        NULL == (p3 = (char*)malloc(300))) {
  14654.       puts("Could not allocate memory block.");
  14655.       exit(EXIT_FAILURE);
  14656.    }
  14657.    free(p2);
  14658.    puts("usage      address   size\n-----      -------   ----");
  14659.  
  14660.    _heap_walk(callback_function);
  14661.  
  14662.    free(p1);
  14663.    free(p3);
  14664.    return 0;
  14665.  
  14666.    /****************************************************************************
  14667.       The output should be similar to :
  14668.  
  14669.       usage      address   size
  14670.       -----      -------   ----
  14671.       allocated  73A10     300
  14672.       allocated  738B0     100
  14673.        :
  14674.        :
  14675.       freed      73920     224
  14676.    ****************************************************************************/
  14677. }
  14678.  
  14679.  
  14680. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14681.  
  14682. Example of _heap_walk 
  14683.  
  14684.      "Managing Memory" in the Programming Guide 
  14685.      "Debugging Your Heaps" in the Programming Guide 
  14686.      _heapchk - Validate Default Memory Heap 
  14687.      _heapmin - Release Unused Memory from Default Heap 
  14688.      _heapset - Validate and Set Default Heap 
  14689.      _uheap_walk - Return Information about Memory Heap 
  14690.      <malloc.h> 
  14691.  
  14692.  
  14693. ΓòÉΓòÉΓòÉ 4.141. hypot - Calculate Hypotenuse ΓòÉΓòÉΓòÉ
  14694.  
  14695.  
  14696. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14697.  
  14698. #include <math.h>
  14699. double hypot(double side1, double side2);
  14700.  
  14701.  
  14702. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14703.  
  14704. Language Level: SAA, XPG4 
  14705.  
  14706. hypot calculates the length of the hypotenuse of a right-angled triangle based 
  14707. on the lengths of two sides side1 and side2.  A call to hypot is equivalent to: 
  14708.  
  14709.    sqrt(side1 * side1 + side2 * side2);
  14710.  
  14711. Return Value 
  14712. hypot returns the length of the hypotenuse. If an overflow results, hypot sets 
  14713. errno to ERANGE and returns the value HUGE_VAL. If an underflow results, hypot 
  14714. sets errno to ERANGE and returns zero. 
  14715.  
  14716.  
  14717. ΓòÉΓòÉΓòÉ <hidden> Example of hypot ΓòÉΓòÉΓòÉ
  14718.  
  14719. /************************************************************************
  14720.  
  14721. This example calculates the hypotenuse of a right-angled triangle with sides of 
  14722. 3.0 and 4.0. 
  14723.  
  14724. ************************************************************************/
  14725.  
  14726. #include <stdio.h>
  14727. #include <math.h>
  14728.  
  14729. int main(void)
  14730. {
  14731.    double x,y,z;
  14732.  
  14733.    x = 3.0;
  14734.    y = 4.0;
  14735.    z = hypot(x, y);
  14736.    printf("The hypotenuse of the triangle with sides %lf and %lf"
  14737.    " is %lf\n", x, y, z);
  14738.    return 0;
  14739.  
  14740.    /****************************************************************************
  14741.       The output should be:
  14742.  
  14743.      The hypotenuse of the triangle with sides 3.000000 and 4.000000 is 5.000000
  14744.    ****************************************************************************/
  14745. }
  14746.  
  14747.  
  14748. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14749.  
  14750. Example of hypot 
  14751.  
  14752.      _fsqrt -  Calculate Square Root 
  14753.      sqrt - Calculate Square Root 
  14754.      <math.h> 
  14755.  
  14756.  
  14757. ΓòÉΓòÉΓòÉ 4.142. iconv - Convert Characters to New Code Set ΓòÉΓòÉΓòÉ
  14758.  
  14759.  
  14760. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14761.  
  14762. #include <iconv.h>
  14763. size_t iconv(iconv_t cd, char **inbuf, size_t *inbytesleft,
  14764.              char **outbuf, size_t *outbytesleft);
  14765.  
  14766.  
  14767. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14768.  
  14769. Language Level:  XPG4 
  14770.  
  14771. iconv converts a sequence of characters in one encoded character set, in the 
  14772. array indirectly pointed to by inbuf, into a sequence of corresponding 
  14773. characters in the another encoded character set. It stores the corresponding 
  14774. sequence in the array indirectly pointed to by outbuf. cd is the conversion 
  14775. descriptor returned from iconv_open that describes which codesets are used in 
  14776. the conversion. 
  14777.  
  14778. inbuf points to a variable that points to the first character in the input 
  14779. buffer, and inbytesleft indicates the number of bytes to the end of the buffer. 
  14780. outbuf points to a variable that points to the first available byte in the 
  14781. output buffer, and outbytesleft indicates the number of available bytes to the 
  14782. end of the buffer. 
  14783.  
  14784. As iconv converts the characters, it updates the variable pointed to by inbuf 
  14785. to point to the next byte in the input buffer, and updates the variable pointed 
  14786. to by outbuf to the byte following the last successfully converted character. 
  14787. It also decrements inbytesleft and outbytesleft to reflect the number of bytes 
  14788. of input remaining and the number of bytes still available for output, 
  14789. respectively. If the entire input string is converted, insize will be 0; if an 
  14790. error stops the conversion, insize will have a nonzero value. 
  14791.  
  14792. If it encounters a valid input character that does not have a defined 
  14793. conversion in cd, iconv translates the character to the ASCII value 0x1a. 
  14794.  
  14795. Sharing a conversion descriptor in iconv across multiple threads may result in 
  14796. undefined behavior. 
  14797.  
  14798. When the target outbuf is too small for the conversion, the remaining converted 
  14799. bytes stay within the run-time, internal buffer, and are processed by the next 
  14800. iconv call. 
  14801.  
  14802. Return Value 
  14803. iconv returns the number of nonidentical conversions performed. In a 
  14804. nonidentical conversion there is no equivalent character image in the target 
  14805. code pages. A substitution is required and the return code counts the number of 
  14806. instances when this happens. 
  14807.  
  14808. If the entire string in the input buffer is converted, inbytesleft points to 0. 
  14809. If the input conversion stops, inbytesleft points to nonzero and errno is set 
  14810. to indicate the condition that caused the conversion to stop. If an error 
  14811. occurs, iconv returns (size_t)-1, and sets errno to one of the following 
  14812. values: 
  14813.  
  14814.  Value       Meaning 
  14815.  EILSEQ      An input byte does not belong to the input codeset. 
  14816.  E2BIG       outbuf is not large enough to hold the converted value. 
  14817.  EINVAL      Incomplete character or shift sequence at the end of the input 
  14818.              buffer. 
  14819.  EBADF       cd is not a valid conversion descriptor. 
  14820.  
  14821.  
  14822. ΓòÉΓòÉΓòÉ <hidden> Example of iconv ΓòÉΓòÉΓòÉ
  14823.  
  14824. /************************************************************************
  14825.  
  14826. This example converts an array of characters coded in encoded character set 
  14827. IBM-850 (in in) to an array of characters coded in encoded character set 
  14828. IBM-037 (stored in out). 
  14829.  
  14830. ************************************************************************/
  14831.  
  14832. #include <iconv.h>
  14833. #include <stdlib.h>
  14834. #include <stdio.h>
  14835.  
  14836. int main(void)
  14837. {
  14838.    const char fromcode[] = "IBM-850";
  14839.    const char tocode[] = "IBM-037";
  14840.    iconv_t    cd;
  14841.    char       in[] = "ABCDEabcde";
  14842.    size_t     in_size;
  14843.    char       *inptr = in;
  14844.    char       out[100];
  14845.    size_t     out_size = sizeof(out);
  14846.    char       *outptr = out;
  14847.    int        i;
  14848.  
  14849.    if ((iconv_t)(-1) == (cd = iconv_open(tocode, fromcode))) {
  14850.       printf("Failed to iconv_open %s to %s.\n", fromcode, tocode);
  14851.       exit(EXIT_FAILURE);
  14852.    }
  14853.    /* Convert the first 3 characters in array "in". */
  14854.    in_size = 3;
  14855.    if ((size_t)(-1) == iconv(cd, &inptr, &in_size, &outptr, &out_size)) {
  14856.       printf("Fail to convert first 3 characters to new code set.\n");
  14857.       exit(EXIT_FAILURE);
  14858.    }
  14859.    /* Convert the rest of the characters in array "in". */
  14860.    in_size = sizeof(in) - 3;
  14861.    if ((size_t)(-1) == iconv(cd, &inptr, &in_size, &outptr, &out_size)) {
  14862.       printf("Fail to convert the rest of the characters to new code set.\n");
  14863.       exit(EXIT_FAILURE);
  14864.    }
  14865.    *outptr = '\0';
  14866.    printf("The hex representation of string %s are:\n  In codepage %s ==> ",
  14867.           in, fromcode);
  14868.    for (i = 0; in[i] != '\0'; i++) {
  14869.       printf("0x%02x ", in[i]);
  14870.    }
  14871.    printf("\n  In codepage %s ==> ", tocode);
  14872.    for (i = 0; out[i] != '\0'; i++) {
  14873.       printf("0x%02x ", out[i]);
  14874.    }
  14875.    if (-1 == iconv_close(cd)) {
  14876.       printf("Fail to iconv_close.\n");
  14877.       exit(EXIT_FAILURE);
  14878.    }
  14879.    return 0;
  14880.  
  14881.    /****************************************************************************
  14882.       The output should be similar to :
  14883.  
  14884.       The hex representation of string ABCDEabcde are:
  14885.         In codepage IBM-850 ==> 0x41 0x42 0x43 0x44 0x45 0x61 0x62 0x63 0x64 0x65
  14886.         In codepage IBM-037 ==> 0xc1 0xc2 0xc3 0xc4 0xc5 0x81 0x82 0x83 0x84 0x85
  14887.    ****************************************************************************/
  14888. }
  14889.  
  14890.  
  14891. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14892.  
  14893. Example of iconv 
  14894.  
  14895.      iconv_close - Remove Conversion Descriptor 
  14896.      iconv_open - Create Conversion Descriptor 
  14897.      setlocale - Set Locale 
  14898.      "Introduction to Locale" in the Programming Guide 
  14899.      <locale.h> 
  14900.  
  14901.  
  14902. ΓòÉΓòÉΓòÉ 4.143. iconv_close - Remove Conversion Descriptor ΓòÉΓòÉΓòÉ
  14903.  
  14904.  
  14905. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14906.  
  14907. #include <iconv.h>
  14908. int iconv_close(iconv_t cd);
  14909.  
  14910.  
  14911. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14912.  
  14913. Language Level:  XPG4 
  14914.  
  14915. iconv_close deallocates the conversion descriptor cd and all other associated 
  14916. resources allocated by the iconv_open function. 
  14917.  
  14918. Return Value 
  14919. If successful, iconv_close returns 0.  Otherwise, iconv_close returns -1 is 
  14920. returned and sets errno to indicate the cause of the error. If cd is not a 
  14921. valid descriptor, an error occurs and iconv_close sets errno to EBADF. 
  14922.  
  14923.  
  14924. ΓòÉΓòÉΓòÉ <hidden> Example of iconv_close ΓòÉΓòÉΓòÉ
  14925.  
  14926. /************************************************************************
  14927.  
  14928. This example shows how you would use iconv_close to remove a conversion 
  14929. descriptor. 
  14930.  
  14931. ************************************************************************/
  14932.  
  14933. #include <iconv.h>
  14934. #include <stdlib.h>
  14935. #include <stdio.h>
  14936.  
  14937. int main(void)
  14938. {
  14939.    const char   fromcode[] = "IBM-850";
  14940.    const char   tocode[] = "IBM-863";
  14941.    iconv_t      cd;
  14942.  
  14943.    if ((iconv_t)(-1) == (cd = iconv_open(tocode, fromcode))) {
  14944.       printf("Failed to iconv_open %s to %s.\n", fromcode, tocode);
  14945.       exit(EXIT_FAILURE);
  14946.    }
  14947.    if (-1 == iconv_close(cd)) {
  14948.       printf("Fail to iconv_close.\n");
  14949.       exit(EXIT_FAILURE);
  14950.    }
  14951.    return 0;
  14952. }
  14953.  
  14954.  
  14955. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14956.  
  14957. Example of iconv_close 
  14958.  
  14959.      iconv - Convert Characters to New Code Set 
  14960.      iconv_open - Create Conversion Descriptor 
  14961.      setlocale - Set Locale 
  14962.      "Introduction to Locale" in the Programming Guide 
  14963.      <locale.h> 
  14964.  
  14965.  
  14966. ΓòÉΓòÉΓòÉ 4.144. iconv_open - Create Conversion Descriptor ΓòÉΓòÉΓòÉ
  14967.  
  14968.  
  14969. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14970.  
  14971. #include <iconv.h>
  14972. iconv_t iconv_open(const char *tocode, const char *fromcode);
  14973.  
  14974.  
  14975. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14976.  
  14977. Language Level:  XPG4 
  14978.  
  14979. iconv_open performs all the initialization needed to convert characters from 
  14980. the encoded character set specified in the array pointed to by fromcode to the 
  14981. encoded character set specified in the array pointed to by tocode. It creates a 
  14982. conversion descriptor that relates the two encoded character sets. You can then 
  14983. use the conversion descriptor with the iconv function to convert characters 
  14984. between the codesets. 
  14985.  
  14986. The conversion descriptor remains valid until you close it with iconv_close. 
  14987.  
  14988. For information about the settings of fromcode, tocode, and their permitted 
  14989. combinations, see the section on internationalization in the Programming Guide. 
  14990.  
  14991. Return Value 
  14992. If successful, iconv_open returns a conversion descriptor of type iconv_t. 
  14993. Otherwise, it returns (iconv_t)-1, and sets errno to indicate the error. If you 
  14994. cannot convert between the encoded character sets specified, an error occurs 
  14995. and iconv_open sets errno to EINVAL. 
  14996.  
  14997.  
  14998. ΓòÉΓòÉΓòÉ <hidden> Example of iconv_open ΓòÉΓòÉΓòÉ
  14999.  
  15000. /************************************************************************
  15001.  
  15002. This example shows how to use iconv_open, iconv, and iconv_close to convert 
  15003. characters from one codeset to another. 
  15004.  
  15005. ************************************************************************/
  15006.  
  15007. #include <iconv.h>
  15008. #include <stdlib.h>
  15009. #include <stdio.h>
  15010.  
  15011. int main(void)
  15012. {
  15013.    const char   fromcode[] = "IBM-932";
  15014.    const char   tocode[] = "IBM-930";
  15015.    iconv_t      cd;
  15016.    char         in[] = "\x81\x40\x81\x80";
  15017.    size_t       in_size = sizeof(in);
  15018.    char         *inptr = in;
  15019.    char         out[100];
  15020.    size_t       out_size = sizeof(out);
  15021.    char         *outptr = out;
  15022.    int          i;
  15023.  
  15024.    if ((iconv_t)(-1) == (cd = iconv_open(tocode, fromcode))) {
  15025.       printf("Failed to iconv_open %s to %s.\n", fromcode, tocode);
  15026.       exit(EXIT_FAILURE);
  15027.    }
  15028.    if ((size_t)(-1) == iconv(cd, &inptr, &in_size, &outptr, &out_size)) {
  15029.       printf("Fail to convert characters to new code set.\n");
  15030.       exit(EXIT_FAILURE);
  15031.    }
  15032.    *outptr = '\0';
  15033.    printf("The hex representation of string %s are:\n  In codepage %s ==> ",
  15034.           in, fromcode);
  15035.    for (i = 0; in[i] != '\0'; i++) {
  15036.       printf("0x%02x ", in[i]);
  15037.    }
  15038.    printf("\n  In codepage %s ==> ", tocode);
  15039.    for (i = 0; out[i] != '\0'; i++) {
  15040.       printf("0x%02x ", out[i]);
  15041.    }
  15042.    if (-1 == iconv_close(cd)) {
  15043.       printf("Fail to iconv_close.\n");
  15044.       exit(EXIT_FAILURE);
  15045.    }
  15046.    return 0;
  15047.  
  15048.    /****************************************************************************
  15049.       The output should be similar to :
  15050.  
  15051.       The hex representation of string ΓöÇ@ΓöÇ╨ö are:
  15052.         In codepage IBM-932 ==> 0x81 0x40 0x81 0x80
  15053.         In codepage IBM-930 ==> 0x0e 0x40 0x40 0x44 0x7b 0x0f
  15054.    ****************************************************************************/
  15055. }
  15056.  
  15057.  
  15058. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15059.  
  15060. Example of iconv_open 
  15061.  
  15062.      iconv - Convert Characters to New Code Set 
  15063.      iconv_close - Remove Conversion Descriptor 
  15064.      setlocale - Set Locale 
  15065.      "Introduction to Locale" in the Programming Guide 
  15066.      <locale.h> 
  15067.  
  15068.  
  15069. ΓòÉΓòÉΓòÉ 4.145. _inp - Read Byte from Input Port ΓòÉΓòÉΓòÉ
  15070.  
  15071.  
  15072. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15073.  
  15074. #include <conio.h>  /* also in <builtin.h>  */
  15075. int _inp(const unsigned int port);
  15076.  
  15077.  
  15078. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15079.  
  15080. Language Level:  Extension 
  15081.  
  15082. _inp reads a byte from the specified input port. The port number must be an 
  15083. unsigned int value in the range 0 to 65 535 inclusive. 
  15084.  
  15085. Note:  _inp is a built-in function, which means it is implemented as an inline 
  15086. instruction and has no backing code in the library.  For this reason: 
  15087.  
  15088.      You cannot take the address of _inp. 
  15089.      You cannot parenthesize a call to _inp. (Parentheses specify a call to 
  15090.       the function's backing code, and _inp has none.) 
  15091.  
  15092.  You can run code containing this function only at ring zero. Otherwise, an 
  15093.  invalid instruction exception is generated. 
  15094.  
  15095.  Return Value 
  15096.  _inp returns the byte value as an integer that was read from the specified 
  15097.  port. There is no error return value, and _inp does not set errno. 
  15098.  
  15099.  
  15100. ΓòÉΓòÉΓòÉ <hidden> Example of _inp ΓòÉΓòÉΓòÉ
  15101.  
  15102. /************************************************************************
  15103.  
  15104. This example uses _inp to read a byte from a specified input port and return 
  15105. the data read. 
  15106.  
  15107. ************************************************************************/
  15108.  
  15109. #include <builtin.h>
  15110.  
  15111. #define LOWER 0
  15112. #define UPPER 65535
  15113.  
  15114. int Add1(int j);
  15115.  
  15116. int    g;
  15117. enum   fruit {apples=10, bananas, cantaloupes};
  15118. int    arr[] = {cantaloupes, bananas, apples};
  15119. struct
  15120. {
  15121.    int  i;
  15122.    char ch;
  15123. } st;
  15124.  
  15125. int main(void)
  15126. {
  15127.    int i;
  15128.    volatile const int c = 0;
  15129.  
  15130.    i = _inp(0);
  15131.    g = _inp(LOWER + 1);    /* put the data read in a global variable  */
  15132.    i = _inp(apples);          /* passing enumerated type as the       */
  15133.                               /* port number                          */
  15134.                               /* ===================================  */
  15135.                               /* Types of port number passed :        */
  15136.                               /* -----------------------------------  */
  15137.    i = _inp(c);               /* - constant                           */
  15138.    i = _inp(arr[c]);          /* - element of array                   */
  15139.    st.i = Add1(c);            /*                                      */
  15140.    i = _inp(st.i);            /* - element of structure               */
  15141.    i = _inp(Add1(LOWER));     /* - return value from a function call  */
  15142.    i = _inp(UPPER);           /* - #define constant                   */
  15143.    i = _inp(256);             /* - the exact port number              */
  15144.                               /* -----------------------------------  */
  15145.    return 0;
  15146. }
  15147.  
  15148. int Add1(int j)
  15149. {
  15150.    j += 1;
  15151.    return j;
  15152. }
  15153.  
  15154.  
  15155. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15156.  
  15157. Example of _inp 
  15158.  
  15159.      _inpw - Read Unsigned Short from Input Port 
  15160.      _inpd - Read Doubleword from Input Port 
  15161.      isatty - Test Handle for Character Device 
  15162.      _outp - Write Byte to Output Port 
  15163.      _outpw - Write Word to Output Port 
  15164.      _outpd - Write Double Word to Output Port 
  15165.      <builtin.h> 
  15166.      <conio.h> 
  15167.  
  15168.  
  15169. ΓòÉΓòÉΓòÉ 4.146. _inpd - Read Doubleword from Input Port ΓòÉΓòÉΓòÉ
  15170.  
  15171.  
  15172. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15173.  
  15174. #include <conio.h>  /* also in <builtin.h> */
  15175. unsigned long _inpd(const unsigned int port);
  15176.  
  15177.  
  15178. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15179.  
  15180. Language Level:  Extension 
  15181.  
  15182. _inpd reads a 4-byte (doubleword) unsigned value from the specified input port. 
  15183. The port number must be an unsigned short value within the range 0 to 65 535 
  15184. inclusive. 
  15185.  
  15186. Note:  _inpd is a built-in function, which means it is implemented as an inline 
  15187. instruction and has no backing code in the library.  For this reason: 
  15188.  
  15189.      You cannot take the address of _inpd. 
  15190.      You cannot parenthesize a call to _inpd. (Parentheses specify a call to 
  15191.       the function's backing code, and _inpd has none.) 
  15192.  
  15193.  You can run code containing this function only at ring zero. Otherwise, an 
  15194.  invalid instruction exception is generated. 
  15195.  
  15196.  Return Value 
  15197.  _inpd returns the value read from the specified port. There is no error return 
  15198.  value, and _inpd does not set errno. 
  15199.  
  15200.  
  15201. ΓòÉΓòÉΓòÉ <hidden> Example of _inpd ΓòÉΓòÉΓòÉ
  15202.  
  15203. /************************************************************************
  15204.  
  15205. This example uses _inpd to read a doubleword value from the specified input 
  15206. port and return the data read. 
  15207.  
  15208. ************************************************************************/
  15209.  
  15210. #include <builtin.h>
  15211.  
  15212. #define LOWER 0
  15213. #define UPPER 65535
  15214.  
  15215. int Add1(int j);
  15216.  
  15217. static long g;
  15218. enum        fruit {apples=10, bananas, cantaloupes};
  15219. int         arr[] = {cantaloupes, bananas, apples};
  15220. union
  15221. {
  15222.    int  i;
  15223.    char ch;
  15224. } un;
  15225.  
  15226. int main(void)
  15227. {
  15228.    unsigned long      l;
  15229.    volatile const int c = 0;
  15230.  
  15231.    un.i = 65534;
  15232.    g = _inpd(255);         /* put the data read in a global variable  */
  15233.                                        /* =========================== */
  15234.                                        /* Types of port number passed:*/
  15235.                                        /* --------------------------- */
  15236.    l = _inpd(c);                       /* - constant                  */
  15237.    l = _inpd(un.i);                    /* - element of union          */
  15238.    l = _inpd(Add1(cantaloupes));       /* - return value from a       */
  15239.                                        /*   function call             */
  15240.    l = _inpd(_inp(arr[Add1(LOWER)]));  /* - return value from a       */
  15241.                                        /*   builtin function call     */
  15242.                                        /* --------------------------- */
  15243.    return 0;
  15244. }
  15245.  
  15246. int Add1(int j)
  15247. {
  15248.    j += 1;
  15249.    return j;
  15250. }
  15251.  
  15252.  
  15253. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15254.  
  15255. Example of _inpd 
  15256.  
  15257.      _inp - Read Byte from Input Port 
  15258.      _inpw - Read Unsigned Short from Input Port 
  15259.      isatty - Test Handle for Character Device 
  15260.      _outp - Write Byte to Output Port 
  15261.      _outpw - Write Word to Output Port 
  15262.      _outpd - Write Double Word to Output Port 
  15263.      <builtin.h> 
  15264.      <conio.h> 
  15265.  
  15266.  
  15267. ΓòÉΓòÉΓòÉ 4.147. _inpw - Read Unsigned Short from Input Port ΓòÉΓòÉΓòÉ
  15268.  
  15269.  
  15270. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15271.  
  15272. #include <conio.h>  /* also in <builtin.h> */
  15273. unsigned short _inpw(const unsigned int port);
  15274.  
  15275.  
  15276. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15277.  
  15278. Language Level:  Extension 
  15279.  
  15280. _inpw reads an unsigned short value from the specified input port. The port 
  15281. number must be an unsigned short value within the range 0 to 65 535 inclusive. 
  15282.  
  15283. Note:  _inpw is a built-in function, which means it is implemented as an inline 
  15284. instruction and has no backing code in the library.  For this reason: 
  15285.  
  15286.      You cannot take the address of _inpw. 
  15287.      You cannot parenthesize a call to _inpw. (Parentheses specify a call to 
  15288.       the function's backing code, and _inpw has none.) 
  15289.  
  15290.  You can run code containing this function only at ring zero. Otherwise, an 
  15291.  invalid instruction exception is generated. 
  15292.  
  15293.  Return Value 
  15294.  _inpw returns the value read from the specified port. There is no error return 
  15295.  value, and _inpw does not set errno. 
  15296.  
  15297.  
  15298. ΓòÉΓòÉΓòÉ <hidden> Example of _inpw ΓòÉΓòÉΓòÉ
  15299.  
  15300. /************************************************************************
  15301.  
  15302. This example uses _inpw to read an unsigned short value from the specified 
  15303. input port and return the data read. 
  15304.  
  15305. ************************************************************************/
  15306.  
  15307. #include <builtin.h>
  15308.  
  15309. #define LOWER 0
  15310. #define UPPER 65535
  15311.  
  15312. int Add1(int j);
  15313.  
  15314. volatile short g;
  15315.  
  15316. int main(void)
  15317. {
  15318.    volatile unsigned short s;
  15319.    volatile const int c = 0;
  15320.    int i = 65534;
  15321.    enum fruit {apples, bananas, cantaloupes};
  15322.    int arr[] = {cantaloupes, bananas, apples};
  15323.  
  15324.    g = _inpw(LOWER);       /* put the data read in a global variable  */
  15325.    s = _inpw(bananas);                 /* passing enumerated type     */
  15326.                                        /* as the port number          */
  15327.                                        /* =========================== */
  15328.                                        /* Types of port number passed:*/
  15329.                                        /* --------------------------- */
  15330.    s = _inpw(c);                       /* - constant                  */
  15331.    s = _inpw(i+1);                     /* - integer                   */
  15332.    s = _inpw(arr[bananas]);            /* - element of array          */
  15333.    s = _inpw(_outp(UPPER,cantaloupes));/* - return value from a       */
  15334.                                        /*   builtin function call     */
  15335.                                        /* --------------------------- */
  15336.    return 0;
  15337. }
  15338.  
  15339. int Add1(int j)
  15340. {
  15341.    j += 1;
  15342.    return j;
  15343. }
  15344.  
  15345.  
  15346. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15347.  
  15348. Example of _inpw 
  15349.  
  15350.      _inp - Read Byte from Input Port 
  15351.      _inpd - Read Doubleword from Input Port 
  15352.      isatty - Test Handle for Character Device 
  15353.      _outp - Write Byte to Output Port 
  15354.      _outpw - Write Word to Output Port 
  15355.      _outpd - Write Double Word to Output Port 
  15356.      <builtin.h> 
  15357.      <conio.h> 
  15358.  
  15359.  
  15360. ΓòÉΓòÉΓòÉ 4.148. _interrupt - Call Interrupt  Procedure ΓòÉΓòÉΓòÉ
  15361.  
  15362.  
  15363. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15364.  
  15365. #include <builtin.h>
  15366. void _interrupt(const unsigned int intnum);
  15367.  
  15368.  
  15369. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15370.  
  15371. Language Level:  Extension 
  15372.  
  15373. _interrupt calls the interrupt procedure specified by intnum using the INT 
  15374. machine instruction. The integer intnum must have a value within the range 0 to 
  15375. 255 inclusive. 
  15376.  
  15377. Note:  _interrupt is a built-in function, which means it is implemented as an 
  15378. inline instruction and has no backing code in the library.  For this reason: 
  15379.  
  15380.      You cannot take the address of _interrupt. 
  15381.      You cannot parenthesize a call to _interrupt. (Parentheses specify a call 
  15382.       to the function's backing code, and _interrupt has none.) 
  15383.  
  15384.  Return Value 
  15385.  There is no return value, and _interrupt does not set errno. 
  15386.  
  15387.  
  15388. ΓòÉΓòÉΓòÉ <hidden> Example of _interrupt ΓòÉΓòÉΓòÉ
  15389.  
  15390. /************************************************************************
  15391.  
  15392. This example calls interrupt 3, which is a breakpoint. 
  15393.  
  15394. ************************************************************************/
  15395.  
  15396. #include <builtin.h>
  15397.  
  15398. int main(void)
  15399. {
  15400.    /* A breakpoint will occur when running this program */
  15401.    /* within a debugger.                                */
  15402.    _interrupt(3);
  15403.  
  15404.    return 0;
  15405. }
  15406.  
  15407.  
  15408. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15409.  
  15410. Example of _interrupt 
  15411.  
  15412.      _disable - Disable Interrupts 
  15413.      _enable - Enable Interrupts 
  15414.      <builtin.h> 
  15415.  
  15416.  
  15417. ΓòÉΓòÉΓòÉ 4.149. isalnum to isxdigit - Test Integer Value ΓòÉΓòÉΓòÉ
  15418.  
  15419.  
  15420. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15421.  
  15422. #include <ctype.h>
  15423.                               /* test for:              */
  15424. int isalnum(int c);  /* alphanumeric character */
  15425. int isalpha(int c);  /* alphabetic character   */
  15426. int iscntrl(int c);  /* control character      */
  15427. int isdigit(int c);  /* decimal digit          */
  15428. int isgraph(int c);  /* printable character, excluding space */
  15429. int islower(int c);  /* lowercase character    */
  15430. int isprint(int c);  /* printable character, including space */
  15431. int ispunct(int c);  /* nonalphanumeric printable character, excluding space */
  15432. int isspace(int c);  /* whitespace character   */
  15433. int isupper(int c);  /* uppercase character    */
  15434. int isxdigit(int c); /* hexadecimal digit      */
  15435.  
  15436.  
  15437. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15438.  
  15439. Language Level:  ANSI, SAA, POSIX, XPG4 
  15440.  
  15441. These functions test a given integer value c to determine if it has a certain 
  15442. property as defined by the LC_CTYPE category of your current locale. The value 
  15443. of c must be representable as an unsigned char, or EOF. 
  15444.  
  15445. The functions test for the following: 
  15446.  
  15447.  isalnum 
  15448.     Alphanumeric character (upper- or lowercase letter, or decimal digit), as 
  15449.     defined in the locale source file in the alnum class of the LC_CTYPE 
  15450.     category of the current locale. 
  15451.  
  15452.  isalpha 
  15453.     Alphabetic character, as defined in the locale source file in the alpha 
  15454.     class of the LC_CTYPE category of the current locale. 
  15455.  
  15456.  iscntrl 
  15457.     Control character, as defined in the locale source file in the cntrl class 
  15458.     of the LC_CTYPE category of the current locale. 
  15459.  
  15460.  isdigit 
  15461.     Decimal digit (0 through 9), as defined in the locale source file in the 
  15462.     digit class of the LC_CTYPE category of the current locale. 
  15463.  
  15464.  isgraph 
  15465.     Printable character, excluding the space character, as defined in the 
  15466.     locale source file in the graph class of the LC_CTYPE category of the 
  15467.     current locale. 
  15468.  
  15469.  islower 
  15470.     Lowercase letter, as defined in the locale source file in the lower class 
  15471.     of the LC_CTYPE category of the current locale. 
  15472.  
  15473.  isprint 
  15474.     Printable character, including the space character, as defined in the 
  15475.     locale source file in the print class of the LC_CTYPE category of the 
  15476.     current locale. 
  15477.  
  15478.  ispunct 
  15479.     Nonalphanumeric printable character, excluding the space character, as 
  15480.     defined in the locale source file in the punct class of the LC_CTYPE 
  15481.     category of the current locale. 
  15482.  
  15483.  isspace 
  15484.     White-space character, as defined in the locale source file in the space 
  15485.     class of the LC_CTYPE category of the current locale. 
  15486.  
  15487.  isupper 
  15488.     Uppercase letter, as defined in the locale source file in the upper class 
  15489.     of the LC_CTYPE category of the current locale. 
  15490.  
  15491.  isxdigit 
  15492.     Hexadecimal digit (0 through 9, a through f, or A through F), as defined in 
  15493.     the locale source file in the xdigit class of the LC_CTYPE category of the 
  15494.     current locale. 
  15495.  
  15496.  You can redefine any character class in the LC_CTYPE category of the current 
  15497.  locale, with some restrictions. See the section about the LC_CTYPE class in 
  15498.  the Programming Guide for details about these restrictions. 
  15499.  
  15500.  Return Value 
  15501.  These functions return a nonzero value if the integer satisfies the test 
  15502.  condition, or 0 if it does not. 
  15503.  
  15504.  
  15505. ΓòÉΓòÉΓòÉ <hidden> Example of isalnum to isxdigit ΓòÉΓòÉΓòÉ
  15506.  
  15507. /************************************************************************
  15508.  
  15509. This example analyzes all characters between 0x0 and 0xFF. The output of this 
  15510. example is a 256-line table showing the characters from 0 to 255, indicating 
  15511. whether they have the properties tested for. 
  15512.  
  15513. ************************************************************************/
  15514.  
  15515. #include <stdio.h>
  15516. #include <stdlib.h>
  15517. #include <ctype.h>
  15518. #include <locale.h>
  15519.  
  15520. #define UPPER_LIMIT   0xFF
  15521. #if (1 == __TOS_OS2__)
  15522.    #define LOCNAME "en_us.ibm-437"     /* OS/2 name        */
  15523. #else
  15524.    #define LOCNAME "en_us.ibm-1252"    /* Windows name     */
  15525. #endif
  15526.  
  15527. int main(void)
  15528. {
  15529.    int ch;
  15530.  
  15531.    if (NULL == setlocale(LC_ALL, LOCNAME)) {
  15532.       printf("Locale \"%s\" could not be loaded\n", LOCNAME);
  15533.       exit(1);
  15534.    }
  15535.    for (ch = 0; ch <= UPPER_LIMIT; ++ch) {
  15536.       printf("%#04x ", ch);
  15537.       printf("%c", isprint(ch)  ? ch     : ' ');
  15538.       printf("%s", isalnum(ch)  ? " AN"  : "   ");
  15539.       printf("%s", isalpha(ch)  ? " A "  : "   ");
  15540.       printf("%s", iscntrl(ch)  ? " C "  : "   ");
  15541.       printf("%s", isdigit(ch)  ? " D "  : "   ");
  15542.       printf("%s", isgraph(ch)  ? " G "  : "   ");
  15543.       printf("%s", islower(ch)  ? " L "  : "   ");
  15544.       printf("%s", ispunct(ch)  ? " PU"  : "   ");
  15545.       printf("%s", isspace(ch)  ? " S "  : "   ");
  15546.       printf("%s", isprint(ch)  ? " PR"  : "   ");
  15547.       printf("%s", isupper(ch)  ? " U "  : "   ");
  15548.       printf("%s", isxdigit(ch) ? " H "  : "   ");
  15549.       putchar('\n');
  15550.    }
  15551.    return 0;
  15552.  
  15553.    /****************************************************************************
  15554.       The output should be similar to :
  15555.       :
  15556.       0x20                        S  PR
  15557.       0x21 !             G     PU    PR
  15558.       0x22 "             G     PU    PR
  15559.       0x23 #             G     PU    PR
  15560.       0x24 $             G     PU    PR
  15561.       0x25 %             G     PU    PR
  15562.       0x26 &             G     PU    PR
  15563.       0x27 '             G     PU    PR
  15564.       0x28 (             G     PU    PR
  15565.       0x29 )             G     PU    PR
  15566.       0x2a *             G     PU    PR
  15567.       0x2b +             G     PU    PR
  15568.       0x2c ,             G     PU    PR
  15569.       0x2d -             G     PU    PR
  15570.       0x2e .             G     PU    PR
  15571.       0x2f /             G     PU    PR
  15572.       0x30 0 AN       D  G           PR    H  H
  15573.       0x31 1 AN       D  G           PR    H  H
  15574.       0x32 2 AN       D  G           PR    H  H
  15575.       0x33 3 AN       D  G           PR    H  H
  15576.       0x34 4 AN       D  G           PR    H  H
  15577.       0x35 5 AN       D  G           PR    H  H
  15578.       0x36 6 AN       D  G           PR    H  H
  15579.       0x37 7 AN       D  G           PR    H  H
  15580.       0x38 8 AN       D  G           PR    H  H
  15581.       0x39 9 AN       D  G           PR    H  H
  15582.       :
  15583.    ****************************************************************************/
  15584. }
  15585.  
  15586.  
  15587. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15588.  
  15589. Example of isalnum to isxdigit 
  15590.  
  15591.      isascii - Test Integer Values 
  15592.      _iscsym - _iscsymf - Test Integer 
  15593.      iswalnum to iswxdigit - Test Wide Integer Value 
  15594.      setlocale - Set Locale 
  15595.      tolower() - toupper() - Convert Character Case 
  15596.      _toascii - _tolower - _toupper - Convert Character 
  15597.      <ctype.h> 
  15598.  
  15599.  
  15600. ΓòÉΓòÉΓòÉ 4.150. isascii - Test Integer Values ΓòÉΓòÉΓòÉ
  15601.  
  15602.  
  15603. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15604.  
  15605. #include <ctype.h>
  15606. int isascii(int c);
  15607.  
  15608.  
  15609. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15610.  
  15611. Language Level:  XPG4, Extension 
  15612.  
  15613. isascii tests if an integer is within the ASCII range.  This macro assumes that 
  15614. the system uses the ASCII character set. 
  15615.  
  15616. Note:  In earlier releases of VisualAge C++, isascii began with an underscore 
  15617. (_isascii). Because it is defined by the X/Open standard, the underscore has 
  15618. been removed. For compatibility, VisualAge for C++ will map _isascii to isascii 
  15619. for you. 
  15620.  
  15621. Return Value 
  15622. isascii returns a nonzero value if the integer is within the ASCII set, and 0 
  15623. if it is not. 
  15624.  
  15625.  
  15626. ΓòÉΓòÉΓòÉ <hidden> Example of isascii ΓòÉΓòÉΓòÉ
  15627.  
  15628. /************************************************************************
  15629.  
  15630. This example tests the integers from 0x7c to 0x82, and prints the corresponding 
  15631. ASCII character if the integer is within the ASCII range. 
  15632.  
  15633. ************************************************************************/
  15634.  
  15635. #include <stdio.h>
  15636. #include <ctype.h>
  15637.  
  15638. int main(void)
  15639. {
  15640.    int ch;
  15641.  
  15642.    for (ch = 0x7c; ch <= 0x82; ch++) {
  15643.       printf("%#04x    ", ch);
  15644.       if (isascii(ch))
  15645.          printf("The ASCII character is %c\n", ch);
  15646.       else
  15647.          printf("Not an ASCII character\n");
  15648.    }
  15649.    return 0;
  15650.  
  15651.    /****************************************************************************
  15652.       The output should be:
  15653.  
  15654.       0x7c    The ASCII character is |
  15655.       0x7d    The ASCII character is }
  15656.       0x7e    The ASCII character is ~
  15657.       0x7f    The ASCII character is 
  15658.       0x80    Not an ASCII character
  15659.       0x81    Not an ASCII character
  15660.       0x82    Not an ASCII character
  15661.    ****************************************************************************/
  15662. }
  15663.  
  15664.  
  15665. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15666.  
  15667. Example of isascii 
  15668.  
  15669.      isalnum to isxdigit - Test Integer Value 
  15670.      _iscsym - _iscsymf - Test Integer 
  15671.      iswalnum to iswxdigit - Test Wide Integer Value 
  15672.      _toascii - _tolower - _toupper - Convert Character 
  15673.      tolower() - toupper() - Convert Character Case 
  15674.      <ctype.h> 
  15675.  
  15676.  
  15677. ΓòÉΓòÉΓòÉ 4.151. isatty - Test Handle for Character Device ΓòÉΓòÉΓòÉ
  15678.  
  15679.  
  15680. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15681.  
  15682. #include <io.h>
  15683. int isatty(int handle);
  15684.  
  15685.  
  15686. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15687.  
  15688. Language Level:  XPG4, Extension 
  15689.  
  15690. isatty determines whether the given handle is associated with a character 
  15691. device (a keyboard, display, or printer or serial port). 
  15692.  
  15693. Note:  In earlier releases of VisualAge C++, isatty began with an underscore 
  15694. (_isatty). Because it is defined by the X/Open standard, the underscore has 
  15695. been removed. For compatibility, VisualAge for C++ will map _isatty to isatty 
  15696. for you. 
  15697.  
  15698. Return Value 
  15699. isatty returns a nonzero value if the device is a character device. Otherwise, 
  15700. the return value is 0. 
  15701.  
  15702.  
  15703. ΓòÉΓòÉΓòÉ <hidden> Example of isatty ΓòÉΓòÉΓòÉ
  15704.  
  15705. /************************************************************************
  15706.  
  15707. This example opens the console and determines if it is a character device: 
  15708.  
  15709. ************************************************************************/
  15710.  
  15711. #include <io.h>
  15712. #include <stdio.h>
  15713. #include <stdlib.h>
  15714.  
  15715. int main(void)
  15716. {
  15717.    int fh;
  15718.  
  15719.    if (-1 == (fh = fileno(stdin))) {
  15720.       perror("Error getting file handle from stdin.\n");
  15721.       return EXIT_FAILURE;
  15722.    }
  15723.  
  15724.    if (0 != isatty(fh))
  15725.       printf("stdin is a character device.\n");
  15726.    else
  15727.       printf("stdin is not a character device.\n");
  15728.  
  15729.    return 0;
  15730.  
  15731.    /****************************************************************************
  15732.       The output should be:
  15733.  
  15734.       stdin is a character device.
  15735.    ****************************************************************************/
  15736. }
  15737.  
  15738.  
  15739. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15740.  
  15741. Example of isatty 
  15742.  
  15743.      _inp - Read Byte from Input Port 
  15744.      _inpd - Read Doubleword from Input Port 
  15745.      _inpw - Read Unsigned Short from Input Port 
  15746.      _outp - Write Byte to Output Port 
  15747.      _outpd - Write Double Word to Output Port 
  15748.      _outpw - Write Word to Output Port 
  15749.      <io.h> 
  15750.  
  15751.  
  15752. ΓòÉΓòÉΓòÉ 4.152. isblank - Test for Blank Character Classification ΓòÉΓòÉΓòÉ
  15753.  
  15754.  
  15755. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15756.  
  15757. #include <ctype.h>
  15758. int isblank(int c);
  15759.  
  15760.  
  15761. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15762.  
  15763. Language Level:  Extension 
  15764.  
  15765. isblank tests whether the current LC_CTYPE locale category assigns c the blank 
  15766. character attribute. 
  15767.  
  15768. The value for c must be representable as an unsigned character, or EOF. 
  15769.  
  15770. In the "POSIX" and "C" locales, the tab and space characters have the blank 
  15771. attribute. 
  15772.  
  15773. Return Value 
  15774. isblank returns a nonzero value if the integer c has the blank attribute; 0 if 
  15775. it does not. 
  15776.  
  15777.  
  15778. ΓòÉΓòÉΓòÉ <hidden> Example of isblank ΓòÉΓòÉΓòÉ
  15779.  
  15780. /************************************************************************
  15781.  
  15782. This example tests if c is a blank type. 
  15783.  
  15784. ************************************************************************/
  15785.  
  15786. #include <ctype.h>
  15787. #include <locale.h>
  15788. #include <stdio.h>
  15789.  
  15790. void check(char c) {
  15791.    if ((' ' != c) && (isprint(c)))
  15792.       printf("  %c is ", c);
  15793.    else
  15794.       printf("x%02x is ", c);
  15795.    if (!isblank(c))
  15796.       printf("not ");
  15797.    puts("a blank type character");
  15798.    return;
  15799. }
  15800.  
  15801. int main(void)
  15802. {
  15803.    printf("In LC_CTYPE category of locale name \"%s\":\n",
  15804.           setlocale(LC_CTYPE, NULL));
  15805.    check('a');
  15806.    check(' ');
  15807.    check(0x00);
  15808.    check('\n');
  15809.    check('\t');
  15810.    return 0;
  15811.  
  15812.    /****************************************************************************
  15813.       The output should be similar to :
  15814.  
  15815.       In LC_CTYPE category of locale name "C":
  15816.         a is not a blank type character
  15817.       x20 is a blank type character
  15818.       x00 is not a blank type character
  15819.       x0a is not a blank type character
  15820.       x09 is a blank type character
  15821.    ****************************************************************************/
  15822. }
  15823.  
  15824.  
  15825. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15826.  
  15827. Example of isblank 
  15828.  
  15829.      isalnum to isxdigit - Test Integer Value 
  15830.      isascii - Test Integer Values 
  15831.      _iscsym - _iscsymf - Test Integer 
  15832.      iswalnum to iswxdigit - Test Wide Integer Value 
  15833.      iswblank - Test for Wide Blank Character Classification 
  15834.      setlocale - Set Locale 
  15835.      <ctype.h> 
  15836.  
  15837.  
  15838. ΓòÉΓòÉΓòÉ 4.153. _iscsym - _iscsymf - Test Integer ΓòÉΓòÉΓòÉ
  15839.  
  15840.  
  15841. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15842.  
  15843. #include <ctype.h>
  15844. int _iscsym(int c);
  15845. int _iscsymf(int c);
  15846.  
  15847.  
  15848. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15849.  
  15850. _iscsymf macro tests if a character is alphabetic or an underscore (_). 
  15851.  
  15852. Language Level:  Extension 
  15853.  
  15854. These macros test if an integer is within a particular ASCII set. The macros 
  15855. assume that the system uses the ASCII character set. 
  15856.  
  15857. _iscsym tests if a character is alphabetic, a digit, or an underscore (_). 
  15858. _iscsymf tests if a character is alphabetic or an underscore. 
  15859.  
  15860. Return Value 
  15861. _iscsym and _iscsymf return a nonzero value if the integer is within the ASCII 
  15862. set for which it tests, and 0 if it is not. 
  15863.  
  15864.  
  15865. ΓòÉΓòÉΓòÉ <hidden> Example of _iscsym - _iscsymf ΓòÉΓòÉΓòÉ
  15866.  
  15867. /************************************************************************
  15868.  
  15869. This example uses _iscsym and _iscsymf to test the characters a, _, and 1. If 
  15870. the character falls within the ASCII set tested for, the macro returns TRUE. 
  15871. Otherwise, it returns FALSE. 
  15872.  
  15873. ************************************************************************/
  15874.  
  15875. #include <stdio.h>
  15876. #include <ctype.h>
  15877.  
  15878. int main(void)
  15879. {
  15880.    int ch[3] =  { 'a','_','1' };
  15881.    int i;
  15882.  
  15883.    for (i = 0; i < 3; i++) {
  15884.       printf("_iscsym('%c') returns %s\n", ch[i], _iscsym(ch[i])?"TRUE":"FALSE");
  15885.       printf("_iscsymf('%c') returns %s\n\n", ch[i], _iscsymf(ch[i])?"TRUE":
  15886.          "FALSE");
  15887.    }
  15888.    return 0;
  15889.  
  15890.    /****************************************************************************
  15891.       The output should be:
  15892.  
  15893.       _iscsym('a') returns TRUE
  15894.       _iscsymf('a') returns TRUE
  15895.  
  15896.       _iscsym('_') returns TRUE
  15897.       _iscsymf('_') returns TRUE
  15898.  
  15899.       _iscsym('1') returns TRUE
  15900.       _iscsymf('1') returns FALSE
  15901.    ****************************************************************************/
  15902. }
  15903.  
  15904.  
  15905. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15906.  
  15907. Example of _iscsym - _iscsymf 
  15908.  
  15909.      isalnum to isxdigit - Test Integer Value 
  15910.      isascii - Test Integer Values 
  15911.      isblank - Test for Blank Character Classification 
  15912.      iswalnum to iswxdigit - Test Wide Integer Value 
  15913.      iswblank - Test for Wide Blank Character Classification 
  15914.      tolower() - toupper() - Convert Character Case 
  15915.      _toascii - _tolower - _toupper - Convert Character 
  15916.      <ctype.h> 
  15917.  
  15918.  
  15919. ΓòÉΓòÉΓòÉ 4.154. iswalnum to iswxdigit - Test Wide Integer Value ΓòÉΓòÉΓòÉ
  15920.  
  15921.  
  15922. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15923.  
  15924. #include <wctype.h>
  15925.                              /* test for:     */
  15926. int iswalnum(wint_t wc);  /* wide alphanumeric character */
  15927. int iswalpha(wint_t wc);  /* wide alphabetic character   */
  15928. int iswcntrl(wint_t wc);  /* wide control character      */
  15929. int iswdigit(wint_t wc);  /* wide decimal digit          */
  15930. int iswgraph(wint_t wc);  /* wide printable character, excluding space */
  15931. int iswlower(wint_t wc);  /* wide lowercase character    */
  15932. int iswprint(wint_t wc);  /* wide printable character, including space */
  15933. int iswpunct(wint_t wc);  /* wide punctuation character, excluding space */
  15934. int iswspace(wint_t wc);  /* wide whitespace character   */
  15935. int iswupper(wint_t wc);  /* wide uppercase character    */
  15936. int iswxdigit(wint_t wc); /* wide hexadecimal digit      */
  15937.  
  15938.  
  15939. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15940.  
  15941. Language Level:  ANSI 93, POSIX, XPG4 
  15942.  
  15943. These functions test a given wide integer value wc to determine whether it has 
  15944. a certain property as defined by the LC_CTYPE category of your current locale. 
  15945. The value of wc must be representable as a wint_t. 
  15946.  
  15947. The functions test for the following: 
  15948.  
  15949.  iswalnum 
  15950.     Wide alphanumeric character (upper- or lowercase letter, or decimal digit), 
  15951.     as defined in the locale source file in the alnum class of the LC_CTYPE 
  15952.     category of the current locale. 
  15953.  
  15954.  iswalpha 
  15955.     Wide alphabetic character, as defined in the locale source file in the 
  15956.     alpha class of the LC_CTYPE category of the current locale. 
  15957.  
  15958.  iswcntrl 
  15959.     Wide control character, as defined in the locale source file in the cntrl 
  15960.     class of the LC_CTYPE category of the current locale. 
  15961.  
  15962.  iswdigit 
  15963.     Wide decimal digit (0 through 9), as defined in the locale source file in 
  15964.     the digit class of the LC_CTYPE category of the current locale. 
  15965.  
  15966.  iswgraph 
  15967.     Wide printable character, excluding the space character, as defined in the 
  15968.     locale source file in the graph class of the LC_CTYPE category of the 
  15969.     current locale. 
  15970.  
  15971.  iswlower 
  15972.     Wide lowercase letter, as defined in the locale source file in the lower 
  15973.     class of the LC_CTYPE category of the current locale. 
  15974.  
  15975.  iswprint 
  15976.     Wide printable character, including the space character, as defined in the 
  15977.     locale source file in the print class of the LC_CTYPE category of the 
  15978.     current locale. 
  15979.  
  15980.  iswpunct 
  15981.     Wide non-alphanumeric printable character, excluding the space character, 
  15982.     as defined in the locale source file in the punct class of the LC_CTYPE 
  15983.     category of the current locale. 
  15984.  
  15985.  iswspace 
  15986.     Wide white-space character, as defined in the locale source file in the 
  15987.     space class of the LC_CTYPE category of the current locale. 
  15988.  
  15989.  iswupper 
  15990.     Wide uppercase letter, as defined in the locale source file in the upper 
  15991.     class of the LC_CTYPE category of the current locale. 
  15992.  
  15993.  iswxdigit 
  15994.     Wide hexadecimal digit (0 through 9, a through f, or A through F), as 
  15995.     defined in the locale source file in the xdigit class of the LC_CTYPE 
  15996.     category of the current locale. 
  15997.  You can redefine any character class in the LC_CTYPE category of the current 
  15998.  locale.  For more information, see "Introduction to Locales" in the 
  15999.  Programming Guide. 
  16000.  
  16001.  Return Value 
  16002.  These functions return a nonzero value if the wide integer satisfies the test 
  16003.  value; 0 if it does not. 
  16004.  
  16005.  
  16006. ΓòÉΓòÉΓòÉ <hidden> Example of iswalnum to iswxdigit ΓòÉΓòÉΓòÉ
  16007.  
  16008. /************************************************************************
  16009.  
  16010. This example analyzes all characters between 0x0 and 0xFF. The output of this 
  16011. example is a 256-line table showing the characters from 0 to 255, indicating 
  16012. whether they have the properties tested for. 
  16013.  
  16014. ************************************************************************/
  16015.  
  16016. #include <locale.h>
  16017. #include <stdlib.h>
  16018. #include <stdio.h>
  16019. #include <wctype.h>
  16020.  
  16021. #define UPPER_LIMIT   0xFF
  16022. #if (1 == __TOS_OS2__)
  16023.    #define LOCNAME "en_us.ibm-437"     /* OS/2 name        */
  16024. #else
  16025.    #define LOCNAME "en_us.ibm-1252"    /* Windows name     */
  16026. #endif
  16027.  
  16028. int main(void)
  16029. {
  16030.    wint_t wc;
  16031.  
  16032.    if (NULL == setlocale(LC_ALL, LOCNAME)) {
  16033.       printf("Locale \"%s\" could not be loaded\n", LOCNAME);
  16034.       exit(1);
  16035.    }
  16036.    for (wc = 0; wc <= UPPER_LIMIT; wc++) {
  16037.       printf("%#4x ", wc);
  16038.       printf("%c", iswprint(wc)  ? wc    : ' ');
  16039.       printf("%s", iswalnum(wc)  ? " AN" : "   ");
  16040.       printf("%s", iswalpha(wc)  ? " A " : "   ");
  16041.       printf("%s", iswcntrl(wc)  ? " C " : "   ");
  16042.       printf("%s", iswdigit(wc)  ? " D " : "   ");
  16043.       printf("%s", iswgraph(wc)  ? " G " : "   ");
  16044.       printf("%s", iswlower(wc)  ? " L " : "   ");
  16045.       printf("%s", iswpunct(wc)  ? " PU" : "   ");
  16046.       printf("%s", iswspace(wc)  ? " S " : "   ");
  16047.       printf("%s", iswprint(wc)  ? " PR" : "   ");
  16048.       printf("%s", iswupper(wc)  ? " U " : "   ");
  16049.       printf("%s", iswxdigit(wc) ? " H " : "   ");
  16050.       putchar('\n');
  16051.    }
  16052.    return 0;
  16053.  
  16054.    /****************************************************************************
  16055.       The output should be similar to :
  16056.       :
  16057.       0x20                        S  PR
  16058.       0x21 !             G     PU    PR
  16059.       0x22 "             G     PU    PR
  16060.       0x23 #             G     PU    PR
  16061.       0x24 $             G     PU    PR
  16062.       0x25 %             G     PU    PR
  16063.       0x26 &             G     PU    PR
  16064.       0x27 '             G     PU    PR
  16065.       0x28 (             G     PU    PR
  16066.       0x29 )             G     PU    PR
  16067.       0x2a *             G     PU    PR
  16068.       0x2b +             G     PU    PR
  16069.       0x2c ,             G     PU    PR
  16070.       0x2d -             G     PU    PR
  16071.       0x2e .             G     PU    PR
  16072.       0x2f /             G     PU    PR
  16073.       0x30 0 AN       D  G           PR    H
  16074.       0x31 1 AN       D  G           PR    H
  16075.       0x32 2 AN       D  G           PR    H
  16076.       0x33 3 AN       D  G           PR    H
  16077.       0x34 4 AN       D  G           PR    H
  16078.       0x35 5 AN       D  G           PR    H
  16079.       0x36 6 AN       D  G           PR    H
  16080.       0x37 7 AN       D  G           PR    H
  16081.       0x38 8 AN       D  G           PR    H
  16082.       0x39 9 AN       D  G           PR    H
  16083.       :
  16084.    ****************************************************************************/
  16085. }
  16086.  
  16087.  
  16088. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16089.  
  16090. Example of iswalnum to iswxdigit 
  16091.  
  16092.      isalnum to isxdigit - Test Integer Value 
  16093.      isascii - Test Integer Values 
  16094.      isblank - Test for Blank Character Classification 
  16095.      _iscsym - _iscsymf - Test Integer 
  16096.      iswblank - Test for Wide Blank Character Classification 
  16097.      iswctype - Test for Character Property 
  16098.      <wctype.h> 
  16099.  
  16100.  
  16101. ΓòÉΓòÉΓòÉ 4.155. iswblank - Test for Wide Blank Character Classification ΓòÉΓòÉΓòÉ
  16102.  
  16103.  
  16104. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16105.  
  16106. #include <wctype.h>
  16107. int iswblank(wint_t wc);
  16108.  
  16109.  
  16110. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16111.  
  16112. Language Level:  Extension 
  16113.  
  16114. iswblank tests whether the current LC_CTYPE locale category assigns the the 
  16115. blank character attribute to the wide character wc. 
  16116.  
  16117. The value for wc must be representable as a wchar_t, or WEOF. 
  16118.  
  16119. The behavior of iswblank is affected by the LC_CTYPE category of the current 
  16120. locale. 
  16121.  
  16122. In the "POSIX" and "C" locales, the tab and space characters have the blank 
  16123. attribute. 
  16124.  
  16125. Return Value 
  16126. iswblank returns a nonzero value if wc has the blank attribute; 0 if it does 
  16127. not. 
  16128.  
  16129.  
  16130. ΓòÉΓòÉΓòÉ <hidden> Example of iswblank ΓòÉΓòÉΓòÉ
  16131.  
  16132. /************************************************************************
  16133.  
  16134. This example tests whether wc is a blank type. 
  16135.  
  16136. ************************************************************************/
  16137.  
  16138. #include <stdio.h>
  16139. #include <wctype.h>
  16140. #include <wchar.h>
  16141. #include <locale.h>
  16142.  
  16143. void check(wchar_t wc) {
  16144.    if ((' ' != wc) && (iswprint(wc)))
  16145.       printf("  %lc is ", wc);
  16146.    else
  16147.       printf("x%02x is ", wc);
  16148.    if (!iswblank(wc))
  16149.       printf("not ");
  16150.    puts("a blank type character");
  16151.    return;
  16152. }
  16153.  
  16154. int main(void)
  16155. {
  16156.    printf("In LC_CTYPE category of locale name \"%s\":\n",
  16157.           setlocale(LC_CTYPE, NULL));
  16158.    check(L'a');
  16159.    check(L' ');
  16160.    check(0x00);
  16161.    check(L'\n');
  16162.    check(L'\t');
  16163.    return 0;
  16164.  
  16165.    /****************************************************************************
  16166.       The output should be similar to :
  16167.  
  16168.       In LC_CTYPE category of locale name "C":
  16169.         a is not a blank type character
  16170.       x20 is a blank type character
  16171.       x00 is not a blank type character
  16172.       x0a is not a blank type character
  16173.       x09 is a blank type character
  16174.    ****************************************************************************/
  16175. }
  16176.  
  16177.  
  16178. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16179.  
  16180. Example of iswblank 
  16181.  
  16182.      isalnum to isxdigit - Test Integer Value 
  16183.      isascii - Test Integer Values 
  16184.      isblank - Test for Blank Character Classification 
  16185.      _iscsym - _iscsymf - Test Integer 
  16186.      iswalnum to iswxdigit - Test Wide Integer Value 
  16187.      iswctype - Test for Character Property 
  16188.      <wctype.h> 
  16189.  
  16190.  
  16191. ΓòÉΓòÉΓòÉ 4.156. iswctype - Test for Character Property ΓòÉΓòÉΓòÉ
  16192.  
  16193.  
  16194. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16195.  
  16196. #include <wctype.h>
  16197. int iswctype(wint_t wc, wctype_t wc_prop);
  16198.  
  16199.  
  16200. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16201.  
  16202. Language Level:  ANSI 93, XPG4 
  16203.  
  16204. iswctype determines whether the wide character wc has the property wc_prop. It 
  16205. is similar in function to the iswalnum through isxdigit functions, but with 
  16206. iswctype you can specify the property to check for, or check for a property 
  16207. other than the standard ones. 
  16208.  
  16209. You must obtain the wc_prop value from a call to wctype.  If you do not, or if 
  16210. the LC_CTYPE category of the locale was modified after you called wctype, the 
  16211. behavior of iswctype is undefined. 
  16212.  
  16213. The value of wc must be representable as an unsigned wchar_t, or WEOF. 
  16214.  
  16215. The following strings correspond to the standard (basic) character classes or 
  16216. properties: 
  16217.  
  16218. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  16219. Γöé "         Γöé "         Γöé "         Γöé "         Γöé
  16220. Γöé "alnum"      Γöé "cntrl"      Γöé "lower"      Γöé "space"      Γöé
  16221. Γöé "alpha"      Γöé "digit"      Γöé "print"      Γöé "upper"      Γöé
  16222. Γöé "blank" "     Γöé "graph" "     Γöé "punct" "     Γöé "xdigit" "    Γöé
  16223. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  16224.  
  16225. The following shows calls to wctype and indicates the equivalent isw* function: 
  16226.  
  16227. iswctype(wc, wctype("alnum"));   /* iswalnum(wc);  */
  16228. iswctype(wc, wctype("alpha"));   /* iswalpha(wc);  */
  16229. iswctype(wc, wctype("blank"));   /* iswblank(wc);  */
  16230. iswctype(wc, wctype("cntrl"));   /* iswcntrl(wc);  */
  16231. iswctype(wc, wctype("digit"));   /* iswdigit(wc);  */
  16232. iswctype(wc, wctype("graph"));   /* iswgraph(wc);  */
  16233. iswctype(wc, wctype("lower"));   /* iswlower(wc);  */
  16234. iswctype(wc, wctype("print"));   /* iswprint(wc);  */
  16235. iswctype(wc, wctype("punct"));   /* iswpunct(wc);  */
  16236. iswctype(wc, wctype("space"));   /* iswspace(wc);  */
  16237. iswctype(wc, wctype("upper"));   /* iswupper(wc);  */
  16238. iswctype(wc, wctype("xdigit"));  /* iswxdigit(wc); */
  16239.  
  16240. Return Value 
  16241. iswctype returns a nonzero value if the wide character has the property tested 
  16242. for. If the value for wc or wc_prop is not valid, the behavior is undefined. 
  16243.  
  16244.  
  16245. ΓòÉΓòÉΓòÉ <hidden> Example of iswctype ΓòÉΓòÉΓòÉ
  16246.  
  16247. /************************************************************************
  16248.  
  16249. This example analyzes all characters between 0x0 and 0xFF. The output of this 
  16250. example is a 256-line table showing the characters from 0 to 255, indicating 
  16251. whether they have the properties tested for. 
  16252.  
  16253. ************************************************************************/
  16254.  
  16255. #include <locale.h>
  16256. #include <stdlib.h>
  16257. #include <stdio.h>
  16258. #include <wctype.h>
  16259.  
  16260. #define UPPER_LIMIT   0xFF
  16261. #if (1 == __TOS_OS2__)
  16262.    #define LOCNAME "en_us.ibm-437"     /* OS/2 name        */
  16263. #else
  16264.    #define LOCNAME "en_us.ibm-1252"    /* Windows name     */
  16265. #endif
  16266.  
  16267. int main(void)
  16268. {
  16269.    wint_t wc;
  16270.  
  16271.    if (NULL == setlocale(LC_ALL, LOCNAME)) {
  16272.       printf("Locale \"%s\" could not be loaded\n", LOCNAME);
  16273.       exit(1);
  16274.    }
  16275.    for (wc = 0; wc <= UPPER_LIMIT; wc++) {
  16276.       printf("%#4x ", wc);
  16277.       printf("%c", iswctype(wc, wctype("print"))  ? wc    : ' ');
  16278.       printf("%s", iswctype(wc, wctype("alnum"))  ? " AN" : "   ");
  16279.       printf("%s", iswctype(wc, wctype("alpha"))  ? " A " : "   ");
  16280.       printf("%s", iswctype(wc, wctype("blank"))  ? " B " : "   ");
  16281.       printf("%s", iswctype(wc, wctype("cntrl"))  ? " C " : "   ");
  16282.       printf("%s", iswctype(wc, wctype("digit"))  ? " D " : "   ");
  16283.       printf("%s", iswctype(wc, wctype("graph"))  ? " G " : "   ");
  16284.       printf("%s", iswctype(wc, wctype("lower"))  ? " L " : "   ");
  16285.       printf("%s", iswctype(wc, wctype("punct"))  ? " PU" : "   ");
  16286.       printf("%s", iswctype(wc, wctype("space"))  ? " S " : "   ");
  16287.       printf("%s", iswctype(wc, wctype("print"))  ? " PR" : "   ");
  16288.       printf("%s", iswctype(wc, wctype("upper"))  ? " U " : "   ");
  16289.       printf("%s", iswctype(wc, wctype("xdigit")) ? " H " : "   ");
  16290.       putchar('\n');
  16291.    }
  16292.    return 0;
  16293.  
  16294.    /****************************************************************************
  16295.       The output should be similar to :
  16296.          .
  16297.          .
  16298.       0x1e            C
  16299.       0x1f            C
  16300.       0x20         B                 S  PR
  16301.       0x21 !                G     PU    PR
  16302.       0x22 "                G     PU    PR
  16303.       0x23 #                G     PU    PR
  16304.       0x24 $                G     PU    PR
  16305.       0x25 %                G     PU    PR
  16306.          .
  16307.          .
  16308.       0x30 0 AN          D  G           PR    H
  16309.       0x31 1 AN          D  G           PR    H
  16310.       0x32 2 AN          D  G           PR    H
  16311.       0x33 3 AN          D  G           PR    H
  16312.       0x34 4 AN          D  G           PR    H
  16313.       0x35 5 AN          D  G           PR    H
  16314.          .
  16315.          .
  16316.       0x43 C AN A           G           PR U  H
  16317.       0x44 D AN A           G           PR U  H
  16318.       0x45 E AN A           G           PR U  H
  16319.       0x46 F AN A           G           PR U  H
  16320.       0x47 G AN A           G           PR U
  16321.          .
  16322.          .
  16323.    ****************************************************************************/
  16324. }
  16325.  
  16326.  
  16327. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16328.  
  16329. Example of iswctype 
  16330.  
  16331.      isalnum to isxdigit - Test Integer Value 
  16332.      isascii - Test Integer Values 
  16333.      isblank - Test for Blank Character Classification 
  16334.      _iscsym - _iscsymf - Test Integer 
  16335.      iswalnum to iswxdigit - Test Wide Integer Value 
  16336.      iswblank - Test for Wide Blank Character Classification 
  16337.      iswalnum to iswxdigit - Test Wide Integer Value 
  16338.      wctype - Get Handle for Character Property Classification 
  16339.      <wctype.h> 
  16340.  
  16341.  
  16342. ΓòÉΓòÉΓòÉ 4.157. _itoa - Convert Integer to String ΓòÉΓòÉΓòÉ
  16343.  
  16344.  
  16345. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16346.  
  16347. #include <stdlib.h>
  16348. char *_itoa(int value, char * string, int radix);
  16349.  
  16350.  
  16351. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16352.  
  16353. Language Level:  Extension 
  16354.  
  16355. _itoa converts the digits of the given value to a character string that ends 
  16356. with a null character and stores the result in string. The radix argument 
  16357. specifies the base of value; it must be in the range 2 to 36. If radix equals 
  16358. 10 and value is negative, the first character of the stored string is the minus 
  16359. sign (-). 
  16360.  
  16361. Note:  The space reserved for string must be large enough to hold the returned 
  16362. string. The function can return up to 33 bytes including the null character 
  16363. (\0). 
  16364.  
  16365. Return Value 
  16366. _itoa returns a pointer to string. There is no error return value. 
  16367.  
  16368.  
  16369. ΓòÉΓòÉΓòÉ <hidden> Example of _itoa ΓòÉΓòÉΓòÉ
  16370.  
  16371. /************************************************************************
  16372.  
  16373. This example converts the integer value -255 to a decimal, a binary, and a hex 
  16374. number, storing its character representation in the array buffer. 
  16375.  
  16376. ************************************************************************/
  16377.  
  16378. #include <stdio.h>
  16379. #include <stdlib.h>
  16380.  
  16381. int main(void)
  16382. {
  16383.    char buffer[35];
  16384.    char *p;
  16385.  
  16386.    p = _itoa(-255, buffer, 10);
  16387.    printf("The result of _itoa(-255) with radix of 10 is %s\n", p);
  16388.    p = _itoa(-255, buffer, 2);
  16389.    printf("The result of _itoa(-255) with radix of 2\n    is %s\n", p);
  16390.    p = _itoa(-255, buffer, 16);
  16391.    printf("The result of _itoa(-255) with radix of 16 is %s\n", p);
  16392.    return 0;
  16393.  
  16394.    /****************************************************************************
  16395.       The output should be:
  16396.  
  16397.       The result of _itoa(-255) with radix of 10 is -255
  16398.       The result of _itoa(-255) with radix of 2
  16399.           is 11111111111111111111111100000001
  16400.       The result of _itoa(-255) with radix of 16 is ffffff01
  16401.    ****************************************************************************/
  16402. }
  16403.  
  16404.  
  16405. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16406.  
  16407. Example of _itoa 
  16408.  
  16409.      _ecvt - Convert Floating-Point to Character 
  16410.      _fcvt - Convert Floating-Point to String 
  16411.      _gcvt - Convert Floating-Point to String 
  16412.      _ltoa - Convert Long Integer to String 
  16413.      _ultoa - Convert Unsigned Long Integer to String 
  16414.      <stdlib.h> 
  16415.  
  16416.  
  16417. ΓòÉΓòÉΓòÉ 4.158. _kbhit - Test for Keystroke ΓòÉΓòÉΓòÉ
  16418.  
  16419.  
  16420. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16421.  
  16422. include <conio.h>
  16423. int _kbhit(void);
  16424.  
  16425.  
  16426. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16427.  
  16428. Language Level:  Extension 
  16429.  
  16430. _kbhit tests if a key has been pressed on the keyboard.  If the result is 
  16431. nonzero, a keystroke is waiting in the buffer. You can read in the keystroke 
  16432. using the _getch or _getche function. By calling _kbhit prior to calling _getch 
  16433. or _getche, you can prevent your program from waiting for a keyboard input. 
  16434.  
  16435. Return Value 
  16436. _kbhit returns a nonzero value if a key has been pressed. Otherwise, it returns 
  16437. 0. 
  16438.  
  16439.  
  16440. ΓòÉΓòÉΓòÉ <hidden> Example of _kbhit ΓòÉΓòÉΓòÉ
  16441.  
  16442. /************************************************************************
  16443.  
  16444. This example uses _kbhit to test for the pressing of a key on the keyboard and 
  16445. to print a statement with the test result. 
  16446.  
  16447. ************************************************************************/
  16448.  
  16449. #include <conio.h>
  16450. #include <stdio.h>
  16451.  
  16452. int main(void)
  16453. {
  16454.    int ch;
  16455.  
  16456.    printf("Type in some letters.\n");
  16457.    printf("If you type in an 'x', the program ends.\n");
  16458.  
  16459.    for ( ; ; ) {
  16460.       while (0 == _kbhit()) {
  16461.       /* Processing without waiting for a key to be pressed */
  16462.       }
  16463.  
  16464.       ch = _getch();
  16465.       printf("You have pressed the '%c' key.\n", ch);
  16466.  
  16467.       if ('x' == ch)
  16468.          break;
  16469.    }
  16470.    return 0;
  16471.  
  16472.    /****************************************************************************
  16473.       The output should be similar to:
  16474.  
  16475.       Type in some letters.
  16476.       If you type in an 'x', the program ends.
  16477.       You have pressed the 'f' key.
  16478.       You have pressed the 'e' key.
  16479.       You have pressed the 'l' key.
  16480.       You have pressed the 'i' key.
  16481.       You have pressed the 'x' key.
  16482.    ****************************************************************************/
  16483. }
  16484.  
  16485.  
  16486. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16487.  
  16488. Example of _kbhit 
  16489.  
  16490.      _getch - _getche - Read Character from Keyboard 
  16491.      <conio.h> 
  16492.  
  16493.  
  16494. ΓòÉΓòÉΓòÉ 4.159. labs - Calculate Absolute Value of Long Integer ΓòÉΓòÉΓòÉ
  16495.  
  16496.  
  16497. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16498.  
  16499. #include <stdlib.h>
  16500. long int labs(long int n);
  16501.  
  16502.  
  16503. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16504.  
  16505. Language Level:  ANSI, SAA, XPG4 
  16506.  
  16507. labs produces the absolute value of its long integer argument n. The result may 
  16508. be undefined when the argument is equal to LONG_MIN, the smallest available 
  16509. long integer (-2 147 483 647). The value LONG_MIN is defined in the <limits.h> 
  16510. include file. 
  16511.  
  16512. Return Value 
  16513. labs returns the absolute value of n. There is no error return value. 
  16514.  
  16515.  
  16516. ΓòÉΓòÉΓòÉ <hidden> Example of labs ΓòÉΓòÉΓòÉ
  16517.  
  16518. /************************************************************************
  16519.  
  16520. This example computes y as the absolute value of the long integer -41567. 
  16521.  
  16522. ************************************************************************/
  16523.  
  16524. #include <stdio.h>
  16525. #include <stdlib.h>
  16526.  
  16527. int main(void)
  16528. {
  16529.    long x,y;
  16530.  
  16531.    x = -41567L;
  16532.    y = labs(x);
  16533.    printf("The absolute value of %ld is %ld\n", x, y);
  16534.    return 0;
  16535.  
  16536.    /****************************************************************************
  16537.       The output should be:
  16538.  
  16539.       The absolute value of -41567 is 41567
  16540.    ****************************************************************************/
  16541. }
  16542.  
  16543.  
  16544. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16545.  
  16546. Example of labs 
  16547.  
  16548.      abs - Calculate Integer Absolute Value 
  16549.      _cabs - Calculate Absolute Value of Complex Number 
  16550.      fabs - Calculate Floating-Point Absolute Value 
  16551.      <limits.h> 
  16552.      llabs - Calculate Absolute Value of Long Long Integer 
  16553.  
  16554.  
  16555. ΓòÉΓòÉΓòÉ 4.160. ldexp - Multiply by a Power of Two ΓòÉΓòÉΓòÉ
  16556.  
  16557.  
  16558. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16559.  
  16560. #include <math.h>
  16561. double ldexp(double x, int exp);
  16562.  
  16563.  
  16564. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16565.  
  16566. Language Level: ANSI, SAA, POSIX, XPG4 
  16567.  
  16568. ldexp calculates the value of x * (2**exp). 
  16569.  
  16570. Return Value 
  16571. ldexp returns the resulting value. If an overflow results, the function returns 
  16572. +HUGE_VAL for a positive result or -HUGE_VAL for a negative result, and sets 
  16573. errno to ERANGE. 
  16574.  
  16575.  
  16576. ΓòÉΓòÉΓòÉ <hidden> Example of ldexp ΓòÉΓòÉΓòÉ
  16577.  
  16578. /************************************************************************
  16579.  
  16580. This example computes y as 1.5 times 2 to the fifth power (1.5 * (2**5)): 
  16581.  
  16582. ************************************************************************/
  16583.  
  16584. #include <stdio.h>
  16585. #include <math.h>
  16586.  
  16587. int main(void)
  16588. {
  16589.    double x,y;
  16590.    int p;
  16591.  
  16592.    x = 1.5;
  16593.    p = 5;
  16594.    y = ldexp(x, p);
  16595.    printf("%lf times 2 to the power of %d is %lf\n", x, p, y);
  16596.    return 0;
  16597.  
  16598.    /****************************************************************************
  16599.       The output should be:
  16600.  
  16601.       1.500000 times 2 to the power of 5 is 48.000000
  16602.    ****************************************************************************/
  16603. }
  16604.  
  16605.  
  16606. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16607.  
  16608. Example of ldexp 
  16609.  
  16610.      exp - Calculate Exponential Function 
  16611.      frexp - Separate Floating-Point Value 
  16612.      modf - Separate Floating-Point Value 
  16613.      <math.h> 
  16614.  
  16615.  
  16616. ΓòÉΓòÉΓòÉ 4.161. ldiv - Perform Long Division ΓòÉΓòÉΓòÉ
  16617.  
  16618.  
  16619. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16620.  
  16621. #include <stdlib.h>
  16622. ldiv_t ldiv(long int numerator, long int denominator);
  16623.  
  16624.  
  16625. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16626.  
  16627. Language Level: ANSI, SAA, XPG4 
  16628.  
  16629. ldiv calculates the quotient and remainder of the division of numerator by 
  16630. denominator. 
  16631.  
  16632. Return Value 
  16633. ldiv returns a structure of type ldiv_t, containing both the quotient (long int 
  16634. quot) and the remainder (long int rem).  If the value cannot be represented, 
  16635. the return value is undefined. If denominator is 0, an exception is raised. 
  16636.  
  16637.  
  16638. ΓòÉΓòÉΓòÉ <hidden> Example of ldiv ΓòÉΓòÉΓòÉ
  16639.  
  16640. /************************************************************************
  16641.  
  16642. This example uses ldiv to calculate the quotients and remainders for a set of 
  16643. two dividends and two divisors. 
  16644.  
  16645. ************************************************************************/
  16646.  
  16647. #include <stdio.h>
  16648. #include <stdlib.h>
  16649.  
  16650. int main(void)
  16651. {
  16652.    long int num[2] =  { 45,-45 };
  16653.    long int den[2] =  { 7,-7 };
  16654.    ldiv_t ans;       /* ldiv_t is a struct type containing two long ints:
  16655.                         'quot' stores quotient; 'rem' stores remainder  */
  16656.    short i,j;
  16657.  
  16658.    printf("Results of long division:\n");
  16659.    for (i = 0; i < 2; i++)
  16660.       for (j = 0; j < 2; j++) {
  16661.          ans = ldiv(num[i], den[j]);
  16662.          printf("Dividend: %6ld  Divisor: %6ld", num[i], den[j]);
  16663.          printf("  Quotient: %6ld  Remainder: %6ld\n", ans.quot, ans.rem);
  16664.       }
  16665.    return 0;
  16666.  
  16667.    /****************************************************************************
  16668.       The output should be:
  16669.  
  16670.       Results of long division:
  16671.       Dividend:  45  Divisor:   7  Quotient:   6  Remainder:   3
  16672.       Dividend:  45  Divisor:  -7  Quotient:  -6  Remainder:   3
  16673.       Dividend: -45  Divisor:   7  Quotient:  -6  Remainder:  -3
  16674.       Dividend: -45  Divisor:  -7  Quotient:   6  Remainder:  -3
  16675.    ****************************************************************************/
  16676. }
  16677.  
  16678.  
  16679. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16680.  
  16681. Example of ldiv 
  16682.  
  16683.      div  - Calculate Quotient and Remainder 
  16684.      lldiv - Perform Long Long Division 
  16685.      <stdlib.h> 
  16686.  
  16687.  
  16688. ΓòÉΓòÉΓòÉ 4.162. lfind - lsearch - Find Key in Array ΓòÉΓòÉΓòÉ
  16689.  
  16690.  
  16691. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16692.  
  16693. #include <search.h>
  16694. char *lfind(char *search_key, char *base,
  16695.              unsigned int *num, unsigned int *width,
  16696.              int (*compare)(const void *key, const void *element));
  16697. char *lsearch(char *search_key, char *base,
  16698.                unsigned int *num, unsigned int *width,
  16699.                int (*compare)(const void *key, const void *element));
  16700.  
  16701.  
  16702. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16703.  
  16704. Language Level:  XPG4, Extension 
  16705.  
  16706. lfind and lsearch perform a linear search for the value search_key in an array 
  16707. of num elements, each of width bytes in size. The argument base points to the 
  16708. base of the array to be searched. If lsearch does not find the search_key, it 
  16709. adds the search_key to the end of the array and increments num by one. If lfind 
  16710. does not find the search_key, it does not add the search_key to the array. 
  16711.  
  16712. Unlike bsearch, lsearch and lfind do not require that you sort the array first. 
  16713. points to the base of the array to be searched. 
  16714.  
  16715. The compare argument is a pointer to a function you must supply that takes a 
  16716. pointer to the key argument and to an array element, in that order. Both lfind 
  16717. and lsearch call this function one or more times during the search. The 
  16718. function must compare the key and the element and return one of the following 
  16719. values: 
  16720.  
  16721.  Value             Meaning 
  16722.  Nonzero           key and element are different. 
  16723.  0                 key and element are identical. 
  16724.  
  16725.  Note:  In earlier releases of VisualAge C++, lfind and lsearch began with an 
  16726.  underscore (_lfind and _lsearch). Because they are defined by the X/Open 
  16727.  standard, the underscore has been removed. For compatibility, VisualAge for 
  16728.  C++ will map _lfind and _lsearch to lfind and lsearch for you. 
  16729.  
  16730.  Return Value 
  16731.  
  16732.  If search_key is found, both lsearch and lfind return a pointer to that 
  16733.  element of the array to which base points. If search_key is not found, lsearch 
  16734.  returns a pointer to a newly added item at the end of the array, while lfind 
  16735.  returns NULL. 
  16736.  
  16737.  
  16738. ΓòÉΓòÉΓòÉ <hidden> Example of lfind ΓòÉΓòÉΓòÉ
  16739.  
  16740. /************************************************************************
  16741.  
  16742. This example uses lfind to search for the keyword PATH in the command-line 
  16743. arguments. 
  16744.  
  16745. ************************************************************************/
  16746.  
  16747. #include <search.h>
  16748. #include <string.h>
  16749. #include <stdio.h>
  16750.  
  16751. #define  CNT           2
  16752.  
  16753. /* Note: Library always calls functions internally with _Optlink              */
  16754. /*       linkage convention.  Ensure that compare() is always                 */
  16755. /*       _Optlink.                                                            */
  16756.  
  16757. int _Optlink compare(const void *arg1,const void *arg2)
  16758. {
  16759.    return (strncmp(*(char **)arg1, *(char **)arg2, strlen(*(char **)arg1)));
  16760. }
  16761.  
  16762. int main(void)
  16763. {
  16764.    char **result;
  16765.    char *key = "PATH";
  16766.    unsigned int num = CNT;
  16767.    char *string[CNT] =  {
  16768.       "PATH = d:\\david\\matthew\\heather\\ed\\simon","LIB = PATH\\abc" };
  16769.  
  16770.    /* The following statement finds the argument that starts with "PATH"      */
  16771.  
  16772.    if ((result = (char **)lfind((char *)&key, (char *)string, &num,
  16773.                   sizeof(char *), compare)) != NULL)
  16774.       printf("%s found\n", *result);
  16775.    else
  16776.       printf("PATH not found \n");
  16777.    return 0;
  16778.  
  16779.    /****************************************************************************
  16780.       The output should be:
  16781.  
  16782.       PATH = d:\david\matthew\heather\ed\simon found
  16783.    ****************************************************************************/
  16784. }
  16785.  
  16786.  
  16787. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16788.  
  16789. Example of lfind 
  16790.  
  16791.      bsearch - Search Arrays 
  16792.      qsort - Sort Array 
  16793.      <search.h> 
  16794.  
  16795.  
  16796. ΓòÉΓòÉΓòÉ 4.163. llabs - Calculate Absolute Value of Long Long Integer ΓòÉΓòÉΓòÉ
  16797.  
  16798.  
  16799. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16800.  
  16801. #include <stdlib.h>
  16802. long long int llabs(long long int n);
  16803.  
  16804.  
  16805. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16806.  
  16807. Language Level: Extension 
  16808.  
  16809. llabs produces the absolute value of its long long integer argument n. The 
  16810. result may be undefined when the argument is equal to LONGLONG_MIN, the 
  16811. smallest available long long integer (-9 223 372 036 854 775 808). The value 
  16812. LONGLONG_MIN is defined in the <limits.h> include file. 
  16813.  
  16814. Return Value 
  16815. llabs returns the absolute value of n. There is no error return value. 
  16816.  
  16817.  
  16818. ΓòÉΓòÉΓòÉ <hidden> Example of llabs ΓòÉΓòÉΓòÉ
  16819.  
  16820. /************************************************************************
  16821.  
  16822. This example computes y as the absolute value of the long long integer -41567. 
  16823.  
  16824. ************************************************************************/
  16825.  
  16826. #include <stdio.h>
  16827. #include <stdlib.h>
  16828.  
  16829. int main(void)
  16830. {
  16831.    long long x,y;
  16832.  
  16833.    x = -41567L;
  16834.    y = llabs(x);
  16835.    printf("The absolute value of %lld is %lld\n", x, y);
  16836.    return 0;
  16837.  
  16838.    /****************************************************************************
  16839.       The output should be:
  16840.  
  16841.       The absolute value of -41567 is 41567
  16842.    ****************************************************************************/
  16843. }
  16844.  
  16845.  
  16846. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16847.  
  16848. Example of llabs 
  16849.  
  16850.      abs - Calculate Integer Absolute Value 
  16851.      fabs - Calculate Floating-Point Absolute Value 
  16852.      labs - Calculate Absolute Value of Long Integer 
  16853.      <limits.h> 
  16854.  
  16855.  
  16856. ΓòÉΓòÉΓòÉ 4.164. lldiv - Perform Long Long Division ΓòÉΓòÉΓòÉ
  16857.  
  16858.  
  16859. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16860.  
  16861. #include <stdlib.h>
  16862. lldiv_t lldiv(long long int numerator, long long int denominator);
  16863.  
  16864.  
  16865. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16866.  
  16867. Language Level: Extension 
  16868.  
  16869. lldiv calculates the quotient and remainder of the division of numerator by 
  16870. denominator. 
  16871.  
  16872. Return Value 
  16873. lldiv returns a structure of type lldiv_t, containing both the quotient (long 
  16874. long int quot) and the remainder (long long int rem).  If the value cannot be 
  16875. represented, the return value is undefined. If denominator is 0, an exception 
  16876. is raised. 
  16877.  
  16878.  
  16879. ΓòÉΓòÉΓòÉ <hidden> Example of lldiv ΓòÉΓòÉΓòÉ
  16880.  
  16881. /************************************************************************
  16882.  
  16883. This example uses lldiv to calculate the quotients and remainders for a set of 
  16884. two dividends and two divisors. 
  16885.  
  16886. ************************************************************************/
  16887.  
  16888. #include <stdio.h>
  16889. #include <stdlib.h>
  16890.  
  16891. int main(void)
  16892. {
  16893.    long long int num[2] =  { 45,-45 };
  16894.    long long int den[2] =  { 7,-7 };
  16895.    lldiv_t ans;       /* lldiv_t is a struct type containing two long long ints:
  16896.                          'quot' stores quotient; 'rem' stores remainder  */
  16897.    short i,j;
  16898.  
  16899.    printf("Results of long long division:\n");
  16900.    for (i = 0; i < 2; i++)
  16901.       for (j = 0; j < 2; j++) {
  16902.          ans = lldiv(num[i], den[j]);
  16903.          printf("Dividend: %4lld   Divisor: %4lld   Quotient: %4lld   "
  16904.                 "Remainder: %4lld\n", num[i], den[j], ans.quot, ans.rem);
  16905.       }
  16906.    return 0;
  16907.  
  16908.    /****************************************************************************
  16909.       The output should be:
  16910.  
  16911.       Results of long long division:
  16912.       Dividend:   45   Divisor:    7   Quotient:    6   Remainder:    3
  16913.       Dividend:   45   Divisor:   -7   Quotient:   -6   Remainder:    3
  16914.       Dividend:  -45   Divisor:    7   Quotient:   -6   Remainder:   -3
  16915.       Dividend:  -45   Divisor:   -7   Quotient:    6   Remainder:   -3
  16916.    ****************************************************************************/
  16917. }
  16918.  
  16919.  
  16920. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16921.  
  16922. Example of lldiv 
  16923.  
  16924.      div  - Calculate Quotient and Remainder 
  16925.      ldiv - Perform Long Division 
  16926.      <stdlib.h> 
  16927.  
  16928.  
  16929. ΓòÉΓòÉΓòÉ 4.165. _llrotl - _llrotr - Rotate Bits of Unsigned Long Long Integer ΓòÉΓòÉΓòÉ
  16930.  
  16931.  
  16932. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16933.  
  16934. #include <stdlib.h>   /* also in <builtin.h> */
  16935. unsigned long long _llrotl(unsigned long long value, int shift);
  16936. unsigned long long _llrotr(unsigned long long value, int shift);
  16937.  
  16938.  
  16939. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16940.  
  16941. Language Level: Extension 
  16942.  
  16943. These functions take a 8-byte unsigned (long long) integer value and rotate it 
  16944. by shift bits. _llrotl. rotates to the left, and _llrotr. to the right. 
  16945.  
  16946. Note:  Both _llrotl and _llrotr are built-in functions, which means they are 
  16947. implemented as inline instructions and have no backing code in the library. For 
  16948. this reason: 
  16949.  
  16950.      You cannot take the address of these functions. 
  16951.      You cannot parenthesize a call to either function. (Parentheses specify a 
  16952.       call to the backing code for the function in the runtime library.) 
  16953.  
  16954.  Return Value 
  16955.  Both functions return the rotated value.  There is no error return. 
  16956.  
  16957.  
  16958. ΓòÉΓòÉΓòÉ <hidden> Example of _llrotl - _llrotr ΓòÉΓòÉΓòÉ
  16959.  
  16960. /************************************************************************
  16961.  
  16962. This example uses _llrotr and _llrotl with different shift values to rotate the 
  16963. integer value 0x01234567: 
  16964.  
  16965. ************************************************************************/
  16966.  
  16967. #include <stdio.h>
  16968. #include <stdlib.h>
  16969.  
  16970. int main(void)
  16971. {
  16972.    unsigned long long val = 0x0123456789abcdefull;
  16973.  
  16974.    printf("The value of 0x%16.16llx rotated 4 bits to the left is 0x%16.16llx\n", val,
  16975.       _llrotl(val, 4));
  16976.    printf("The value of 0x%16.16llx rotated 16 bits to the right is 0x%16.16llx\n",
  16977.       val, _llrotr(val, 16));
  16978.    return 0;
  16979.  
  16980.    /*********************************************************************************
  16981.    The output should be:
  16982.  
  16983.    The value of 0x0123456789abcdef rotated 4 bits to the left is 0x123456789abcdef0
  16984.    The value of 0x0123456789abcdef rotated 16 bits to the right is 0xcdef0123456789ab
  16985.    **********************************************************************************/
  16986. }
  16987.  
  16988.  
  16989. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16990.  
  16991. Example of _llrotl - _llrotr 
  16992.  
  16993.      _crotl - _crotr - Rotate Bits of Character Value 
  16994.      _lrotl - _lrotr - Rotate Bits of Unsigned Long Value 
  16995.      _rotl - _rotr - Rotate Bits of Unsigned Integer 
  16996.      _srotl - _srotr - Rotate Bits of Unsigned Short Value 
  16997.      swab - Swap Adjacent Bytes 
  16998.      <builtin.h> 
  16999.      <stdlib.h> 
  17000.  
  17001.  
  17002. ΓòÉΓòÉΓòÉ 4.166. _loadmod - Load DLL ΓòÉΓòÉΓòÉ
  17003.  
  17004.  
  17005. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17006.  
  17007. #include <stdlib.h>
  17008. int _loadmod(char *module_name, unsigned long *module_handle);
  17009.  
  17010.  
  17011. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17012.  
  17013. Language Level:  Extension 
  17014.  
  17015. _loadmod loads a dynamic link library (DLL) for the calling process. The 
  17016. module_name is the name of the DLL to be loaded, and the module_handle is the 
  17017. file handle associated with the DLL. 
  17018.  
  17019. Note:  _loadmod and _freemod perform exactly the same function as the Windows 
  17020. APIs LoadLibrary and FreeLibrary. They are provided for compatibility with 
  17021. earlier VisualAge for C++ releases only, and will not be supported in future 
  17022. versions. Use LoadLibrary and FreeLibrary instead. For more details on these 
  17023. APIs, see the Win32 Programmer's Reference. 
  17024.  
  17025. If the operation is successful, _loadmod returns the handle of the loaded DLL 
  17026. to the calling process.  The process can use this handle with the Win32 API 
  17027. GetProcAddress to get the address of the required function from within the DLL. 
  17028. Once the reference is established, the calling process can then call the 
  17029. specific function. 
  17030.  
  17031. Return Value 
  17032. _loadmod returns 0 if the DLL was successfully loaded. If unsuccessful, 
  17033. _loadmod returns -1, and sets errno to one of the following values: 
  17034.  
  17035.  Value          Meaning 
  17036.  EMODNAME       The specified module_name is not valid. 
  17037.  EOS2ERR        A system error occurred. Check _doserrno for the specific 
  17038.                 Windows error code. 
  17039.  
  17040.  
  17041. ΓòÉΓòÉΓòÉ <hidden> Example of _loadmod ΓòÉΓòÉΓòÉ
  17042.  
  17043. /************************************************************************
  17044.  
  17045. In this example, _loadmod loads the DLL mark and gets the address of the 
  17046. function PLUS within the DLL.  It then calls that function, which adds two 
  17047. integers passed to it. The types FARPROC and HMODULE are required to use the 
  17048. Win32 GetProcAddress API, and are defined by including the <windows.h> header 
  17049. file. 
  17050.  
  17051. Note:  To run this program, you must first create mark.dll. Copy the code for 
  17052. the PLUS function into a file called mark.c, and the code for the .DEF file 
  17053. into mark.def.  Eliminate the comments from these two files. Compile with the 
  17054. command: 
  17055.  
  17056.    icc /Ge- mark.c mark.def
  17057. You can then run the example. 
  17058.  
  17059. ************************************************************************/
  17060.  
  17061. #include <windows.h>
  17062. #include <stdio.h>
  17063. #include <stdlib.h>
  17064.  
  17065. typedef (_Optlink *fptr)(int, int);
  17066.  
  17067. int main(void) {
  17068.  
  17069.    int x = 4, y = 7;
  17070.    unsigned long handle;
  17071.    char *modname = "MARK";                          /* DLL name             */
  17072.    char *fname = "PLUS";                            /* function name        */
  17073.    fptr faddr;                                      /* pointer to function  */
  17074.  
  17075.    /*  dynamically load the 'mark' DLL                        */
  17076.  
  17077.    if (_loadmod(modname, &handle)) {
  17078.       printf("Error loading module %s\n", modname);
  17079.       return EXIT_FAILURE;
  17080.    }
  17081.  
  17082.    /* get function address from DLL                 */
  17083.  
  17084.    faddr = (fptr)GetProcAddress((HMODULE)handle, fname);
  17085.    if (NULL != faddr) {
  17086.       printf("Calling the function from the %s DLL to add %d and %d\n",
  17087.              modname, x, y);
  17088.       printf("The result from the function call is %d\n", faddr(x, y));
  17089.    }
  17090.    else {
  17091.       DWORD rc = GetLastError();
  17092.       printf("Error locating address of function %s, rc=%d\n", fname, rc);
  17093.       _freemod(handle);
  17094.       return EXIT_FAILURE;
  17095.    }
  17096.  
  17097.    if (_freemod(handle)) {
  17098.       printf("Error in freeing the %s DLL module\n", modname);
  17099.       return EXIT_FAILURE;
  17100.    }
  17101.  
  17102.    printf("Reference to the %s DLL module has been freed\n", modname);
  17103.  
  17104.    /****************************************************************************
  17105.         The output should be:
  17106.  
  17107.         Calling the function from MARK DLL to add 4 and 7
  17108.         The result of the function call is 11
  17109.         Reference to the MARK DLL module has been freed
  17110.    *****************************************************************************/
  17111. }
  17112.  
  17113.  
  17114. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17115.  
  17116. Example of _loadmod 
  17117.  
  17118.      _freemod - Free User DLL 
  17119.      <stdlib.h> 
  17120.  
  17121.  
  17122. ΓòÉΓòÉΓòÉ 4.167. localdtconv - Return Date and Time Formatting Convention ΓòÉΓòÉΓòÉ
  17123.  
  17124.  
  17125. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17126.  
  17127. #include <locale.h>
  17128. struct dtconv *localdtconv(void);
  17129.  
  17130.  
  17131. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17132.  
  17133. Language Level:  Extension 
  17134.  
  17135. localdtconv determines the date and time formatting conventions of the current 
  17136. locale and places the information in a structure of type struct dtconv. The 
  17137. dtconv structure is described in detail on page <locale.h>. 
  17138.  
  17139. Subsequent calls to localdtconv or to setlocale with LC_ALL or LC_TIME can 
  17140. overwrite the structure. 
  17141.  
  17142. Return Value 
  17143. localdtconv returns the address of the dtconv structure. 
  17144.  
  17145.  
  17146. ΓòÉΓòÉΓòÉ <hidden> Example of localdtconv ΓòÉΓòÉΓòÉ
  17147.  
  17148. /************************************************************************
  17149.  
  17150. This example sets the Spanish locale, calls localdtconv to determine how date 
  17151. and time are formatted, and prints the fields from the resulting structure. 
  17152.  
  17153. ************************************************************************/
  17154.  
  17155. #include <stdio.h>
  17156. #include <stdlib.h>
  17157. #include <locale.h>
  17158. #include <stdlib.h>
  17159.  
  17160. #if (1 == __TOS_OS2__)
  17161.    #define LOCNAME "es_es.ibm-437"     /* OS/2 name        */
  17162. #else
  17163.    #define LOCNAME "es_es.ibm-1252"    /* Windows name     */
  17164. #endif
  17165.  
  17166. int main(void)
  17167. {
  17168.    struct dtconv *p;
  17169.    int           i;
  17170.  
  17171.    if (NULL == setlocale(LC_ALL, LOCNAME)) {
  17172.       printf("Locale \"%s\" could not be loaded\n", LOCNAME);
  17173.       exit(1);
  17174.    } else {
  17175.       p = localdtconv();
  17176.       printf("SPAIN date/time convention.\n");
  17177.       printf(" Abbreviated month names:");
  17178.       for (i = 0; i < 12; ++i)
  17179.          printf(" %s", p->abbrev_month_names[i]);
  17180.       printf("\n Full month names:");
  17181.       for (i = 0; i < 12; ++i)
  17182.          printf(" %s", p->month_names[i]);
  17183.       printf("\n Abbreviated day names:");
  17184.       for (i = 0; i < 7; ++i)
  17185.          printf(" %s", p->abbrev_day_names[i]);
  17186.       printf("\n Full day names:");
  17187.       for (i = 0; i < 7; ++i)
  17188.          printf(" %s", p->day_names[i]);
  17189.       printf("\n Date and time format:  %s\n", p->date_time_format);
  17190.       printf(" Date format:  %s\n",            p->date_format);
  17191.       printf(" Time format:  %s\n",            p->time_format);
  17192.       printf(" AM string:  %s\n",              p->am_string);
  17193.       printf(" PM string:  %s\n",              p->pm_string);
  17194.       printf(" Long date format:  %s\n",       p->time_format_ampm);
  17195.    }
  17196.    return 0;
  17197.  
  17198.    /****************************************************************************
  17199.       The output should be similar to :
  17200.  
  17201.       SPAIN date/time convention.
  17202.        Abbreviated month names: Ene Feb Mar Abr May Jun Jul Ago Sep Oct Nov Dic
  17203.        Full month names: Enero Febrero Marzo Abril Mayo Junio Julio Agosto
  17204.                          Septiembre Octubre Noviembre Diciembre
  17205.        Abbreviated day names: Do Lu Ma Mi Ju Vi Sa
  17206.        Full day names: Domingo Lunes Martes Miercoles Jueves Viernes Sabado
  17207.        Date and time format:  %a %e %b %H:%M:%S %Y
  17208.        Date format:  %d/%m/%y
  17209.        Time format:  %H:%M:%S
  17210.        AM string:
  17211.        PM string:
  17212.        Long date format:  %I:%M:%S %p
  17213.    ****************************************************************************/
  17214. }
  17215.  
  17216.  
  17217. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17218.  
  17219. Example of localdtconv 
  17220.  
  17221.      localeconv - Retrieve Information from the Environment 
  17222.      localtime - Convert Time 
  17223.      setlocale - Set Locale 
  17224.      strftime - Convert to Formatted Time 
  17225.      strptime - Convert to Formatted Date and Time 
  17226.      wcsftime - Convert to Formatted Date and Time 
  17227.      <locale.h> 
  17228.  
  17229.  
  17230. ΓòÉΓòÉΓòÉ 4.168. localeconv - Retrieve Information from the Environment ΓòÉΓòÉΓòÉ
  17231.  
  17232.  
  17233. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17234.  
  17235. #include <locale.h>
  17236. struct lconv *localeconv(void);
  17237.  
  17238.  
  17239. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17240.  
  17241. Language Level:  ANSI, SAA, XPG4 
  17242.  
  17243. localeconv retrieves information about the environment for the current locale 
  17244. and places the information in a structure of type struct lconv. Subsequent 
  17245. calls to localeconv, or to setlocale with the argument LC_ALL, LC_MONETARY, or 
  17246. LC_NUMERIC, can overwrite the structure. 
  17247.  
  17248. The structure contains the members listed below. Defaults shown are for the "C" 
  17249. locale. Pointers to strings with a value of "" indicate that the value is not 
  17250. available in this locale or is of zero length. Character types with a value of 
  17251. UCHAR_MAX indicate that the value is not available in this locale. 
  17252.  
  17253. ELEMENT          PURPOSE OF ELEMENT             DEFAULT
  17254. "char *decimal_point"   Decimal-point character for formatting   "."
  17255.              nonmonetary quantities.
  17256. "char *thousands_sep"   Character used to separate groups of    ""
  17257.              digits to the left of the decimal-point
  17258.              character in formatted nonmonetary quan-
  17259.              tities.
  17260. "char *grouping"     Size of each group of digits in for-    ""
  17261.              matted nonmonetary quantities.  The
  17262.              value of each character in the string
  17263.              determines the number of digits in a
  17264.              group.  "CHAR_MAX" indicates that there
  17265.              are no further groupings.  "0" indicates
  17266.              that the previous element is to be used
  17267.              for the remainder of the digits.
  17268. "char           International currency symbol.  The     ""
  17269. *int_curr_symbol"     first three characters contain the
  17270.              alphabetic international currency
  17271.              symbol.  The fourth character (usually a
  17272.              space) separates the international cur-
  17273.              rency symbol from the monetary quantity.
  17274. "char           Local currency symbol.           ""
  17275. *currency_symbol"
  17276. "char           Decimal-point character for formatting   "."
  17277. *mon_decimal_point"    monetary quantities.
  17278. "char           Separator for digits in formatted mone-   ""
  17279. *mon_thousands_sep"    tary quantities.
  17280. "char *mon_grouping"   Size of each group of digits in for-    ""
  17281.              matted monetary quantities.  The value
  17282.              of each character in the string deter-
  17283.              mines the number of digits in a group.
  17284.              "CHAR_MAX" indicates that there are no
  17285.              further groupings.  "0" indicates that
  17286.              the previous element is to be used for
  17287.              the remainder of the digits.
  17288. "char *positive_sign"   Positive sign used in monetary quanti-   ""
  17289.              ties.
  17290. "char *negative_sign"   Negative sign used in monetary quanti-   ""
  17291.              ties.
  17292. "char int_frac_digits"  Number of displayed digits to the right   UCHAR_MAX
  17293.              of the decimal place for internationally
  17294.              formatted monetary quantities.
  17295. "char frac_digits"    Number of digits to the right of the    UCHAR_MAX
  17296.              decimal place in monetary quantities.
  17297. "char p_cs_precedes"   1 if the "currency_symbol" precedes the   UCHAR_MAX
  17298.              value for a nonnegative formatted mone-
  17299.              tary quantity; "0" if it does not.
  17300. "char p_sep_by_space"   1 if the "currency_symbol" is separated   UCHAR_MAX
  17301.              by a space from the value of a nonnega-
  17302.              tive formatted monetary quantity;  "0"
  17303.              if it is not.
  17304. "char n_cs_precedes"   1 if the "currency_symbol" precedes the   UCHAR_MAX
  17305.              value for a negative formatted monetary
  17306.              quantity; "0" if it does not.
  17307. "char n_sep_by_space"   1 if the "currency_symbol" is separated   UCHAR_MAX
  17308.              by a space from the value of a negative
  17309.              formatted monetary quantity;  "0" if it
  17310.              is not.
  17311. "char p_sign_posn"    Position of the "positive_sign" for a    UCHAR_MAX
  17312.              nonnegative formatted monetary quantity.
  17313. "char n_sign_posn"    Position of the "negative_sign" for a    UCHAR_MAX
  17314.              negative formatted monetary quantity.
  17315. "char           Symbol to appear to the left of a      ""(""
  17316. *left_parenthesis"    negative-valued monetary symbol (such as
  17317.              a loss or deficit).
  17318. "char           Symbol to appear to the right of a     "")""
  17319. *right_parenthesis"    negative-valued monetary symbol (such as
  17320.              a loss or deficit).
  17321. "char *debit_sign"    String to indicate a non-negative-valued  ""DB""
  17322.              formatted monetary quantity.
  17323. "char *credit_sign"    String to indicate a negative-valued    ""CR""
  17324.              formatted monetary quantity.
  17325.  
  17326. The grouping and mon_grouping members can have the following values: 
  17327.  
  17328.  Value        Meaning 
  17329.  CHAR_MAX     No further grouping is to be performed. 
  17330.  0            The previous element is to be repeatedly used for the rest of the 
  17331.               digits. 
  17332.  other        The number of digits that comprise the current group.  The next 
  17333.               element is examined to determine the size of the next group of 
  17334.               digits before the current group. 
  17335.  
  17336.  The n_sign_posn and p_sign_posn elements can have the following values: 
  17337.  
  17338.  Value Meaning 
  17339.   0    The quantity and currency_symbol are enclosed in parentheses. 
  17340.   1    The sign precedes the quantity and currency_symbol. 
  17341.   2    The sign follows the quantity and currency_symbol. 
  17342.   3    The sign precedes the currency_symbol. 
  17343.   4    The sign follows the currency_symbol. 
  17344.   5    Use debit_sign for p_sign_posn or credit_sign for n_sign_posn. 
  17345.  
  17346.  Return Value 
  17347.  localeconv returns a pointer to the lconv structure. 
  17348.  
  17349.  
  17350. ΓòÉΓòÉΓòÉ <hidden> Example of localeconv ΓòÉΓòÉΓòÉ
  17351.  
  17352. /************************************************************************
  17353.  
  17354. This example prints out the default decimal point for your locale and then the 
  17355. decimal point for the LC_C_FRANCE locale. 
  17356.  
  17357. ************************************************************************/
  17358.  
  17359. #include <stdio.h>
  17360. #include <stdlib.h>
  17361. #include <locale.h>
  17362.  
  17363. #if (1 == __TOS_OS2__)
  17364.    #define LOCNAME "fr_fr.ibm-437"     /* OS/2 name        */
  17365. #else
  17366.    #define LOCNAME "fr_fr.ibm-1252"    /* Windows name     */
  17367. #endif
  17368.  
  17369. int main(void)
  17370. {
  17371.    struct lconv *mylocale;
  17372.  
  17373.    mylocale = localeconv();
  17374.    printf("Default decimal point is a %s\n", mylocale->decimal_point);
  17375.    if (NULL == setlocale(LC_ALL, LOCNAME)) {
  17376.       printf("Locale \"%s\" could not be loaded\n", LOCNAME);
  17377.       exit(1);
  17378.    }
  17379.    mylocale = localeconv();
  17380.    printf("France's decimal point is a %s\n", mylocale->decimal_point);
  17381.    return 0;
  17382.  
  17383.    /****************************************************************************
  17384.       The output should be similar to :
  17385.  
  17386.       Default decimal point is a .
  17387.       France's decimal point is a ,
  17388.    ****************************************************************************/
  17389. }
  17390.  
  17391.  
  17392. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17393.  
  17394. Example of localeconv 
  17395.  
  17396.      setlocale - Set Locale 
  17397.      <locale.h> 
  17398.  
  17399.  
  17400. ΓòÉΓòÉΓòÉ 4.169. localtime - Convert Time ΓòÉΓòÉΓòÉ
  17401.  
  17402.  
  17403. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17404.  
  17405. #include <time.h>
  17406. struct tm *localtime(const time_t *timeval);
  17407.  
  17408.  
  17409. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17410.  
  17411. Language Level: ANSI, SAA, POSIX, XPG4 
  17412.  
  17413. localtime breaks down timeval, corrects for the local time zone and Daylight 
  17414. Saving Time, if appropriate, and stores the corrected time in a structure of 
  17415. type tm.  See gmtime for a description of the fields in a tm structure. 
  17416.  
  17417. The time value is usually obtained by a call to the time function. 
  17418.  
  17419. Note: 
  17420.  
  17421.    1. gmtime and localtime may use a common, statically allocated buffer for 
  17422.       the conversion.  Each call to one of these functions may alter the result 
  17423.       of the previous call. 
  17424.  
  17425.    2. The time and date functions begin at 00:00:00 Coordinated Universal Time, 
  17426.       January 1, 1970. 
  17427.  
  17428.  Return Value 
  17429.  localtime returns a pointer to the structure result. If unsuccessful, it 
  17430.  returns NULL. 
  17431.  
  17432.  
  17433. ΓòÉΓòÉΓòÉ <hidden> Example of localtime ΓòÉΓòÉΓòÉ
  17434.  
  17435. /************************************************************************
  17436.  
  17437. This example queries the system clock and displays the local time. 
  17438.  
  17439. ************************************************************************/
  17440.  
  17441. #include <time.h>
  17442. #include <stdio.h>
  17443.  
  17444. int main(void)
  17445. {
  17446.    struct tm *newtime;
  17447.    time_t ltime;
  17448.  
  17449.    time(<ime);
  17450.    newtime = localtime(<ime);
  17451.    printf("The date and time is %s", asctime(newtime));
  17452.    return 0;
  17453.  
  17454.    /****************************************************************************
  17455.       The output should be similar to:
  17456.  
  17457.       The date and time is Wed Oct 31 15:00 1995
  17458.    ****************************************************************************/
  17459. }
  17460.  
  17461.  
  17462. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17463.  
  17464. Example of localtime 
  17465.  
  17466.      asctime - Convert Time to Character String 
  17467.      ctime - Convert Time to Character String 
  17468.      gmtime - Convert Time 
  17469.      mktime - Convert Local Time 
  17470.      time - Determine Current Time 
  17471.      <time.h> 
  17472.  
  17473.  
  17474. ΓòÉΓòÉΓòÉ 4.170. log - Calculate Natural Logarithm ΓòÉΓòÉΓòÉ
  17475.  
  17476.  
  17477. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17478.  
  17479. #include <math.h>
  17480. double log(double x);
  17481.  
  17482.  
  17483. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17484.  
  17485. Language Level: ANSI, SAA, POSIX, XPG4 
  17486.  
  17487. log calculates the natural logarithm (base e) of x. 
  17488.  
  17489. Return Value 
  17490. log returns the computed value.  If x is negative, log sets errno to EDOM and 
  17491. may return the value -HUGE_VAL. If x is zero, log returns the value -HUGE_VAL, 
  17492. and may set errno to ERANGE. 
  17493.  
  17494.  
  17495. ΓòÉΓòÉΓòÉ <hidden> Example of log ΓòÉΓòÉΓòÉ
  17496.  
  17497. /************************************************************************
  17498.  
  17499. This example calculates the natural logarithm of 1000.0. 
  17500.  
  17501. ************************************************************************/
  17502.  
  17503. #include <stdio.h>
  17504. #include <math.h>
  17505.  
  17506. int main(void)
  17507. {
  17508.    double x = 1000.0,y;
  17509.  
  17510.    y = log(x);
  17511.    printf("The natural logarithm of %lf is %lf\n", x, y);
  17512.    return 0;
  17513.  
  17514.    /****************************************************************************
  17515.       The output should be:
  17516.  
  17517.       The natural logarithm of 1000.000000 is 6.907755
  17518.    ****************************************************************************/
  17519. }
  17520.  
  17521.  
  17522. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17523.  
  17524. Example of log 
  17525.  
  17526.      exp - Calculate Exponential Function 
  17527.      log10 - Calculate Base 10 Logarithm 
  17528.      pow - Compute Power 
  17529.      <math.h> 
  17530.  
  17531.  
  17532. ΓòÉΓòÉΓòÉ 4.171. log10 - Calculate Base 10 Logarithm ΓòÉΓòÉΓòÉ
  17533.  
  17534.  
  17535. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17536.  
  17537. #include <math.h>
  17538. double log10(double x);
  17539.  
  17540.  
  17541. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17542.  
  17543. Language Level:  ANSI, SAA, POSIX, XPG4 
  17544.  
  17545. log10 calculates the base 10 logarithm of x. 
  17546.  
  17547. Return Value 
  17548. log10 returns the computed value. If x is negative, log10 sets errno to EDOM 
  17549. and may return the value -HUGE_VAL. If x is zero, log10 returns the value 
  17550. -HUGE_VAL, and may set errno to ERANGE. 
  17551.  
  17552.  
  17553. ΓòÉΓòÉΓòÉ <hidden> Example of log10 ΓòÉΓòÉΓòÉ
  17554.  
  17555. /************************************************************************
  17556.  
  17557. This example calculates the base 10 logarithm of 1000.0. 
  17558.  
  17559. ************************************************************************/
  17560.  
  17561. #include <stdio.h>
  17562. #include <math.h>
  17563.  
  17564. int main(void)
  17565. {
  17566.    double x = 1000.0,y;
  17567.  
  17568.    y = log10(x);
  17569.    printf("The base 10 logarithm of %lf is %lf\n", x, y);
  17570.    return 0;
  17571.  
  17572.    /****************************************************************************
  17573.       The output should be:
  17574.  
  17575.       The base 10 logarithm of 1000.000000 is 3.000000
  17576.    ****************************************************************************/
  17577. }
  17578.  
  17579.  
  17580. ΓòÉΓòÉΓòÉ <hidden> Relative Information ΓòÉΓòÉΓòÉ
  17581.  
  17582. Example of log10 
  17583.  
  17584.      exp - Calculate Exponential Function 
  17585.      log - Calculate Natural Logarithm 
  17586.      pow - Compute Power 
  17587.      <math.h> 
  17588.  
  17589.  
  17590. ΓòÉΓòÉΓòÉ 4.172. longjmp - Restore Stack Environment ΓòÉΓòÉΓòÉ
  17591.  
  17592.  
  17593. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17594.  
  17595. #include <setjmp.h>
  17596. void longjmp(jmp_buf env, int value);
  17597.  
  17598.  
  17599. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17600.  
  17601. Language Level: ANSI, SAA, POSIX, XPG4 
  17602.  
  17603. longjmp restores a stack environment previously saved in env by setjmp. setjmp 
  17604. and longjmp provide a way to perform a nonlocal goto. They are often used in 
  17605. signal handlers. 
  17606.  
  17607. A call to setjmp causes the current stack environment to be saved in env.  A 
  17608. subsequent call to longjmp restores the saved environment and returns control 
  17609. to a point in the program corresponding to the setjmp call.  Execution resumes 
  17610. as if the setjmp call had just returned the given value. 
  17611.  
  17612. All variables (except register variables) that are accessible to the function 
  17613. that receives control contain the values they had when longjmp was called. The 
  17614. values of variables that are allocated to registers by the compiler are 
  17615. unpredictable. Because any auto variable could be allocated to a register in 
  17616. optimized code, you should consider the values of all auto variables to be 
  17617. unpredictable after a longjmp call. 
  17618.  
  17619. Note:  Ensure that the function that calls setjmp does not return before you 
  17620. call the corresponding longjmp function. Calling longjmp after the function 
  17621. calling setjmp returns causes unpredictable program behavior. 
  17622.  
  17623. The value argument must be nonzero. If you give a zero argument for value, 
  17624. longjmp substitutes 1 in its place. 
  17625.  
  17626. C++ Considerations  When you call setjmp in a C++ program, ensure that that 
  17627.                     part of the program does not also create C++ objects that 
  17628.                     need to be destroyed. When you call longjmp, objects 
  17629.                     existing at the time of the setjmp call will still exist, 
  17630.                     but any destructors called after setjmp are not called. 
  17631.                     Click here for an example. 
  17632.  
  17633.  Return Value 
  17634.  longjmp does not use the normal function call and return mechanisms;  it has 
  17635.  no return value. 
  17636.  
  17637.  
  17638. ΓòÉΓòÉΓòÉ <hidden> Example of C++ setjmp/longjmp Restriction ΓòÉΓòÉΓòÉ
  17639.  
  17640. Given the following program: 
  17641.  
  17642. #include <stdio.h>
  17643. #include <setjmp.h>
  17644.  
  17645. class A {
  17646.    int i;
  17647.    public:
  17648.       A(int I) {i = I; printf("Constructed at line %d\n", i);}
  17649.       ~A() {printf("Destroying object constructed at line %d\n",i);}
  17650.    };
  17651. jmp_buf jBuf;
  17652.  
  17653. int main(void) {
  17654.    A a1(__LINE__);
  17655.    if (!setjmp(jBuf)) {
  17656.      A a2(__LINE__);
  17657.      printf("Press y (and Enter) to longjmp; anything else to return norm
  17658.      char c = getchar();
  17659.      if (c == 'y')
  17660.         longjmp(jBuf, 1);
  17661.    }
  17662.    A a3(__LINE__);
  17663.    return 0;
  17664. }
  17665.  
  17666. If you return normally, the output would be: 
  17667.  
  17668. Constructed at line 13
  17669. Constructed at line 15
  17670. Press y (and Enter) to longjmp; anything else to return normally
  17671. x
  17672. Destroying object constructed at line 15
  17673. Constructed at line 21
  17674. Destroying object constructed at line 21
  17675. Destroying object constructed at line 13
  17676.  
  17677. If you called longjmp, the output would be: 
  17678.  
  17679. Constructed at line 13
  17680. Constructed at line 15
  17681. Press y (and Enter) to longjmp; anything else to return normally
  17682. y
  17683. Constructed at line 21
  17684. Destroying object constructed at line 21
  17685. Destroying object constructed at line 13
  17686.  
  17687. Notice that the object from line 15 is not destroyed. 
  17688.  
  17689.  
  17690. ΓòÉΓòÉΓòÉ <hidden> Example of longjmp ΓòÉΓòÉΓòÉ
  17691.  
  17692. /************************************************************************
  17693.  
  17694. This example saves the stack environment at the statement: 
  17695.  
  17696.    if(setjmp(mark) != 0) ...
  17697.  
  17698. When the system first performs the if statement, it saves the environment in 
  17699. mark and sets the condition to FALSE because setjmp returns a 0 when it saves 
  17700. the environment. The program prints the message: 
  17701.  
  17702.   setjmp has been called
  17703.  
  17704. The subsequent call to function p tests for a local error condition, which can 
  17705. cause it to call longjmp.  Then, control returns to the original setjmp 
  17706. function using the environment saved in mark.  This time, the condition is TRUE 
  17707. because -1 is the return value from longjmp. The example then performs the 
  17708. statements in the block, prints longjmp has been called, calls recover, and 
  17709. leaves the program. 
  17710.  
  17711. ************************************************************************/
  17712.  
  17713. #include <stdio.h>
  17714. #include <stdlib.h>
  17715. #include <setjmp.h>
  17716.  
  17717. int p(void);
  17718. int recover(void);
  17719. jmp_buf mark;
  17720.  
  17721. int main(void)
  17722. {
  17723.    if (setjmp(mark) != 0) {
  17724.       printf("longjmp has been called\n");
  17725.       recover();
  17726.       exit(1);
  17727.    }
  17728.    printf("setjmp has been called\n");
  17729.  
  17730.    p();
  17731.  
  17732.    return 0;
  17733.  
  17734.    /****************************************************************************
  17735.       The output should be:
  17736.  
  17737.       setjmp has been called
  17738.       longjmp has been called
  17739.    ****************************************************************************/
  17740. }
  17741.  
  17742. int p(void)
  17743. {
  17744.    int error = 0;
  17745.  
  17746.    error = 9;
  17747.  
  17748.    if (error != 0)
  17749.       longjmp(mark, -1);
  17750.    return 0;
  17751. }
  17752.  
  17753. int recover(void)
  17754. {
  17755.    return 0;
  17756. }
  17757.  
  17758.  
  17759. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17760.  
  17761. Example of longjmp 
  17762.  
  17763.      setjmp - Preserve Environment 
  17764.      goto in the Language Reference 
  17765.      <setjmp.h> 
  17766.  
  17767.  
  17768. ΓòÉΓòÉΓòÉ 4.173. _lrotl - _lrotr - Rotate Bits of Unsigned Long Value ΓòÉΓòÉΓòÉ
  17769.  
  17770.  
  17771. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17772.  
  17773. #include <stdlib.h>   /* also in <builtin.h> */
  17774. unsigned long _lrotl(unsigned long value, int shift);
  17775. unsigned long _lrotr(unsigned long value, int shift);
  17776.  
  17777.  
  17778. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17779.  
  17780. Language Level:  Extension 
  17781.  
  17782. _lrotl and _lrotr rotate the unsigned long integer value by shift bits. _lrotl 
  17783. rotates to the left, and _lrotr to the right. 
  17784.  
  17785. Note:  Both _lrotl and _lrotr are built-in functions, which means they are 
  17786. implemented as inline instructions and have no backing code in the library. For 
  17787. this reason: 
  17788.  
  17789.      You cannot take the address of these functions. 
  17790.      You cannot parenthesize a call to either function. (Parentheses specify a 
  17791.       call to the function's backing code, and these functions have none.) 
  17792.  
  17793.  Return Value 
  17794.  Both functions return the rotated value.  There is no error return value. 
  17795.  
  17796.  
  17797. ΓòÉΓòÉΓòÉ <hidden> Example of _lrotl - _lrotr ΓòÉΓòÉΓòÉ
  17798.  
  17799. /************************************************************************
  17800.  
  17801. This example uses _lrotl and _lrotr with different shift values to rotate the 
  17802. long integer value 0x01234567. 
  17803.  
  17804. ************************************************************************/
  17805.  
  17806. #include <stdio.h>
  17807. #include <stdlib.h>
  17808.  
  17809. int main(void)
  17810. {
  17811.    unsigned long val = 0X01234567;
  17812.  
  17813.    printf("The value of 0x%8.8lx rotated 4 bits to the left is 0x%8.8lx\n", val,
  17814.       _lrotl(val, 4));
  17815.    printf("The value of 0x%8.8lx rotated 16 bits to the right is 0x%8.8lx\n",
  17816.       val, _lrotr(val, 16));
  17817.    return 0;
  17818.  
  17819.    /****************************************************************************
  17820.       The output should be:
  17821.  
  17822.       The value of 0x01234567 rotated 4 bits to the left is 0x12345670
  17823.       The value of 0x01234567 rotated 16 bits to the right is 0x45670123
  17824.    ****************************************************************************/
  17825. }
  17826.  
  17827.  
  17828. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17829.  
  17830. Example of _lrotl - _lrotr 
  17831.  
  17832.      _crotl - _crotr - Rotate Bits of Character Value 
  17833.      _rotl - _rotr - Rotate Bits of Unsigned Integer 
  17834.      _srotl - _srotr - Rotate Bits of Unsigned Short Value 
  17835.      <builtin.h> 
  17836.      <stdlib.h> 
  17837.  
  17838.  
  17839. ΓòÉΓòÉΓòÉ 4.174. lseek - Move File Pointer ΓòÉΓòÉΓòÉ
  17840.  
  17841.  
  17842. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17843.  
  17844. #include <io.h>  /* constants in <stdio.h> */
  17845. long lseek(int handle, long offset, int origin);
  17846.  
  17847.  
  17848. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17849.  
  17850. Language Level:  XPG4, Extension 
  17851.  
  17852. lseek moves any file pointer associated with handle to a new location that is 
  17853. offset bytes from the origin. The next operation on the file takes place at the 
  17854. new location. The origin must be one of the following constants, defined in 
  17855. <stdio.h>: 
  17856.  
  17857.  Origin         Definition 
  17858.  SEEK_SET       Beginning of file 
  17859.  SEEK_CUR       Current position of file pointer 
  17860.  SEEK_END       End of file. 
  17861.  
  17862.  lseek can reposition the pointer anywhere in a file. The pointer can also be 
  17863.  positioned beyond the end of the file; the data between the EOF and the new 
  17864.  file position is undefined. (See _chsize - Alter Length of File for more 
  17865.  information on extending the length of the file.) An attempt to position the 
  17866.  pointer before the beginning of the file causes an error. 
  17867.  
  17868.  Note:  In earlier releases of VisualAge C++, lseek began with an underscore 
  17869.  (_lseek). Because it is defined by the X/Open standard, the underscore has 
  17870.  been removed. For compatibility, VisualAge for C++ will map _lseek to lseek 
  17871.  for you. 
  17872.  
  17873.  Return Value 
  17874.  lseek returns the offset, in bytes, of the new position from the beginning of 
  17875.  the file. A return value of -1L indicates an error, and lseek sets errno to 
  17876.  one of the following values: 
  17877.  
  17878.  Value        Meaning 
  17879.  EBADF        The file handle is incorrect. 
  17880.  EINVAL       The value for origin is incorrect, or the position specified by 
  17881.               offset is before the beginning of the file. 
  17882.  EOS2ERR      The call to the operating system was not successful. 
  17883.  
  17884.  On devices incapable of seeking (such as keyboards and printers), lseek 
  17885.  returns -1 and sets errno to EOS2ERR. 
  17886.  
  17887.  
  17888. ΓòÉΓòÉΓòÉ <hidden> Example of lseek ΓòÉΓòÉΓòÉ
  17889.  
  17890. /************************************************************************
  17891.  
  17892. This example opens the file sample.dat and, if successful, moves the file 
  17893. pointer to the eighth position in the file. The example then attempts to read 
  17894. bytes from the file, starting at the new pointer position, and reads them into 
  17895. the buffer. 
  17896.  
  17897. ************************************************************************/
  17898.  
  17899. #include <io.h>
  17900. #include <stdio.h>
  17901. #include <stdlib.h>
  17902. #include <fcntl.h>
  17903. #include <string.h>
  17904.  
  17905. int main(void)
  17906. {
  17907.    long length;
  17908.    int fh;
  17909.    char buffer[20];
  17910.  
  17911.    memset(buffer, '\0', 20);               /* Initialize the buffer           */
  17912.    printf("\nCreating sample.dat.\n");
  17913.    system("echo Sample Program > sample.dat");
  17914.    if (-1 == (fh = open("sample.dat", O_RDWR|O_APPEND))) {
  17915.       perror("Unable to open sample.dat.");
  17916.       exit(EXIT_FAILURE);
  17917.    }
  17918.    if (-1 == lseek(fh, 7, SEEK_SET)) {     /* place the file pointer at the   */
  17919.       perror("Unable to lseek");           /* eighth position in the file     */
  17920.       close(fh);
  17921.       return EXIT_FAILURE;
  17922.    }
  17923.    if (8 != read(fh, buffer, 8)) {
  17924.       perror("Unable to read from sample.dat.");
  17925.       close(fh);
  17926.       return EXIT_FAILURE;
  17927.    }
  17928.    printf("Successfully read in the following:\n%s.\n", buffer);
  17929.    close(fh);
  17930.    return 0;
  17931.  
  17932.    /****************************************************************************
  17933.       The output should be:
  17934.  
  17935.       Creating sample.dat.
  17936.       Successfully read in the following:
  17937.       Program .
  17938.    ****************************************************************************/
  17939. }
  17940.  
  17941.  
  17942. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17943.  
  17944. Example of lseek 
  17945.  
  17946.      _chsize - Alter Length of File 
  17947.      fseek - Reposition File Position 
  17948.      _tell - Get Pointer Position 
  17949.      <io.h> 
  17950.      <stdio.h> 
  17951.  
  17952.  
  17953. ΓòÉΓòÉΓòÉ 4.175. _ltoa - Convert Long Integer to String ΓòÉΓòÉΓòÉ
  17954.  
  17955.  
  17956. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17957.  
  17958. #include <stdlib.h>
  17959. char *_ltoa(long value, char *string, int radix);
  17960.  
  17961.  
  17962. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17963.  
  17964. Language Level:  Extension 
  17965.  
  17966. _ltoa converts the digits of the given long integer value to a character string 
  17967. that ends with a null character and stores the result in string. The radix 
  17968. argument specifies the base of value; it must be in the range 2 to 36. If radix 
  17969. equals 10 and value is negative, the first character of the stored string is 
  17970. the minus sign (-). 
  17971.  
  17972. Note:  The space allocated for string must be large enough to hold the returned 
  17973. string. The function can return up to 33 bytes, including the null character 
  17974. (\0). 
  17975.  
  17976. Return Value 
  17977. _ltoa returns a pointer to string. There is no error return value. 
  17978.  
  17979.  
  17980. ΓòÉΓòÉΓòÉ <hidden> Example of _ltoa ΓòÉΓòÉΓòÉ
  17981.  
  17982. /************************************************************************
  17983.  
  17984. This example converts the long integer -255L to a decimal, binary, and hex 
  17985. value, and stores its character representation in the array buffer. 
  17986.  
  17987. ************************************************************************/
  17988.  
  17989. #include <stdio.h>
  17990. #include <stdlib.h>
  17991.  
  17992. int main(void)
  17993. {
  17994.    char buffer[35];
  17995.    char *p;
  17996.  
  17997.    p = _ltoa(-255L, buffer, 10);
  17998.    printf("The result of _ltoa(-255) with radix of 10 is %s\n", p);
  17999.    p = _ltoa(-255L, buffer, 2);
  18000.    printf("The result of _ltoa(-255) with radix of 2\n    is %s\n", p);
  18001.    p = _ltoa(-255L, buffer, 16);
  18002.    printf("The result of _ltoa(-255) with radix of 16 is %s\n", p);
  18003.    return 0;
  18004.  
  18005.    /****************************************************************************
  18006.       The output should be:
  18007.  
  18008.       The result of _ltoa(-255) with radix of 10 is -255
  18009.       The result of _ltoa(-255) with radix of 2
  18010.           is 11111111111111111111111100000001
  18011.       The result of _ltoa(-255) with radix of 16 is ffffff01
  18012.    ****************************************************************************/
  18013. }
  18014.  
  18015.  
  18016. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18017.  
  18018. Example of _ltoa 
  18019.  
  18020.      atol - Convert Character String to Long Integer 
  18021.      _ecvt - Convert Floating-Point to Character 
  18022.      _fcvt - Convert Floating-Point to String 
  18023.      _gcvt - Convert Floating-Point to String 
  18024.      _itoa - Convert Integer to String 
  18025.      strtol - Convert Character String to Long Integer 
  18026.      _ultoa - Convert Unsigned Long Integer to String 
  18027.      wcstol - Convert Wide-Character to Long Integer 
  18028.      <stdlib.h> 
  18029.  
  18030.  
  18031. ΓòÉΓòÉΓòÉ 4.176. __lxchg - Exchange Integer Value with Memory ΓòÉΓòÉΓòÉ
  18032.  
  18033.  
  18034. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18035.  
  18036. #include <builtin.h>
  18037. int _Builtin __lxchg(volatile int*lockptr, int value);
  18038.  
  18039.  
  18040. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18041.  
  18042. Language Level:  Extension 
  18043.  
  18044. __lxchg puts the specified value in the memory location pointed to by lockptr, 
  18045. and returns the value that was previously in that location. 
  18046.  
  18047. Use this function to implement fast-RAM semaphores to serialize access to a 
  18048. critical resource (so that only one thread can use it at a time). You can also 
  18049. use system semaphores to serialize resource access, but they are slower. 
  18050. Typically you would create both a fast-RAM semaphore and a system semaphore for 
  18051. the resource. 
  18052.  
  18053. To implement a fast-RAM semaphore, allocate a volatile memory location lockptr 
  18054. (for __lxchg, it must be of type int), and statically initialize it to 0 to 
  18055. indicate that the resource is free (not being used). To give a thread access to 
  18056. the resource, call __lxchg from the thread to exchange a non-zero value with 
  18057. that memory location. If __lxchg returns 0, the thread can access the resource; 
  18058. it has also set the memory location so that other threads can tell the resource 
  18059. is in use. When your thread no longer needs the resource, call __lxchg again to 
  18060. reset the memory location to 0. 
  18061.  
  18062. If __lxchg returns a non-zero value, another thread is already using the 
  18063. resource, and the calling thread must wait for access using a Windows 
  18064. semaphore. You could then use the Windows semaphore to inform your waiting 
  18065. thread when the resource is unlocked by the thread currently using it. 
  18066.  
  18067. It is important that you set the memory to a nonzero value when you are using 
  18068. the resource.  You can use the same nonzero value for all threads, or a unique 
  18069. value for each. 
  18070.  
  18071. Note:  __lxchg is a built-in function, which means it is implemented as an 
  18072. inline instruction and has no backing code in the library.  For this reason: 
  18073.  
  18074.      You cannot take the address of __lxchg. 
  18075.      You cannot parenthesize a call to __lxchg. (Parentheses specify a call to 
  18076.       the function's backing code, and __lxchg has none.) 
  18077.  
  18078.  Return Value 
  18079.  __lxchg returns the previous value stored in the memory location pointed to by 
  18080.  lockptr. 
  18081.  
  18082.  
  18083. ΓòÉΓòÉΓòÉ <hidden> Example of __lxchg ΓòÉΓòÉΓòÉ
  18084.  
  18085. /************************************************************************
  18086.  
  18087. This example creates five separate threads, each associated with a State. At 
  18088. most two threads can have a State of Eating at the same time. When a thread 
  18089. calls PickUpChopSticks, that function checks the states of the preceding 
  18090. threads to make sure they are not already Eating. If the call to __lxchg is 
  18091. successful, the thread has locked the Lock semaphore and can change its State 
  18092. to Eating. It then calls __lxchg a second time to unlock the semaphore, and 
  18093. returns. 
  18094.  
  18095. If __lxchg cannot lock the semaphore, another thread has it locked.  The 
  18096. current thread then suspends itself briefly with Sleep and tries again. The 
  18097. semaphore is used to ensure that two threads cannot simultaneously change their 
  18098. State to Eating, which would cause a deadlock. (Note that although the 
  18099. semaphore solves the problem of deadlock, it is not an optimal solution; some 
  18100. threads may never get the semaphore or the State of Eating.) 
  18101.  
  18102. Note:  You must compile this example with the multithread (/Gm) option. The 
  18103. example runs in an infinite loop; press Ctrl-C to end it. 
  18104.  
  18105. ************************************************************************/
  18106.  
  18107.    #pragma strings(readonly)
  18108.  
  18109. #if  (1 == __TOS_OS2__)
  18110.       #define   INCL_DOS                             /*  For OS/2  */
  18111.       #include <os2.h>
  18112.       #define SLEEP  DosSleep(1)
  18113. #else
  18114.      #include <windows.h>                          /*  For Windows  */
  18115.      #define SLEEP  Sleep(1)
  18116. #endif
  18117.  
  18118.    #include <stdlib.h>
  18119.    #include <stdio.h>
  18120.    #include <builtin.h>
  18121.  
  18122.    typedef enum {
  18123.       Thinking,
  18124.       Eating,
  18125.       Hungry
  18126.    } States;
  18127.  
  18128.    #define UNLOCKED 0
  18129.    #define LOCKED   1
  18130.    #define NUM_PHILOSOPHERS 5
  18131.  
  18132.    static volatile int Lock;
  18133.    static States State[NUM_PHILOSOPHERS];
  18134.    static const int NameMap[NUM_PHILOSOPHERS] = {0, 1, 2, 3, 4};
  18135.    static const char * const Names[NUM_PHILOSOPHERS] = {"Plato",
  18136.                                                         "Socrates",
  18137.                                                         "Kant",
  18138.                                                         "Hegel",
  18139.                                                         "Nietsche"};
  18140.  
  18141.    void PickUpChopSticks(int Ident);
  18142.    void PutDownChopSticks(int Ident);
  18143.    void Think(int Ident);
  18144.    void Eat(int Ident);
  18145.    void _Optlink StartPhilosopher(void *pIdent);
  18146.  
  18147.    void _Optlink StartPhilosopher(void *pIdent)
  18148.    {
  18149.       int Ident = *(int *)pIdent;
  18150.       while (1) {
  18151.          State[Ident] = Hungry;
  18152.          printf("%s hungry.\n", Names[Ident]);
  18153.          PickUpChopSticks(Ident);
  18154.          Eat(Ident);
  18155.          PutDownChopSticks(Ident);
  18156.          Think(Ident);
  18157.       }
  18158.    }
  18159.  
  18160.    int main(int argc, char *argv[], char *envp[])
  18161.    {
  18162.       int           i;
  18163.       unsigned long tid;
  18164.  
  18165.       for (i = 0; i < NUM_PHILOSOPHERS; i++) {
  18166.          tid = _beginthread(StartPhilosopher, NULL, 8192, (void *)&NameMap[i]);
  18167.          if (tid == -1) {
  18168.             printf("Unable to start %s.\n", Names[i]);
  18169.          }
  18170.          else {
  18171.             printf("%s started with Thread Id = %d.\n", Names[i], tid);
  18172.          }
  18173.       }
  18174. #if  (1 == __TOS_OS2__)
  18175.       DosWaitThread(&tid, DCWW_WAIT);
  18176. #else
  18177.       WaitForSingleObject((HANDLE)tid, INFINITE);
  18178. #endif
  18179.       return 0;
  18180.    }
  18181.  
  18182.    void PickUpChopSticks(int Ident)
  18183.    {
  18184.       while (1) {
  18185.          if (State[(Ident + NUM_PHILOSOPHERS - 1) % NUM_PHILOSOPHERS] != Eating &&
  18186.              State[(Ident + 1) % NUM_PHILOSOPHERS] != Eating                    &&
  18187.              !__lxchg(&Lock, LOCKED)) {
  18188.                State[Ident] = Eating;
  18189.                __lxchg(&Lock, UNLOCKED);
  18190.                return;
  18191.          }
  18192.          else {
  18193.             SLEEP;
  18194.          }
  18195.       }
  18196.    }
  18197.  
  18198.    void PutDownChopSticks(int Ident)
  18199.    {
  18200.       State[Ident] = Thinking;
  18201.    }
  18202.  
  18203.    void Eat(int Ident)
  18204.    {
  18205.       printf("%s eating.\n", Names[Ident]);
  18206.       SLEEP;
  18207.    }
  18208.  
  18209.    void Think(int Ident)
  18210.    {
  18211.       printf("%s thinking.\n", Names[Ident]);
  18212.       SLEEP;
  18213.    }
  18214.  
  18215. /****************************************************************************
  18216.          The output should be similar to :
  18217.  
  18218.          Plato started with Thread Id = 2.
  18219.          Socrates started with Thread Id = 3.
  18220.          Kant started with Thread Id = 4.
  18221.          Hegel started with Thread Id = 5.
  18222.          Nietsche started with Thread Id = 6.
  18223.          Plato hungry.
  18224.          Plato eating.
  18225.          Socrates hungry.
  18226.          Kant hungry.
  18227.          Kant eating.
  18228.          Hegel hungry.
  18229.          Nietsche hungry.
  18230.          Kant thinking.
  18231.          Plato thinking.
  18232.          Plato hungry.
  18233.          Plato eating.
  18234.          Kant hungry.
  18235.          Kant eating.
  18236.             :
  18237.  
  18238. ****************************************************************************/
  18239.  
  18240.  
  18241. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18242.  
  18243. Example of __lxchg 
  18244.  
  18245.      __cxchg - Exchange Character Value with Memory 
  18246.      __sxchg - Exchange Integer Value with Memory 
  18247.      <builtin.h> 
  18248.  
  18249.  
  18250. ΓòÉΓòÉΓòÉ 4.177. _makepath - Create Path ΓòÉΓòÉΓòÉ
  18251.  
  18252.  
  18253. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18254.  
  18255. #include <stdlib.h>
  18256. void _makepath(char *path, char *drive, char *dir, char *fname, char *ext);
  18257.  
  18258.  
  18259. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18260.  
  18261. Language Level:  Extension 
  18262.  
  18263. _makepath creates a single path name, composed of a drive letter, directory 
  18264. path, file name, and file name extension. 
  18265.  
  18266. The path argument should point to an empty buffer large enough to hold the 
  18267. complete path name. The constant _MAX_PATH, defined in <stdlib.h>, specifies 
  18268. the maximum size allowed for path. The other arguments point to the following 
  18269. buffers containing the path name elements: 
  18270.  
  18271.  drive   A letter (A, B, ...) corresponding to the desired drive and an 
  18272.          optional following colon. _makepath inserts the colon automatically in 
  18273.          the composite path name if it is missing.  If drive is a null 
  18274.          character or an empty string, no drive letter or colon appears in the 
  18275.          composite path string. 
  18276.  
  18277.  dir     The path of directories, not including the drive designator or the 
  18278.          actual file name.  The trailing slash is optional, and either slash 
  18279.          (/) or backslash (\) or both can be used in a single dir argument.  If 
  18280.          a trailing slash or backslash is not specified, it is inserted 
  18281.          automatically.  If dir is a null character or an empty string, no 
  18282.          slash is inserted in the composite path string. 
  18283.  
  18284.  fname   The base file name without any extensions. 
  18285.  
  18286.  ext     The actual file name extension, with or without a leading period. 
  18287.          _makepath inserts the period automatically if it does not appear in 
  18288.          ext.  If ext is a null character or an empty string, no period is 
  18289.          inserted in the composite path string. 
  18290.  
  18291.  The size limits on the above four fields are those specified by the constants 
  18292.  _MAX_DRIVE, _MAX_DIR, _MAX_FNAME, and _MAX_EXT, which are defined in 
  18293.  <stdlib.h>. The composite path should be no larger than the _MAX_PATH constant 
  18294.  also defined in <stdlib.h>; otherwise, the operating system does not handle it 
  18295.  correctly. 
  18296.  
  18297.  Note:  No checking is done to see if the syntax of the file name is correct. 
  18298.  
  18299.  Return Value 
  18300.  There is no return value. 
  18301.  
  18302.  
  18303. ΓòÉΓòÉΓòÉ <hidden> Example of _makepath ΓòÉΓòÉΓòÉ
  18304.  
  18305. /************************************************************************
  18306.  
  18307. This example builds a file name path from the specified components. 
  18308.  
  18309. ************************************************************************/
  18310.  
  18311. #include <stdio.h>
  18312. #include <stdlib.h>
  18313.  
  18314. int main(void)
  18315. {
  18316.    char path_buffer[_MAX_PATH];
  18317.    char drive[_MAX_DRIVE];
  18318.    char dir[_MAX_DIR];
  18319.    char fname[_MAX_FNAME];
  18320.    char ext[_MAX_EXT];
  18321.  
  18322.    _makepath(path_buffer, "c", "qc\\bob\\eclibref\\e", "makepath", "c");
  18323.    printf("Path created with _makepath: %s\n\n", path_buffer);
  18324.    _splitpath(path_buffer, drive, dir, fname, ext);
  18325.    printf("Path extracted with _splitpath:\n");
  18326.    printf("drive: %s\n", drive);
  18327.    printf("directory: %s\n", dir);
  18328.    printf("file name: %s\n", fname);
  18329.    printf("extension: %s\n", ext);
  18330.    return 0;
  18331.  
  18332.    /****************************************************************************
  18333.       The output should be:
  18334.  
  18335.       Path created with _makepath: c:qc\bob\eclibref\e\makepath.c
  18336.  
  18337.       Path extracted with _splitpath:
  18338.       drive: c:
  18339.       directory: qc\bob\eclibref\e\
  18340.       file name: makepath
  18341.       extension: .c
  18342.    ****************************************************************************/
  18343. }
  18344.  
  18345.  
  18346. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18347.  
  18348. Example of _makepath 
  18349.  
  18350.      _fullpath - Get Full Path Name of Partial Path 
  18351.      _splitpath - Decompose Path Name 
  18352.      <stdlib.h> 
  18353.  
  18354.  
  18355. ΓòÉΓòÉΓòÉ 4.178. malloc - Reserve Storage Block ΓòÉΓòÉΓòÉ
  18356.  
  18357.  
  18358. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18359.  
  18360. #include <stdlib.h>  /* also in <malloc.h> */
  18361. void *malloc(size_t size);
  18362.  
  18363.  
  18364. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18365.  
  18366. Language Level:  ANSI, SAA, POSIX, XPG4, Extension 
  18367.  
  18368. malloc reserves a block of storage of size bytes. Unlike calloc, malloc does 
  18369. not initialize all elements to 0. 
  18370.  
  18371. Heap-specific, and debug versions of this function (_umalloc, and 
  18372. _debug_malloc) are also available. malloc always operates on the default heap. 
  18373. For more information about memory management, see Managing Memory in the 
  18374. Programming Guide. 
  18375.  
  18376. Return Value 
  18377. malloc returns a pointer to the reserved space. The storage space to which the 
  18378. return value points is suitably aligned for storage of any type of object. The 
  18379. return value is NULL if not enough storage is available, or if size was 
  18380. specified as zero. 
  18381.  
  18382.  
  18383. ΓòÉΓòÉΓòÉ <hidden> Example of malloc ΓòÉΓòÉΓòÉ
  18384.  
  18385. /************************************************************************
  18386.  
  18387. This example prompts for the number of array entries you want and then reserves 
  18388. enough space in storage for the entries. If malloc was successful, the example 
  18389. assigns values to the entries and prints out each entry;  otherwise, it prints 
  18390. out an error. 
  18391.  
  18392. ************************************************************************/
  18393.  
  18394. #include <stdio.h>
  18395. #include <stdlib.h>
  18396.  
  18397. int main(void)
  18398. {
  18399.    long *array;                              /* start of the array            */
  18400.    long *index;                                           /* index variable   */
  18401.    int i;                                                 /* index variable   */
  18402.    int num;                             /* number of entries of the array     */
  18403.  
  18404.    printf("Enter the size of the array\n");
  18405.    scanf("%i", &num);
  18406.  
  18407.    /* allocate num entries                                                    */
  18408.  
  18409.    if ((index = array = (long *)malloc(num *sizeof(long))) != NULL) {
  18410.       for (i = 0; i < num; ++i)             /* put values in array            */
  18411.          *index++ = i;                      /* using pointer notation         */
  18412.       for (i = 0; i < num; ++i)             /* print the array out            */
  18413.          printf("array[ %i ] = %i\n", i, array[i]);
  18414.    }
  18415.    else {                                                 /* malloc error     */
  18416.       perror("Out of storage");
  18417.       abort();
  18418.    }
  18419.    return 0;
  18420.  
  18421.    /****************************************************************************
  18422.       The output should be similar to:
  18423.  
  18424.       Enter the size of the array
  18425.       5
  18426.       array[ 0 ] = 0
  18427.       array[ 1 ] = 1
  18428.       array[ 2 ] = 2
  18429.       array[ 3 ] = 3
  18430.       array[ 4 ] = 4
  18431.    ****************************************************************************/
  18432. }
  18433.  
  18434.  
  18435. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18436.  
  18437. Example of malloc 
  18438.  
  18439.      calloc - Reserve and Initialize Storage 
  18440.      _debug_malloc - Allocate Memory 
  18441.      _debug_umalloc - Reserve Memory Blocks from User Heap 
  18442.      free - Release Storage Blocks 
  18443.      _mheap - Query Memory Heap for Allocated Object 
  18444.      _msize - Return Number of Bytes Allocated 
  18445.      realloc - Change Reserved Storage Block Size 
  18446.      _umalloc - Reserve Memory Blocks from User Heap 
  18447.      <malloc.h> 
  18448.      <stdlib.h> 
  18449.  
  18450.  
  18451. ΓòÉΓòÉΓòÉ 4.179. _matherr - Process Math Library Errors ΓòÉΓòÉΓòÉ
  18452.  
  18453.  
  18454. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18455.  
  18456. #include <math.h>
  18457. int _matherr(struct exception *x);
  18458.  
  18459.  
  18460. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18461.  
  18462. Language Level:  Extension 
  18463.  
  18464. _matherr processes errors generated by the functions in the math library. The 
  18465. math functions call _matherr whenever they detect an error. The _matherr 
  18466. function supplied with the VisualAge for C++ library performs no error handling 
  18467. and returns 0 to the calling function. 
  18468.  
  18469. You can provide a different definition of _matherr to carry out special error 
  18470. handling. Be sure to use the /NOE link option, if you are using your own 
  18471. _matherr function. For VisualAge for C++ compiler, you can use the /B option on 
  18472. the icc command line to pass the /NOE option to the linker, as in the 
  18473. following: 
  18474.  
  18475.    icc /B"/NOE" yourfile.c
  18476.  
  18477. When an error occurs in a math routine, _matherr is called with a pointer to 
  18478. the following structure (defined in <math.h>) as an argument: 
  18479.  
  18480.    struct exception {
  18481.        int type;
  18482.        char *name;
  18483.        double arg1, arg2, retval;
  18484.    };
  18485.  
  18486. The type field specifies the type of math error. It has one of the following 
  18487. values, defined in <math.h>: 
  18488.  
  18489.  Value          Meaning 
  18490.  DOMAIN         Argument domain error 
  18491.  OVERFLOW       Overflow range error 
  18492.  UNDERFLOW      Underflow range error 
  18493.  TLOSS          Total loss of significance 
  18494.  PLOSS          Partial loss of significance 
  18495.  SING           Argument singularity. 
  18496.  
  18497.  PLOSS is provided for compatibility with other compilers; VisualAge for C++ 
  18498.  does not generate this value. 
  18499.  
  18500.  The name is a pointer to a null-ended string containing the name of the 
  18501.  function that caused the error. The arg1 and arg2 fields specify the argument 
  18502.  values that caused the error. If only one argument is given, it is stored in 
  18503.  arg1. The retval is the default return value; you can change it. 
  18504.  
  18505.  Return Value 
  18506.  The return value from _matherr must specify whether or not an error actually 
  18507.  occurred. If _matherr returns 0, an error message appears, and errno is set to 
  18508.  an appropriate error value. If _matherr returns a nonzero value, no error 
  18509.  message appears and errno remains unchanged. 
  18510.  
  18511.  
  18512. ΓòÉΓòÉΓòÉ <hidden> Example of _matherr ΓòÉΓòÉΓòÉ
  18513.  
  18514. /************************************************************************
  18515.  
  18516. This example provides a _matherr function to handle errors from the log or 
  18517. log10 functions. The arguments to these logarithmic functions must be positive 
  18518. double values. _matherr processes a negative value in an argument (a domain 
  18519. error) by returning the log of its absolute value. It suppresses the error 
  18520. message normally displayed when this error occurs.  If the error is a zero 
  18521. argument or if some other routine produced the error, the example takes the 
  18522. default actions. 
  18523.  
  18524. Note:  You must compile this example with the /B"/NOE" compiler option. 
  18525.  
  18526. ************************************************************************/
  18527.  
  18528. #include <math.h>
  18529. #include <string.h>
  18530. #include <stdio.h>
  18531. #include <stdlib.h>
  18532.  
  18533. int main(void)
  18534. {
  18535.    int value;
  18536.  
  18537.    printf("Trying to evaluate log10(-1000.00) will create a math exception.\n");
  18538.    value = log10(-1000.00);
  18539.    printf("The _matherr() exception handler evaluates the expression to\n");
  18540.    printf("log10(-1000.00) = %d\n", value);
  18541.    return 0;
  18542.  
  18543.    /****************************************************************************
  18544.       The output should be:
  18545.  
  18546.       Trying to evaluate log10(-1000.00) will create a math exception.
  18547.       inside _matherr
  18548.       The _matherr() exception handler evaluates the expression to
  18549.       log10(-1000.00) = 3
  18550.    ****************************************************************************/
  18551. }
  18552.  
  18553. int _matherr(struct exception *x)
  18554. {
  18555.    printf("inside _matherr\n");
  18556.    if (DOMAIN == x->type) {
  18557.       if (0 == strcmp(x->name, "log")) {
  18558.          x->retval = log(-(x->arg1));
  18559.          return EXIT_FAILURE;
  18560.       }
  18561.       else
  18562.          if (0 == strcmp(x->name, "log10")) {
  18563.             x->retval = log10(-(x->arg1));
  18564.             return EXIT_FAILURE;
  18565.          }
  18566.    }
  18567.    return 0;                                  /* Use default actions          */
  18568. }
  18569.  
  18570.  
  18571. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18572.  
  18573. Example of _matherr 
  18574.  
  18575.      log - Calculate Natural Logarithm 
  18576.      log10 - Calculate Base 10 Logarithm 
  18577.      <math.h> 
  18578.  
  18579.  
  18580. ΓòÉΓòÉΓòÉ 4.180. max - Return Larger of Two Values ΓòÉΓòÉΓòÉ
  18581.  
  18582.  
  18583. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18584.  
  18585. #include <stdlib.h>
  18586. type max(type a, type b);
  18587.  
  18588.  
  18589. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18590.  
  18591. Language Level:  Extension 
  18592.  
  18593. max compares two values and determines the larger of the two. The data type can 
  18594. be any arithmetic data type, signed or unsigned.  Both arguments must have the 
  18595. same type for each call to max. 
  18596.  
  18597. Note:  Because max is a macro, if the evaluation of the arguments contains side 
  18598. effects (post-increment operators, for example), the results of both the side 
  18599. effects and the macro will be undefined. 
  18600.  
  18601. Return Value 
  18602. max returns the larger of the two values. 
  18603.  
  18604.  
  18605. ΓòÉΓòÉΓòÉ <hidden> Example of max ΓòÉΓòÉΓòÉ
  18606.  
  18607. /************************************************************************
  18608.  
  18609. This example prints the larger of the two values, a and b. 
  18610.  
  18611. ************************************************************************/
  18612.  
  18613. #include <stdlib.h>
  18614. #include <stdio.h>
  18615.  
  18616. int main(void)
  18617. {
  18618.    int a = 10;
  18619.    int b = 21;
  18620.  
  18621.    printf("The larger of %d and %d is %d\n", a, b, max(a, b));
  18622.    return 0;
  18623.  
  18624.    /****************************************************************************
  18625.       The output should be:
  18626.  
  18627.       The larger of 10 and 21 is 21
  18628.    ****************************************************************************/
  18629. }
  18630.  
  18631.  
  18632. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18633.  
  18634. Example of max 
  18635.  
  18636.      min - Return Lesser of Two Values 
  18637.      <stdlib.h> 
  18638.  
  18639.  
  18640. ΓòÉΓòÉΓòÉ 4.181. mblen - Determine Length of Multibyte Character ΓòÉΓòÉΓòÉ
  18641.  
  18642.  
  18643. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18644.  
  18645. #include <stdlib.h>
  18646. int mblen(const char *string, size_t n);
  18647.  
  18648.  
  18649. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18650.  
  18651. Language Level:  ANSI, SAA, XPG4 
  18652.  
  18653. mblen determines the length in bytes of the multibyte character pointed to by 
  18654. string. A maximum of n bytes is examined. 
  18655.  
  18656. The behavior of mblen is affected by the LC_CTYPE category of the current 
  18657. locale. 
  18658.  
  18659. Return Value 
  18660. If string is NULL, mblen returns 0. 
  18661.  
  18662. Note:  On platforms that support shift states, mblen can also return a nonzero 
  18663. value to indicate that the multibyte encoding is state-dependent.  Because 
  18664. VisualAge for C++ does not support state-dependent encoding, mblen always 
  18665. returns 0 when string is NULL. 
  18666.  
  18667. If string is not NULL, mblen returns: 
  18668.  
  18669.      0 if string points to the null character 
  18670.      The number of bytes comprising the multibyte character 
  18671.      The value -1 if string does not point to a valid multibyte character. 
  18672.  
  18673.  
  18674. ΓòÉΓòÉΓòÉ <hidden> Example of mblen ΓòÉΓòÉΓòÉ
  18675.  
  18676. /************************************************************************
  18677.  
  18678. This example uses mblen and mbtowc to convert a multibyte character into a 
  18679. single wide character. 
  18680.  
  18681. ************************************************************************/
  18682.  
  18683. #include <stdio.h>
  18684. #include <stdlib.h>
  18685. #include <wchar.h>
  18686. #include <locale.h>
  18687.  
  18688. #define LOCNAME "ja_jp.ibm-932"
  18689.  
  18690. int main(void)
  18691. {
  18692.    char     mb_string[] = "\x81\x41\x81\xc2" "b";
  18693.    int      length;
  18694.    wchar_t  widechar;
  18695.  
  18696.    if (NULL == setlocale(LC_ALL, LOCNAME)) {
  18697.       printf("Locale \"%s\" could not be loaded\n", LOCNAME);
  18698.       exit(1);
  18699.    }
  18700.    length = mblen(mb_string, MB_CUR_MAX);
  18701.    mbtowc(&widechar, mb_string, length);
  18702.    printf("The wide character %lc has length of %d.\n", widechar, length);
  18703.    return 0;
  18704.  
  18705.    /****************************************************************************
  18706.       The output should be similar to :
  18707.  
  18708.       The wide character ΓöÇA has length of 2.
  18709.    ****************************************************************************/
  18710. }
  18711.  
  18712.  
  18713. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18714.  
  18715. Example of mblen 
  18716.  
  18717.      mbrlen - Calculate Length of Multibyte Character 
  18718.      mbrtowc - Convert Multibyte Character to Wide Character 
  18719.      mbsrtowcs - Convert Multibyte String to Wide-Character String 
  18720.      mbstowcs - Convert Multibyte String to Wide-Character String 
  18721.      mbtowc - Convert Multibyte Character to Wide Character 
  18722.      setlocale - Set Locale 
  18723.      strlen - Determine String Length 
  18724.      wcrtomb - Convert Wide Character to Multibyte Character 
  18725.      wcslen - Calculate Length of Wide-Character String 
  18726.      wcsrtombs - Convert Wide-Character String to Multibyte String 
  18727.      wctomb -  Convert Wide Character to Multibyte Character 
  18728.      <locale.h> 
  18729.      <stdlib.h> 
  18730.  
  18731.  
  18732. ΓòÉΓòÉΓòÉ 4.182. mbrlen - Calculate Length of Multibyte Character ΓòÉΓòÉΓòÉ
  18733.  
  18734.  
  18735. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18736.  
  18737. #include <wchar.h>
  18738. size_t mbrlen(const char *string, size_t n,
  18739.               mbstate_t *state);
  18740.  
  18741.  
  18742. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18743.  
  18744. Language Level:  ANSI 93 
  18745.  
  18746. mbrlen is a restartable version of mblen and performs the same function. It 
  18747. determines the length in bytes of the multibyte character pointed to by string. 
  18748. A maximum of n bytes are examined. 
  18749.  
  18750. With mbrlen, you can begin processing a string, and then another. Once you have 
  18751. begun processing the second string, you may switch back and continue with the 
  18752. first string. On platforms that support shift states, state represents the 
  18753. initial shift state of the string (0).  If you read in only part of the string, 
  18754. mbrlen sets state to the string's shift state at the point you stopped.  You 
  18755. can then call mbrlen again for that string and pass in the updated state value 
  18756. to continue reading where you left off. 
  18757.  
  18758. Note:  Because the Windows code pages do not have shift states, the state 
  18759. parameter is provided only for compatibility with other ANSI/ISO platforms. 
  18760. VisualAge for C++ ignores the value passed for state. 
  18761.  
  18762. The behavior of mbrlen is affected by the LC_CTYPE category of the current 
  18763. locale. 
  18764.  
  18765. Return Value 
  18766. If string is a null pointer, mbrlen returns 0. 
  18767.  
  18768. If string is not a null pointer, mbrlen returns the first of the following that 
  18769. applies: 
  18770.  
  18771.  0    If the next n or fewer bytes complete the valid multibyte character that 
  18772.       corresponds to the null wide character. 
  18773.  
  18774.  positive If the next n or fewer bytes complete the valid multibyte character; 
  18775.       the value returned is the number of bytes that complete the multibyte 
  18776.       character. 
  18777.  
  18778.  -2   If the next n bytes form an incomplete (but potentially valid) multibyte 
  18779.       character, and all n bytes have been processed. 
  18780.  
  18781.  -1   If an encoding error occurs (when the next n or fewer bytes do not form a 
  18782.       complete and valid multibyte character).  mbrlen sets errno to EILSEQ. 
  18783.  
  18784.  
  18785. ΓòÉΓòÉΓòÉ <hidden> Example of mbrlen ΓòÉΓòÉΓòÉ
  18786.  
  18787. /************************************************************************
  18788.  
  18789. This example uses mbrlen to determine the length of the strings mbs1 and mbs2. 
  18790.  
  18791. ************************************************************************/
  18792.  
  18793. #include <wchar.h>
  18794. #include <stdio.h>
  18795. #include <stdlib.h>
  18796. #include <locale.h>
  18797.  
  18798. #define LOCNAME "ja_jp.ibm-932"
  18799.  
  18800. int main(void)
  18801. {
  18802.    char       mbs1[] = "abc";
  18803.    char       mbs2[] = "\x81\x41" "a" "\x81\xc1";
  18804.    mbstate_t  ss1 = 0;
  18805.    mbstate_t  ss2 = 0;
  18806.    size_t     length1, length2;
  18807.  
  18808.    if (NULL == setlocale(LC_ALL, LOCNAME)) {
  18809.       printf("Locale \"%s\" could not be loaded\n", LOCNAME);
  18810.       exit(1);
  18811.    }
  18812.    length1 =  mbrlen(mbs1, MB_CUR_MAX, &ss1);             /* first char  */
  18813.    length2 =  mbrlen(mbs2, MB_CUR_MAX, &ss2);             /* first char  */
  18814.    length1 += mbrlen(mbs1 + length1, MB_CUR_MAX, &ss1);   /* second char */
  18815.    length2 += mbrlen(mbs2 + length2, MB_CUR_MAX, &ss2);   /* second char */
  18816.    length1 += mbrlen(mbs1 + length1, MB_CUR_MAX, &ss1);   /* third char  */
  18817.    length2 += mbrlen(mbs2 + length2, MB_CUR_MAX, &ss2);   /* third char  */
  18818.    printf("Length of the first multibyte string = %d\n", length1);
  18819.    printf("Length of the second multibyte string = %d\n", length2);
  18820.    return 0;
  18821.  
  18822.    /****************************************************************************
  18823.       The output should be similiar to :
  18824.  
  18825.       Length of the first multibyte string = 3
  18826.       Length of the second multibyte string = 5
  18827.    ****************************************************************************/
  18828. }
  18829.  
  18830.  
  18831. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18832.  
  18833. Example of mbrlen 
  18834.  
  18835.      mblen - Determine Length of Multibyte Character 
  18836.      mbtowc - Convert Multibyte Character to Wide Character 
  18837.      mbrtowc - Convert Multibyte Character to Wide Character 
  18838.      mbsrtowcs - Convert Multibyte String to Wide-Character String 
  18839.      setlocale - Set Locale 
  18840.      wcrtomb - Convert Wide Character to Multibyte Character 
  18841.      wcsrtombs - Convert Wide-Character String to Multibyte String 
  18842.      <locale.h> 
  18843.      <wchar.h> 
  18844.  
  18845.  
  18846. ΓòÉΓòÉΓòÉ 4.183. mbrtowc - Convert Multibyte Character to Wide Character ΓòÉΓòÉΓòÉ
  18847.  
  18848.  
  18849. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18850.  
  18851. #include <wchar.h>
  18852. size_t mbrtowc (wchar_t *pwc, const char *string,
  18853.                 size_t n, mbstate_t *ps);
  18854.  
  18855.  
  18856. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18857.  
  18858. Language Level:  ANSI 93 
  18859.  
  18860. mbrtowc is a restartable version of mbtowc, and performs the same function. It 
  18861. first determines the length of the multibyte character pointed to by string. It 
  18862. then converts the multibyte character to the corresponding wide character, and 
  18863. stores the converted character in the location pointed to by pwc, if pwc is not 
  18864. a null pointer. A maximum of n bytes are examined. 
  18865.  
  18866. With mbrtowc, you can switch from one multibyte string to another. On systems 
  18867. that support shift states, ps represents the initial shift state of the string 
  18868. (0).  If you read in only part of the string, mbrtowc sets ps to the string's 
  18869. shift state at the point you stopped.  You can then call mbrtowc again for that 
  18870. string and pass in the updated ps value to continue reading where you left off. 
  18871.  
  18872. Note:  Because Windows code pages do not support shift states, the ps parameter 
  18873. is provided only for compatibility with other ANSI/ISO platforms.  VisualAge 
  18874. for C++ ignores the value passed for ps. 
  18875.  
  18876. The behavior of mbrtowc is affected by the LC_CTYPE category of the current 
  18877. locale. 
  18878.  
  18879. Return Value 
  18880. If string is a null pointer, mbrtowc returns 0. 
  18881.  
  18882. If string is not a null pointer, mbrtowc returns the first of the following 
  18883. that applies: 
  18884.  
  18885.  0    If the next n or fewer bytes complete the valid multibyte character that 
  18886.       corresponds to the null wide character. 
  18887.  
  18888.  positive If the next n or fewer bytes complete the valid multibyte character; 
  18889.       the value returned is the number of bytes that complete the multibyte 
  18890.       character. 
  18891.  
  18892.  -2   If the next n bytes form an incomplete (but potentially valid) multibyte 
  18893.       character, and all n bytes have been processed. 
  18894.  
  18895.  -1   If an encoding error occurs (when the next n or fewer bytes do not form a 
  18896.       complete and valid multibyte character).  mbrtowc sets errno to EILSEQ. 
  18897.  
  18898.  
  18899. ΓòÉΓòÉΓòÉ <hidden> Example of mbrtowc ΓòÉΓòÉΓòÉ
  18900.  
  18901. /************************************************************************
  18902.  
  18903. This example uses mbrlen to move to the second character in a string, then 
  18904. calls mbrtowc to convert the multibyte character to a wide character. 
  18905.  
  18906. ************************************************************************/
  18907.  
  18908. #include <wchar.h>
  18909. #include <stdio.h>
  18910. #include <stdlib.h>
  18911. #include <locale.h>
  18912.  
  18913. #define LOCNAME "ja_jp.ibm-932"
  18914.  
  18915. int main(void)
  18916. {
  18917.    char       mbs1[] = "abc";
  18918.    char       mbs2[] = "\x81\x41\x81\x42" "m";
  18919.    mbstate_t  ss1 = 0;
  18920.    mbstate_t  ss2 = 0;
  18921.    size_t     length1, length2;
  18922.    wchar_t    wc1, wc2;
  18923.  
  18924.    if (NULL == setlocale(LC_ALL, LOCNAME)) {
  18925.       printf("Locale \"%s\" could not be loaded\n", LOCNAME);
  18926.       exit(1);
  18927.    }
  18928.    length1 = mbrlen(mbs1, MB_CUR_MAX, &ss1);
  18929.    length2 = mbrlen(mbs2, MB_CUR_MAX, &ss2);
  18930.    mbrtowc(&wc1, mbs1 + length1, MB_CUR_MAX, &ss1);
  18931.    mbrtowc(&wc2, mbs2 + length2, MB_CUR_MAX, &ss2);
  18932.    printf("The second wide character in mbs1 is: <%lc>\n", wc1);
  18933.    printf("The second wide character in mbs2 is: <%lc>\n", wc2);
  18934.    return 0;
  18935.  
  18936.    /****************************************************************************
  18937.       The output should be similiar to :
  18938.  
  18939.       The second wide character in mbs1 is: <b>
  18940.       The second wide character in mbs2 is: <ΓöÇB>
  18941.    ****************************************************************************/
  18942. }
  18943.  
  18944.  
  18945. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18946.  
  18947. Example of mbrtowc 
  18948.  
  18949.      mblen - Determine Length of Multibyte Character 
  18950.      mbrlen - Calculate Length of Multibyte Character 
  18951.      mbsrtowcs - Convert Multibyte String to Wide-Character String 
  18952.      setlocale - Set Locale 
  18953.      wcrtomb - Convert Wide Character to Multibyte Character 
  18954.      wcsrtombs - Convert Wide-Character String to Multibyte String 
  18955.      <locale.h> 
  18956.      <wchar.h> 
  18957.  
  18958.  
  18959. ΓòÉΓòÉΓòÉ 4.184. mbsinit -  Test Object for Initial State ΓòÉΓòÉΓòÉ
  18960.  
  18961.  
  18962. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18963.  
  18964. #include <wchar.h>
  18965. int mbsinit(mbstate_t *state);
  18966.  
  18967.  
  18968. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18969.  
  18970. Language Level:  Extension 
  18971.  
  18972. mbsinit determines whether the state describes an initial conversion state. 
  18973.  
  18974. Note:  mbsinit is provided only for compatibility with EBCDIC systems that 
  18975. support conversion or shift states. The Windows code pages do not use shift 
  18976. states for multibyte character encoding. 
  18977.  
  18978. Return Value 
  18979. If state is a null pointer or points to 0, mbsinit returns a nonzero value. If 
  18980. state points to any other value, mbsinit returns 0. On systems that support 
  18981. shift states, mbsinit returns nonzero if state describes an initial conversion 
  18982. state, or 0 otherwise. 
  18983.  
  18984.  
  18985. ΓòÉΓòÉΓòÉ <hidden> Example of mbsinit ΓòÉΓòÉΓòÉ
  18986.  
  18987. /************************************************************************
  18988.  
  18989. This example checks the conversion state to see if it is in the initial state. 
  18990.  
  18991. ************************************************************************/
  18992.  
  18993. #include <wchar.h>
  18994. #include <stdio.h>
  18995. #include <stdlib.h>
  18996.  
  18997. int main(void)
  18998. {
  18999.    char      *string = "ABC";
  19000.    mbstate_t state = 0;
  19001.    wchar_t   wc;
  19002.  
  19003.    mbrtowc(&wc, string, MB_CUR_MAX, &state);
  19004.    if (0 != mbsinit(&state))
  19005.       printf("In initial conversion state.\n");
  19006.    return 0;
  19007.  
  19008.    /****************************************************************************
  19009.       The output should be similar to :
  19010.  
  19011.       In initial conversion state.
  19012.    ****************************************************************************/
  19013. }
  19014.  
  19015.  
  19016. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19017.  
  19018. Example of mbsinit 
  19019.  
  19020.      mbrlen - Calculate Length of Multibyte Character 
  19021.      mbrtowc - Convert Multibyte Character to Wide Character 
  19022.      mbsrtowcs - Convert Multibyte String to Wide-Character String 
  19023.      setlocale - Set Locale 
  19024.      wcrtomb - Convert Wide Character to Multibyte Character 
  19025.      wcsrtombs - Convert Wide-Character String to Multibyte String 
  19026.      <locale.h> 
  19027.      <wchar.h> 
  19028.  
  19029.  
  19030. ΓòÉΓòÉΓòÉ 4.185. mbsrtowcs - Convert Multibyte String to Wide-Character String ΓòÉΓòÉΓòÉ
  19031.  
  19032.  
  19033. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19034.  
  19035. #include <wchar.h>
  19036. size_t mbsrtowcs (wchar_t *dest, const char **src,
  19037.                   size_t len, mbstate_t *ps);
  19038.  
  19039.  
  19040. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19041.  
  19042. Language Level:  ANSI 93 
  19043.  
  19044. mbsrtowcs is a restartable version of mbstowcs, and performs the same function. 
  19045. It converts the sequence of multibyte characters from the array indirectly 
  19046. pointed to by src into a sequence of corresponding wide characters, and then 
  19047. stores the converted characters in the array pointed to by dest. 
  19048.  
  19049. Conversion continues up to and including the terminating wchar_t null 
  19050. character. The terminating null wide character is also stored. Conversion stops 
  19051. earlier if a sequence of bytes does not form a valid multibyte character, or 
  19052. when len codes have been stored into the array pointed to by dest. Each 
  19053. conversion takes place as if by a call to the mbrtowc function. 
  19054.  
  19055. mbsrtowcs assigns the object pointed to by src either a null pointer (if 
  19056. conversion stopped because a terminating null character was reached) or the 
  19057. address just past the last multibyte character converted. 
  19058.  
  19059. With mbsrtowcs, you can switch from one multibyte string to another. On 
  19060. platforms that support shift states, ps represents the initial shift state of 
  19061. the string (0).  If you read in only part of the string, mbsrtowcs sets ps to 
  19062. the string's shift state at the point you stopped.  You can then call mbsrtowcs 
  19063. again for that string and pass in the updated ps value to continue reading 
  19064. where you left off. 
  19065.  
  19066. Note:  Because Windows does not have shift states, the ps parameter is provided 
  19067. only for compatibility with other ANSI/ISO platforms.  VisualAge for C++ 
  19068. ignores the value passed for ps. 
  19069.  
  19070. The behavior of mbsrtowcs is affected by the LC_CTYPE category of the current 
  19071. locale. 
  19072.  
  19073. Return Value 
  19074. mbsrtowcs returns the number of multibyte characters successfully converted, 
  19075. not including the terminating null character. If dest is a null pointer, the 
  19076. value of len is ignored and mbsrtowcs returns the number of elements required 
  19077. for the converted wide characters. 
  19078.  
  19079. If the input string contains an invalid multibyte character, mbsrtowcs sets 
  19080. errno to EILSEQ and returns (size_t)-1. 
  19081.  
  19082.  
  19083. ΓòÉΓòÉΓòÉ <hidden> Example of mbsrtowcs ΓòÉΓòÉΓòÉ
  19084.  
  19085. /************************************************************************
  19086.  
  19087. This example uses mbsrtowcs to convert the multibyte characters in the arrays 
  19088. mbs1 and mbs2, and store them in the arrays wcs1 and wcs2. 
  19089.  
  19090. ************************************************************************/
  19091.  
  19092. #include <wchar.h>
  19093. #include <stdio.h>
  19094. #include <stdlib.h>
  19095. #include <locale.h>
  19096.  
  19097. #define SIZE 10
  19098.  
  19099. int main(void)
  19100. {
  19101.    char        mbs1[] = "abc";
  19102.    char        mbs2[] = "\x81\x41" "m" "\x81\x42";
  19103.    const char  *pmbs1 = mbs1;
  19104.    const char  *pmbs2 = mbs2;
  19105.    mbstate_t   ss1 = 0;
  19106.    mbstate_t   ss2 = 0;
  19107.    wchar_t     wcs1[SIZE], wcs2[SIZE];
  19108.  
  19109.    if (NULL == setlocale(LC_ALL, "ja_jp.ibm-932")) {
  19110.       printf("setlocale failed.\n");
  19111.       exit(EXIT_FAILURE);
  19112.    }
  19113.    mbsrtowcs(wcs1, &pmbs1, SIZE, &ss1);
  19114.    mbsrtowcs(wcs2, &pmbs2, SIZE, &ss2);
  19115.    printf("The first wide character string is %ls.\n", wcs1);
  19116.    printf("The second wide character string is %ls.\n", wcs2);
  19117.    return 0;
  19118.  
  19119.    /****************************************************************************
  19120.       The output should be similiar to :
  19121.  
  19122.       The first wide character string is abc.
  19123.       The second wide character string is ΓöÇAmΓöÇB.
  19124.    ****************************************************************************/
  19125. }
  19126.  
  19127.  
  19128. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19129.  
  19130. Example of mbsrtowcs 
  19131.  
  19132.      mblen - Determine Length of Multibyte Character 
  19133.      mbrlen - Calculate Length of Multibyte Character 
  19134.      mbrtowc - Convert Multibyte Character to Wide Character 
  19135.      mbstowcs - Convert Multibyte String to Wide-Character String 
  19136.      setlocale - Set Locale 
  19137.      wcrtomb - Convert Wide Character to Multibyte Character 
  19138.      wcsrtombs - Convert Wide-Character String to Multibyte String 
  19139.      <locale.h> 
  19140.      <wchar.h> 
  19141.  
  19142.  
  19143. ΓòÉΓòÉΓòÉ 4.186. mbstowcs - Convert Multibyte String to Wide-Character String ΓòÉΓòÉΓòÉ
  19144.  
  19145.  
  19146. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19147.  
  19148. #include <stdlib.h>
  19149. size_t mbstowcs(wchar_t *dest, const char *string, size_t len);
  19150.  
  19151.  
  19152. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19153.  
  19154. Language Level: ANSI, SAA, XPG4 
  19155.  
  19156. mbstowcs converts the multibyte character string pointed to by string into the 
  19157. wide-character array pointed to by dest. Depending on the encoding scheme used 
  19158. by the code set, the multibyte character string can contain any combination of 
  19159. single-byte or double-byte characters. 
  19160.  
  19161. The conversion stops after len bytes in dest are filled or after a wchar_t null 
  19162. character is encountered. The terminating null character is converted to a wide 
  19163. character with the value 0; characters that follow it are not processed. 
  19164.  
  19165. The behavior of mbstowcs is affected by the LC_CTYPE category of the current 
  19166. locale. 
  19167.  
  19168. Return Value 
  19169. If successful, mbstowcs returns the number of characters converted and stored 
  19170. in dest, not counting the terminating null character. The string pointed to by 
  19171. dest ends with a null character unless mbstowcs returns the value len. 
  19172.  
  19173. If it encounters an invalid multibyte character, mbstowcs returns (size_t)-1. 
  19174. If dest is a null pointer, the value of len is ignored and mbstowcs returns the 
  19175. number of elements required for the converted wide characters. 
  19176.  
  19177.  
  19178. ΓòÉΓòÉΓòÉ <hidden> Example of mbstowcs ΓòÉΓòÉΓòÉ
  19179.  
  19180. /************************************************************************
  19181.  
  19182. This example uses mbstowcs to convert the multibyte character mbs to a a wide 
  19183. character string and store it in wcs. 
  19184.  
  19185. ************************************************************************/
  19186.  
  19187. #include <wchar.h>
  19188. #include <stdio.h>
  19189. #include <stdlib.h>
  19190. #include <locale.h>
  19191.  
  19192. #define SIZE 10
  19193. #define LOCNAME "ja_jp.ibm-932"
  19194.  
  19195. int main(void)
  19196. {
  19197.    char        mbs[] = "\x81\x41" "m" "\x81\x42";
  19198.    wchar_t     wcs[SIZE];
  19199.  
  19200.    if (NULL == setlocale(LC_ALL, LOCNAME)) {
  19201.       printf("Locale \"%s\" could not be loaded\n", LOCNAME);
  19202.       exit(1);
  19203.    }
  19204.    mbstowcs(wcs, mbs, SIZE);
  19205.    printf("The wide character string is %ls.\n", wcs);
  19206.    return 0;
  19207.  
  19208.    /****************************************************************************
  19209.       The output should be similiar to :
  19210.  
  19211.       The wide character string is ΓöÇAmΓöÇB.
  19212.    ****************************************************************************/
  19213. }
  19214.  
  19215.  
  19216. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19217.  
  19218. Example of mbstowcs 
  19219.  
  19220.      mblen - Determine Length of Multibyte Character 
  19221.      mbsrtowcs - Convert Multibyte String to Wide-Character String 
  19222.      mbtowc - Convert Multibyte Character to Wide Character 
  19223.      setlocale - Set Locale 
  19224.      wcslen - Calculate Length of Wide-Character String 
  19225.      wcstombs - Convert Wide-Character String to Multibyte String 
  19226.      <locale.h> 
  19227.      <stdlib.h> 
  19228.  
  19229.  
  19230. ΓòÉΓòÉΓòÉ 4.187. mbtowc - Convert Multibyte Character to Wide Character ΓòÉΓòÉΓòÉ
  19231.  
  19232.  
  19233. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19234.  
  19235. #include <stdlib.h>
  19236. int mbtowc(wchar_t *pwc, const char *string, size_t n);
  19237.  
  19238.  
  19239. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19240.  
  19241. Language Level:  ANSI, SAA, XPG4 
  19242.  
  19243. mbtowc first determines the length of the multibyte character pointed to by 
  19244. string. It then converts the multibyte character to the corresponding wide 
  19245. character, and stores it in the location pointed to by pwc, if pwc is not a 
  19246. null pointer. mbtowc examines a maximum of n bytes from string. 
  19247.  
  19248. If pwc is a null pointer, the multibyte character is not converted. 
  19249.  
  19250. The behavior of mbtowc is affected by the LC_CTYPE category of the current 
  19251. locale. 
  19252.  
  19253. Return Value 
  19254. If string is NULL, mbtowc returns 0. 
  19255.  
  19256. Note:  On platforms that support shift states, mbtowc can also return a nonzero 
  19257. value to indicate that the multibyte encoding is state dependent. Because 
  19258. VisualAge for C++ does not support state-dependent encoding, mbtowc always 
  19259. returns 0 when string is NULL. 
  19260.  
  19261. If string is not NULL, mbtowc returns: 
  19262.  
  19263.      The number of bytes comprising the converted multibyte character, if n or 
  19264.       fewer bytes form a valid multibyte character. 
  19265.      0 if string points to the null character. 
  19266.      -1 if string does not point to a valid multibyte character, and the next 
  19267.       n bytes do not form a valid multibyte character. 
  19268.  
  19269.  
  19270. ΓòÉΓòÉΓòÉ <hidden> Example of mbtowc ΓòÉΓòÉΓòÉ
  19271.  
  19272. /************************************************************************
  19273.  
  19274. This example uses mbtowc to convert the second multibyte character in mbs to a 
  19275. wide character. 
  19276.  
  19277. ************************************************************************/
  19278.  
  19279. #include <stdio.h>
  19280. #include <stdlib.h>
  19281. #include <wchar.h>
  19282. #include <locale.h>
  19283.  
  19284. #define LOCNAME "ja_jp.ibm-932"
  19285.  
  19286. int main(void)
  19287. {
  19288.    char     mb_string[] = "\x81\x41\x81\x42" "c" "\x00";
  19289.    int      length;
  19290.    wchar_t  widechar;
  19291.  
  19292.    if (NULL == setlocale(LC_ALL, LOCNAME)) {
  19293.       printf("Locale \"%s\" could not be loaded\n", LOCNAME);
  19294.       exit(1);
  19295.    }
  19296.    length = mblen(mb_string, MB_CUR_MAX);
  19297.    length = mbtowc(&widechar, mb_string + length, MB_CUR_MAX);
  19298.    printf("The wide character %lc has length of %d.\n", widechar, length);
  19299.    return 0;
  19300.  
  19301.    /****************************************************************************
  19302.       The output should be similar to :
  19303.  
  19304.       The wide character ΓöÇB has length of 2.
  19305.    ****************************************************************************/
  19306. }
  19307.  
  19308.  
  19309. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19310.  
  19311. Example of mbtowc 
  19312.  
  19313.      mblen - Determine Length of Multibyte Character 
  19314.      mbrtowc - Convert Multibyte Character to Wide Character 
  19315.      mbstowcs - Convert Multibyte String to Wide-Character String 
  19316.      setlocale - Set Locale 
  19317.      wcslen - Calculate Length of Wide-Character String 
  19318.      wctomb -  Convert Wide Character to Multibyte Character 
  19319.      <locale.h> 
  19320.      <stdlib.h> 
  19321.  
  19322.  
  19323. ΓòÉΓòÉΓòÉ 4.188. memccpy - Copy Bytes ΓòÉΓòÉΓòÉ
  19324.  
  19325.  
  19326. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19327.  
  19328. #include <string.h>     /* also in <memory.h> */
  19329. void *memccpy(void *dest, void *src, int c, unsigned cnt);
  19330.  
  19331.  
  19332. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19333.  
  19334. Language Level:  Extension 
  19335.  
  19336. memccpy copies bytes from src to dest, up to and including the first occurrence 
  19337. of the character c or until cnt bytes have been copied, whichever comes first. 
  19338.  
  19339. Return Value 
  19340. If the character c is copied, memccpy returns a pointer to the byte in dest 
  19341. that immediately follows the character. If c is not copied, memccpy returns 
  19342. NULL. 
  19343.  
  19344.  
  19345. ΓòÉΓòÉΓòÉ <hidden> Example of memccpy ΓòÉΓòÉΓòÉ
  19346.  
  19347. /************************************************************************
  19348.  
  19349. This example copies up to 55 characters, or until it copies the '.' character, 
  19350. from the source to the buffer. 
  19351.  
  19352. ************************************************************************/
  19353.  
  19354. #include <stdio.h>
  19355. #include <stdlib.h>
  19356. #include <string.h>
  19357.  
  19358. char source[60];
  19359. char result[60];
  19360.  
  19361. int main(void)
  19362. {
  19363.    memcpy(source, "This is the string. This part won't be copied.", 55);
  19364.    if (NULL == memccpy(result, source, '.', 55)) {
  19365.       printf("Error in copying source.\n");
  19366.       exit(EXIT_FAILURE);
  19367.    }
  19368.    else
  19369.       printf("%s\n", result);
  19370.    return 0;
  19371.  
  19372.    /****************************************************************************
  19373.       The output should be:
  19374.  
  19375.       This is the string.
  19376.    ****************************************************************************/
  19377. }
  19378.  
  19379.  
  19380. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19381.  
  19382. Example of memccpy 
  19383.  
  19384.      memchr - Search Buffer 
  19385.      memcmp - Compare Buffers 
  19386.      memcpy - Copy Bytes 
  19387.      memmove - Copy Bytes 
  19388.      memset - Set Bytes to Value 
  19389.      <memory.h> 
  19390.      <string.h> 
  19391.  
  19392.  
  19393. ΓòÉΓòÉΓòÉ 4.189. memchr - Search Buffer ΓòÉΓòÉΓòÉ
  19394.  
  19395.  
  19396. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19397.  
  19398. #include <string.h>  /* also in <memory.h> */
  19399. void *memchr(const void *buf, int c, size_t count);
  19400.  
  19401.  
  19402. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19403.  
  19404. Language Level: ANSI, SAA, XPG4, Extension 
  19405.  
  19406. memchr searches the first count bytes of buf for the first occurrence of c 
  19407. converted to an unsigned character. The search continues until it finds c or 
  19408. examines count bytes. 
  19409.  
  19410. Return Value 
  19411. memchr returns a pointer to the location of c in buf. It returns NULL if c is 
  19412. not within the first count bytes of buf. 
  19413.  
  19414.  
  19415. ΓòÉΓòÉΓòÉ <hidden> Example of memchr ΓòÉΓòÉΓòÉ
  19416.  
  19417. /************************************************************************
  19418.  
  19419. This example finds the first occurrence of "x" in the string that you provide. 
  19420. If it is found, the string that starts with that character is printed. 
  19421.  
  19422. ************************************************************************/
  19423.  
  19424. #include <stdio.h>
  19425. #include <string.h>
  19426.  
  19427. int main(int argc,char **argv)
  19428. {
  19429.    char *result;
  19430.  
  19431.    if (argc != 2)
  19432.       printf("Usage: %s string\n", argv[0]);
  19433.    else {
  19434.       if ((result = (char *)memchr(argv[1], 'x', strlen(argv[1]))) != NULL)
  19435.          printf("The string starting with x is %s\n", result);
  19436.       else
  19437.          printf("The letter x cannot be found in the string\n");
  19438.    }
  19439.    return 0;
  19440.  
  19441.    /****************************************************************************
  19442.       If the program is passed the argument 'boxing', the output should be:
  19443.  
  19444.       The string starting with x is xing
  19445.    ****************************************************************************/
  19446. }
  19447.  
  19448.  
  19449. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19450.  
  19451. Example of memchr 
  19452.  
  19453.      memccpy - Copy Bytes 
  19454.      memcmp - Compare Buffers 
  19455.      memcpy - Copy Bytes 
  19456.      memicmp - Compare Bytes 
  19457.      memmove - Copy Bytes 
  19458.      memset - Set Bytes to Value 
  19459.      strchr - Search for Character 
  19460.      <memory.h> 
  19461.      <string.h> 
  19462.  
  19463.  
  19464. ΓòÉΓòÉΓòÉ 4.190. memcmp - Compare Buffers ΓòÉΓòÉΓòÉ
  19465.  
  19466.  
  19467. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19468.  
  19469. #include <string.h>  /* also in <memory.h> */
  19470. int memcmp(const void *buf1, const void *buf2, size_t count);
  19471.  
  19472.  
  19473. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19474.  
  19475. Language Level: ANSI, SAA, XPG4, Extension 
  19476.  
  19477. memcmp compares the first count bytes of buf1 and buf2. 
  19478.  
  19479. Return Value 
  19480. memcmp returns a value indicating the relationship between the two buffers as 
  19481. follows: 
  19482.  
  19483.  Value               Meaning 
  19484.  Less than 0         buf1 less than buf2 
  19485.  0                   buf1 identical to buf2 
  19486.  Greater than 0      buf1 greater than buf2 
  19487.  
  19488.  
  19489. ΓòÉΓòÉΓòÉ <hidden> Example of memcmp ΓòÉΓòÉΓòÉ
  19490.  
  19491. /************************************************************************
  19492.  
  19493. This example reports the relation between the two arguments passed to main to 
  19494. determine which, if either, is greater. 
  19495.  
  19496. ************************************************************************/
  19497.  
  19498. #include <stdio.h>
  19499. #include <string.h>
  19500.  
  19501. int main(int argc,char **argv)
  19502. {
  19503.    int len;
  19504.    int result;
  19505.  
  19506.    if (argc != 3) {
  19507.       printf("Usage: %s string1 string2\n", argv[0]);
  19508.    }
  19509.    else {
  19510.  
  19511.       /* Determine the length to be used for comparison                       */
  19512.  
  19513.       if (strlen(argv[1]) < strlen(argv[2]))
  19514.          len = strlen(argv[1]);
  19515.       else
  19516.          len = strlen(argv[2]);
  19517.       result = memcmp(argv[1], argv[2], len);
  19518.       printf("When the first %i characters are compared,\n", len);
  19519.       if (0 == result)
  19520.          printf("\"%s\" is identical to \"%s\"\n", argv[1], argv[2]);
  19521.       else
  19522.          if (result < 0)
  19523.  
  19524.             printf("\"%s\" is less than \"%s\"\n", argv[1], argv[2]);
  19525.          else
  19526.             printf("\"%s\" is greater than \"%s\"\n", argv[1], argv[2]);
  19527.    }
  19528.    return 0;
  19529.  
  19530.    /****************************************************************************
  19531.       If the program is passed the arguments "firststring secondstring",
  19532.       the output should be:
  19533.  
  19534.       When the first 11 characters are compared,
  19535.       "firststring" is less than "secondstring"
  19536.    ****************************************************************************/
  19537. }
  19538.  
  19539.  
  19540. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19541.  
  19542. Example of memcmp 
  19543.  
  19544.      memccpy - Copy Bytes 
  19545.      memchr - Search Buffer 
  19546.      memcpy - Copy Bytes 
  19547.      memicmp - Compare Bytes 
  19548.      memmove - Copy Bytes 
  19549.      memset - Set Bytes to Value 
  19550.      strcmp - Compare Strings 
  19551.      <memory.h> 
  19552.      <string.h> 
  19553.  
  19554.  
  19555. ΓòÉΓòÉΓòÉ 4.191. memcpy - Copy Bytes ΓòÉΓòÉΓòÉ
  19556.  
  19557.  
  19558. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19559.  
  19560. #include <string.h>  /* also <memory.h> */
  19561. void *memcpy(void *dest, const void *src, size_t count);
  19562.  
  19563.  
  19564. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19565.  
  19566. Language Level: ANSI, SAA, XPG4, Extension 
  19567.  
  19568. memcpy copies count bytes of src to dest. The behavior is undefined if copying 
  19569. takes place between objects that overlap. (The memmove function allows copying 
  19570. between objects that may overlap.) 
  19571.  
  19572. Return Value 
  19573. memcpy returns a pointer to dest. 
  19574.  
  19575.  
  19576. ΓòÉΓòÉΓòÉ <hidden> Example of memcpy ΓòÉΓòÉΓòÉ
  19577.  
  19578. /************************************************************************
  19579.  
  19580. This example copies the contents of source to target. 
  19581.  
  19582. ************************************************************************/
  19583.  
  19584. #include <string.h>
  19585. #include <stdio.h>
  19586.  
  19587. #define  MAX_LEN       80
  19588. char source[MAX_LEN] = "This is the source string";
  19589. char target[MAX_LEN] = "This is the target string";
  19590.  
  19591. int main(void)
  19592. {
  19593.    printf("Before memcpy, target is \"%s\"\n", target);
  19594.    memcpy(target, source, sizeof(source));
  19595.    printf("After memcpy, target becomes \"%s\"\n", target);
  19596.    return 0;
  19597.  
  19598.    /****************************************************************************
  19599.       The output should be:
  19600.  
  19601.       Before memcpy, target is "This is the target string"
  19602.       After memcpy, target becomes "This is the source string"
  19603.    ****************************************************************************/
  19604. }
  19605.  
  19606.  
  19607. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19608.  
  19609. Example of memcpy 
  19610.  
  19611.      memccpy - Copy Bytes 
  19612.      memchr - Search Buffer 
  19613.      memcmp - Compare Buffers 
  19614.      memicmp - Compare Bytes 
  19615.      memmove - Copy Bytes 
  19616.      memset - Set Bytes to Value 
  19617.      strcpy - Copy Strings 
  19618.      <memory.h> 
  19619.      <string.h> 
  19620.  
  19621.  
  19622. ΓòÉΓòÉΓòÉ 4.192. memicmp - Compare Bytes ΓòÉΓòÉΓòÉ
  19623.  
  19624.  
  19625. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19626.  
  19627. #include <string.h>    /* also in <memory.h> */
  19628. int memicmp(void *buf1, void *buf2, unsigned int cnt);
  19629.  
  19630.  
  19631. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19632.  
  19633. Language Level:  Extension 
  19634.  
  19635. memicmp compares the first cnt bytes of buf1 and buf2 without regard to the 
  19636. case of letters in the two buffers.  The function converts all uppercase 
  19637. characters into lowercase and then performs the comparison. 
  19638.  
  19639. Return Value 
  19640. The return value of memicmp indicates the result as follows: 
  19641.  
  19642.  Value               Meaning 
  19643.  Less than 0         buf1 less than buf2 
  19644.  0                   buf1 identical to buf2 
  19645.  Greater than 0      buf1 greater than buf2. 
  19646.  
  19647.  
  19648. ΓòÉΓòÉΓòÉ <hidden> Example of memicmp ΓòÉΓòÉΓòÉ
  19649.  
  19650. /************************************************************************
  19651.  
  19652. This example copies two strings that each contain a substring of 29 characters 
  19653. that are the same except for case. The example then compares the first 29 bytes 
  19654. without regard to case. 
  19655.  
  19656. ************************************************************************/
  19657.  
  19658. #include <stdio.h>
  19659. #include <string.h>
  19660.  
  19661. char first[100],second[100];
  19662.  
  19663. int main(void)
  19664. {
  19665.    int result;
  19666.  
  19667.    strcpy(first, "Those Who Will Not Learn From History");
  19668.    strcpy(second, "THOSE WHO WILL NOT LEARN FROM their mistakes");
  19669.    printf("Comparing the first 29 characters of two strings.\n");
  19670.    result = memicmp(first, second, 29);
  19671.    printf("The first 29 characters of String 1 are ");
  19672.    if (result < 0)
  19673.       printf("less than String 2.\n");
  19674.    else
  19675.       if (0 == result)
  19676.          printf("equal to String 2.\n");
  19677.       else
  19678.          printf("greater than String 2.\n");
  19679.    return 0;
  19680.  
  19681.    /****************************************************************************
  19682.       The output should be:
  19683.  
  19684.       Comparing the first 29 characters of two strings.
  19685.       The first 29 characters of String 1 are equal to String 2
  19686.    ****************************************************************************/
  19687. }
  19688.  
  19689.  
  19690. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19691.  
  19692. Example of memicmp 
  19693.  
  19694.      memchr - Search Buffer 
  19695.      memcmp - Compare Buffers 
  19696.      memcpy - Copy Bytes 
  19697.      memmove - Copy Bytes 
  19698.      memset - Set Bytes to Value 
  19699.      strcmp - Compare Strings 
  19700.      <memory.h> 
  19701.      <string.h> 
  19702.  
  19703.  
  19704. ΓòÉΓòÉΓòÉ 4.193. memmove - Copy Bytes ΓòÉΓòÉΓòÉ
  19705.  
  19706.  
  19707. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19708.  
  19709. #include <string.h>  /* also in <memory.h> */
  19710. void *memmove(void *dest, const void *src, size_t count);
  19711.  
  19712.  
  19713. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19714.  
  19715. Language Level: ANSI, SAA, XPG4, Extension 
  19716.  
  19717. memmove copies count bytes of src to dest. memmove allows copying between 
  19718. objects that may overlap. The behavior is as if the src is first copied into a 
  19719. temporary array. 
  19720.  
  19721. Return Value 
  19722. memmove returns a pointer to dest. 
  19723.  
  19724.  
  19725. ΓòÉΓòÉΓòÉ <hidden> Example of memmove ΓòÉΓòÉΓòÉ
  19726.  
  19727. /************************************************************************
  19728.  
  19729. This example copies the word shiny from position target + 2 to position target 
  19730. + 8. 
  19731.  
  19732. ************************************************************************/
  19733.  
  19734. #include <string.h>
  19735. #include <stdio.h>
  19736.  
  19737. #define  SIZE          21
  19738. char target[SIZE] = "a shiny white sphere";
  19739.  
  19740. int main(void)
  19741. {
  19742.    char *p = target+8;                    /* p points at the starting character
  19743.                                              of the word we want to replace   */
  19744.    char *source = target+2;                               /* start of "shiny" */
  19745.  
  19746.    printf("Before memmove, target is \"%s\"\n", target);
  19747.    memmove(p, source, 5);
  19748.    printf("After memmove, target becomes \"%s\"\n", target);
  19749.    return 0;
  19750.  
  19751.    /****************************************************************************
  19752.       The output should be:
  19753.  
  19754.       Before memmove, target is "a shiny white sphere"
  19755.       After memmove, target becomes "a shiny shiny sphere"
  19756.    ****************************************************************************/
  19757. }
  19758.  
  19759.  
  19760. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19761.  
  19762. Example of memmove 
  19763.  
  19764.      memccpy - Copy Bytes 
  19765.      memchr - Search Buffer 
  19766.      memcmp - Compare Buffers 
  19767.      memcpy - Copy Bytes 
  19768.      memicmp - Compare Bytes 
  19769.      memset - Set Bytes to Value 
  19770.      strcpy - Copy Strings 
  19771.      <memory.h> 
  19772.      <string.h> 
  19773.  
  19774.  
  19775. ΓòÉΓòÉΓòÉ 4.194. memset - Set Bytes to Value ΓòÉΓòÉΓòÉ
  19776.  
  19777.  
  19778. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19779.  
  19780. #include <string.h>  /* also in <memory.h> */
  19781. void *memset(void *dest, int c, size_t count);
  19782.  
  19783.  
  19784. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19785.  
  19786. Language Level: ANSI, SAA, XPG4, Extension 
  19787.  
  19788. memset sets the first count bytes of dest to the value c.  The value of c is 
  19789. converted to an unsigned character. 
  19790.  
  19791. Return Value 
  19792.  
  19793. memset returns a pointer to dest. 
  19794.  
  19795.  
  19796. ΓòÉΓòÉΓòÉ <hidden> Example of memset ΓòÉΓòÉΓòÉ
  19797.  
  19798. /************************************************************************
  19799.  
  19800. This example sets 10 bytes of the buffer to A and the next 10 bytes to B. 
  19801.  
  19802. ************************************************************************/
  19803.  
  19804. #include <string.h>
  19805. #include <stdio.h>
  19806.  
  19807. #define  BUF_SIZE      20
  19808.  
  19809. int main(void)
  19810. {
  19811.    char buffer[BUF_SIZE+1];
  19812.    char *string;
  19813.  
  19814.    memset(buffer, 0, sizeof(buffer));
  19815.    string = (char *)memset(buffer, 'A', 10);
  19816.    printf("\nBuffer contents: %s\n", string);
  19817.    memset(buffer+10, 'B', 10);
  19818.    printf("\nBuffer contents: %s\n", buffer);
  19819.    return 0;
  19820.  
  19821.    /****************************************************************************
  19822.       The output should be:
  19823.  
  19824.       Buffer contents: AAAAAAAAAA
  19825.       Buffer contents: AAAAAAAAAABBBBBBBBBB
  19826.    ****************************************************************************/
  19827. }
  19828.  
  19829.  
  19830. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19831.  
  19832. Example of memset 
  19833.  
  19834.      memccpy - Copy Bytes 
  19835.      memchr - Search Buffer 
  19836.      memcmp - Compare Buffers 
  19837.      memcpy - Copy Bytes 
  19838.      memicmp - Compare Bytes 
  19839.      memmove - Copy Bytes 
  19840.      strnset - strset - Set Characters in String 
  19841.      <memory.h> 
  19842.      <string.h> 
  19843.  
  19844.  
  19845. ΓòÉΓòÉΓòÉ 4.195. _mheap - Query Memory Heap for Allocated Object ΓòÉΓòÉΓòÉ
  19846.  
  19847.  
  19848. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19849.  
  19850. #include <umalloc.h>
  19851. Heap_t _mheap(void *ptr);
  19852.  
  19853.  
  19854. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19855.  
  19856. Language Level:  Extension 
  19857.  
  19858. _mheap determines from which heap the object specified by ptr was allocated. 
  19859. The ptr must be a valid pointer that was returned from a runtime allocation 
  19860. function (_ucalloc, malloc, realloc, and so on).  If the pointer is not valid, 
  19861. the results of _mheap are undefined. 
  19862.  
  19863. For more information about creating and using heaps, see the chapter on 
  19864. Managing Memory in the Programming Guide. 
  19865.  
  19866. Return Value: 
  19867. _mheap returns the handle of the heap from which the object was allocated.  If 
  19868. the object was allocated from the runtime heap, _mheap returns _RUNTIME_HEAP. 
  19869. If the object passed to _mheap is NULL, _mheap returns NULL. If the object is 
  19870. not valid, _mheap either returns NULL or the results are unpredictable and an 
  19871. exception may occur. 
  19872.  
  19873.  
  19874. ΓòÉΓòÉΓòÉ <hidden> Example of _mheap ΓòÉΓòÉΓòÉ
  19875.  
  19876. /************************************************************************
  19877.  
  19878. This example allocates a block of memory from the heap, then uses _mheap to 
  19879. determine which heap the block came from. 
  19880.  
  19881. *********************************************************************** /
  19882.  
  19883. #include <stdlib.h>
  19884. #include <stdio.h>
  19885. #include <umalloc.h>
  19886.  
  19887. int main(void)
  19888. {
  19889.    char  *ptr;
  19890.  
  19891.    if (NULL == (ptr = (char*)malloc(10))) {
  19892.       puts("Could not allocate memory block.");
  19893.       exit(EXIT_FAILURE);
  19894.    }
  19895.    printf("Handle of heap used is 0x%x\n", _mheap(ptr));
  19896.    return 0;
  19897.  
  19898.    /****************************************************************************
  19899.       The output should be similar to :
  19900.  
  19901.       Handle of heap used is 0x70000
  19902.    ****************************************************************************/
  19903. }
  19904.  
  19905.  
  19906. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19907.  
  19908. Example of _mheap 
  19909.  
  19910.      "Managing Memory" in the Programming Guide 
  19911.      _msize - Return Number of Bytes Allocated 
  19912.      _ucreate - Create a Memory Heap 
  19913.      _ustats - Get Information about Heap 
  19914.      <umalloc.h> 
  19915.  
  19916.  
  19917. ΓòÉΓòÉΓòÉ 4.196. min - Return Lesser of Two Values ΓòÉΓòÉΓòÉ
  19918.  
  19919.  
  19920. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19921.  
  19922. #include <stdlib.h>
  19923. type min(type a, type b);
  19924.  
  19925.  
  19926. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19927.  
  19928. Language Level:  Extension 
  19929.  
  19930. min compares two values and determines the smaller of the two. The data type 
  19931. can be any arithmetic data type, signed or unsigned.  The type must be the same 
  19932. for both arguments to min. 
  19933.  
  19934. Note:  Because min is a macro, if the evaluation of the arguments contains side 
  19935. effects (post-increment operators, for example), the results of both the side 
  19936. effects and the macro will be undefined. 
  19937.  
  19938. Return Value 
  19939. min returns the smaller of the two values. 
  19940.  
  19941.  
  19942. ΓòÉΓòÉΓòÉ <hidden> Example of min ΓòÉΓòÉΓòÉ
  19943.  
  19944. /************************************************************************
  19945.  
  19946. This example prints the smaller of the two values, a and b. 
  19947.  
  19948. ************************************************************************/
  19949.  
  19950. #include <stdlib.h>
  19951. #include <stdio.h>
  19952.  
  19953. int main(void)
  19954. {
  19955.    int a = 10;
  19956.    int b = 21;
  19957.  
  19958.    printf("The smaller of %d and %d is %d\n", a, b, min(a, b));
  19959.    return 0;
  19960.  
  19961.    /****************************************************************************
  19962.       The output should be:
  19963.  
  19964.       The smaller of 10 and 21 is 10
  19965.    ****************************************************************************/
  19966. }
  19967.  
  19968.  
  19969. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19970.  
  19971. Example of min 
  19972.  
  19973.      max - Return Larger of Two Values 
  19974.      <stdlib.h> 
  19975.  
  19976.  
  19977. ΓòÉΓòÉΓòÉ 4.197. mkdir - Create New Directory ΓòÉΓòÉΓòÉ
  19978.  
  19979.  
  19980. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19981.  
  19982. #include <direct.h>
  19983. int mkdir(char *pathname);
  19984.  
  19985.  
  19986. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19987.  
  19988. Language Level:  XPG4, Extension 
  19989.  
  19990. mkdir creates a new directory with the specified pathname.  Because only one 
  19991. directory can be created at a time, only the last component of pathname can 
  19992. name a new directory. 
  19993.  
  19994. Note:  In earlier releases of VisualAge C++, mkdir began with an underscore 
  19995. (_mkdir). Because it is defined by the X/Open standard, the underscore has been 
  19996. removed. For compatibility, VisualAge for C++ will map _mkdir to mkdir for you. 
  19997.  
  19998. Return Value 
  19999. mkdir returns the value 0 if the directory was created.  A return value of -1 
  20000. indicates an error, and errno is set to one of the following values: 
  20001.  
  20002.  Value          Meaning 
  20003.  EACCESS        The directory was not created;  the given name is the name of 
  20004.                 an existing file, directory, or device. 
  20005.  ENOENT         The pathname was not found. 
  20006.  
  20007.  
  20008. ΓòÉΓòÉΓòÉ <hidden> Example of mkdir ΓòÉΓòÉΓòÉ
  20009.  
  20010. /************************************************************************
  20011.  
  20012. This example creates two new directories:  one at the root on drive C:, and one 
  20013. in the tmp subdirectory of the current working directory. 
  20014.  
  20015. ************************************************************************/
  20016.  
  20017. #include <stdio.h>
  20018. #include <direct.h>
  20019. #include <string.h>
  20020.  
  20021. int main(void)
  20022. {
  20023.    char *dir1,*dir2;
  20024.  
  20025.  /*  Create the directory "aleng" in the root directory of the C: drive.      */
  20026.  
  20027.    dir1 = "c:\\aleng";
  20028.    if (0 == (mkdir(dir1)))
  20029.       printf("%s directory was created.\n", dir1);
  20030.    else
  20031.       printf("%s directory was not created.\n", dir1);
  20032.  
  20033.  /*  Create the subdirectory "simon" in the current directory.                */
  20034.  
  20035.    dir2 = "simon";
  20036.    if (0 == (mkdir(dir2)))
  20037.       printf("%s directory was created.\n", dir2);
  20038.    else
  20039.       printf("%s directory was not created.\n", dir2);
  20040.  
  20041.  /*  Remove the directory "aleng" from the root directory of the C: drive.    */
  20042.  
  20043.    printf("Removing directory 'aleng' from the root directory.\n");
  20044.    if (rmdir(dir1))
  20045.       perror(NULL);
  20046.    else
  20047.       printf("%s directory was removed.\n", dir1);
  20048.  
  20049.  /*  Remove the subdirectory "simon" from the current directory.              */
  20050.  
  20051.    printf("Removing subdirectory 'simon' from the current directory.\n");
  20052.    if (rmdir(dir2))
  20053.       perror(NULL);
  20054.    else
  20055.       printf("%s directory was removed.\n", dir2);
  20056.    return 0;
  20057.  
  20058.    /****************************************************************************
  20059.       The output should be:
  20060.  
  20061.       c:\aleng directory was created.
  20062.       simon directory was created.
  20063.       Removing directory 'aleng' from the root directory.
  20064.       c:\aleng directory was removed.
  20065.       Removing subdirectory 'simon' from the current directory.
  20066.       simon directory was removed.
  20067.    ****************************************************************************/
  20068. }
  20069.  
  20070.  
  20071. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20072.  
  20073. Example of mkdir 
  20074.  
  20075.      chdir - Change Current Working Directory 
  20076.      _getcwd - Get Path Name of Current Directory 
  20077.      _getdcwd - Get Full Path Name of Current Directory 
  20078.      rmdir - Remove Directory 
  20079.      <direct.h> 
  20080.  
  20081.  
  20082. ΓòÉΓòÉΓòÉ 4.198. mktime - Convert Local Time ΓòÉΓòÉΓòÉ
  20083.  
  20084.  
  20085. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20086.  
  20087. #include <time.h>
  20088. time_t mktime(struct tm *time);
  20089.  
  20090.  
  20091. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20092.  
  20093. Language Level: ANSI, SAA, POSIX, XPG4 
  20094.  
  20095. mktime converts local time, stored as a tm structure pointed to by time, into a 
  20096. time_t structure suitable for use with other time functions. The values of some 
  20097. structure elements pointed to by time are not restricted to the ranges shown 
  20098. for gmtime. 
  20099.  
  20100. The values of tm_wday and tm_yday passed to mktime are ignored and are assigned 
  20101. their correct values on return. 
  20102.  
  20103. Note:  The time and date functions begin at 00:00:00 Coordinated Universal 
  20104. Time, January 1, 1970. 
  20105.  
  20106. Return Value 
  20107. mktime returns the calendar time having type time_t.  The value (time_t)(-1) is 
  20108. returned if the calendar time cannot be represented. 
  20109.  
  20110.  
  20111. ΓòÉΓòÉΓòÉ <hidden> Example of mktime ΓòÉΓòÉΓòÉ
  20112.  
  20113. /************************************************************************
  20114.  
  20115. This example prints the day of the week that is 40 days and 16 hours from the 
  20116. current date. 
  20117.  
  20118. ************************************************************************/
  20119.  
  20120. #include <stdio.h>
  20121. #include <time.h>
  20122.  
  20123. char *wday[] =  { "Sunday", "Monday", "Tuesday", "Wednesday",
  20124.                   "Thursday", "Friday", "Saturday" } ;
  20125.  
  20126. int main(void)
  20127. {
  20128.    time_t t1,t3;
  20129.    struct tm *t2;
  20130.  
  20131.    t1 = time(NULL);
  20132.    t2 = localtime(&t1);
  20133.    t2->tm_mday += 40;
  20134.    t2->tm_hour += 16;
  20135.    t3 = mktime(t2);
  20136.    printf("40 days and 16 hours from now, it will be a %9s \n", wday[t2->tm_wday
  20137.       ]);
  20138.    return 0;
  20139.  
  20140.    /****************************************************************************
  20141.       The output should be similar to:
  20142.  
  20143.       40 days and 16 hours from now, it will be a Sunday
  20144.    ****************************************************************************/
  20145. }
  20146.  
  20147.  
  20148. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20149.  
  20150. Example of mktime 
  20151.  
  20152.      asctime - Convert Time to Character String 
  20153.      ctime - Convert Time to Character String 
  20154.      gmtime - Convert Time 
  20155.      localtime - Convert Time 
  20156.      time - Determine Current Time 
  20157.      <time.h> 
  20158.  
  20159.  
  20160. ΓòÉΓòÉΓòÉ 4.199. modf - Separate Floating-Point Value ΓòÉΓòÉΓòÉ
  20161.  
  20162.  
  20163. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20164.  
  20165. #include <math.h>
  20166. double modf(double x, double *intptr);
  20167.  
  20168.  
  20169. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20170.  
  20171. Language Level: ANSI, SAA, POSIX, XPG4 
  20172.  
  20173. modf breaks down the floating-point value x into fractional and integral parts. 
  20174. The signed fractional portion of x is returned.  The integer portion is stored 
  20175. as a double value pointed to by intptr.  Both the fractional and integral parts 
  20176. are given the same sign as x. 
  20177.  
  20178. Return Value 
  20179. modf returns the signed fractional portion of x. 
  20180.  
  20181.  
  20182. ΓòÉΓòÉΓòÉ <hidden> Example of modf ΓòÉΓòÉΓòÉ
  20183.  
  20184. /************************************************************************
  20185.  
  20186. This example breaks the floating-point number -14.876 into its fractional and 
  20187. integral components. 
  20188.  
  20189. ************************************************************************/
  20190.  
  20191. #include <stdio.h>
  20192. #include <math.h>
  20193.  
  20194. int main(void)
  20195. {
  20196.    double x,y,d;
  20197.  
  20198.    x = -14.876;
  20199.    y = modf(x, &d);
  20200.    printf("x = %lf\n", x);
  20201.    printf("Integral part = %lf\n", d);
  20202.    printf("Fractional part = %lf\n", y);
  20203.    return 0;
  20204.  
  20205.    /****************************************************************************
  20206.       The output should be:
  20207.  
  20208.       x = -14.876000
  20209.       Integral part = -14.000000
  20210.       Fractional part = -0.876000
  20211.    ****************************************************************************/
  20212. }
  20213.  
  20214.  
  20215. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20216.  
  20217. Example of modf 
  20218.  
  20219.      fmod - Calculate Floating-Point Remainder 
  20220.      frexp - Separate Floating-Point Value 
  20221.      ldexp - Multiply by a Power of Two 
  20222.      <math.h> 
  20223.  
  20224.  
  20225. ΓòÉΓòÉΓòÉ 4.200. _msize - Return Number of Bytes Allocated ΓòÉΓòÉΓòÉ
  20226.  
  20227.  
  20228. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20229.  
  20230. #include <stdlib.h>  /* also in <malloc.h> */
  20231. size_t _msize(void *ptr)
  20232.  
  20233.  
  20234. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20235.  
  20236. Language Level:  Extension 
  20237.  
  20238. _msize determines the number of bytes that were allocated to the pointer 
  20239. argument ptr. The ptr must have been returned from one of the runtime memory 
  20240. allocation functions (_ucalloc, malloc, and so on). 
  20241.  
  20242. You cannot pass the argument of an object that has been freed. 
  20243.  
  20244. Return Value 
  20245. _msize returns the number of bytes allocated. If the argument is not a valid 
  20246. pointer returned from a memory allocation function, the return value is 
  20247. undefined. If NULL is passed, _msize returns 0. 
  20248.  
  20249.  
  20250. ΓòÉΓòÉΓòÉ <hidden> Example of _msize ΓòÉΓòÉΓòÉ
  20251.  
  20252. /************************************************************************
  20253.  
  20254. This example displays the size of an allocated object from malloc. 
  20255.  
  20256. ************************************************************************/
  20257.  
  20258. #include <stdlib.h>
  20259. #include <stdio.h>
  20260. #include <string.h>
  20261.  
  20262. int main(void)
  20263. {
  20264.    char *ptr;
  20265.  
  20266.    if (NULL == (ptr = (char*)malloc(10))) {
  20267.       puts("Could not allocate memory block.");
  20268.       exit(EXIT_FAILURE);
  20269.    }
  20270.    memset(ptr, 'x', 5);
  20271.    printf("The size of the allocated object is %u.\n",_msize(ptr));
  20272.    return 0;
  20273.  
  20274.    /****************************************************************************
  20275.       The output should be similar to :
  20276.  
  20277.       The size of the allocated object is 10.
  20278.    ****************************************************************************/
  20279. }
  20280.  
  20281.  
  20282. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20283.  
  20284. Example of _msize 
  20285.  
  20286.      calloc - Reserve and Initialize Storage 
  20287.      malloc - Reserve Storage Block 
  20288.      realloc - Change Reserved Storage Block Size 
  20289.      <malloc.h> 
  20290.      <stdlib.h> 
  20291.  
  20292.  
  20293. ΓòÉΓòÉΓòÉ 4.201. nl_langinfo - Retrieve Locale Information ΓòÉΓòÉΓòÉ
  20294.  
  20295.  
  20296. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20297.  
  20298. #include <nl_types.h>
  20299. #include <langinfo.h>
  20300. char *nl_langinfo(nl_item item);
  20301.  
  20302.  
  20303. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20304.  
  20305. Language Level:  XPG4 
  20306.  
  20307. nl_langinfo retrieves from the current locale the string that describes the 
  20308. requested information specified by item. 
  20309.  
  20310. The constant names and values for item are defined in <langinfo.h>. For a list 
  20311. of macros that define the constants used to identify the information queried in 
  20312. the current locale, see the table of defined macros under langinfo.h. 
  20313.  
  20314. You cannot retrieve the following information for the current locale: 
  20315.  
  20316.    t_fmt_ampm
  20317.    era
  20318.    era_year
  20319.    era_d_fmt
  20320.    alt_digits
  20321.    t_fmt_ampm
  20322.    alt_digits
  20323.  
  20324. Return Value 
  20325. nl_langinfo returns a pointer to a null-terminated string containing 
  20326. information about the active language or cultural area. The active language or 
  20327. cultural area is determined by the most recent setlocale call. Subsequent calls 
  20328. to the setlocale function may modify the string that the return value points 
  20329. to. Your own code cannot modify the array. 
  20330.  
  20331. If item is not valid, nl_langinfo returns a pointer to an empty string. 
  20332.  
  20333.  
  20334. ΓòÉΓòÉΓòÉ <hidden> Example of nl_langinfo ΓòÉΓòÉΓòÉ
  20335.  
  20336. /************************************************************************
  20337.  
  20338. This example uses nl_langinfo to retrieve the current codeset name. 
  20339.  
  20340. ************************************************************************/
  20341.  
  20342. #include <nl_types.h>
  20343. #include <langinfo.h>
  20344. #include <stdio.h>
  20345.  
  20346. int main(void)
  20347. {
  20348.    printf("Current codeset is %s\n", nl_langinfo(CODESET));
  20349.    return 0;
  20350.  
  20351.    /****************************************************************************
  20352.       The output should be similar to :
  20353.  
  20354.       Current codeset is IBM-850
  20355.    ****************************************************************************/
  20356. }
  20357.  
  20358.  
  20359. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20360.  
  20361. Example of nl_langinfo 
  20362.  
  20363.      localdtconv - Return Date and Time Formatting Convention 
  20364.      localeconv - Retrieve Information from the Environment 
  20365.      setlocale - Set Locale 
  20366.      <langinfo.h> 
  20367.      <nl_types.h> 
  20368.  
  20369.  
  20370. ΓòÉΓòÉΓòÉ 4.202. _onexit - Record Termination Function ΓòÉΓòÉΓòÉ
  20371.  
  20372.  
  20373. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20374.  
  20375. #include <stdlib.h>
  20376. onexit_t _onexit(onexit_t func);
  20377.  
  20378.  
  20379. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20380.  
  20381. Language Level:  Extension 
  20382.  
  20383. _onexit records the address of a function func to call when the program ends 
  20384. normally.  Successive calls to _onexit create a stack of functions that run in 
  20385. a last-in, first-out order. The functions passed to _onexit cannot take 
  20386. parameters. 
  20387.  
  20388. You can record up to 32 termination functions with calls to _onexit and atexit. 
  20389. If you exceed 32 functions, _onexit returns the value NULL. 
  20390.  
  20391. Note:  For portability, use the ANSI/ISO standard atexit function, which is 
  20392. equivalent to _onexit. 
  20393.  
  20394. Return Value 
  20395. If successful, _onexit returns a pointer to the function; otherwise, it returns 
  20396. a NULL value. 
  20397.  
  20398.  
  20399. ΓòÉΓòÉΓòÉ <hidden> Example of _onexit ΓòÉΓòÉΓòÉ
  20400.  
  20401. /************************************************************************
  20402.  
  20403. This example specifies and defines four distinct functions that run 
  20404. consecutively at the completion of main. 
  20405.  
  20406. ************************************************************************/
  20407.  
  20408. #include <stdio.h>
  20409. #include <stdlib.h>
  20410.  
  20411. int fn1(void)
  20412. {
  20413.    printf("next.\n");
  20414.    return 0;
  20415. }
  20416.  
  20417. int fn2(void)
  20418. {
  20419.    printf("run ");
  20420.    return 0;
  20421. }
  20422.  
  20423. int fn3(void)
  20424. {
  20425.    printf("is ");
  20426.    return 0;
  20427. }
  20428.  
  20429. int fn4(void)
  20430. {
  20431.    printf("This ");
  20432.    return 0;
  20433. }
  20434.  
  20435. int main(void)
  20436. {
  20437.    _onexit((onexit_t)fn1);
  20438.    _onexit((onexit_t)fn2);
  20439.    _onexit((onexit_t)fn3);
  20440.    _onexit((onexit_t)fn4);
  20441.    printf("This is run first.\n");
  20442.    return 0;
  20443.  
  20444.    /****************************************************************************
  20445.       The output should be:
  20446.  
  20447.       This is run first.
  20448.       This is run next.
  20449.    ****************************************************************************/
  20450. }
  20451.  
  20452.  
  20453. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20454.  
  20455. Example of _onexit 
  20456.  
  20457.      abort - Stop a Program 
  20458.      atexit - Record Program Termination Function 
  20459.      exit - End Program 
  20460.      _exit - End Process 
  20461.      <stdlib.h> 
  20462.  
  20463.  
  20464. ΓòÉΓòÉΓòÉ 4.203. open - Open File ΓòÉΓòÉΓòÉ
  20465.  
  20466.  
  20467. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20468.  
  20469. #include <io.h>
  20470. #include <fcntl.h>
  20471. #include <sys\stat.h>
  20472. int open(char *pathname, int oflag, int pmode);
  20473.  
  20474.  
  20475. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20476.  
  20477. Language Level:  XPG4, Extension 
  20478.  
  20479. open opens the file specified by pathname and prepares the file for subsequent 
  20480. reading or writing as defined by oflag. open can also prepare the file for 
  20481. reading and writing. 
  20482.  
  20483. The oflag is an integer expression formed by combining one or more of the 
  20484. following constants, defined in <fcntl.h>. To specify more than one constant, 
  20485. join the constants with the bitwise OR operator (|); for example, O_CREAT | 
  20486. O_TEXT. 
  20487.  
  20488.  Oflag         Meaning 
  20489.  O_APPEND      Reposition the file pointer to the end of the file before every 
  20490.                write operation. 
  20491.  O_CREAT       Create and open a new file.  This flag has no effect if the file 
  20492.                specified by pathname exists. 
  20493.  O_EXCL        Return an error value if the file specified by pathname exists. 
  20494.                This flag applies only when used with O_CREAT. 
  20495.  O_RDONLY      Open the file for reading only.  If this flag is given, neither 
  20496.                O_RDWR nor O_WRONLY can be given. 
  20497.  O_RDWR        Open the file for reading and writing.  If this flag is given, 
  20498.                neither O_RDONLY nor O_WRONLY can be given. 
  20499.  O_TRUNC       Open and truncate an existing file to 0 length. The file must 
  20500.                have write permission. The contents of the file are destroyed, 
  20501.                and O_TRUNC cannot be specified with O_RDONLY. 
  20502.  O_WRONLY      Open the file for writing only.  If this flag is given, neither 
  20503.                O_RDONLY nor O_RDWR can be given. 
  20504.  O_BINARY      Open the file in binary (untranslated) mode. 
  20505.  O_TEXT        Open the file in text (translated) mode. 
  20506.  
  20507.  If neither O_BINARY or O_TEXT is specified, the default will be O_TEXT; it is 
  20508.  an error to specify both O_BINARY and O_TEXT. You must specify one of the 
  20509.  access mode flags, O_RDONLY, O_WRONLY, or O_RDWR.  There is no default. 
  20510.  
  20511.  Warning: Use O_TRUNC with care; it destroys the complete contents of an 
  20512.  existing file. 
  20513.  
  20514.  For more details on text and binary modes and their differences, see "Stream 
  20515.  Processing" in the Programming Guide. 
  20516.  
  20517.  The pmode argument is an integer expression containing one or both of the 
  20518.  constants S_IWRITE and S_IREAD, defined in <sys\stat.h>. The pmode is required 
  20519.  only when O_CREAT is specified. If the file exists, pmode is ignored. 
  20520.  Otherwise, pmode specifies the permission settings for the file. These are set 
  20521.  when the new file is closed for the first time. The meaning of the pmode 
  20522.  argument is as follows: 
  20523.  
  20524.  Value                   Meaning 
  20525.  S_IWRITE                Writing permitted 
  20526.  S_IREAD                 Reading permitted 
  20527.  S_IREAD | S_IWRITE      Reading and writing permitted. 
  20528.  
  20529.  If write permission is not given, the file is read-only. Under the Windows 
  20530.  operating system, all files are readable; you cannot give write-only 
  20531.  permission. The modes S_IWRITE and S_IREAD | S_IWRITE are equivalent. 
  20532.  
  20533.  open applies the current file permission mask to pmode before setting the 
  20534.  permissions. (See umask - Sets File Mask of Current Process.) 
  20535.  
  20536.  Note:  In earlier releases of VisualAge C++, open began with an underscore 
  20537.  (_open). Because it is defined by the X/Open standard, the underscore has been 
  20538.  removed. For compatibility, VisualAge for C++ will map _open to open for you. 
  20539.  
  20540.  Return Value 
  20541.  open returns a file handle for the opened file. A return value of -1 indicates 
  20542.  an error, and errno is set to one of the following values: 
  20543.  
  20544.  Value          Meaning 
  20545.  EACCESS        The given pathname is a directory; or the file is read-only but 
  20546.                 an open for writing was attempted; or a sharing violation 
  20547.                 occurred. 
  20548.  EEXIST         The O_CREAT and O_EXCL flags are specified, but the named file 
  20549.                 already exists. 
  20550.  EMFILE         No more file handles are available. 
  20551.  EINVAL         An incorrect argument was passed. 
  20552.  ENOENT         The file or pathname were not found. 
  20553.  EOS2ERR        The call to the operating system was not successful. 
  20554.  
  20555.  
  20556. ΓòÉΓòÉΓòÉ <hidden> Example of open ΓòÉΓòÉΓòÉ
  20557.  
  20558. /************************************************************************
  20559.  
  20560. This example opens the file edopen.dat by creating it as a new file, truncating 
  20561. it if it exists, and opening it so it can be read and written to. The open 
  20562. command issued also grants permission to read from and write to the file. 
  20563.  
  20564. ************************************************************************/
  20565.  
  20566. #include <io.h>
  20567. #include <stdio.h>
  20568. #include <fcntl.h>
  20569. #include <sys\stat.h>
  20570. #include <stdlib.h>
  20571.  
  20572. int main(void)
  20573. {
  20574.    int fh;
  20575.  
  20576.    if (-1 == (fh = open("edopen.dat", O_CREAT|O_TRUNC|O_RDWR,
  20577.                          S_IREAD|S_IWRITE))) {
  20578.       perror("Unable to open edopen.dat");
  20579.       return EXIT_FAILURE;
  20580.    }
  20581.    printf("File was successfully opened.\n");
  20582.    if (-1 == close(fh)) {
  20583.       perror("close error");
  20584.       return EXIT_FAILURE;
  20585.    }
  20586.    return 0;
  20587.  
  20588.    /****************************************************************************
  20589.       The output should be:
  20590.  
  20591.       File was successfully opened.
  20592.    ****************************************************************************/
  20593. }
  20594.  
  20595.  
  20596. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20597.  
  20598. Example of open 
  20599.  
  20600.      close - Close File Associated with Handle 
  20601.      creat - Create New File 
  20602.      fdopen - Associates Input Or Output With File 
  20603.      fopen - Open Files 
  20604.      _sopen - Open Shared File 
  20605.      umask - Sets File Mask of Current Process 
  20606.      <fcntl.h> 
  20607.      <io.h> 
  20608.      <sys\stat.h> 
  20609.  
  20610.  
  20611. ΓòÉΓòÉΓòÉ 4.204. _outp - Write Byte to Output Port ΓòÉΓòÉΓòÉ
  20612.  
  20613.  
  20614. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20615.  
  20616. #include <conio.h>  /* also in <builtin.h> */
  20617. int _outp( const unsigned int port, const int value );
  20618.  
  20619.  
  20620. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20621.  
  20622. Language Level:  Extension 
  20623.  
  20624. _outp writes a byte value to the specified port. The port number must be an 
  20625. unsigned integer value within the range 0 to 65 535 inclusive. The byte value 
  20626. must be within the range 0 to 255 inclusive. 
  20627.  
  20628. Note:  _outp is a built-in function, which means it is implemented as an inline 
  20629. instruction and has no backing code in the library.  For this reason: 
  20630.  
  20631.      You cannot take the address of _outp. 
  20632.      You cannot parenthesize a call to _outp. (Parentheses specify a call to 
  20633.       the function's backing code, and _outp has none.) 
  20634.  
  20635.  You can run code containing this function only at ring zero. Otherwise, an 
  20636.  invalid instruction exception is generated. 
  20637.  
  20638.  Return Value 
  20639.  _outp returns the integer value that was output to the specified port. There 
  20640.  is no error return value, and _outp does not set errno. 
  20641.  
  20642.  
  20643. ΓòÉΓòÉΓòÉ <hidden> Example of _outp ΓòÉΓòÉΓòÉ
  20644.  
  20645. /************************************************************************
  20646.  
  20647. This example uses _outp to write a byte to a specified output port and return 
  20648. the data written. 
  20649.  
  20650. ************************************************************************/
  20651.  
  20652. #include <builtin.h>
  20653.  
  20654. #define LOWER  0
  20655. #define UPPER1 255
  20656. #define UPPER2 65535
  20657.  
  20658. int Add1(int j);
  20659.  
  20660. static int g;
  20661. enum fruit {apples=10, bananas, cantaloupes};
  20662. enum fruit f = cantaloupes;
  20663. int arr[] = {cantaloupes, bananas, apples};
  20664. struct
  20665. {
  20666.    int  i;
  20667.    char ch;
  20668. } st;
  20669.  
  20670. int main(void)
  20671. {
  20672.    static int i;
  20673.    volatile const int c = 0;
  20674.  
  20675.    st.i = c - bananas;
  20676.    g = _outp(LOWER,apples);
  20677.    i = _outp(255, 0);
  20678.                                      /* ============================= */
  20679.                                      /* Types of port number passed : */
  20680.                                      /* ----------------------------- */
  20681.    i = _outp(UPPER2,UPPER1);         /* - #define constant            */
  20682.    i = _outp(st.i, bananas);         /* - element of structure        */
  20683.    i = _outp(f,arr[1]);              /* - enumerated variable         */
  20684.    i = _outp(_inp(arr[2]),apples);   /* - return value from a         */
  20685.                                      /*   builtin function call       */
  20686.                                      /* ----------------------------- */
  20687.    i = _outp(_outp(apples,Add1(LOWER)),6);
  20688.    return 0;
  20689. }
  20690.  
  20691. int Add1(int j)
  20692. {
  20693.    j += 1;
  20694.    return j;
  20695. }
  20696.  
  20697.  
  20698. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20699.  
  20700. Example of _outp 
  20701.  
  20702.      _inp - Read Byte from Input Port 
  20703.      _inpw - Read Unsigned Short from Input Port 
  20704.      _inpd - Read Doubleword from Input Port 
  20705.      _outpw - Write Word to Output Port 
  20706.      _outpd - Write Double Word to Output Port 
  20707.      <builtin.h> 
  20708.      <conio.h> 
  20709.  
  20710.  
  20711. ΓòÉΓòÉΓòÉ 4.205. _outpd - Write Double Word to Output Port ΓòÉΓòÉΓòÉ
  20712.  
  20713.  
  20714. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20715.  
  20716. #include <conio.h>  /* also in <builtin.h */
  20717. unsigned long _outpd( const unsigned int port, const unsigned long value );
  20718.  
  20719.  
  20720. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20721.  
  20722. Language Level:  Extension 
  20723.  
  20724. _outpd writes an unsigned long value to the specified port. The port number 
  20725. must be a value within the range 0 to 65 535 inclusive. The unsigned long value 
  20726. must be within the range 0 to 4 294 967 295 inclusive. 
  20727.  
  20728. Note:  _outpd is a built-in function, which means it is implemented as an 
  20729. inline instruction and has no backing code in the library.  For this reason: 
  20730.  
  20731.      You cannot take the address of _outpd. 
  20732.      You cannot parenthesize a call to _outpd. (Parentheses specify a call to 
  20733.       the function's backing code, and _outpd has none.) 
  20734.  
  20735.  You can run code containing this function only at ring zero. Otherwise, an 
  20736.  invalid instruction exception is generated. 
  20737.  
  20738.  Return Value 
  20739.  _outpd returns the unsigned long value that was output to the specified port. 
  20740.  There is no error return value, and _outpd does not set errno. 
  20741.  
  20742.  
  20743. ΓòÉΓòÉΓòÉ <hidden> Example of _outpd ΓòÉΓòÉΓòÉ
  20744.  
  20745. /************************************************************************
  20746.  
  20747. This example uses _outpd to write a doubleword value to a specified output port 
  20748. and return the data written. 
  20749.  
  20750. ************************************************************************/
  20751.  
  20752. #include <builtin.h>
  20753.  
  20754. #define LOWER  0
  20755. #define UPPER1 65535
  20756. #define UPPER2 4294967295
  20757.  
  20758. int Add1(int j);
  20759.  
  20760. volatile long g;
  20761. enum fruit {apples=10, bananas, cantaloupes};
  20762. enum fruit f = cantaloupes;
  20763. int arr[] = {cantaloupes, bananas, apples};
  20764. union
  20765. {
  20766.    volatile int  i;
  20767.    volatile char ch;
  20768. } un;
  20769.  
  20770. int main(void)
  20771. {
  20772.    unsigned long l;
  20773.    volatile const short c = 0;
  20774.  
  20775.    un.i = bananas * f;
  20776.    g = _outpd(0,LOWER);
  20777.                                      /* ============================= */
  20778.                                      /* Types of port number passed : */
  20779.                                      /* ----------------------------- */
  20780.    l = _outpd(UPPER1, UPPER2);       /* - #define constant            */
  20781.    l = _outpd(un.i ,f);              /* - element of union            */
  20782.    l = _outpd(Add1(c), apples);      /* - return value from a         */
  20783.                                      /*   function call               */
  20784.                                      /* ----------------------------- */
  20785.    l = _outpd(_outpw(255,Add1(LOWER)),6);
  20786.    return 0;
  20787. }
  20788.  
  20789. int Add1(int j)
  20790. {
  20791.    j += 1;
  20792.    return j;
  20793. }
  20794.  
  20795.  
  20796. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20797.  
  20798. Example of _outpd 
  20799.  
  20800.      _inp - Read Byte from Input Port 
  20801.      _inpw - Read Unsigned Short from Input Port 
  20802.      _inpd - Read Doubleword from Input Port 
  20803.      _outp - Write Byte to Output Port 
  20804.      _outpw - Write Word to Output Port 
  20805.      <builtin.h> 
  20806.      <conio.h> 
  20807.  
  20808.  
  20809. ΓòÉΓòÉΓòÉ 4.206. _outpw - Write Word to Output Port ΓòÉΓòÉΓòÉ
  20810.  
  20811.  
  20812. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20813.  
  20814. #include <conio.h>  /* also in <builtin.h */
  20815. unsigned short _outpw( const unsigned int port, const unsigned short word );
  20816.  
  20817.  
  20818. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20819.  
  20820. Language Level:  Extension 
  20821.  
  20822. _outpw writes an unsigned short word to the specified port. The port number 
  20823. must be an unsigned integer value within the range 0 to 65 535 inclusive. The 
  20824. unsigned short word must be in the range 0 to 65 535. 
  20825.  
  20826. Note:  _outpw is a built-in function, which means it is implemented as an 
  20827. inline instruction and has no backing code in the library.  For this reason: 
  20828.  
  20829.      You cannot take the address of _outpw. 
  20830.      You cannot parenthesize a call to _outpw. (Parentheses specify a call to 
  20831.       the function's backing code, and _outpw has none.) 
  20832.  
  20833.  You can run code containing this function only at ring zero. Otherwise, an 
  20834.  invalid instruction exception is generated. 
  20835.  
  20836.  Return Value 
  20837.  _outpw returns the value that was output to the specified port. There is no 
  20838.  error return value, and _outpw does not set errno. 
  20839.  
  20840.  
  20841. ΓòÉΓòÉΓòÉ <hidden> Example of _outpw ΓòÉΓòÉΓòÉ
  20842.  
  20843. /************************************************************************
  20844.  
  20845. This example uses _outpw to write an unsigned short value to a specified output 
  20846. port and return the data written. 
  20847.  
  20848. ************************************************************************/
  20849.  
  20850. #include <builtin.h>
  20851.  
  20852. #define LOWER 0
  20853. #define UPPER 65535
  20854.  
  20855. int Add1(int j);
  20856.  
  20857. unsigned int g;
  20858.  
  20859. int main(void)
  20860. {
  20861.    enum fruit {apples = 10, bananas, cantaloupes};
  20862.    enum fruit f = cantaloupes;
  20863.    int arr[] = {cantaloupes, bananas, apples};
  20864.    unsigned short s;
  20865.    static int i = 0;
  20866.    volatile const int c = 255;
  20867.  
  20868.    g = _outpw(cantaloupes, i);
  20869.                                      /* ============================= */
  20870.                                      /* Types of port number passed : */
  20871.                                      /* ----------------------------- */
  20872.    s = _outpw(UPPER, LOWER);         /* - #define constant            */
  20873.    s = _outpw(c, Add1(255));         /* - constant                    */
  20874.    s = _outpw(_inpw(arr[2]),apples); /* - return value from a         */
  20875.                                      /*   builtin function call       */
  20876.                                      /* ----------------------------- */
  20877.    s = _outpw(_outpw(bananas ,UPPER),6);
  20878.    return 0;
  20879. }
  20880.  
  20881. int Add1(int j)
  20882. {
  20883.    j += 1;
  20884.    return j;
  20885. }
  20886.  
  20887.  
  20888. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20889.  
  20890. Example of _outpw 
  20891.  
  20892.      _inp - Read Byte from Input Port 
  20893.      _inpw - Read Unsigned Short from Input Port 
  20894.      _inpd - Read Doubleword from Input Port 
  20895.      _outp - Write Byte to Output Port 
  20896.      _outpd - Write Double Word to Output Port 
  20897.      <builtin.h> 
  20898.      <conio.h> 
  20899.  
  20900.  
  20901. ΓòÉΓòÉΓòÉ 4.207. perror - Print Error Message ΓòÉΓòÉΓòÉ
  20902.  
  20903.  
  20904. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20905.  
  20906. #include <stdio.h>
  20907. void perror(const char *string);
  20908.  
  20909.  
  20910. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20911.  
  20912. Language Level:  ANSI, SAA, POSIX, XPG4 
  20913.  
  20914. perror prints an error message to stderr.  If string is not NULL and does not 
  20915. point to a null character, the string pointed to by string is printed to the 
  20916. standard error stream, followed by a colon and a space.  The message associated 
  20917. with the value in errno is then printed followed by a new-line character. 
  20918.  
  20919. To produce accurate results, you should ensure that perror is called 
  20920. immediately after a library function returns with an error;  otherwise, 
  20921. subsequent calls may alter the errno value. 
  20922.  
  20923. Return Value 
  20924. There is no return value. 
  20925.  
  20926.  
  20927. ΓòÉΓòÉΓòÉ <hidden> Example of perror ΓòÉΓòÉΓòÉ
  20928.  
  20929. /************************************************************************
  20930.  
  20931. This example tries to open a stream.  If fopen fails, the example prints a 
  20932. message and ends the program. 
  20933.  
  20934. ************************************************************************/
  20935.  
  20936. #include <stdio.h>
  20937. #include <stdlib.h>
  20938. int main(void)
  20939. {
  20940.    FILE *fh;
  20941.  
  20942.    if (NULL == (fh = fopen("myfile.mjq", "r"))) {
  20943.       perror("Could not open data file");
  20944.       abort();
  20945.    }
  20946.    return 0;
  20947.  
  20948.    /****************************************************************************
  20949.       The output should be:
  20950.  
  20951.       Could not open data file: The file cannot be found.
  20952.    ****************************************************************************/
  20953. }
  20954.  
  20955.  
  20956. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20957.  
  20958. Example of perror 
  20959.  
  20960.      clearerr - Reset Error Indicators 
  20961.      ferror - Test for Read/Write Errors 
  20962.      strerror - Set Pointer to Runtime Error Message 
  20963.      _strerror - Set Pointer to System Error String 
  20964.      Runtime Return Codes and Messages in the User's Guide 
  20965.      <stdio.h> 
  20966.  
  20967.  
  20968. ΓòÉΓòÉΓòÉ 4.208. pow - Compute Power ΓòÉΓòÉΓòÉ
  20969.  
  20970.  
  20971. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20972.  
  20973. #include <math.h>
  20974. double pow(double x, double y);
  20975.  
  20976.  
  20977. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20978.  
  20979. Language Level: ANSI, SAA, POSIX, XPG4 
  20980.  
  20981. pow calculates the value of x to the power of y. 
  20982.  
  20983. Return Value 
  20984. If y is 0, pow returns the value 1. If x is 0 and y is negative, pow sets errno 
  20985. to EDOM and returns 0. If both x and y are 0, or if x is negative and y is not 
  20986. an integer, pow sets errno to EDOM, and returns 0. 
  20987.  
  20988. If an overflow results, pow sets errno to ERANGE and returns +HUGE_VAL for a 
  20989. large result or -HUGE_VAL for a small result. 
  20990.  
  20991.  
  20992. ΓòÉΓòÉΓòÉ <hidden> Example of pow ΓòÉΓòÉΓòÉ
  20993.  
  20994. /************************************************************************
  20995.  
  20996. This example calculates the value of 2**3. 
  20997.  
  20998. ************************************************************************/
  20999.  
  21000. #include <stdio.h>
  21001. #include <math.h>
  21002.  
  21003. int main(void)
  21004. {
  21005.    double x,y,z;
  21006.  
  21007.    x = 2.0;
  21008.    y = 3.0;
  21009.    z = pow(x, y);
  21010.    printf("%lf to the power of %lf is %lf\n", x, y, z);
  21011.    return 0;
  21012.  
  21013.    /****************************************************************************
  21014.       The output should be:
  21015.  
  21016.       2.000000 to the power of 3.000000 is 8.000000
  21017.    ****************************************************************************/
  21018. }
  21019.  
  21020.  
  21021. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21022.  
  21023. Example of pow 
  21024.  
  21025.      exp - Calculate Exponential Function 
  21026.      _fsqrt -  Calculate Square Root 
  21027.      log - Calculate Natural Logarithm 
  21028.      log10 - Calculate Base 10 Logarithm 
  21029.      sqrt - Calculate Square Root 
  21030.      <math.h> 
  21031.  
  21032.  
  21033. ΓòÉΓòÉΓòÉ 4.209. printf - Print Formatted Characters ΓòÉΓòÉΓòÉ
  21034.  
  21035.  
  21036. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21037.  
  21038. #include <stdio.h>
  21039. int printf(const char *format-string, argument-list);
  21040.  
  21041.  
  21042. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21043.  
  21044. Language Level: ANSI, SAA, POSIX, XPG4, Extension 
  21045.  
  21046. printf formats and prints a series of characters and values to the standard 
  21047. output stream stdout.  The format-string consists of ordinary characters, 
  21048. escape sequences, and format specifications.  The ordinary characters are 
  21049. copied in order of their appearance to stdout.  Format specifications, 
  21050. beginning with a percent sign (%), determine the output format for any 
  21051. argument-list following the format-string. 
  21052.  
  21053. The format-string is read left to right.  When the first format specification 
  21054. is found, the value of the first argument after the format-string is converted 
  21055. and output according to the format specification.  The second format 
  21056. specification causes the second argument after the format-string to be 
  21057. converted and output, and so on through the end of the format-string.  If there 
  21058. are more arguments than there are format specifications, the extra arguments 
  21059. are evaluated and ignored.  The results are undefined if there are not enough 
  21060. arguments for all the format specifications. A format specification has the 
  21061. following form: 
  21062.  
  21063. >>ΓöÇΓöÇ%ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇtypeΓöÇΓöÇ><
  21064.     ΓööΓöÇflagsΓöÇΓöÿ  ΓööΓöÇwidthΓöÇΓöÿ  ΓööΓöÇ.ΓöÇΓöÇprecisionΓöÇΓöÿ  Γö£ΓöÇhΓöÇΓöÇΓöñ
  21065.                         Γö£ΓöÇlΓöÇΓöÇΓöñ
  21066.                         Γö£ΓöÇLΓöÇΓöÇΓöñ
  21067.                         ΓööΓöÇllΓöÇΓöÿ
  21068. Each field of the format specification is a single, or double character, or 
  21069. number signifying a particular format option.  The type character, which 
  21070. appears after the last optional format field, determines whether the associated 
  21071. argument is interpreted as a character, a string, a number, or pointer.  The 
  21072. simplest format specification contains only the percent sign and a type 
  21073. character (for example, %s). 
  21074.  
  21075. The following optional fields control other aspects of the formatting: 
  21076.  
  21077.  Field       Description 
  21078.  
  21079.  flags       Justification of output and printing of signs, blanks, decimal 
  21080.              points, octal, and hexadecimal prefixes, and the semantics for 
  21081.              wchar_t precision unit. 
  21082.  
  21083.  width       Minimum number of characters (bytes) output. 
  21084.  
  21085.  precision   Maximum number of characters (bytes) printed for all or part of 
  21086.              the output field, or minimum number of digits printed for integer 
  21087.              values. 
  21088.  
  21089.  h,l,L       Size of argument expected. 
  21090.  
  21091.  If a percent sign (%) is followed by a character that has no meaning as a 
  21092.  format field, the character is simply copied to stdout.  For example, to print 
  21093.  a percent sign character, use %%. 
  21094.  
  21095.  In extended mode, printf also converts floating-point values of NaN and 
  21096.  infinity to the strings "NAN" or "nan" and "INFINITY" or "infinity". The case 
  21097.  and sign of the string is determined by the format specifiers.  See Infinity 
  21098.  and NaN Support for more information on infinity and NaN values. 
  21099.  
  21100.  If you specify a null string for the %s or %ls format specifier, printf prints 
  21101.  (null). (In previous releases of VisualAge C++, printf produced no output for 
  21102.  a null string.) 
  21103.  
  21104.  Return Value 
  21105.  printf returns the number of bytes printed. 
  21106.  
  21107.  
  21108. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21109.  
  21110. Example of printf 
  21111.  
  21112.      Format Specification - Types 
  21113.      Format Specification - Flags 
  21114.      Format Specification - Width 
  21115.      Format Specification - Precision 
  21116.      Format Specification - h,l,L 
  21117.      fprintf - Write Formatted Data to a Stream 
  21118.      fscanf - Read Formatted Data 
  21119.      scanf - Read Data 
  21120.      sprintf - Print Formatted Data to Buffer 
  21121.      sscanf - Read Data 
  21122.      Infinity and NaN Support 
  21123.      <stdio.h> 
  21124.  
  21125.  
  21126. ΓòÉΓòÉΓòÉ 4.209.1. Format Specification - Types ΓòÉΓòÉΓòÉ
  21127.  
  21128. The type characters and their meanings are given in the following table: 
  21129.  
  21130. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  21131. Γöé CHAR-   Γöé ARGUMENT  Γöé OUTPUT FORMAT                     Γöé
  21132. Γöé ACTER   Γöé       Γöé                            Γöé
  21133. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21134. Γöé d, i   Γöé Integer   Γöé Signed decimal integer.                Γöé
  21135. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21136. Γöé u     Γöé Integer   Γöé Unsigned decimal integer.               Γöé
  21137. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21138. Γöé o     Γöé Integer   Γöé Unsigned octal integer.                Γöé
  21139. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21140. Γöé x     Γöé Integer   Γöé Unsigned hexadecimal integer, using abcdef.      Γöé
  21141. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21142. Γöé X     Γöé Integer   Γöé Unsigned hexadecimal integer, using ABCDEF.      Γöé
  21143. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21144. Γöé f     Γöé Double   Γöé Signed value having the form [-]dddd.dddd, where   Γöé
  21145. Γöé      Γöé       Γöé dddd is one or more decimal digits.  The number of  Γöé
  21146. Γöé      Γöé       Γöé digits before the decimal point depends on the mag-  Γöé
  21147. Γöé      Γöé       Γöé nitude of the number.  The number of digits after   Γöé
  21148. Γöé      Γöé       Γöé the decimal point is equal to the requested preci-  Γöé
  21149. Γöé      Γöé       Γöé sion.  NaN and infinity values are printed in lower- Γöé
  21150. Γöé      Γöé       Γöé case ("nan" and "infinity").             Γöé
  21151. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21152. Γöé F     Γöé Double   Γöé In extended mode ("/Se" option), identical to the   Γöé
  21153. Γöé      Γöé       Γöé "f" format except that NaN and infinity values are  Γöé
  21154. Γöé      Γöé       Γöé printed in uppercase ("NAN" and "INFINITY").  In   Γöé
  21155. Γöé      Γöé       Γöé modes other than extended, "F" is treated like any  Γöé
  21156. Γöé      Γöé       Γöé other character not included in this table.      Γöé
  21157. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21158. Γöé e     Γöé Double   Γöé Signed value having the form [-]d.dddd"e"[sign]ddd,  Γöé
  21159. Γöé      Γöé       Γöé where d is a single-decimal digit, dddd is one or   Γöé
  21160. Γöé      Γöé       Γöé more decimal digits, ddd is 2 or 3 decimal digits,  Γöé
  21161. Γöé      Γöé       Γöé and sign is + or -.                  Γöé
  21162. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21163. Γöé E     Γöé Double   Γöé Identical to the "e" format except that "E" intro-  Γöé
  21164. Γöé      Γöé       Γöé duces the exponent instead of "e".          Γöé
  21165. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21166. Γöé g     Γöé Double   Γöé Signed value printed in "f" or "e" format.  The "e"  Γöé
  21167. Γöé      Γöé       Γöé format is used only when the exponent of the value  Γöé
  21168. Γöé      Γöé       Γöé is less than -4 or greater than precision.  Trailing Γöé
  21169. Γöé      Γöé       Γöé zeros are truncated, and the decimal point appears  Γöé
  21170. Γöé      Γöé       Γöé only if one or more digits follow it.         Γöé
  21171. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21172. Γöé G     Γöé Double   Γöé Identical to the "g" format except that "E" intro-  Γöé
  21173. Γöé      Γöé       Γöé duces the exponent (where appropriate) instead of   Γöé
  21174. Γöé      Γöé       Γöé "e".                         Γöé
  21175. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21176. Γöé c     Γöé Character  Γöé Single character.                   Γöé
  21177. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21178. Γöé lc    Γöé Wide char- Γöé Multibyte character (converted as if by a call to   Γöé
  21179. Γöé      Γöé acter    Γöé wcrtomb).                       Γöé
  21180. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21181. Γöé s     Γöé String   Γöé Characters printed up to the first null character   Γöé
  21182. Γöé      Γöé       Γöé (\"0") or until precision is reached.  If you     Γöé
  21183. Γöé      Γöé       Γöé specify a null string, "(null)" is printed.      Γöé
  21184. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21185. Γöé ls    Γöé Wide-    Γöé Multibyte characters, printed up to the first     Γöé
  21186. Γöé      Γöé character  Γöé "wchar_t" null character ("L\0") is encountered in  Γöé
  21187. Γöé      Γöé string.   Γöé the wide-character string, or until the specified   Γöé
  21188. Γöé      Γöé       Γöé precision is reached.  Conversion takes place as if  Γöé
  21189. Γöé      Γöé       Γöé by a call to wcrtomb.  The displayed result does not Γöé
  21190. Γöé      Γöé       Γöé include the terminating null character.  If you do  Γöé
  21191. Γöé      Γöé       Γöé not specify the precision, you must end the wide-   Γöé
  21192. Γöé      Γöé       Γöé character string with a null character.  A partial  Γöé
  21193. Γöé      Γöé       Γöé multibyte character cannot be written.  If you    Γöé
  21194. Γöé      Γöé       Γöé specify a null string, "(null)" is printed.      Γöé
  21195. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21196. Γöé n     Γöé Pointer to Γöé Number of characters successfully written so far to  Γöé
  21197. Γöé      Γöé integer   Γöé the stream or buffer; this value is stored in the   Γöé
  21198. Γöé      Γöé       Γöé integer whose address is given as the argument.    Γöé
  21199. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21200. Γöé p     Γöé Pointer   Γöé Pointer to void converted to a sequence of printable Γöé
  21201. Γöé      Γöé       Γöé characters.                      Γöé
  21202. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  21203.  
  21204.  
  21205. ΓòÉΓòÉΓòÉ 4.209.2. Format Specification - Flags ΓòÉΓòÉΓòÉ
  21206.  
  21207. The flag characters and their meanings are as follows (notice that more than 
  21208. one flag can appear in a format specification): 
  21209.  
  21210. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  21211. Γöé Table 3. Flag Characters                           Γöé
  21212. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21213. Γöé FLAG    Γöé MEANING                  Γöé DEFAULT        Γöé
  21214. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21215. Γöé -     Γöé Left-justify the result within the field  Γöé Right-justify.    Γöé
  21216. Γöé      Γöé width.                   Γöé            Γöé
  21217. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21218. Γöé +     Γöé Prefix the output value with a sign (+ or Γöé Sign appears only   Γöé
  21219. Γöé      Γöé -) if the output value is of a signed   Γöé for negative signed  Γöé
  21220. Γöé      Γöé type.                   Γöé values (-).      Γöé
  21221. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21222. Γöé blank(' ')Γöé Prefix the output value with a blank if  Γöé No blank.       Γöé
  21223. Γöé      Γöé the output value is signed and positive.  Γöé            Γöé
  21224. Γöé      Γöé The "+" flag overrides the blank flag if  Γöé            Γöé
  21225. Γöé      Γöé both appear, and a positive signed value  Γöé            Γöé
  21226. Γöé      Γöé will be output with a sign.        Γöé            Γöé
  21227. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21228. Γöé #     Γöé When used with the "o", "x", or "X"    Γöé No prefix.      Γöé
  21229. Γöé      Γöé formats, the "#" flag prefixes any     Γöé            Γöé
  21230. Γöé      Γöé nonzero output value with "0", "0"x, or  Γöé            Γöé
  21231. Γöé      Γöé "0"X, respectively.            Γöé            Γöé
  21232. Γöé      Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21233. Γöé      Γöé When used with the "f", "F", "e", or "E"  Γöé Decimal point     Γöé
  21234. Γöé      Γöé formats, the "#" flag forces the output  Γöé appears only if    Γöé
  21235. Γöé      Γöé value to contain a decimal point in all  Γöé digits follow it.   Γöé
  21236. Γöé      Γöé cases.                   Γöé            Γöé
  21237. Γöé      Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21238. Γöé      Γöé When used with the "g" or "G" formats,   Γöé Decimal point     Γöé
  21239. Γöé      Γöé the "#" flag forces the output value to  Γöé appears only if    Γöé
  21240. Γöé      Γöé contain a decimal point in all cases and  Γöé digits follow it;   Γöé
  21241. Γöé      Γöé prevents the truncation of trailing    Γöé trailing zeros are  Γöé
  21242. Γöé      Γöé zeros.                   Γöé truncated.      Γöé
  21243. Γöé      Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21244. Γöé      Γöé When used with the "ls" format, the "#"  Γöé Precision indicates  Γöé
  21245. Γöé      Γöé flag causes precision to be measured in  Γöé the maximum number  Γöé
  21246. Γöé      Γöé "wchar_t" characters.           Γöé of bytes to be    Γöé
  21247. Γöé      Γöé                      Γöé output.        Γöé
  21248. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21249. Γöé "0"    Γöé When used with the "d", "i", "o", "u",   Γöé Space padding.    Γöé
  21250. Γöé      Γöé "x", "X", "e", "E", "f", "F"" g", or "G"  Γöé            Γöé
  21251. Γöé      Γöé formats, the "0" flag causes leading    Γöé            Γöé
  21252. Γöé      Γöé "0"'s to pad the output to the field    Γöé            Γöé
  21253. Γöé      Γöé width.  The "0" flag is ignored if preci- Γöé            Γöé
  21254. Γöé      Γöé sion is specified for an integer or if   Γöé            Γöé
  21255. Γöé      Γöé the "-" flag is specified.         Γöé            Γöé
  21256. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  21257.  
  21258. The # flag should not be used with c, lc, d, i, u, s, or p types. 
  21259.  
  21260.  
  21261. ΓòÉΓòÉΓòÉ 4.209.3. Format Specification - Width ΓòÉΓòÉΓòÉ
  21262.  
  21263. Width is a nonnegative decimal integer controlling the minimum number of 
  21264. characters printed.  If the number of characters in the output value is less 
  21265. than the specified width, blanks are added on the left or the right (depending 
  21266. on whether the - flag is specified) until the minimum width is reached. 
  21267.  
  21268. Width never causes a value to be truncated;  if the number of characters in the 
  21269. output value is greater than the specified width, or width is not given, all 
  21270. characters of the value are printed (subject to the precision specification). 
  21271.  
  21272. For the ls type, width is specified in bytes. If the number of bytes in the 
  21273. output value is less than the specified width, single-byte blanks are added on 
  21274. the left or the right (depending on whether the - flag is specified) until the 
  21275. minimum width is reached. 
  21276.  
  21277. The width specification can be an asterisk (*), in which case an argument from 
  21278. the argument list supplies the value.  The width argument must precede the 
  21279. value being formatted in the argument list. 
  21280.  
  21281.  
  21282. ΓòÉΓòÉΓòÉ 4.209.4. Format Specification - Precision ΓòÉΓòÉΓòÉ
  21283.  
  21284. Precision is a nonnegative decimal integer preceded by a period, which 
  21285. specifies the number of characters to be printed or the number of decimal 
  21286. places. Unlike the width specification, the precision can cause truncation of 
  21287. the output value or rounding of a floating-point value. 
  21288.  
  21289. The precision specification can be an asterisk (*), in which case an argument 
  21290. from the argument list supplies the value. The precision argument must precede 
  21291. the value being formatted in the argument list. 
  21292.  
  21293. The interpretation of the precision value and the default when the precision is 
  21294. omitted depend upon the type, as shown in the following table: 
  21295.  
  21296. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  21297. Γöé TYPE  Γöé MEANING                   Γöé DEFAULT         Γöé
  21298. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21299. Γöé   i  Γöé Precision specifies the minimum number of  Γöé If precision is "0" or Γöé
  21300. Γöé   d  Γöé digits to be printed.  If the number of   Γöé omitted entirely, or  Γöé
  21301. Γöé   u  Γöé digits in the argument is less than preci- Γöé if the period (.)    Γöé
  21302. Γöé   o  Γöé sion, the output value is padded on the   Γöé appears without a    Γöé
  21303. Γöé   x  Γöé left with zeros.  The value is not trun-  Γöé number following it,  Γöé
  21304. Γöé   X  Γöé cated when the number of digits exceeds   Γöé the precision is set  Γöé
  21305. Γöé     Γöé precision.                 Γöé to 1.          Γöé
  21306. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21307. Γöé   f  Γöé Precision specifies the number of digits  Γöé Default precision is  Γöé
  21308. Γöé   F  Γöé to be printed after the decimal point.   Γöé six.  If precision is  Γöé
  21309. Γöé   e  Γöé The last digit printed is rounded.     Γöé "0" or the period    Γöé
  21310. Γöé   E  Γöé                       Γöé appears without a    Γöé
  21311. Γöé     Γöé                       Γöé number following it,  Γöé
  21312. Γöé     Γöé                       Γöé no decimal point is   Γöé
  21313. Γöé     Γöé                       Γöé printed.        Γöé
  21314. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21315. Γöé   g  Γöé Precision specifies the maximum number of  Γöé All significant digits Γöé
  21316. Γöé   G  Γöé significant digits printed.         Γöé are printed.      Γöé
  21317. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21318. Γöé   c  Γöé No effect.                 Γöé The character is    Γöé
  21319. Γöé     Γöé                       Γöé printed.        Γöé
  21320. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21321. Γöé   lc  Γöé No effect.                 Γöé The "wchar_t" char-   Γöé
  21322. Γöé     Γöé                       Γöé acter is printed.    Γöé
  21323. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21324. Γöé   s  Γöé Precision specifies the maximum number of  Γöé Characters are printed Γöé
  21325. Γöé     Γöé characters to be printed.  Characters in  Γöé until a null character Γöé
  21326. Γöé     Γöé excess of precision are not printed.    Γöé is encountered.     Γöé
  21327. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21328. Γöé   ls  Γöé Precision specifies the maximum number of  Γöé "wchar_t" characters  Γöé
  21329. Γöé     Γöé bytes to be printed.  Bytes in excess of  Γöé are printed until a   Γöé
  21330. Γöé     Γöé precision are not printed; however, multi- Γöé null character is    Γöé
  21331. Γöé     Γöé byte integrity is always preserved.     Γöé encountered.      Γöé
  21332. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  21333.  
  21334.  
  21335. ΓòÉΓòÉΓòÉ 4.209.5. Format Specification - h, l, L ΓòÉΓòÉΓòÉ
  21336.  
  21337. The h, l, and L characters specify the size of the expected argument.  Their 
  21338. meanings are as follows: 
  21339.  
  21340.  h    A prefix with the integer types d, i, o, u, x, X, and n that specifies 
  21341.       that the argument is short int or unsigned short int. 
  21342.  
  21343.  l    A prefix with d, i, o, u, x, X, and n types that specifies that the 
  21344.       argument is a long int or unsigned long int. 
  21345.  
  21346.  L    A prefix with e, E, f, g, or G types that specifies that the argument is 
  21347.       long double. 
  21348.  
  21349.  
  21350. ΓòÉΓòÉΓòÉ <hidden> Example of printf ΓòÉΓòÉΓòÉ
  21351.  
  21352. /************************************************************************
  21353.  
  21354. This example prints data in a variety of formats. 
  21355.  
  21356. ************************************************************************/
  21357.  
  21358. #include <stdio.h>
  21359.  
  21360. int main(void)
  21361. {
  21362.    char ch = 'h',*string = "computer";
  21363.    int count = 234,hex = 0x10,oct = 010,dec = 10;
  21364.    double fp = 251.7366;
  21365.  
  21366.    printf("%d   %+d    %06d     %X    %x     %o\n\n", count, count, count, count
  21367.       , count, count);
  21368.    printf("1234567890123%n4567890123456789\n\n", &count);
  21369.    printf("Value of count should be 13; count = %d\n\n", count);
  21370.    printf("%10c%5c\n\n", ch, ch);
  21371.    printf("%25s\n%25.4s\n\n", string, string);
  21372.    printf("%f    %.2f    %e    %E\n\n", fp, fp, fp, fp);
  21373.    printf("%i    %i     %i\n\n", hex, oct, dec);
  21374.    return 0;
  21375.  
  21376.    /****************************************************************************
  21377.       The output should be:
  21378.  
  21379.       234   +234    000234     EA    ea     352
  21380.  
  21381.       12345678901234567890123456789
  21382.  
  21383.       Value of count should be 13; count = 13
  21384.  
  21385.                h    h
  21386.  
  21387.                        computer
  21388.                            comp
  21389.  
  21390.       251.736600    251.74    2.517366e+02    2.517366E+02
  21391.  
  21392.       16    8     10
  21393.    ****************************************************************************/
  21394. }
  21395.  
  21396.  
  21397. ΓòÉΓòÉΓòÉ 4.210. putc - putchar - Write a Character ΓòÉΓòÉΓòÉ
  21398.  
  21399.  
  21400. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21401.  
  21402. #include <stdio.h>
  21403. int putc(int c, FILE *stream);
  21404. int putchar(int c);
  21405.  
  21406.  
  21407. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21408.  
  21409. Language Level: ANSI, SAA, POSIX, XPG4 
  21410.  
  21411. putc converts c to unsigned char and then writes c to the output stream at the 
  21412. current position. putchar is equivalent to putc(c, stdout). 
  21413.  
  21414. putc is equivalent to fputc except that, if it is implemented as a macro, putc 
  21415. can evaluate stream more than once. Therefore, the stream argument to putc 
  21416. should not be an expression with side effects. 
  21417.  
  21418. Return Value 
  21419. putc and putchar return the character written.  A return value of EOF indicates 
  21420. an error. 
  21421.  
  21422.  
  21423. ΓòÉΓòÉΓòÉ <hidden> Example of putc - putchar ΓòÉΓòÉΓòÉ
  21424.  
  21425. /************************************************************************
  21426.  
  21427. This example writes the contents of a buffer to a data stream. In this example, 
  21428. the body of the for statement is null because the example carries out the 
  21429. writing operation in the test expression. 
  21430.  
  21431. ************************************************************************/
  21432.  
  21433.  #include <stdio.h>
  21434.  
  21435.  #define  LENGTH 80
  21436.  
  21437.  int main(void)
  21438.  {
  21439.     FILE *stream = stdout;
  21440.     int i, ch;
  21441.     char buffer[LENGTH + 1] = "Hello world";
  21442.     /* This could be replaced by using the fwrite routine */
  21443.     for ( i = 0;
  21444.          (i < sizeof(buffer)) && ((ch = putc(buffer[i], stream)) != EOF);
  21445.           ++i);
  21446.     return 0;
  21447.  
  21448.  
  21449.  /************************************************************************
  21450.  Output should be:
  21451.  
  21452.  Hello world
  21453.  ************************************************************************/
  21454.  }
  21455.  
  21456.  
  21457. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21458.  
  21459. Example of putc - putchar 
  21460.  
  21461.      fputc - Write Character 
  21462.      _fputchar - Write Character 
  21463.      fwrite - Write Items 
  21464.      getc - getchar - Read a Character 
  21465.      _putch - Write Character to Screen 
  21466.      puts - Write a String 
  21467.      write - Writes from Buffer to File 
  21468.      <stdio.h> 
  21469.  
  21470.  
  21471. ΓòÉΓòÉΓòÉ 4.211. _putch - Write Character to Screen ΓòÉΓòÉΓòÉ
  21472.  
  21473.  
  21474. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21475.  
  21476. #include <conio.h>
  21477. int _putch(int c);
  21478.  
  21479.  
  21480. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21481.  
  21482. Language Level:  Extension 
  21483.  
  21484. _putch writes the character c directly to the screen. 
  21485.  
  21486. Return Value 
  21487. If successful, _putch returns c. If an error occurs, _putch returns EOF. 
  21488.  
  21489.  
  21490. ΓòÉΓòÉΓòÉ <hidden> Example of _putch ΓòÉΓòÉΓòÉ
  21491.  
  21492. /************************************************************************
  21493.  
  21494. This example defines a function gchar that is similar to _getche using the 
  21495. _putch and _getch functions: 
  21496.  
  21497. ************************************************************************/
  21498.  
  21499. #include <conio.h>
  21500.  
  21501. int gchar(void)
  21502. {
  21503.    int ch;
  21504.  
  21505.    ch = _getch();
  21506.    _putch(ch);
  21507.    return (ch);
  21508. }
  21509.  
  21510.  
  21511. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21512.  
  21513. Example of _putch 
  21514.  
  21515.      _cputs - Write String to Screen 
  21516.      _cprintf - Print Characters to Screen 
  21517.      fputc - Write Character 
  21518.      _getch - _getche - Read Character from Keyboard 
  21519.      putc - putchar - Write a Character 
  21520.      puts - Write a String 
  21521.      write - Writes from Buffer to File 
  21522.      <conio.h> 
  21523.  
  21524.  
  21525. ΓòÉΓòÉΓòÉ 4.212. putenv - Modify Environment Variables ΓòÉΓòÉΓòÉ
  21526.  
  21527.  
  21528. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21529.  
  21530. #include <stdlib.h>
  21531. int putenv(char *envstring);
  21532.  
  21533.  
  21534. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21535.  
  21536. Language Level:  XPG4, Extension 
  21537.  
  21538. putenv adds new environment variables or modifies the values of existing 
  21539. environment variables. Environment variables define the environment in which a 
  21540. process runs (for example, the default search path for libraries to be linked 
  21541. with a program). 
  21542.  
  21543. The envstring argument must be a pointer to a string with the form: 
  21544.  
  21545.    varname=string
  21546.  
  21547. where varname is the name of the environment variable to be added or modified 
  21548. and string is the value of the variable. See the Notes below. 
  21549.  
  21550. If varname is already part of the environment, string replaces its current 
  21551. value; if not, the new varname is added to the environment with the value 
  21552. string. To set a variable to an empty value, specify an empty string. A 
  21553. variable can be removed from the environment by specifying varname only, for 
  21554. example: 
  21555.  
  21556.    putenv("PATH");
  21557.  
  21558. Do not free the envstring pointer while the entry it points to is in use, or 
  21559. the environment variable will point into freed space. A similar problem can 
  21560. occur if you pass a pointer to a local variable to putenv and then exit from 
  21561. the function in which the variable is declared. Once you have added the 
  21562. envstring with putenv, any change to the entry it points to changes the 
  21563. environment used by your program. 
  21564.  
  21565. The environment manipulated by putenv is local to the process currently 
  21566. running, that is, changes are local to the run-time environment to which the 
  21567. call to putenv is made. For example, if you have an exe and a dll both linking 
  21568. statically to the run-time library, if you call putenv in the exe, the changes 
  21569. will not be reflected in the dll. 
  21570.  
  21571. You cannot enter new items in your command-level environment using putenv. 
  21572. When the program ends, the environment reverts to the parent process 
  21573. environment. This environment is passed on to some child processes created by 
  21574. the _spawn, exec, or system functions, and they get any new environment 
  21575. variables added using putenv. 
  21576.  
  21577. GetEnvironmentVariable will not reflect any changes made using putenv, but 
  21578. getenv will reflect the changes. 
  21579.  
  21580. Notes 
  21581.  
  21582.    1. putenv can change the value of _environ, thus invalidating the envp 
  21583.       argument to the main function. 
  21584.  
  21585.    2. You cannot use %envvar%, where envvar is any Windows environment 
  21586.       variable, with putenv to concatenate new envstring and old envstring. 
  21587.  
  21588.    3. In earlier releases of VisualAge C++, putenv began with an underscore 
  21589.       (_putenv). Because it is defined by the X/Open standard, the underscore 
  21590.       has been removed. For compatibility, VisualAge for C++ will map _putenv 
  21591.       to putenv for you. 
  21592.  
  21593.  Return Value 
  21594.  putenv returns 0 if it is successful. A return value of -1 indicates an error. 
  21595.  
  21596.  
  21597. ΓòÉΓòÉΓòÉ <hidden> Example of putenv ΓòÉΓòÉΓòÉ
  21598.  
  21599. /************************************************************************
  21600.  
  21601. This example tries to change the environment variable PATH, and then uses 
  21602. getenv to get the current path. If the call to putenv fails, the example writes 
  21603. an error message. 
  21604.  
  21605. ************************************************************************/
  21606.  
  21607. #include <stdlib.h>
  21608. #include <stdio.h>
  21609.  
  21610. int main(void)
  21611. {
  21612.    char *pathvar;
  21613.  
  21614.    if (-1 == putenv("PATH=a:\\bin;b:\\andy")) {
  21615.       printf("putenv failed - out of memory\n");
  21616.       return EXIT_FAILURE;
  21617.    }
  21618.  
  21619.    /* getting and printing the current environment path                       */
  21620.  
  21621.    pathvar = getenv("PATH");
  21622.    printf("The current path is: %s\n", pathvar);
  21623.    return 0;
  21624.  
  21625.    /****************************************************************************
  21626.       The output should be:
  21627.  
  21628.       The current path is: a:\bin;b:\andy
  21629.    ****************************************************************************/
  21630. }
  21631.  
  21632.  
  21633. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21634.  
  21635. Example of putenv 
  21636.  
  21637.      execl - _execvpe - Load and Run Child Process 
  21638.      getenv - Search for Environment Variables 
  21639.      _spawnl - _spawnvpe - Start and Run Child Processes 
  21640.      system - Invoke the Command Processor 
  21641.      "envp Parameter to main" in the Programming Guide 
  21642.      <stdlib.h> 
  21643.  
  21644.  
  21645. ΓòÉΓòÉΓòÉ 4.213. puts - Write a String ΓòÉΓòÉΓòÉ
  21646.  
  21647.  
  21648. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21649.  
  21650. #include <stdio.h>
  21651. int puts(const char *string);
  21652.  
  21653.  
  21654. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21655.  
  21656. Language Level: ANSI, SAA, POSIX, XPG4 
  21657.  
  21658. puts writes the given string to the standard output stream stdout;  it also 
  21659. appends a new-line character to the output.  The terminating null character is 
  21660. not written. 
  21661.  
  21662. Return Value 
  21663. puts returns EOF if an error occurs.  A nonnegative return value indicates that 
  21664. no error has occurred. 
  21665.  
  21666.  
  21667. ΓòÉΓòÉΓòÉ <hidden> Example of puts ΓòÉΓòÉΓòÉ
  21668.  
  21669. /************************************************************************
  21670.  
  21671. This example writes Hello World to stdout. 
  21672.  
  21673. ************************************************************************/
  21674.  
  21675. #include <stdio.h>
  21676.  
  21677. int main(void)
  21678. {
  21679.    if (EOF == puts("Hello World"))
  21680.       printf("Error in puts\n");
  21681.    return 0;
  21682.  
  21683.    /****************************************************************************
  21684.       The output should be:
  21685.  
  21686.       Hello World
  21687.    ****************************************************************************/
  21688. }
  21689.  
  21690.  
  21691. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21692.  
  21693. Example of puts 
  21694.  
  21695.      _cputs - Write String to Screen 
  21696.      fputs - Write String 
  21697.      gets - Read a Line 
  21698.      putc - putchar - Write a Character 
  21699.      <stdio.h> 
  21700.  
  21701.  
  21702. ΓòÉΓòÉΓòÉ 4.214. putwc - Write Wide Character ΓòÉΓòÉΓòÉ
  21703.  
  21704.  
  21705. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21706.  
  21707. #include <stdio.h>
  21708. #include <wchar.h>
  21709. wint_t putwc(wint_t wc, FILE *stream);
  21710.  
  21711.  
  21712. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21713.  
  21714. Language Level: ANSI 93, XPG4 
  21715.  
  21716. putwc converts the wide character wc to a multibyte character, and writes it to 
  21717. the stream at the current position. It also advances the file position 
  21718. indicator for the stream appropriately. 
  21719.  
  21720. putwc function is equivalent to fputwc except that, if it is implemented as a 
  21721. macro, putwc can evaluate stream more than once. Therefore, the stream argument 
  21722. to putwc should not be an expression with side effects. 
  21723.  
  21724. The behavior of putwc is affected by the LC_CTYPE category of the current 
  21725. locale. Using a non-wide-character function with putwc on the same stream 
  21726. results in undefined behavior. 
  21727.  
  21728. After calling putwc, flush the buffer or reposition the stream pointer before 
  21729. calling a write function for the stream, unless EOF has been reached. After a 
  21730. write operation on the stream, flush the buffer or reposition the stream 
  21731. pointer before calling putwc. 
  21732.  
  21733. Return Value 
  21734. putwc returns the wide character written. If a write error occurs, putwc sets 
  21735. the error indicator for the stream and returns WEOF. If an encoding error 
  21736. occurs when a wide character is converted to a multibyte character, putwc sets 
  21737. errno to EILSEQ and returns WEOF. 
  21738.  
  21739.  
  21740. ΓòÉΓòÉΓòÉ <hidden> Example of putwc ΓòÉΓòÉΓòÉ
  21741.  
  21742. /************************************************************************
  21743.  
  21744. The following example uses putwc to convert the wide characters in wcs to 
  21745. multibyte characters and write them to the file putwc.out. 
  21746.  
  21747. ************************************************************************/
  21748.  
  21749. #include <stdio.h>
  21750. #include <wchar.h>
  21751. #include <stdlib.h>
  21752. #include <errno.h>
  21753.  
  21754. int main(void)
  21755. {
  21756.    FILE    *stream;
  21757.    wchar_t *wcs = L"A character string.";
  21758.    int     i;
  21759.  
  21760.    if (NULL == (stream = fopen("putwc.out", "w"))) {
  21761.       printf("Unable to open: \"putwc.out\".\n");
  21762.       exit(EXIT_FAILURE);
  21763.    }
  21764.  
  21765.    for (i = 0; wcs[i] != L'\0'; i++) {
  21766.       errno = 0;
  21767.       if (WEOF == putwc(wcs[i], stream)) {
  21768.          printf("Unable to putwc() the wide character.\n"
  21769.                 "wcs[%d] = 0x%lx\n", i, wcs[i]);
  21770.          if (EILSEQ == errno)
  21771.             printf("An invalid wide character was encountered.\n");
  21772.          exit(EXIT_FAILURE);
  21773.       }
  21774.    }
  21775.    fclose(stream);
  21776.    return 0;
  21777.  
  21778.    /****************************************************************************
  21779.       The output file putwc.out should contain :
  21780.  
  21781.       A character string.
  21782.    ****************************************************************************/
  21783. }
  21784.  
  21785.  
  21786. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21787.  
  21788. Example of putwc 
  21789.  
  21790.      fputc - Write Character 
  21791.      _fputchar - Write Character 
  21792.      fputwc - Write Wide Character 
  21793.      getwc - Read Wide Character from Stream 
  21794.      putc - putchar - Write a Character 
  21795.      _putch - Write Character to Screen 
  21796.      putwchar - Write Wide Character to stdout 
  21797.      <stdio.h> 
  21798.      <wchar.h> 
  21799.  
  21800.  
  21801. ΓòÉΓòÉΓòÉ 4.215. putwchar - Write Wide Character to stdout ΓòÉΓòÉΓòÉ
  21802.  
  21803.  
  21804. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21805.  
  21806. #include <wchar.h>
  21807. wint_t putwchar(wint_t wc);
  21808.  
  21809.  
  21810. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21811.  
  21812. Language Level:  ANSI 93, XPG4 
  21813.  
  21814. putwchar converts the wide character wc to a multibyte character and writes it 
  21815. to stdout. A call to putwchar is equivalent to putwc(wc, stdout). 
  21816.  
  21817. The behavior of putwchar is affected by the LC_CTYPE category of the current 
  21818. locale. Using a non-wide-character function with putwchar on the same stream 
  21819. results in undefined behavior. 
  21820.  
  21821. After calling putwchar, flush the buffer or reposition the stream pointer 
  21822. before calling a write function for the stream, unless EOF has been reached. 
  21823. After a write operation on the stream, flush the buffer or reposition the 
  21824. stream pointer before calling putwchar. 
  21825.  
  21826. Return Value 
  21827. putwchar returns the wide character written. If a write error occurs, putwchar 
  21828. sets the error indicator for the stream and returns WEOF. If an encoding error 
  21829. occurs when a wide character is converted to a multibyte character, putwchar 
  21830. sets errno to EILSEQ and returns WEOF. 
  21831.  
  21832.  
  21833. ΓòÉΓòÉΓòÉ <hidden> Example of putwchar ΓòÉΓòÉΓòÉ
  21834.  
  21835. /************************************************************************
  21836.  
  21837. This example uses putwchar to write the string in wcs. 
  21838.  
  21839. ************************************************************************/
  21840.  
  21841. #include <stdio.h>
  21842. #include <wchar.h>
  21843. #include <errno.h>
  21844. #include <stdlib.h>
  21845.  
  21846. int main(void)
  21847. {
  21848.    wchar_t *wcs = L"A character string.";
  21849.    int     i;
  21850.  
  21851.    for (i = 0; wcs[i] != L'\0'; i++) {
  21852.       errno = 0;
  21853.       if (WEOF == putwchar(wcs[i])) {
  21854.          printf("Unable to putwchar() the wide character.\n");
  21855.          printf("wcs[%d] = 0x%lx\n", i, wcs[i]);
  21856.          if (EILSEQ == errno)
  21857.             printf("An invalid wide character was encountered.\n");
  21858.          exit(EXIT_FAILURE);
  21859.       }
  21860.    }
  21861.    return 0;
  21862.  
  21863.    /****************************************************************************
  21864.       The output should be similar to :
  21865.  
  21866.       A character string.
  21867.    ****************************************************************************/
  21868. }
  21869.  
  21870.  
  21871. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21872.  
  21873. Example of putwchar 
  21874.  
  21875.      fputc - Write Character 
  21876.      _fputchar - Write Character 
  21877.      fputwc - Write Wide Character 
  21878.      getwchar - Get Wide Character from stdin 
  21879.      putc - putchar - Write a Character 
  21880.      _putch - Write Character to Screen 
  21881.      <wchar.h> 
  21882.  
  21883.  
  21884. ΓòÉΓòÉΓòÉ 4.216. qsort - Sort Array ΓòÉΓòÉΓòÉ
  21885.  
  21886.  
  21887. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21888.  
  21889. #include <stdlib.h>
  21890. void qsort(void *base, size_t num, size_t width,
  21891.            int(*compare)(const void *key, const void *element));
  21892.  
  21893.  
  21894. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21895.  
  21896. Language Level:  ANSI, SAA, POSIX, XPG4 
  21897.  
  21898. qsort sorts an array of num elements, each of width bytes in size.  The base 
  21899. pointer is a pointer to the array to be sorted. qsort overwrites this array 
  21900. with the sorted elements. 
  21901.  
  21902. The compare argument is a pointer to a function you must supply that takes a 
  21903. pointer to the key argument and to an array element, in that order. qsort calls 
  21904. this function one or more times during the search. The function must compare 
  21905. the key and the element and return one of the following values: 
  21906.  
  21907.  Value              Meaning 
  21908.  Less than 0        key less than element 
  21909.  0                  key equal to element 
  21910.  Greater than 0     key greater than element 
  21911.  
  21912.  The sorted array elements are stored in ascending order, as defined by your 
  21913.  compare function.  You can sort in reverse order by reversing the sense of 
  21914.  "greater than" and "less than" in compare.  The order of the elements is 
  21915.  unspecified when two elements compare equally. 
  21916.  
  21917.  Return Value 
  21918.  There is no return value. 
  21919.  
  21920.  
  21921. ΓòÉΓòÉΓòÉ <hidden> Example of qsort ΓòÉΓòÉΓòÉ
  21922.  
  21923. /************************************************************************
  21924.  
  21925. This example sorts the arguments (argv) in ascending lexical sequence, using 
  21926. the comparison function compare() supplied in the example. 
  21927.  
  21928. ************************************************************************/
  21929.  
  21930. #include <stdio.h>
  21931. #include <stdlib.h>
  21932. #include <string.h>
  21933.  
  21934. /* --------------------------------------------------------------             */
  21935. /* compare() routine called internally by qsort()                             */
  21936. /*                                                                            */
  21937. /* Assert: Library always calls functions internally with                     */
  21938. /*         _Optlink linkage convention. Ensure that compare() is              */
  21939. /*         always _Optlink.                                                   */
  21940. /* --------------------------------------------------------------             */
  21941.  
  21942. int _Optlink compare(const void *arg1,const void *arg2)
  21943. {
  21944.    return (strcmp(*(char **)arg1, *(char **)arg2));
  21945. }
  21946.  
  21947. int main(int argc,char *argv[])
  21948. {
  21949.    int i;
  21950.    argv++;
  21951.    argc--;
  21952.  
  21953.    qsort((char *)argv, argc, sizeof(char *), compare);
  21954.    for (i = 0; i < argc; ++i)
  21955.       printf("%s\n", argv[i]);
  21956.    return 0;
  21957.  
  21958.    /****************************************************************************
  21959.       Assuming command line of: qsort kent theresa andrea laura brenden
  21960.       Output should be:
  21961.  
  21962.         andrea
  21963.         brenden
  21964.         kent
  21965.         laura
  21966.         theresa
  21967.    ****************************************************************************/
  21968. }
  21969.  
  21970.  
  21971. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21972.  
  21973. Example of qsort 
  21974.  
  21975.      bsearch - Search Arrays 
  21976.      lfind - lsearch - Find Key in Array 
  21977.      <search.h> 
  21978.      <stdlib.h> 
  21979.  
  21980.  
  21981. ΓòÉΓòÉΓòÉ 4.217. raise - Send Signal ΓòÉΓòÉΓòÉ
  21982.  
  21983.  
  21984. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21985.  
  21986. #include <signal.h>
  21987. int raise(int sig);
  21988.  
  21989.  
  21990. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21991.  
  21992. Language Level: ANSI, SAA, XPG4 
  21993.  
  21994. raise sends the signal sig to the running program. You can then use signal to 
  21995. handle sig. 
  21996.  
  21997. Signals and signal handling are described in signal - Handle Interrupt Signals, 
  21998. and in the Programming Guide under Signal and Exception Handling. 
  21999.  
  22000. Return Value 
  22001. raise returns 0 if successful, nonzero if unsuccessful. 
  22002.  
  22003.  
  22004. ΓòÉΓòÉΓòÉ <hidden> Example of raise ΓòÉΓòÉΓòÉ
  22005.  
  22006. /************************************************************************
  22007.  
  22008. This example establishes a signal handler called sig_hand for the signal 
  22009. SIGUSR1. The signal handler is called whenever the SIGUSR1 signal is raised and 
  22010. will ignore the first nine occurrences of the signal.  On the tenth raised 
  22011. signal, it exits the program with an error code of 10.  Note that the signal 
  22012. handler must be reestablished each time it is called. 
  22013.  
  22014. ************************************************************************/
  22015.  
  22016. #include <stdio.h>
  22017. #include <stdlib.h>
  22018. #include <signal.h>
  22019.  
  22020. void sig_hand(int);        /* declaration of sig_hand() as a function         */
  22021. int main(void)
  22022. {
  22023.    signal(SIGUSR1, (_SigFunc)sig_hand);    /* set up handler for SIGUSR1      */
  22024.  
  22025.    raise(SIGUSR1);                      /* signal SIGUSR1 is raised           */
  22026.                       /* sig_hand() is called                                 */
  22027.    return 0;
  22028. }
  22029.  
  22030. void sig_hand(int sig)
  22031. {
  22032.    static int count = 0;                 /* initialized only once             */
  22033.    count++;
  22034.  
  22035.    if (10 == count)     /* ignore the first 9 occurrences of this signal      */
  22036.       exit(10);
  22037.    else
  22038.       signal(SIGUSR1,(_SigFunc)sig_hand);               /* set up the handler again    */
  22039.    raise(SIGUSR1);
  22040. }
  22041.  
  22042.  
  22043. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22044.  
  22045. Example of raise 
  22046.  
  22047.      signal - Handle Interrupt Signals 
  22048.      Signal and Exception Handling in the Programming Guide 
  22049.      <signal.h> 
  22050.  
  22051.  
  22052. ΓòÉΓòÉΓòÉ 4.218. rand - Generate Random Number ΓòÉΓòÉΓòÉ
  22053.  
  22054.  
  22055. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22056.  
  22057. #include <stdlib.h>
  22058. int rand(void);
  22059.  
  22060.  
  22061. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22062.  
  22063. Language Level: ANSI, SAA, POSIX, XPG4 
  22064.  
  22065. rand generates a pseudo-random integer in the range 0 to RAND_MAX (macro 
  22066. defined in <stdlib.h>). Use srand before calling rand to set a starting point 
  22067. for the random number generator. If you do not call srand first, the default 
  22068. seed is 1. 
  22069.  
  22070. Return Value 
  22071. rand returns a pseudo-random number. 
  22072.  
  22073.  
  22074. ΓòÉΓòÉΓòÉ <hidden> Example of rand ΓòÉΓòÉΓòÉ
  22075.  
  22076. /************************************************************************
  22077.  
  22078. This example prints the first 10 pseudo-random numbers generated. 
  22079.  
  22080. ************************************************************************/
  22081.  
  22082. #include <stdlib.h>
  22083. #include <stdio.h>
  22084.  
  22085. int main(void)
  22086. {
  22087.    int x;
  22088.  
  22089.    for (x = 1; x <= 10; x++)
  22090.       printf("iteration %d, rand=%d\n", x, rand());
  22091.    return 0;
  22092.  
  22093.    /****************************************************************************
  22094.       The output should be:
  22095.  
  22096.       iteration 1, rand=16838
  22097.       iteration 2, rand=5758
  22098.       iteration 3, rand=10113
  22099.       iteration 4, rand=17515
  22100.       iteration 5, rand=31051
  22101.       iteration 6, rand=5627
  22102.       iteration 7, rand=23010
  22103.       iteration 8, rand=7419
  22104.       iteration 9, rand=16212
  22105.       iteration 10, rand=4086
  22106.    ****************************************************************************/
  22107. }
  22108.  
  22109.  
  22110. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22111.  
  22112. Example of rand 
  22113.  
  22114.      srand - Set Seed for rand Function 
  22115.      <stdlib.h> 
  22116.  
  22117.  
  22118. ΓòÉΓòÉΓòÉ 4.219. read - Read Into Buffer ΓòÉΓòÉΓòÉ
  22119.  
  22120.  
  22121. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22122.  
  22123. #include <io.h>
  22124. int read(int handle, char *buffer, unsigned int count);
  22125.  
  22126.  
  22127. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22128.  
  22129. Language Level:  XPG4, Extension 
  22130.  
  22131. read reads count bytes from the file associated with handle into buffer. The 
  22132. read operation begins at the current position of the file pointer associated 
  22133. with the given file. After the read operation, the file pointer points to the 
  22134. next unread character. 
  22135.  
  22136. Note:  In earlier releases of VisualAge C++, read began with an underscore 
  22137. (_read). Because it is defined by the X/Open standard, the underscore has been 
  22138. removed. For compatibility, VisualAge for C++ will map _read to read for you. 
  22139.  
  22140. Return Value 
  22141. read returns the number of bytes placed in buffer.  This number can be less 
  22142. than count if there are fewer than count  bytes left in the file or if the file 
  22143. was opened in text mode.  (See the note below.) The return value 0 indicates an 
  22144. attempt to read at end-of-file. A return value -1 indicates an error. If -1 is 
  22145. returned, the current file position is undefined, and errno is set to one of 
  22146. the following values: 
  22147.  
  22148.  Value        Meaning 
  22149.  EBADF        The given handle is incorrect, or the file is not open for 
  22150.               reading, or the file is locked. 
  22151.  EOS2ERR      The call to the operating system was not successful. 
  22152.  
  22153.  Note:  If the file was opened in text mode, the return value might not 
  22154.  correspond to the number of bytes actually read.  When text mode is in effect, 
  22155.  the pair of characters carriage return and line feed are replaced by a single 
  22156.  newline character. 
  22157.  
  22158.  
  22159. ΓòÉΓòÉΓòÉ <hidden> Example of read ΓòÉΓòÉΓòÉ
  22160.  
  22161. /************************************************************************
  22162.  
  22163. This example opens the file sample.dat and attempts to read from it. 
  22164.  
  22165. ************************************************************************/
  22166.  
  22167. #include <io.h>
  22168. #include <stdio.h>
  22169. #include <stdlib.h>
  22170. #include <fcntl.h>
  22171. #include <string.h>
  22172.  
  22173. int main(void)
  22174. {
  22175.    int fh;
  22176.    char buffer[20];
  22177.  
  22178.    memset(buffer, '\0', 20);
  22179.    printf("\nCreating sample.dat.\n");
  22180.    system("echo Sample Program > sample.dat");
  22181.    if (-1 == (fh = open("sample.dat", O_RDWR|O_APPEND))) {
  22182.       perror("Unable to open sample.dat.");
  22183.       return EXIT_FAILURE;
  22184.    }
  22185.    if (7 != read(fh, buffer, 7)) {
  22186.       perror("Unable to read from sample.dat.");
  22187.       close(fh);
  22188.       return EXIT_FAILURE;
  22189.    }
  22190.    printf("Successfully read in the following:\n%s\n ", buffer);
  22191.    close(fh);
  22192.    return 0;
  22193.  
  22194.    /****************************************************************************
  22195.       The output should be:
  22196.  
  22197.       Creating sample.dat.
  22198.       Successfully read in the following:
  22199.       Sample
  22200.    ****************************************************************************/
  22201. }
  22202.  
  22203.  
  22204. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22205.  
  22206. Example of read 
  22207.  
  22208.      creat - Create New File 
  22209.      fread - Read Items 
  22210.      open - Open File 
  22211.      _sopen - Open Shared File 
  22212.      write - Writes from Buffer to File 
  22213.      <io.h> 
  22214.  
  22215.  
  22216. ΓòÉΓòÉΓòÉ 4.220. realloc - Change Reserved Storage Block Size ΓòÉΓòÉΓòÉ
  22217.  
  22218.  
  22219. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22220.  
  22221. #include <stdlib.h>  /* also in <malloc.h> */
  22222. void *realloc(void *ptr, size_t size);
  22223.  
  22224.  
  22225. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22226.  
  22227. Language Level:  ANSI, SAA, POSIX, XPG4, Extension 
  22228.  
  22229. realloc changes the size of a previously reserved storage block.  The ptr 
  22230. argument points to the beginning of the block.  The size argument gives the new 
  22231. size of the block, in bytes.  The contents of the block are unchanged up to the 
  22232. shorter of the new and old sizes. realloc allocates the new block from the same 
  22233. heap the original block was in. 
  22234.  
  22235. If ptr is NULL, realloc reserves a block of storage of size bytes from the 
  22236. current thread's default heap (equivalent to calling malloc(size)). 
  22237.  
  22238. If size is 0 and the ptr is not NULL, realloc frees the storage allocated to 
  22239. ptr and returns NULL. 
  22240.  
  22241. Return Value 
  22242. realloc returns a pointer to the reallocated storage block.  The storage 
  22243. location of the block may be moved by the realloc function.  Thus, the ptr 
  22244. argument to realloc is not necessarily the same as the return value. 
  22245.  
  22246. If size is 0, realloc returns NULL. If there is not enough storage to expand 
  22247. the block to the given size, the original block is unchanged and realloc 
  22248. returns NULL. 
  22249.  
  22250. The storage to which the return value points is aligned for storage of any type 
  22251. of object. 
  22252.  
  22253.  
  22254. ΓòÉΓòÉΓòÉ <hidden> Example of realloc ΓòÉΓòÉΓòÉ
  22255.  
  22256. /************************************************************************
  22257.  
  22258. This example allocates storage for the prompted size of array and then uses 
  22259. realloc to reallocate the block to hold the new size of the array. The contents 
  22260. of the array are printed after each allocation. 
  22261.  
  22262. ************************************************************************/
  22263.  
  22264. #include <stdio.h>
  22265. #include <stdlib.h>
  22266.  
  22267. int main(void)
  22268. {
  22269.    long *array;                         /* start of the array            */
  22270.    long *ptr;                           /* pointer to array */
  22271.    int i;                               /* index variable   */
  22272.    int num1,num2;                       /* number of entries of the array     */
  22273.    void print_array(long *ptr_array, int size);
  22274.  
  22275.    printf("Enter the size of the array\n");
  22276.    scanf("%i", &num1);
  22277.  
  22278.    /* allocate num1 entries using malloc()                                    */
  22279.  
  22280.    if ((array = (long *)malloc(num1 *sizeof(long))) != NULL) {
  22281.       for (ptr = array, i = 0; i < num1; ++i)             /* assign values    */
  22282.          *ptr++ = i;
  22283.       print_array(array, num1);
  22284.       printf("\n");
  22285.    }
  22286.    else {                                                 /* malloc error     */
  22287.       perror("Out of storage");
  22288.       abort();
  22289.    }
  22290.  
  22291.    /* Change the size of the array ...                                        */
  22292.  
  22293.    printf("Enter the size of the new array\n");
  22294.    scanf("%i", &num2);
  22295.    if ((array =(long *) realloc(array, num2 *sizeof(long))) != NULL) {
  22296.       for (ptr = array+num1, i = num1; i <= num2; ++i)
  22297.          *ptr++ = i+2000;                /* assign values to new elements     */
  22298.       print_array(array, num2);
  22299.    }
  22300.    else {                                                 /* realloc error    */
  22301.       perror("Out of storage");
  22302.       abort();
  22303.    }
  22304.    return 0;
  22305.  
  22306.    /****************************************************************************
  22307.       The output should be similar to:
  22308.  
  22309.       Enter the size of the array
  22310.       2
  22311.       The array of size 2 is:
  22312.         array[ 0 ] = 0
  22313.         array[ 1 ] = 1
  22314.       Enter the size of the new array
  22315.       4
  22316.       The array of size 4 is:
  22317.         array[ 0 ] = 0
  22318.         array[ 1 ] = 1
  22319.         array[ 2 ] = 2002
  22320.         array[ 3 ] = 2003
  22321.    ****************************************************************************/
  22322. }
  22323.  
  22324. void print_array(long *ptr_array,int size)
  22325. {
  22326.    int i;
  22327.    long *index = ptr_array;
  22328.  
  22329.    printf("The array of size %d is:\n", size);
  22330.    for (i = 0; i < size; ++i)                             /* print the array
  22331.                                                              out              */
  22332.       printf("  array[ %i ] = %li\n", i, ptr_array[i]);
  22333. }
  22334.  
  22335.  
  22336. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22337.  
  22338. Example of realloc 
  22339.  
  22340.      calloc - Reserve and Initialize Storage 
  22341.      _debug_realloc - Reallocate Memory Block 
  22342.      free - Release Storage Blocks 
  22343.      malloc - Reserve Storage Block 
  22344.      _msize - Return Number of Bytes Allocated 
  22345.      <malloc.h> 
  22346.      <stdlib.h> 
  22347.  
  22348.  
  22349. ΓòÉΓòÉΓòÉ 4.221. regcomp - Compile Regular Expression ΓòÉΓòÉΓòÉ
  22350.  
  22351.  
  22352. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22353.  
  22354. #include <regex.h>
  22355. int regcomp(regex_t *preg, const char *pattern, int cflags);
  22356.  
  22357.  
  22358. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22359.  
  22360. Language Level:  POSIX, XPG4 
  22361.  
  22362. regcomp compiles the source regular expression pointed to by pattern into an 
  22363. executable version and stores it in the location pointed to by preg. You can 
  22364. then use regexec to compare the regular expression to other strings. 
  22365.  
  22366. The cflags flag defines the attributes of the compilation process: 
  22367.  
  22368.  REG_EXTENDED Support extended regular expressions. 
  22369.  
  22370.  REG_NEWLINE Treat new-line character as a special end-of-line character; it 
  22371.       then establishes the line boundaries matched by the ^ and $ patterns, and 
  22372.       can only be matched within a string explicitly using \n. (If you omit 
  22373.       this flag, the new-line character is treated like any other character.) 
  22374.  
  22375.  REG_ICASE Ignore case in match. 
  22376.  
  22377.  REG_NOSUB Ignore the number of subexpressions specified in pattern. When you 
  22378.       compare a string to the compiled pattern (using regexec), the string must 
  22379.       match the entire pattern. regexec then returns a value that indicates 
  22380.       only if a match was found; it does not indicate at what point in the 
  22381.       string the match begins, or what the matching string is. 
  22382.  
  22383.  Regular expressions are a context-independent syntax that can represent a wide 
  22384.  variety of character sets and character set orderings, which can be 
  22385.  interpreted differently depending on the current locale. The functions 
  22386.  regcomp, regerror, regexec, and regfree use regular expressions in a similar 
  22387.  way to the UNIX awk, ed, grep, and egrep commands. Regular expressions are 
  22388.  described in more detail under "Regular Expressions" in the Programming Guide. 
  22389.  
  22390.  Return Value 
  22391.  If regcomp is successful, it returns 0. Otherwise, it returns an error code 
  22392.  that you can use in a call to regerror, and the content of preg is undefined. 
  22393.  
  22394.  
  22395. ΓòÉΓòÉΓòÉ <hidden> Example of regcomp ΓòÉΓòÉΓòÉ
  22396.  
  22397. /************************************************************************
  22398.  
  22399. This example compiles an extended regular expression. 
  22400.  
  22401. ************************************************************************/
  22402.  
  22403. #include <regex.h>
  22404. #include <stdio.h>
  22405. #include <stdlib.h>
  22406.  
  22407. int main(void)
  22408. {
  22409.    regex_t preg;
  22410.    char    *pattern = ".*(simple).*";
  22411.    int     rc;
  22412.  
  22413.    if (0 != (rc = regcomp(&preg, pattern, REG_EXTENDED))) {
  22414.       printf("regcomp() failed, returning nonzero (%d)\n", rc);
  22415.       exit(EXIT_FAILURE);
  22416.    }
  22417.    printf("regcomp() is sucessful.\n");
  22418.    return 0;
  22419.  
  22420.    /****************************************************************************
  22421.       The output should be similar to :
  22422.  
  22423.       regcomp() is sucessful.
  22424.    ****************************************************************************/
  22425. }
  22426.  
  22427.  
  22428. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22429.  
  22430. Example of regcomp 
  22431.  
  22432.      regerror - Return Error Message for Regular Expression 
  22433.      regexec - Execute Compiled Regular Expression 
  22434.      regfree - Free Memory for Regular Expression 
  22435.      "Regular Expressions" in the Programming Guide 
  22436.      <regex.h> 
  22437.  
  22438.  
  22439. ΓòÉΓòÉΓòÉ 4.222. regerror - Return Error Message for Regular Expression ΓòÉΓòÉΓòÉ
  22440.  
  22441.  
  22442. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22443.  
  22444. #include <regex.h>
  22445. size_t regerror(int errcode,  const regex_t *preg,
  22446.                 char *errbuf, size_t errbuf_size);
  22447.  
  22448.  
  22449. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22450.  
  22451. Language Level:  POSIX, XPG4 
  22452.  
  22453. regerror finds the description for the error code errcode for the regular 
  22454. expression preg. The description for errcode is assigned to errbuf. errbuf_size 
  22455. is a value that you provide that specifies the maximum message size that can be 
  22456. stored (the size of errbuf). 
  22457.  
  22458. Regular expressions are described in detail under "Regular Expressions" in the 
  22459. Programming Guide. 
  22460.  
  22461. The description strings for errcode are: 
  22462.  
  22463.  errcode             Description String 
  22464.  REG_NOMATCH         RE pattern not found 
  22465.  REG_BADPAT          Invalid regular expression 
  22466.  REG_ECOLLATE        Invalid collating element 
  22467.  REG_ECTYPE          Invalid character class 
  22468.  REG_EESCAPE         Last character is \ 
  22469.  REG_ESUBREG         Invalid number in \digit 
  22470.  REG_EBRACK          [] imbalance 
  22471.  REG_EPAREN          \( \) or () imbalance 
  22472.  REG_EBRACE          \{ \} or { } imbalance 
  22473.  REG_BADBR           Invalid \{ \} range exp 
  22474.  REG_ERANGE          Invalid range exp endpoint 
  22475.  REG_ESPACE          Out of memory 
  22476.  REG_BADRPT          ?*+ not preceded by valid RE 
  22477.  REG_ECHAR           Invalid multibyte character 
  22478.  REG_EBOL            ^ anchor and not BOL 
  22479.  REG_EEOL            $ anchor and not EOL 
  22480.  
  22481.  The error descriptions are in the CPPWRERR.DLL message file. The directory for 
  22482.  this file must be in your PATH environment variable for the messages to be 
  22483.  found. 
  22484.  
  22485.  Return Value 
  22486.  regerror returns the size of the buffer needed to hold the string that 
  22487.  describes the error condition. 
  22488.  
  22489.  
  22490. ΓòÉΓòÉΓòÉ <hidden> Example of regerror ΓòÉΓòÉΓòÉ
  22491.  
  22492. /************************************************************************
  22493.  
  22494. This example compiles an invalid regular expression, and prints an error 
  22495. message using regerror. 
  22496.  
  22497. ************************************************************************/
  22498.  
  22499. #include <regex.h>
  22500. #include <stdio.h>
  22501. #include <stdlib.h>
  22502.  
  22503. int main(void)
  22504. {
  22505.    regex_t preg;
  22506.    char    *pattern = "a[missing.bracket";
  22507.    int     rc;
  22508.    char    buffer[100];
  22509.  
  22510.    if (0 != (rc = regcomp(&preg, pattern, REG_EXTENDED))) {
  22511.       regerror(rc, &preg, buffer, 100);
  22512.       printf("regcomp() failed with '%s'\n", buffer);
  22513.       exit(EXIT_FAILURE);
  22514.    }
  22515.    return 0;
  22516.  
  22517.    /****************************************************************************
  22518.       The output should be similar to :
  22519.  
  22520.       regcomp() failed with '[] imbalance'
  22521.    ****************************************************************************/
  22522. }
  22523.  
  22524.  
  22525. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22526.  
  22527. Example of regerror 
  22528.  
  22529.      regcomp - Compile Regular Expression 
  22530.      regexec - Execute Compiled Regular Expression 
  22531.      regfree - Free Memory for Regular Expression 
  22532.      "Regular Expressions" in the Programming Guide 
  22533.      <regex.h> 
  22534.  
  22535.  
  22536. ΓòÉΓòÉΓòÉ 4.223. regexec - Execute Compiled Regular Expression ΓòÉΓòÉΓòÉ
  22537.  
  22538.  
  22539. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22540.  
  22541. #include <regex.h>
  22542. int regexec(const regex_t *preg, const char *string,
  22543.             size_t nmatch, regmatch_t *pmatch, int eflags);
  22544.  
  22545.  
  22546. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22547.  
  22548. Language Level:  POSIX, XPG4 
  22549.  
  22550. regexec compares the null-terminated string against the compiled regular 
  22551. expression preg to find a match between the two. (Regular expressions are 
  22552. described in "Regular Expressions" in the Programming Guide.) 
  22553.  
  22554. nmatch is the number of substrings in string that regexec should try to match 
  22555. with subexpressions in preg. The array you supply for pmatch must have at least 
  22556. nmatch elements. 
  22557.  
  22558. regexec fills in the elements of the array pmatch with offsets of the 
  22559. substrings in string that correspond to the parenthesized subexpressions of the 
  22560. original pattern given to regcomp to create preg. The zeroth element of the 
  22561. array corresponds to the entire pattern.  If there are more than nmatch 
  22562. subexpressions, only the first nmatch - 1 are stored. If nmatch is 0, or if the 
  22563. REG_NOSUB flag was set when preg was created with regcomp, regexec ignores the 
  22564. pmatch argument. 
  22565.  
  22566. The eflags flag defines customizable behavior of regexec: 
  22567.  
  22568.  REG_NOTBOL 
  22569.       Indicates that the first character of string is not the beginning of 
  22570.       line. 
  22571.  
  22572.  REG_NOTEOL 
  22573.       Indicates that the first character of string is not the end of line. 
  22574.  
  22575.  When a basic or extended regular expression is matched, any given 
  22576.  parenthesized subexpression of the original pattern could participate in the 
  22577.  match of several different substrings of string. The following rules determine 
  22578.  which substrings are reported in pmatch: 
  22579.  
  22580.    1. If a subexpression participated in a match several times, regexec stores 
  22581.       the offset of the last matching substring in pmatch. 
  22582.  
  22583.    2. If a subexpression did not match in the source string, regexec sets the 
  22584.       offset shown in pmatch to -1. 
  22585.  
  22586.    3. If a subexpression contains subexpressions, the data in pmatch refers to 
  22587.       the last such subexpression. 
  22588.  
  22589.    4. If a subexpression matches a zero-length string, the offsets in pmatch 
  22590.       refer to the byte immediately following the matching string. 
  22591.  
  22592.  If the REG_NOSUB flag was set when preg was created by regcomp, the contents 
  22593.  of pmatch are unspecified. If the REG_NEWLINE flag was not set when preg was 
  22594.  created, new-line characters are allowed in string. 
  22595.  
  22596.  Note:  If MB_CUR_MAX is specified as 2, the charmap file does not specify the 
  22597.  DBCS characters, and a collating element (for example, [:a:]) is specified in 
  22598.  the pattern, the DBCS characters will not match against the collating-element 
  22599.  even if they have an equivalent weight to the collating-element. 
  22600.  
  22601.  Return Value 
  22602.  If a match is found, regexec returns 0. Otherwise, it returns a nonzero value 
  22603.  indicating either no match or an error. 
  22604.  
  22605.  
  22606. ΓòÉΓòÉΓòÉ <hidden> Example of regexec ΓòÉΓòÉΓòÉ
  22607.  
  22608. /************************************************************************
  22609.  
  22610. This example compiles an expression and matches a string against it. The first 
  22611. substring uses the full pattern. The second substring uses the sub-expression 
  22612. inside the full pattern. 
  22613.  
  22614. ************************************************************************/
  22615.  
  22616. #include <regex.h>
  22617. #include <stdio.h>
  22618. #include <stdlib.h>
  22619.  
  22620. int main(void)
  22621. {
  22622.    regex_t    preg;
  22623.    char       *string = "a very simple simple simple string";
  22624.    char       *pattern = "\\(sim[a-z]le\\) \\1";
  22625.    int        rc;
  22626.    size_t     nmatch = 2;
  22627.    regmatch_t pmatch[2];
  22628.  
  22629.    if (0 != (rc = regcomp(&preg, pattern, 0))) {
  22630.       printf("regcomp() failed, returning nonzero (%d)\n", rc);
  22631.       exit(EXIT_FAILURE);
  22632.    }
  22633.  
  22634.    if (0 != (rc = regexec(&preg, string, nmatch, pmatch, 0))) {
  22635.       printf("Failed to match '%s' with '%s',returning %d.\n",
  22636.       string, pattern, rc);
  22637.    }
  22638.    else {
  22639.       printf("With the whole expression, "
  22640.              "a matched substring \"%.*s\" is found at position %d to %d.\n",
  22641.              pmatch[0].rm_eo - pmatch[0].rm_so, &string[pmatch[0].rm_so],
  22642.              pmatch[0].rm_so, pmatch[0].rm_eo - 1);
  22643.       printf("With the sub-expression, "
  22644.              "a matched substring \"%.*s\" is found at position %d to %d.\n",
  22645.              pmatch[1].rm_eo - pmatch[1].rm_so, &string[pmatch[1].rm_so],
  22646.              pmatch[1].rm_so, pmatch[1].rm_eo - 1);
  22647.    }
  22648.    regfree(&preg);
  22649.    return 0;
  22650.  
  22651.    /****************************************************************************
  22652.       The output should be similar to :
  22653.  
  22654.       With the whole expression, a matched substring "simple simple" is found
  22655.       at position 7 to 19.
  22656.       With the sub-expression, a matched substring "simple" is found
  22657.       at position 7 to 12.
  22658.    ****************************************************************************/
  22659. }
  22660.  
  22661.  
  22662. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22663.  
  22664. Example of regexec 
  22665.  
  22666.      regcomp - Compile Regular Expression 
  22667.      regerror - Return Error Message for Regular Expression 
  22668.      regfree - Free Memory for Regular Expression 
  22669.      "Regular Expressions" in the Programming Guide 
  22670.      <regex.h> 
  22671.  
  22672.  
  22673. ΓòÉΓòÉΓòÉ 4.224. regfree - Free Memory for Regular Expression ΓòÉΓòÉΓòÉ
  22674.  
  22675.  
  22676. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22677.  
  22678. #include <regex.h>
  22679. void regfree(regex_t *preg);
  22680.  
  22681.  
  22682. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22683.  
  22684. Language Level:  POSIX, XPG4 
  22685.  
  22686. regfree frees any memory that was allocated by regcomp to implement the regular 
  22687. expression preg. After the call to regfree, the expression defined by preg is 
  22688. no longer a compiled regular or extended expression. 
  22689.  
  22690. Regular expressions are described in "Regular Expressions" in the Programming 
  22691. Guide. 
  22692.  
  22693. Return Value 
  22694. There is no return value. 
  22695.  
  22696.  
  22697. ΓòÉΓòÉΓòÉ <hidden> Example of regfree ΓòÉΓòÉΓòÉ
  22698.  
  22699. /************************************************************************
  22700.  
  22701. This example compiles an extended regular expression and frees it. 
  22702.  
  22703. ************************************************************************/
  22704.  
  22705. #include <regex.h>
  22706. #include <stdio.h>
  22707. #include <stdlib.h>
  22708.  
  22709. int main(void)
  22710. {
  22711.    regex_t    preg;
  22712.    char       *pattern = ".*(simple).*";
  22713.    int        rc;
  22714.  
  22715.    if (0 != (rc = regcomp(&preg, pattern, REG_EXTENDED))) {
  22716.       printf("regcomp() failed, returning nonzero (%d)\n", rc);
  22717.       exit(EXIT_FAILURE);
  22718.    }
  22719.    regfree(&preg);
  22720.    printf("Memory allocated for reg is freed.\n");
  22721.    return 0;
  22722.  
  22723.    /****************************************************************************
  22724.       The output should be similar to :
  22725.  
  22726.       Memory allocated for reg is freed.
  22727.    ****************************************************************************/
  22728. }
  22729.  
  22730.  
  22731. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22732.  
  22733. Example of regfree 
  22734.  
  22735.      regcomp - Compile Regular Expression 
  22736.      regerror - Return Error Message for Regular Expression 
  22737.      regexec - Execute Compiled Regular Expression 
  22738.      "Regular Expressions" in the Programming Guide 
  22739.      <regex.h> 
  22740.  
  22741.  
  22742. ΓòÉΓòÉΓòÉ 4.225. remove - Delete File ΓòÉΓòÉΓòÉ
  22743.  
  22744.  
  22745. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22746.  
  22747. #include <stdio.h>
  22748. int remove(const char *filename);
  22749.  
  22750.  
  22751. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22752.  
  22753. Language Level: ANSI, SAA, POSIX, XPG4 
  22754.  
  22755. remove deletes the file specified by filename. 
  22756.  
  22757. Note:  You cannot remove a nonexistent file or a file that is open. 
  22758.  
  22759. Return Value 
  22760. remove returns 0 if it successfully deletes the file. A nonzero return value 
  22761. indicates an error. 
  22762.  
  22763.  
  22764. ΓòÉΓòÉΓòÉ <hidden> Example of remove ΓòÉΓòÉΓòÉ
  22765.  
  22766. /************************************************************************
  22767.  
  22768. This example uses remove to remove a file. It issues a message if an error 
  22769. occurs. 
  22770.  
  22771. ************************************************************************/
  22772.  
  22773. #include <stdio.h>
  22774.  
  22775. int main(void)
  22776. {
  22777.    char *FileName = "file2rm.mjq";
  22778.    FILE *fp;
  22779.  
  22780.    fp = fopen(FileName, "w");
  22781.    fprintf(fp, "Hello world\n");
  22782.    fclose(fp);
  22783.    if (remove(FileName) != 0)
  22784.       perror("Could not remove file");
  22785.    else
  22786.       printf("File \"%s\" removed successfully.\n", FileName);
  22787.    return 0;
  22788.  
  22789.    /****************************************************************************
  22790.       The output should be:
  22791.  
  22792.       File "file2rm.mjq" removed successfully.
  22793.    ****************************************************************************/
  22794. }
  22795.  
  22796.  
  22797. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22798.  
  22799. Example of remove 
  22800.  
  22801.      fopen - Open Files 
  22802.      rename - Rename File 
  22803.      _rmtmp - Remove Temporary Files 
  22804.      unlink - Delete File 
  22805.      <stdio.h> 
  22806.  
  22807.  
  22808. ΓòÉΓòÉΓòÉ 4.226. rename - Rename File ΓòÉΓòÉΓòÉ
  22809.  
  22810.  
  22811. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22812.  
  22813. #include <stdio.h>  /* also in <io.h> */
  22814. int rename(const char *oldname, const char *newname);
  22815.  
  22816.  
  22817. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22818.  
  22819. Language Level: ANSI, SAA, POSIX, XPG4 
  22820.  
  22821. rename renames the file specified by oldname to the name given by newname. The 
  22822. oldname pointer must specify the name of an existing file. The newname pointer 
  22823. must not specify the name of an existing file. Both oldname and newname must be 
  22824. on the same drive; you cannot rename files across drives. You cannot rename a 
  22825. file with the name of an existing file. You also cannot rename an open file. 
  22826.  
  22827. Return Value 
  22828. rename returns 0 if successful. On an error, it returns a nonzero value. 
  22829.  
  22830.  
  22831. ΓòÉΓòÉΓòÉ <hidden> Example of rename ΓòÉΓòÉΓòÉ
  22832.  
  22833. /************************************************************************
  22834.  
  22835. This example uses rename to rename a file. It issues a message if errors occur. 
  22836.  
  22837. ************************************************************************/
  22838.  
  22839. #include <stdio.h>
  22840.  
  22841. int main(void)
  22842. {
  22843.    char *OldName = "oldfile.mjq";
  22844.    char *NewName = "newfile.mjq";
  22845.    FILE *fp;
  22846.  
  22847.    fp = fopen(OldName, "w");
  22848.    fprintf(fp, "Hello world\n");
  22849.    fclose(fp);
  22850.    if (rename(OldName, NewName) != 0)
  22851.       perror("Could not rename file");
  22852.    else
  22853.       printf("File \"%s\" is renamed to \"%s\".\n", OldName, NewName);
  22854.    return 0;
  22855.  
  22856.    /****************************************************************************
  22857.       The output should be:
  22858.  
  22859.       File "oldfile.mjq" is renamed to "newfile.mjq".
  22860.    ****************************************************************************/
  22861. }
  22862.  
  22863.  
  22864. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22865.  
  22866. Example of rename 
  22867.  
  22868.      fopen - Open Files 
  22869.      remove - Delete File 
  22870.      <stdio.h> 
  22871.  
  22872.  
  22873. ΓòÉΓòÉΓòÉ 4.227. rewind - Adjust Current File Position ΓòÉΓòÉΓòÉ
  22874.  
  22875.  
  22876. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22877.  
  22878. #include <stdio.h>
  22879. void rewind(FILE *stream);
  22880.  
  22881.  
  22882. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22883.  
  22884. Language Level: ANSI, SAA, POSIX, XPG4 
  22885.  
  22886. rewind repositions the file pointer associated with stream to the beginning of 
  22887. the file. A call to rewind is the same as: 
  22888.  
  22889.    (void)fseek(stream, 0L, SEEK_SET);
  22890.  
  22891. except that rewind also clears the error indicator for the stream. 
  22892.  
  22893. Return Value 
  22894. There is no return value. 
  22895.  
  22896.  
  22897. ΓòÉΓòÉΓòÉ <hidden> Example of rewind ΓòÉΓòÉΓòÉ
  22898.  
  22899. /************************************************************************
  22900.  
  22901. This example first opens a file myfile.dat for input and output.  It writes 
  22902. integers to the file, uses rewind to reposition the file pointer to the 
  22903. beginning of the file, and then reads the data back in. 
  22904.  
  22905. ************************************************************************/
  22906.  
  22907. #include <stdio.h>
  22908.  
  22909. FILE *stream;
  22910. int data1,data2,data3,data4;
  22911.  
  22912. int main(void)
  22913. {
  22914.    data1 = 1;
  22915.    data2 = -37;
  22916.  
  22917.        /* Place data in the file                                              */
  22918.  
  22919.    stream = fopen("myfile.dat", "w+");
  22920.    fprintf(stream, "%d %d\n", data1, data2);
  22921.  
  22922.        /* Now read the data file                                              */
  22923.  
  22924.    rewind(stream);
  22925.    fscanf(stream, "%d", &data3);
  22926.    fscanf(stream, "%d", &data4);
  22927.    printf("The values read back in are: %d and %d\n", data3, data4);
  22928.    return 0;
  22929.  
  22930.    /****************************************************************************
  22931.       The output should be:
  22932.  
  22933.       The values read back in are: 1 and -37
  22934.    ****************************************************************************/
  22935. }
  22936.  
  22937.  
  22938. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22939.  
  22940. Example of rewind 
  22941.  
  22942.      fgetpos - Get File Position 
  22943.      fseek - Reposition File Position 
  22944.      fsetpos - Set File Position 
  22945.      ftell - Get Current Position 
  22946.      lseek - Move File Pointer 
  22947.      _tell - Get Pointer Position 
  22948.      <stdio.h> 
  22949.  
  22950.  
  22951. ΓòÉΓòÉΓòÉ 4.228. rmdir - Remove Directory ΓòÉΓòÉΓòÉ
  22952.  
  22953.  
  22954. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22955.  
  22956. #include <direct.h>
  22957. int rmdir(char *pathname);
  22958.  
  22959.  
  22960. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22961.  
  22962. Language Level:  XPG4, Extension 
  22963.  
  22964. rmdir deletes the directory specified by pathname.  The directory must be 
  22965. empty, and it must not contain any files or subdirectories. 
  22966.  
  22967. Note:  In earlier releases of VisualAge C++, rmdir began with an underscore 
  22968. (_rmdir). Because it is defined by the X/Open standard, the underscore has been 
  22969. removed. For compatibility, VisualAge for C++ will map _rmdir to rmdir for you. 
  22970.  
  22971. Return Value 
  22972. rmdir returns the value 0 if the directory is successfully deleted. A return 
  22973. value of -1 indicates an error, and errno is set to one of the following 
  22974. values: 
  22975.  
  22976.  Value          Meaning 
  22977.  
  22978.  EACCESS        One of the following has occurred: 
  22979.  
  22980.                     The given path name is not a directory. 
  22981.                     The directory is not empty. 
  22982.                     The directory is read only. 
  22983.                     The directory is the current working directory or root 
  22984.                      directory being used by a process. 
  22985.  
  22986.  ENOENT         The path name was not found. 
  22987.  
  22988.  
  22989. ΓòÉΓòÉΓòÉ <hidden> Example of rmdir ΓòÉΓòÉΓòÉ
  22990.  
  22991. /************************************************************************
  22992.  
  22993. This example deletes two directories: one in the root directory, and the other 
  22994. in the current working directory. 
  22995.  
  22996. ************************************************************************/
  22997.  
  22998. #include <stdio.h>
  22999. #include <direct.h>
  23000. #include <string.h>
  23001.  
  23002. int main(void)
  23003. {
  23004.    char *dir1,*dir2;
  23005.  
  23006.  /*  Create the directory "aleng" in the root directory of the C: drive.      */
  23007.  
  23008.    dir1 = "c:\\aleng";
  23009.    if (0 == (mkdir(dir1)))
  23010.       printf("%s directory was created.\n", dir1);
  23011.    else
  23012.       printf("%s directory was not created.\n", dir1);
  23013.  
  23014.  /*  Create the subdirectory "simon" in the current directory.                */
  23015.  
  23016.    dir2 = "simon";
  23017.    if (0 == (mkdir(dir2)))
  23018.       printf("%s directory was created.\n", dir2);
  23019.    else
  23020.       printf("%s directory was not created.\n", dir2);
  23021.  
  23022.  /*  Remove the directory "aleng" from the root directory of the C: drive.    */
  23023.  
  23024.    printf("Removing directory 'aleng' from the root directory.\n");
  23025.    if (rmdir(dir1))
  23026.       perror(NULL);
  23027.    else
  23028.       printf("%s directory was removed.\n", dir1);
  23029.  
  23030.  /*  Remove the subdirectory "simon" from the current directory.              */
  23031.  
  23032.    printf("Removing subdirectory 'simon' from the current directory.\n");
  23033.    if (rmdir(dir2))
  23034.       perror(NULL);
  23035.    else
  23036.       printf("%s directory was removed.\n", dir2);
  23037.    return 0;
  23038.  
  23039.    /****************************************************************************
  23040.       The output should be:
  23041.  
  23042.       c:\aleng directory was created.
  23043.       simon directory was created.
  23044.       Removing directory 'aleng' from the root directory.
  23045.       c:\aleng directory was removed.
  23046.       Removing subdirectory 'simon' from the current directory.
  23047.       simon directory was removed.
  23048.    ****************************************************************************/
  23049. }
  23050.  
  23051.  
  23052. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23053.  
  23054. Example of rmdir 
  23055.  
  23056.      chdir - Change Current Working Directory 
  23057.      _getdcwd - Get Full Path Name of Current Directory 
  23058.      _getcwd - Get Path Name of Current Directory 
  23059.      mkdir - Create New Directory 
  23060.      <direct.h> 
  23061.  
  23062.  
  23063. ΓòÉΓòÉΓòÉ 4.229. _rmem_init - Initialize Memory Functions for Subsystem DLL ΓòÉΓòÉΓòÉ
  23064.  
  23065.  
  23066. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23067.  
  23068. int _rmem_init(void);
  23069. /* no header file - defined in runtime startup code */
  23070.  
  23071.  
  23072. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23073.  
  23074. Language Level:  Extension 
  23075.  
  23076. _rmem_init initializes the memory functions for subsystem DLLs.  Although 
  23077. subsystems do not require a runtime environment (and therefore do not call 
  23078. _CRT_init), they do require the library memory functions. For DLLs that do use 
  23079. a runtime environment, the memory functions are initialized with the 
  23080. environment by _CRT_init. 
  23081.  
  23082. By default, all DLLs call the VisualAge for C++ _DLL_InitTerm function, which 
  23083. in turn calls _rmem_init for you. However, if you are writing your own 
  23084. subsystem _DLL_InitTerm function (for example, to perform actions other than 
  23085. memory initialization and termination), you must call _rmem_init from your 
  23086. version of _DLL_InitTerm before you can call any other library functions. 
  23087.  
  23088. If your DLL contains C++ code, you must also call __ctordtorInit after 
  23089. _rmem_init to ensure that static constructors and destructors are initialized 
  23090. properly.  __ctordtorInit is defined in the runtime startup code as: 
  23091.  
  23092.    void __ctordtorInit(void);
  23093.  
  23094. Return Value 
  23095. If the memory functions were successfully initialized, _rmem_init returns 0. A 
  23096. return code of -1 indicates an error. If an error occurs, an error message is 
  23097. written to file handle 2, which is the usual destination of stderr. 
  23098.  
  23099.  
  23100. ΓòÉΓòÉΓòÉ <hidden> Example of _rmem_init ΓòÉΓòÉΓòÉ
  23101.  
  23102. /************************************************************************
  23103.  
  23104. This example shows the _DLL_InitTerm function from the VisualAge for C++ sample 
  23105. program for building subsystem DLLs, which calls _rmem_init to initialize the 
  23106. memory functions. 
  23107.  
  23108. ************************************************************************/
  23109.  
  23110. #pragma strings(readonly)
  23111. /******************************************************************************/
  23112. /* _DLL_InitTerm - Initialization/Termination function for the DLL that is    */
  23113. /*                 invoked by the loader.  When the /Ge- compile option is    */
  23114. /*                 used the linker is told that this is the function to       */
  23115. /*                 execute when the DLL is first loaded and last freed for    */
  23116. /*                 each process.                                              */
  23117. /*                                                                            */
  23118. /* DLLREGISTER  - Called by _DLL_InitTerm for each process that loads the     */
  23119. /*                DLL.                                                        */
  23120. /*                                                                            */
  23121. /* DLLDEREGISTER- Called by _DLL_InitTerm for each process that frees the     */
  23122. /*                DLL.                                                        */
  23123. /*                                                                            */
  23124. /******************************************************************************/
  23125.  
  23126. #include <windows.h>
  23127. #include <stdlib.h>
  23128. #include <stdio.h>
  23129. #include <string.h>
  23130.  
  23131. #pragma linkage ( PLUS, system )
  23132. int PLUS( int a, int b ) {
  23133.   return a + b ;
  23134. }
  23135.  
  23136. unsigned long _System _DLL_InitTerm ( unsigned long hModule, unsigned long ulFlag );
  23137.  
  23138. static unsigned long DLLREGISTER ( void );
  23139. static unsigned long DLLDEREGISTER( void );
  23140.  
  23141. #define SHARED_SEMAPHORE_NAME "SAMPLE05.DLL.LOCK"
  23142.  
  23143. /* The following data will be per-process data.  It will not be shared among  */
  23144. /* different processes.                                                       */
  23145.  
  23146. static HANDLE hSharedSem;               /* Shared semaphore                   */
  23147. static ULONG  ulProcessTotal;           /* Total of increments for a process  */
  23148. static DWORD  dwProcess;               /* Process identifier                  */
  23149.  
  23150. /* This is the global segment that is shared by every process                 */
  23151.  
  23152. #pragma data_seg( GLOBAL_SEG )
  23153.  
  23154. static ULONG ulProcessCount;           /* total number of processes           */
  23155.  
  23156. /* _DLL_InitTerm() - called by the loader for DLL initialization/termination  */
  23157. /* This function must return a non-zero value if successful and a zero value  */
  23158. /* if unsuccessful.                                                           */
  23159.  
  23160. unsigned long _DLL_InitTerm ( unsigned long hModule, unsigned long ulFlag ) {
  23161.  
  23162.    /* If ulFlag is zero then initialization is required:                      */
  23163.    /*    If the shared memory pointer is NULL then the DLL is being loaded    */
  23164.    /*    for the first time so acquire the named shared storage for the       */
  23165.    /*    process control structures.  A linked list of process control        */
  23166.    /*    structures will be maintained.  Each time a new process loads this   */
  23167.    /*    DLL, a new process control structure is created and it is inserted   */
  23168.    /*    at the end of the list by calling DLLREGISTER.                       */
  23169.    /*                                                                         */
  23170.    /* If ulFlag is 1 then termination is required:                            */
  23171.    /*    Call DLLDEREGISTER which will remove the process  control structure  */
  23172.    /*    and free the shared memory block from its virtual address space.     */
  23173.  
  23174.   switch ( ulFlag ) {
  23175.  
  23176.      case 0:
  23177.            if ( !ulProcessCount ) {
  23178.              _rmem_init();
  23179.              /* Create the shared mutex semaphore                             */
  23180.              if ( !CreateMutex( NULL, FALSE, SHARED_SEMAPHORE_NAME )) {
  23181.                 printf("CreateMutex rc = %d\n", GetLastError());
  23182.                 return 0;
  23183.             }
  23184.            }
  23185.  
  23186.            /* Register the current process                                    */
  23187.            if ( DLLREGISTER() )
  23188.              return 0;
  23189.            break;
  23190.  
  23191.     case 1:
  23192.            /* Deregister the current process                                  */
  23193.            if ( DLLDEREGISTER() )
  23194.              return 0;
  23195.  
  23196.            _rmem_term();
  23197.            break;
  23198.  
  23199.  
  23200.     default:
  23201.            return 0;
  23202.  
  23203.   }
  23204.  
  23205.   /* Indicate success.  Non-zero means success!!!                             */
  23206.  
  23207.   return 1;
  23208.  
  23209. }
  23210.  
  23211. /* DLLREGISTER - Registers the current process so that it can use this        */
  23212. /*               subsystem.  Called by _DLL_InitTerm when the DLL is first    */
  23213. /*               loaded for the current process.                              */
  23214.  
  23215. static unsigned long DLLREGISTER( void ) {
  23216.  
  23217.   DWORD pid;
  23218.   DWORD rc;
  23219.  
  23220.   pid = GetCurrentProcessId();
  23221.  
  23222.   /* Open the shared mutex semaphore for this process.                        */
  23223.   if ( ! (hSharedSem = OpenMutex ( MUTEX_ALL_ACCESS | SYNCHRONIZE,  FALSE,
  23224.                                   SHARED_SEMAPHORE_NAME )) ) {
  23225.      rc = GetLastError();
  23226.      printf("OpenMutex rc = %d\n",  rc);
  23227.      return rc;
  23228.   }
  23229.  
  23230.   /*Acquire the shared mutex semaphore.                                       */
  23231.   if ( WaitForSingleObject(hSharedSem, INFINITE) != WAIT_OBJECT_0) {
  23232.      rc = GetLastError();
  23233.      printf("WaitForSingleObject rc = %d\n", rc);
  23234.      return rc;
  23235.   }
  23236.  
  23237.   /* Increment the count of processes registered.                             */
  23238.   ++ulProcessCount;
  23239.  
  23240.   /* Initialize the per-process data.                                         */
  23241.   ulProcessTotal = 0;
  23242.   dwProcess = pid;
  23243.  
  23244.   /* Release the shared mutex semaphore.                                      */
  23245.   if ( ! ReleaseMutex( hSharedSem ) ) {
  23246.      rc = GetLastError();
  23247.      printf("ReleaseMutex rc = %d\n", rc);
  23248.      return rc;
  23249.   }
  23250.  
  23251.   return 0;
  23252.  
  23253. }
  23254.  
  23255. /* DLLDEREGISTER - Deregisters the current process from this subsystem.       */
  23256. /*                 Called by _DLL_InitTerm when the DLL is freed for the      */
  23257. /*                 last time by the current process.                          */
  23258.  
  23259. static unsigned long DLLDEREGISTER( void ) {
  23260.  
  23261.   DWORD rc;
  23262.  
  23263.   /* Acquire the shared mutex semaphore.                                      */
  23264.   if ( WaitForSingleObject(hSharedSem, INFINITE) != WAIT_OBJECT_0) {
  23265.      rc = GetLastError();
  23266.      printf("WaitForSingleObject rc = %d\n", rc);
  23267.      return rc;
  23268.   }
  23269.  
  23270.   /* Decrement the count of processes registered.                             */
  23271.   --ulProcessCount;
  23272.  
  23273.   /* Tell the user that the current process has been deregistered.            */
  23274.   printf( "\nProcess %d has been deregistered.\n\n", dwProcess);
  23275.  
  23276.   /* Release the shared mutex semaphore.                                      */
  23277.   if ( ! ReleaseMutex( hSharedSem ) ) {
  23278.      rc = GetLastError();
  23279.      printf("ReleaseMutex rc = %d\n", rc);
  23280.      return rc;
  23281.   }
  23282.  
  23283.   /* Close the shared mutex semaphore for this process.                       */
  23284.   if ( ! CloseHandle ( hSharedSem ) ) {
  23285.      rc = GetLastError();
  23286.      printf("CloseHandle rc = %d\n", rc);
  23287.      return rc;
  23288.   }
  23289.  
  23290.  return 0;
  23291.  
  23292. }
  23293.  
  23294.  
  23295. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23296.  
  23297. Example of _rmem_init 
  23298.  
  23299.      Building Subsystem DLLs in the Programming Guide 
  23300.      _CRT_init - Initialize DLL Runtime Environment 
  23301.      _CRT_term - Terminate DLL Runtime Environment 
  23302.      _DLL_InitTerm - Initialize and Terminate DLL Environment 
  23303.      _rmem_term - Terminate Memory Functions for Subsystem DLL 
  23304.  
  23305.  
  23306. ΓòÉΓòÉΓòÉ 4.230. _rmem_term - Terminate Memory Functions for Subsystem DLL ΓòÉΓòÉΓòÉ
  23307.  
  23308.  
  23309. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23310.  
  23311. int _rmem_term(void);
  23312. /* no header file - defined in runtime startup code */
  23313.  
  23314.  
  23315. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23316.  
  23317. Language Level:  Extension 
  23318.  
  23319. _rmem_term terminates the memory functions for subsystem DLLs.  It is only 
  23320. needed for DLLs where the runtime library is statically linked. 
  23321.  
  23322. By default, all DLLs call the VisualAge for C++ _DLL_InitTerm function, which 
  23323. in turn calls _rmem_term for you. However, if you are writing your own 
  23324. _DLL_InitTerm function (for example, to perform actions other than memory 
  23325. initialization and termination), and your DLL statically links to the C runtime 
  23326. libraries, you need to call _rmem_term from your subsystem _DLL_InitTerm 
  23327. function. (For DLLs with a runtime environment, this termination is done by 
  23328. _CRT_term.) 
  23329.  
  23330. If your DLL contains C++ code, you must also call __ctordtorTerm before you 
  23331. call _rmem_term to ensure that static constructors and destructors are 
  23332. terminated correctly. __ctordtorTerm is defined in the runtime startup code as: 
  23333.  
  23334.    void __ctordtorTerm(void);
  23335.  
  23336. Once you have called _rmem_term, you cannot call any other library functions. 
  23337.  
  23338. If your DLL is dynamically linked, you cannot call library functions in the 
  23339. termination section of your _DLL_InitTerm function. 
  23340.  
  23341. Return Value 
  23342. _rmem_term returns 0 if the memory functions were successfully terminated. A 
  23343. return value of -1 indicates an error. 
  23344.  
  23345.  
  23346. ΓòÉΓòÉΓòÉ <hidden> Example of _rmem_term ΓòÉΓòÉΓòÉ
  23347.  
  23348. /************************************************************************
  23349.  
  23350. This example shows the _DLL_InitTerm function from the VisualAge for C++ sample 
  23351. program for building subsystem DLLs, which calls _rmem_term to terminate the 
  23352. library memory functions. 
  23353.  
  23354. ************************************************************************/
  23355.  
  23356. #pragma strings(readonly)
  23357. /******************************************************************************/
  23358. /* _DLL_InitTerm - Initialization/Termination function for the DLL that is    */
  23359. /*                 invoked by the loader.  When the /Ge- compile option is    */
  23360. /*                 used the linker is told that this is the function to       */
  23361. /*                 execute when the DLL is first loaded and last freed for    */
  23362. /*                 each process.                                              */
  23363. /*                                                                            */
  23364. /* DLLREGISTER  - Called by _DLL_InitTerm for each process that loads the     */
  23365. /*                DLL.                                                        */
  23366. /*                                                                            */
  23367. /* DLLDEREGISTER- Called by _DLL_InitTerm for each process that frees the     */
  23368. /*                DLL.                                                        */
  23369. /*                                                                            */
  23370. /******************************************************************************/
  23371.  
  23372. #include <windows.h>
  23373. #include <stdlib.h>
  23374. #include <stdio.h>
  23375. #include <string.h>
  23376.  
  23377. #pragma linkage ( PLUS, system )
  23378. int PLUS( int a, int b ) {
  23379.   return a + b ;
  23380. }
  23381.  
  23382. unsigned long _System _DLL_InitTerm ( unsigned long hModule, unsigned long ulFlag );
  23383.  
  23384. static unsigned long DLLREGISTER ( void );
  23385. static unsigned long DLLDEREGISTER( void );
  23386.  
  23387. #define SHARED_SEMAPHORE_NAME "SAMPLE05.DLL.LOCK"
  23388.  
  23389. /* The following data will be per-process data.  It will not be shared among  */
  23390. /* different processes.                                                       */
  23391.  
  23392. static HANDLE hSharedSem;               /* Shared semaphore                   */
  23393. static ULONG  ulProcessTotal;           /* Total of increments for a process  */
  23394. static DWORD  dwProcess;               /* Process identifier                  */
  23395.  
  23396. /* This is the global segment that is shared by every process                 */
  23397.  
  23398. #pragma data_seg( GLOBAL_SEG )
  23399.  
  23400. static ULONG ulProcessCount;           /* total number of processes           */
  23401.  
  23402. /* _DLL_InitTerm() - called by the loader for DLL initialization/termination  */
  23403. /* This function must return a non-zero value if successful and a zero value  */
  23404. /* if unsuccessful.                                                           */
  23405.  
  23406. unsigned long _DLL_InitTerm ( unsigned long hModule, unsigned long ulFlag ) {
  23407.  
  23408.    /* If ulFlag is zero then initialization is required:                      */
  23409.    /*    If the shared memory pointer is NULL then the DLL is being loaded    */
  23410.    /*    for the first time so acquire the named shared storage for the       */
  23411.    /*    process control structures.  A linked list of process control        */
  23412.    /*    structures will be maintained.  Each time a new process loads this   */
  23413.    /*    DLL, a new process control structure is created and it is inserted   */
  23414.    /*    at the end of the list by calling DLLREGISTER.                       */
  23415.    /*                                                                         */
  23416.    /* If ulFlag is 1 then termination is required:                            */
  23417.    /*    Call DLLDEREGISTER which will remove the process  control structure  */
  23418.    /*    and free the shared memory block from its virtual address space.     */
  23419.  
  23420.   switch ( ulFlag ) {
  23421.  
  23422.      case 0:
  23423.            if ( !ulProcessCount ) {
  23424.              _rmem_init();
  23425.              /* Create the shared mutex semaphore                             */
  23426.              if ( !CreateMutex( NULL, FALSE, SHARED_SEMAPHORE_NAME )) {
  23427.                 printf("CreateMutex rc = %d\n", GetLastError());
  23428.                 return 0;
  23429.             }
  23430.            }
  23431.  
  23432.            /* Register the current process                                    */
  23433.            if ( DLLREGISTER() )
  23434.              return 0;
  23435.            break;
  23436.  
  23437.     case 1:
  23438.            /* Deregister the current process                                  */
  23439.            if ( DLLDEREGISTER() )
  23440.              return 0;
  23441.  
  23442.            _rmem_term();
  23443.            break;
  23444.  
  23445.  
  23446.     default:
  23447.            return 0;
  23448.  
  23449.   }
  23450.  
  23451.   /* Indicate success.  Non-zero means success!!!                             */
  23452.  
  23453.   return 1;
  23454.  
  23455. }
  23456.  
  23457. /* DLLREGISTER - Registers the current process so that it can use this        */
  23458. /*               subsystem.  Called by _DLL_InitTerm when the DLL is first    */
  23459. /*               loaded for the current process.                              */
  23460.  
  23461. static unsigned long DLLREGISTER( void ) {
  23462.  
  23463.   DWORD pid;
  23464.   DWORD rc;
  23465.  
  23466.   pid = GetCurrentProcessId();
  23467.  
  23468.   /* Open the shared mutex semaphore for this process.                        */
  23469.   if ( ! (hSharedSem = OpenMutex ( MUTEX_ALL_ACCESS | SYNCHRONIZE,  FALSE,
  23470.                                   SHARED_SEMAPHORE_NAME )) ) {
  23471.      rc = GetLastError();
  23472.      printf("OpenMutex rc = %d\n",  rc);
  23473.      return rc;
  23474.   }
  23475.  
  23476.   /*Acquire the shared mutex semaphore.                                       */
  23477.   if ( WaitForSingleObject(hSharedSem, INFINITE) != WAIT_OBJECT_0) {
  23478.      rc = GetLastError();
  23479.      printf("WaitForSingleObject rc = %d\n", rc);
  23480.      return rc;
  23481.   }
  23482.  
  23483.   /* Increment the count of processes registered.                             */
  23484.   ++ulProcessCount;
  23485.  
  23486.   /* Initialize the per-process data.                                         */
  23487.   ulProcessTotal = 0;
  23488.   dwProcess = pid;
  23489.  
  23490.   /* Release the shared mutex semaphore.                                      */
  23491.   if ( ! ReleaseMutex( hSharedSem ) ) {
  23492.      rc = GetLastError();
  23493.      printf("ReleaseMutex rc = %d\n", rc);
  23494.      return rc;
  23495.   }
  23496.  
  23497.   return 0;
  23498.  
  23499. }
  23500.  
  23501. /* DLLDEREGISTER - Deregisters the current process from this subsystem.       */
  23502. /*                 Called by _DLL_InitTerm when the DLL is freed for the      */
  23503. /*                 last time by the current process.                          */
  23504.  
  23505. static unsigned long DLLDEREGISTER( void ) {
  23506.  
  23507.   DWORD rc;
  23508.  
  23509.   /* Acquire the shared mutex semaphore.                                      */
  23510.   if ( WaitForSingleObject(hSharedSem, INFINITE) != WAIT_OBJECT_0) {
  23511.      rc = GetLastError();
  23512.      printf("WaitForSingleObject rc = %d\n", rc);
  23513.      return rc;
  23514.   }
  23515.  
  23516.   /* Decrement the count of processes registered.                             */
  23517.   --ulProcessCount;
  23518.  
  23519.   /* Tell the user that the current process has been deregistered.            */
  23520.   printf( "\nProcess %d has been deregistered.\n\n", dwProcess);
  23521.  
  23522.   /* Release the shared mutex semaphore.                                      */
  23523.   if ( ! ReleaseMutex( hSharedSem ) ) {
  23524.      rc = GetLastError();
  23525.      printf("ReleaseMutex rc = %d\n", rc);
  23526.      return rc;
  23527.   }
  23528.  
  23529.   /* Close the shared mutex semaphore for this process.                       */
  23530.   if ( ! CloseHandle ( hSharedSem ) ) {
  23531.      rc = GetLastError();
  23532.      printf("CloseHandle rc = %d\n", rc);
  23533.      return rc;
  23534.   }
  23535.  
  23536.  return 0;
  23537.  
  23538. }
  23539.  
  23540.  
  23541. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23542.  
  23543. Example of _rmem_term 
  23544.  
  23545.      Building Subsystem DLLs in the Programming Guide 
  23546.      _CRT_init - Initialize DLL Runtime Environment 
  23547.      _CRT_term - Terminate DLL Runtime Environment 
  23548.      _DLL_InitTerm - Initialize and Terminate DLL Environment 
  23549.      _rmem_init - Initialize Memory Functions for Subsystem DLL 
  23550.  
  23551.  
  23552. ΓòÉΓòÉΓòÉ 4.231. _rmtmp - Remove Temporary Files ΓòÉΓòÉΓòÉ
  23553.  
  23554.  
  23555. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23556.  
  23557. #include <stdio.h>
  23558. int _rmtmp(void);
  23559.  
  23560.  
  23561. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23562.  
  23563. Language Level:  Extension 
  23564.  
  23565. _rmtmp closes and removes all temporary files opened from the run-time 
  23566. environment from where the call to _rmtmp has been made. 
  23567.  
  23568. Return Value 
  23569. _rmtmp returns the number of temporary files deleted. 
  23570.  
  23571.  
  23572. ΓòÉΓòÉΓòÉ <hidden> Example of _rmtmp ΓòÉΓòÉΓòÉ
  23573.  
  23574. /************************************************************************
  23575.  
  23576. This example uses _rmtmp to remove a temporary file. 
  23577.  
  23578. ************************************************************************/
  23579.  
  23580. #include <stdio.h>
  23581.  
  23582. int main(void)
  23583. {
  23584.    int num;
  23585.    FILE *stream;
  23586.  
  23587.    if (NULL == (stream = tmpfile()))
  23588.       printf("Could not open new temporary file\n");
  23589.    else {
  23590.       num = _rmtmp();
  23591.       printf("Number of temporary files removed = %d\n", num);
  23592.    }
  23593.    return 0;
  23594.  
  23595.    /****************************************************************************
  23596.       The output should be:
  23597.  
  23598.       Number of temporary files removed = 1
  23599.    ****************************************************************************/
  23600. }
  23601.  
  23602.  
  23603. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23604.  
  23605. Example of _rmtmp 
  23606.  
  23607.      _flushall - Write Buffers to Files 
  23608.      remove - Delete File 
  23609.      tmpfile - Create Temporary File 
  23610.      tmpnam - Produce Temporary File Name 
  23611.      unlink - Delete File 
  23612.      <stdio.h> 
  23613.  
  23614.  
  23615. ΓòÉΓòÉΓòÉ 4.232. _rotl - _rotr - Rotate Bits of Unsigned Integer ΓòÉΓòÉΓòÉ
  23616.  
  23617.  
  23618. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23619.  
  23620. #include <stdlib.h>   /* also in <builtin.h> */
  23621. unsigned int _rotl(unsigned int value, int shift);
  23622. unsigned int _rotr(unsigned int value, int shift);
  23623.  
  23624.  
  23625. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23626.  
  23627. Language Level:  Extension 
  23628.  
  23629. These functions take a 4-byte integer value and rotate it by shift bits. _rotl 
  23630. rotates to the left, and _rotr to the right. 
  23631.  
  23632. Note:  Both _rotl and _rotr are built-in functions, which means they are 
  23633.        implemented as inline instructions and have no backing code in the 
  23634.        library. For this reason: 
  23635.  
  23636.      You cannot take the address of these functions. 
  23637.      You cannot parenthesize a call to either function. (Parentheses specify a 
  23638.       call to the backing code for the function in the runtime library.) 
  23639.  
  23640.  Portability Consideration  Because the size of an int is only 2 bytes in 
  23641.  16-bit compilers, if you are migrating 16-bit programs, some parts of your 
  23642.  programs may have to be rewritten if they use this function. 
  23643.  
  23644.  Return Value 
  23645.  Both functions return the rotated value.  There is no error return. 
  23646.  
  23647.  
  23648. ΓòÉΓòÉΓòÉ <hidden> Example of _rotl - _rotr ΓòÉΓòÉΓòÉ
  23649.  
  23650. /************************************************************************
  23651.  
  23652. This example uses _rotr and _rotl with different shift values to rotate the 
  23653. integer value 0x01234567: 
  23654.  
  23655. ************************************************************************/
  23656.  
  23657. #include <stdio.h>
  23658. #include <stdlib.h>
  23659.  
  23660. int main(void)
  23661. {
  23662.    unsigned int val = 0X01234567;
  23663.  
  23664.    printf("The value of 0x%8.8lx rotated 4 bits to the left is 0x%8.8lx\n", val,
  23665.       _rotl(val, 4));
  23666.    printf("The value of 0x%8.8lx rotated 16 bits to the right is 0x%8.8lx\n",
  23667.       val, _rotr(val, 16));
  23668.    return 0;
  23669.  
  23670.    /****************************************************************************
  23671.       The output should be:
  23672.  
  23673.       The value of 0x01234567 rotated 4 bits to the left is 0x12345670
  23674.       The value of 0x01234567 rotated 16 bits to the right is 0x45670123
  23675.    ****************************************************************************/
  23676. }
  23677.  
  23678.  
  23679. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23680.  
  23681. Example of _rotl - _rotr 
  23682.  
  23683.      _crotl - _crotr - Rotate Bits of Character Value 
  23684.      _lrotl - _lrotr - Rotate Bits of Unsigned Long Value 
  23685.      _llrotl - _llrotr - Rotate Bits of Unsigned Long Long Integer 
  23686.      _srotl - _srotr - Rotate Bits of Unsigned Short Value 
  23687.      swab - Swap Adjacent Bytes 
  23688.      <builtin.h> 
  23689.      <stdlib.h> 
  23690.  
  23691.  
  23692. ΓòÉΓòÉΓòÉ 4.233. rpmatch - Test for Yes/No Response Match ΓòÉΓòÉΓòÉ
  23693.  
  23694.  
  23695. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23696.  
  23697. #include <stdlib.h>
  23698. int rpmatch(const char *response);
  23699.  
  23700.  
  23701. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23702.  
  23703. Language Level:  POSIX, Extension 
  23704.  
  23705. rpmatch tests whether the string pointed to by response matches either the 
  23706. affirmative or the negative response set by LC_MESSAGES category in the current 
  23707. locale. 
  23708.  
  23709. Return Value 
  23710. rpmatch returns: 
  23711.  
  23712.  1    If the response string matches the affirmative expression. 
  23713.  0    If the response string matches the negative expression. 
  23714.  -1   If the response string does not match either the affirmative or the 
  23715.       negative expression. 
  23716.  
  23717.  
  23718. ΓòÉΓòÉΓòÉ <hidden> Example of rpmatch ΓòÉΓòÉΓòÉ
  23719.  
  23720. /************************************************************************
  23721.  
  23722. This example asks for a reply, and checks the response. 
  23723.  
  23724. ************************************************************************/
  23725.  
  23726. #include <stdlib.h>
  23727. #include <stdio.h>
  23728.  
  23729. int main(void)
  23730. {
  23731.    char  *response;
  23732.    char  buffer[100];
  23733.    int   rc;
  23734.  
  23735.    printf("Enter reply:\n");
  23736.    response = fgets(buffer, 100, stdin);
  23737.    rc = rpmatch(response);
  23738.    if (rc > 0)
  23739.       printf("Response was affirmative\n");
  23740.    else if (rc == 0)
  23741.            printf("Response was negative\n");
  23742.         else
  23743.            printf("Response was neither negative or affirmative\n");
  23744.    return 0;
  23745.  
  23746.    /****************************************************************************
  23747.       Assuming you enter : No
  23748.  
  23749.       The output should be :
  23750.  
  23751.       Response was negative
  23752.    ****************************************************************************/
  23753. }
  23754.  
  23755.  
  23756. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23757.  
  23758. Example of rpmatch 
  23759.  
  23760.      setlocale - Set Locale 
  23761.      <stdlib.h> 
  23762.  
  23763.  
  23764. ΓòÉΓòÉΓòÉ 4.234. scanf - Read Data ΓòÉΓòÉΓòÉ
  23765.  
  23766.  
  23767. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23768.  
  23769. #include <stdio.h>
  23770. int scanf(const char *format-string, argument-list);
  23771.  
  23772.  
  23773. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23774.  
  23775. Language Level: ANSI, ANSI 93, SAA, POSIX, XPG4, Extension 
  23776.  
  23777. scanf reads data from the standard input stream stdin into the locations given 
  23778. by each entry in argument-list.  Each argument must be a pointer to a variable 
  23779. with a type that corresponds to a type specifier in format-string. The 
  23780. format-string controls the interpretation of the input fields. 
  23781.  
  23782. The format-string can contain one or more of the following: 
  23783.  
  23784.      White-space characters, as specified by isspace (such as blanks and 
  23785.       new-line characters). A white-space character causes scanf to read, but 
  23786.       not to store, all consecutive white-space characters in the input up to 
  23787.       the next character that is not white space.  One white-space character in 
  23788.       format-string matches any combination of white-space characters in the 
  23789.       input. 
  23790.  
  23791.      Characters that are not white space, except for the percent sign 
  23792.       character (%).  A non-white-space character causes scanf to read, but not 
  23793.       to store, a matching non-white-space character.  If the next character in 
  23794.       stdin does not match, scanf ends. 
  23795.  
  23796.      Format specifications, introduced by the percent sign (%).  A format 
  23797.       specification causes scanf to read and convert characters in the input 
  23798.       into values of a specified type.  The value is assigned to an argument in 
  23799.       the argument list. 
  23800.  
  23801.  scanf reads format-string from left to right.  Characters outside of format 
  23802.  specifications are expected to match the sequence of characters in stdin;  the 
  23803.  matched characters in stdin are scanned but not stored.  If a character in 
  23804.  stdin conflicts with format-string, scanf ends.  The conflicting character is 
  23805.  left in stdin as if it had not been read. 
  23806.  
  23807.  When the first format specification is found, the value of the first input 
  23808.  field is converted according to the format specification and stored in the 
  23809.  location specified by the first entry in argument-list.  The second format 
  23810.  specification converts the second input field and stores it in the second 
  23811.  entry in argument-list, and so on through the end of format-string. 
  23812.  
  23813.  An input field is defined as all characters up to the first white-space 
  23814.  character (space, tab, or new line), up to the first character that cannot be 
  23815.  converted according to the format specification, or until the field width is 
  23816.  reached, whichever comes first.  If there are too many arguments for the 
  23817.  format specifications, the extra arguments are ignored.  The results are 
  23818.  undefined if there are not enough arguments for the format specifications. 
  23819.  
  23820.  A format specification has the following form: 
  23821.  
  23822.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  23823.   Γöé                                        Γöé
  23824.   Γöé >>ΓöÇΓöÇ%ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇtypeΓöÇΓöÇ><                   Γöé
  23825.   Γöé     ΓööΓöÇ*ΓöÇΓöÿ  ΓööΓöÇwidthΓöÇΓöÿ  Γö£ΓöÇhΓöÇΓöÇΓöñ                        Γöé
  23826.   Γöé              Γö£ΓöÇlΓöÇΓöÇΓöñ                        Γöé
  23827.   Γöé              Γö£ΓöÇLΓöÇΓöÇΓöñ                        Γöé
  23828.   Γöé              ΓööΓöÇllΓöÇΓöÿ                        Γöé
  23829.   Γöé                                        Γöé
  23830.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  23831.  
  23832.  Each field of the format specification is a single character or a number 
  23833.  signifying a particular format option.  The type character, which appears 
  23834.  after the last optional format field, determines whether the input field is 
  23835.  interpreted as a character, a string, or a number.  The simplest format 
  23836.  specification contains only the percent sign and a type character (for 
  23837.  example, %s). 
  23838.  
  23839.  The fields of the format specification are discussed in scanf Format 
  23840.  Specification Fields and scanf Format Specification - Types. If a percent sign 
  23841.  (%) is followed by a character that has no meaning as a format control 
  23842.  character, that character and following characters up to the next percent sign 
  23843.  are treated as an ordinary sequence of characters;  that is, a sequence of 
  23844.  characters that must match the input.  For example, to specify a percent-sign 
  23845.  character, use %%. 
  23846.  
  23847.  scanf scans each input field character by character.  It might stop reading a 
  23848.  particular input field either before it reaches a space character, when the 
  23849.  specified width is reached, or when the next character cannot be converted as 
  23850.  specified.  When a conflict occurs between the specification and the input 
  23851.  character, the next input field begins at the first unread character.  The 
  23852.  conflicting character, if there was one, is considered unread and is the first 
  23853.  character of the next input field or the first character in subsequent read 
  23854.  operations on stdin. 
  23855.  
  23856.  In extended mode, scanf also reads in the strings the strings "INFINITY", 
  23857.  "INF", and "NAN" (in upper or lowercase) and converts them to the 
  23858.  corresponding floating-point value.  The sign of the value is determined by 
  23859.  the format specification. See Infinity and NaN Support for more information on 
  23860.  infinity and NaN values. 
  23861.  
  23862.  Return Value 
  23863.  scanf returns the number of fields that were successfully converted and 
  23864.  assigned. The return value does not include fields that were read but not 
  23865.  assigned. 
  23866.  
  23867.  The return value is EOF for an attempt to read at end-of-file if no conversion 
  23868.  was performed. A return value of 0 means that no fields were assigned. 
  23869.  
  23870.  
  23871. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23872.  
  23873. scanf Example 1 
  23874.  
  23875. scanf Example 2 
  23876.  
  23877.      scanf Format Specification Fields 
  23878.      scanf Format Specification - Types 
  23879.      fscanf - Read Formatted Data 
  23880.      printf - Print Formatted Characters 
  23881.      sscanf - Read Data 
  23882.      Infinity and NaN Support 
  23883.      <stdio.h> 
  23884.  
  23885.  
  23886. ΓòÉΓòÉΓòÉ 4.234.1. scanf Format Specification Fields ΓòÉΓòÉΓòÉ
  23887.  
  23888. The scanf format specification fields are described below. The type field is 
  23889. described in scan Format Specification - Types. 
  23890.  
  23891.  * 
  23892.     An asterisk (*) following the percent sign suppresses assignment of the 
  23893.     next input field, which is interpreted as a field of the specified type. 
  23894.     The field is scanned but not stored. 
  23895.  
  23896.  width 
  23897.     The width is a positive decimal integer controlling the maximum number of 
  23898.     characters to be read from stdin.  No more than width characters are 
  23899.     converted and stored at the corresponding argument.  Fewer than width 
  23900.     characters are read if a white-space character (space, tab, or new line), 
  23901.     or a character that cannot be converted according to the given format 
  23902.     occurs before width is reached. 
  23903.  
  23904.  h, l, L 
  23905.     The optional prefix ll shows that you use the long long version of the 
  23906.     following type, while the prefix h indicates that the short version is to 
  23907.     be used. The optional prefix l, and the optional prefix L, shows that you 
  23908.     use the long version of the following type. The corresponding argument 
  23909.     should point to a long longobject (for the ll character0, to a long or 
  23910.     double object (for the l character), a long double object (for the L 
  23911.     character), or a short object (with the h character).  The l, ll, and h 
  23912.     modifiers can be used with the d, i, o, x, and u type characters. The l 
  23913.     modifier can also be used with the e, f, and g type characters.  The L 
  23914.     modifier can be used with the e, f and g type characters. The l and h 
  23915.     modifiers are ignored if specified for any other type. Note that the l 
  23916.     modifier is also used with the c and s characters to indicate a multibyte 
  23917.     character or string. 
  23918.  
  23919.  
  23920. ΓòÉΓòÉΓòÉ 4.234.2. scan Format Specification - Types ΓòÉΓòÉΓòÉ
  23921.  
  23922. The type characters and their meanings are in the following table: 
  23923.  
  23924. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  23925. Γöé CHAR- Γöé TYPE OF INPUT EXPECTED       Γöé TYPE OF ARGUMENT         Γöé
  23926. Γöé ACTER Γöé                  Γöé                  Γöé
  23927. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23928. Γöé "d"  Γöé Decimal integer          Γöé Pointer to INT          Γöé
  23929. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23930. Γöé "o"  Γöé Octal integer           Γöé Pointer to UNSIGNED INT      Γöé
  23931. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23932. Γöé "x",  Γöé Hexadecimal integer        Γöé Pointer to UNSIGNED INT      Γöé
  23933. Γöé "X"  Γöé                  Γöé                  Γöé
  23934. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23935. Γöé "i"  Γöé Decimal, hexadecimal, or octal   Γöé Pointer to INT          Γöé
  23936. Γöé    Γöé integer              Γöé                  Γöé
  23937. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23938. Γöé "u"  Γöé Unsigned decimal integer      Γöé Pointer to UNSIGNED INT      Γöé
  23939. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23940. Γöé "e,  Γöé Floating-point value consisting  Γöé Pointer to FLOAT         Γöé
  23941. Γöé f, g" Γöé of an optional sign (+ or -);  a  Γöé                  Γöé
  23942. Γöé    Γöé series of one or more decimal   Γöé                  Γöé
  23943. Γöé "E,  Γöé digits possibly containing a    Γöé                  Γöé
  23944. Γöé G"   Γöé decimal point;  and an optional  Γöé                  Γöé
  23945. Γöé    Γöé exponent (e or E) followed by a  Γöé                  Γöé
  23946. Γöé    Γöé possibly signed integer value.   Γöé                  Γöé
  23947. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23948. Γöé "c"  Γöé Character;  white-space charac-  Γöé Pointer to CHAR large enough for Γöé
  23949. Γöé    Γöé ters that are ordinarily skipped  Γöé input field            Γöé
  23950. Γöé    Γöé are read when "c" is specified   Γöé                  Γöé
  23951. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23952. Γöé "lc"  Γöé Multibyte characters.  The multi- Γöé Pointer to WCHAR_T large enough  Γöé
  23953. Γöé    Γöé byte characters are converted to  Γöé for input field          Γöé
  23954. Γöé    Γöé wide characters as if by a call  Γöé                  Γöé
  23955. Γöé    Γöé to mbrtowc.  The field width    Γöé                  Γöé
  23956. Γöé    Γöé specifies the number of wide    Γöé                  Γöé
  23957. Γöé    Γöé characters matched; if no width  Γöé                  Γöé
  23958. Γöé    Γöé is specified, one character is   Γöé                  Γöé
  23959. Γöé    Γöé matched.              Γöé                  Γöé
  23960. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23961. Γöé "s"  Γöé String               Γöé Pointer to character array large Γöé
  23962. Γöé    Γöé                  Γöé enough for input field plus a   Γöé
  23963. Γöé    Γöé                  Γöé terminating null character    Γöé
  23964. Γöé    Γöé                  Γöé ("\0"), which is automatically  Γöé
  23965. Γöé    Γöé                  Γöé appended             Γöé
  23966. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23967. Γöé "ls"  Γöé Multibyte string.  None of the   Γöé Pointer to WCHAR_T array large  Γöé
  23968. Γöé    Γöé characters can be single-byte   Γöé enough for the input field and  Γöé
  23969. Γöé    Γöé white-space characters (as speci- Γöé the terminating null wide char-  Γöé
  23970. Γöé    Γöé fied by the isspace function).   Γöé acter ("L\0"), which is added   Γöé
  23971. Γöé    Γöé Each multibyte character in the  Γöé automatically.          Γöé
  23972. Γöé    Γöé sequence is converted to a wide  Γöé                  Γöé
  23973. Γöé    Γöé character as if by a call to    Γöé                  Γöé
  23974. Γöé    Γöé mbrtowc.              Γöé                  Γöé
  23975. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23976. Γöé "n"  Γöé No input read from stream or    Γöé Pointer to INT, into which is   Γöé
  23977. Γöé    Γöé buffer               Γöé stored the number of characters  Γöé
  23978. Γöé    Γöé                  Γöé successfully read from the    Γöé
  23979. Γöé    Γöé                  Γöé stream or buffer up to that    Γöé
  23980. Γöé    Γöé                  Γöé point in the call to scanf    Γöé
  23981. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23982. Γöé "p"  Γöé Pointer to "void" converted to   Γöé Pointer to "void"         Γöé
  23983. Γöé    Γöé series of characters        Γöé                  Γöé
  23984. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  23985.  
  23986. To read strings not delimited by space characters, substitute a set of 
  23987. characters in brackets ([ ]) for the s (string) type character.  The 
  23988. corresponding input field is read up to the first character that does not 
  23989. appear in the bracketed character set.  If the first character in the set is a 
  23990. caret (^), the effect is reversed:  the input field is read up to the first 
  23991. character that does appear in the rest of the character set. 
  23992.  
  23993. To store a string without storing an ending null character (\0), use the 
  23994. specification %ac, where a is a decimal integer.  In this instance, the c type 
  23995. character means that the argument is a pointer to a character array.  The next 
  23996. a characters are read from the input stream into the specified location, and no 
  23997. null character is added. 
  23998.  
  23999. The input for a %x format specifier is interpreted as a hexadecimal number. 
  24000.  
  24001.  
  24002. ΓòÉΓòÉΓòÉ <hidden> scanf Example 1 ΓòÉΓòÉΓòÉ
  24003.  
  24004. /************************************************************************
  24005.  
  24006. This example scans various types of data. 
  24007.  
  24008. ************************************************************************/
  24009.  
  24010. #include <stdio.h>
  24011.  
  24012. int main(void)
  24013. {
  24014.    int i;
  24015.    float fp;
  24016.    char c,s[81];
  24017.  
  24018.    printf("Enter an integer, a real number, a character and a string : \n");
  24019.    if (scanf("%d %f %c %s", &i, &fp, &c, s) != 4)
  24020.       printf("Not all of the fields were assigned\n");
  24021.    else {
  24022.       printf("integer = %d\n", i);
  24023.       printf("real number = %f\n", fp);
  24024.       printf("character = %c\n", c);
  24025.       printf("string = %s\n", s);
  24026.    }
  24027.    return 0;
  24028.  
  24029.    /****************************************************************************
  24030.       The output should be similar to:
  24031.  
  24032.       Enter an integer, a real number, a character and a string :
  24033.       12 2.5 a yes
  24034.       integer = 12
  24035.       real number = 2.500000
  24036.       character = a
  24037.       string = yes
  24038.    ****************************************************************************/
  24039. }
  24040.  
  24041.  
  24042. ΓòÉΓòÉΓòÉ <hidden> scanf Example 2 ΓòÉΓòÉΓòÉ
  24043.  
  24044. /************************************************************************
  24045. This example converts a hexadecimal integer to a decimal integer.  The while 
  24046. loop ends if the input value is not a hexadecimal integer. 
  24047.  
  24048. ************************************************************************/
  24049.  
  24050. #include <stdio.h>
  24051.  
  24052. int main(void)
  24053. {
  24054.    int number;
  24055.  
  24056.    printf("Enter a hexadecimal number or anything else to quit:\n");
  24057.    while (scanf("%x", &number)) {
  24058.       printf("Hexadecimal Number = %x\n", number);
  24059.       printf("Decimal Number     = %d\n", number);
  24060.    }
  24061.    return 0;
  24062.  
  24063.    /****************************************************************************
  24064.       The output should be similar to:
  24065.  
  24066.       Enter a hexadecimal number or anything else to quit:
  24067.       0x231
  24068.       Hexadecimal Number = 231
  24069.       Decimal Number     = 561
  24070.       0xf5e
  24071.       Hexadecimal Number = f5e
  24072.       Decimal Number     = 3934
  24073.       0x1
  24074.       Hexadecimal Number = 1
  24075.       Decimal Number     = 1
  24076.       q
  24077.    ****************************************************************************/
  24078. }
  24079.  
  24080.  
  24081. ΓòÉΓòÉΓòÉ 4.235. _searchenv - Search for File ΓòÉΓòÉΓòÉ
  24082.  
  24083.  
  24084. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24085.  
  24086. #include <stdlib.h>
  24087. void _searchenv(char *name, char *env_var, char *path);
  24088.  
  24089.  
  24090. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24091.  
  24092. Language Level:  Extension 
  24093.  
  24094. _searchenv searches for the target file in the specified domain.  The env_var 
  24095. variable can be any environment variable that specifies a list of directory 
  24096. paths, such as PATH, LIB, INCLUDE, or other user-defined variables.  Most 
  24097. often, it is PATH, causing a search for name in all directories specified in 
  24098. the PATH variable. 
  24099.  
  24100. The routine first searches for the file in the current working directory.  If 
  24101. it does not find the file, it next looks through the directories specified by 
  24102. the environment variable. 
  24103.  
  24104. If the target file is found in one of the directories, the fully-qualified file 
  24105. name is copied into the buffer that path points to. You must ensure sufficient 
  24106. space for the constructed file name. If the target file is not found, path 
  24107. contains an empty null-terminated string. 
  24108.  
  24109. Return Value 
  24110. There is no return value. 
  24111.  
  24112.  
  24113. ΓòÉΓòÉΓòÉ <hidden> Example of _searchenv ΓòÉΓòÉΓòÉ
  24114.  
  24115. /************************************************************************
  24116.  
  24117. This example searches for the files _searche.c and icc.exe. 
  24118.  
  24119. ************************************************************************/
  24120.  
  24121. #include <stdio.h>
  24122. #include <stdlib.h>
  24123.  
  24124. int main(void)
  24125. {
  24126.    char path_buffer[_MAX_PATH];
  24127.  
  24128.    _searchenv("icc.exe", "PATH", path_buffer);
  24129.    printf("path: %s\n", path_buffer);
  24130.    _searchenv("_searche.c", "DPATH", path_buffer);
  24131.    printf("path: %s\n", path_buffer);
  24132.    return 0;
  24133.  
  24134.    /****************************************************************************
  24135.       The output should be similar to:
  24136.  
  24137.       path: C:\ibmcpp\bin\icc.exe
  24138.       path: C:\src\_searche.c
  24139.    ****************************************************************************/
  24140. }
  24141.  
  24142.  
  24143. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24144.  
  24145. Example of _searchenv 
  24146.  
  24147.      getenv - Search for Environment Variables 
  24148.      putenv - Modify Environment Variables 
  24149.      <stdlib.h> 
  24150.  
  24151.  
  24152. ΓòÉΓòÉΓòÉ 4.236. setbuf - Control Buffering ΓòÉΓòÉΓòÉ
  24153.  
  24154.  
  24155. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24156.  
  24157. #include <stdio.h>
  24158. void setbuf(FILE *stream, char *buffer);
  24159.  
  24160.  
  24161. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24162.  
  24163. Language Level: ANSI, SAA, POSIX, XPG4 
  24164.  
  24165. setbuf controls buffering for the specified stream. The stream pointer must 
  24166. refer to an open file before any I/O or repositioning has been done. 
  24167.  
  24168. If the buffer argument is NULL, the stream is unbuffered. If not, the buffer 
  24169. must point to a character array of length BUFSIZ, which is the buffer size 
  24170. defined in the <stdio.h> include file. The system uses the buffer, which you 
  24171. specify, for input/output buffering instead of the default system-allocated 
  24172. buffer for the given stream. 
  24173.  
  24174. setbuf is similar to setvbuf, however setvbuf is more flexible and may 
  24175. supercede setbuf in the future. 
  24176.  
  24177. Note:  Under VisualAge for C++, streams are fully buffered by default, with the 
  24178. exceptions of stderr, which is line-buffered, and memory files, which are 
  24179. unbuffered. 
  24180.  
  24181. Return Value 
  24182. There is no return value. 
  24183.  
  24184.  
  24185. ΓòÉΓòÉΓòÉ <hidden> Example of setbuf ΓòÉΓòÉΓòÉ
  24186.  
  24187. /************************************************************************
  24188.  
  24189. This example opens the file setbuf.dat for writing. It then calls setbuf to 
  24190. establish a buffer of length BUFSIZ. When string is written to the stream, the 
  24191. buffer buf is used and contains the string before it is flushed to the file. 
  24192.  
  24193. ************************************************************************/
  24194.  
  24195. #include <stdio.h>
  24196. #include <string.h>
  24197.  
  24198. #define FILENAME  "setbuf.dat"
  24199.  
  24200. int main(void)
  24201. {
  24202.    char buf[BUFSIZ];
  24203.    char string[] = "hello world";
  24204.    FILE *stream;
  24205.  
  24206.    memset(buf, '\0', BUFSIZ);           /* initialize buf to null characters  */
  24207.    stream = fopen(FILENAME, "wb");
  24208.    setbuf(stream, buf);                                   /* set up buffer    */
  24209.    fwrite(string, sizeof(string), 1, stream);
  24210.    printf("%s\n", buf);                   /* string is found in buf now       */
  24211.    fclose(stream);                  /* buffer is flushed out to output stream */
  24212.    return 0;
  24213.  
  24214.    /****************************************************************************
  24215.       The output file should contain:
  24216.  
  24217.       hello world
  24218.  
  24219.       The output should be:
  24220.  
  24221.       hello world
  24222.    ****************************************************************************/
  24223. }
  24224.  
  24225.  
  24226. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24227.  
  24228. Example of setbuf 
  24229.  
  24230.      fclose - Close Stream 
  24231.      fflush - Write Buffer to File 
  24232.      _flushall - Write Buffers to Files 
  24233.      fopen - Open Files 
  24234.      setvbuf - Control Buffering 
  24235.      <stdio.h> 
  24236.  
  24237.  
  24238. ΓòÉΓòÉΓòÉ 4.237. _set_crt_msg_handle - Change Runtime Message Output Destination ΓòÉΓòÉΓòÉ
  24239.  
  24240.  
  24241. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24242.  
  24243. #include <stdio.h>
  24244. int _set_crt_msg_handle(int fh);
  24245.  
  24246.  
  24247. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24248.  
  24249. Language Level:  Extension 
  24250.  
  24251. _set_crt_msg_handle changes the file handle to which runtime messages are sent, 
  24252. which is usually file handle 2, to fh. Runtime messages include exception 
  24253. handling messages and output from debug memory management routines. 
  24254.  
  24255. Use _set_crt_msg_handle to trap runtime message output in applications where 
  24256. handle 2 is not defined, such as Windows graphical user interface applications. 
  24257.  
  24258. The file handle fh must be a writable file or pipe handle. Set fh only for the 
  24259. current library environment. 
  24260.  
  24261. Return Value 
  24262. _set_crt_msg_handle returns the handle to be used for runtime message output. 
  24263. If an handle that is not valid is passed as an argument, it is ignored and no 
  24264. change takes place. 
  24265.  
  24266.  
  24267. ΓòÉΓòÉΓòÉ <hidden> Example of _set_crt_msg_handle ΓòÉΓòÉΓòÉ
  24268.  
  24269. /************************************************************************
  24270.  
  24271. This example causes an exception by dereferencing a null pointer and uses 
  24272. _set_crt_msg_handle to send the exception messages to the file _scmhdl.out. 
  24273.  
  24274. ************************************************************************/
  24275.  
  24276. #include <sys\stat.h>
  24277. #include <io.h>
  24278. #include <fcntl.h>
  24279. #include <stdio.h>
  24280. #include <stdlib.h>
  24281.  
  24282. int main(void)
  24283. {
  24284.    int   fh;
  24285.    char  *p = NULL;
  24286.  
  24287.    if (-1 == (fh = open("_scmhdl.out", O_CREAT|O_TRUNC|O_RDWR,
  24288.                         S_IREAD|S_IWRITE))) {
  24289.       perror("Unable to open the file _scmhdl.out.");
  24290.       exit(EXIT_FAILURE);
  24291.    }
  24292.    /* change file handle where messages are sent */
  24293.    if (fh != _set_crt_msg_handle(fh)) {
  24294.       perror("Could not change massage output handle.");
  24295.       exit(EXIT_FAILURE);
  24296.    }
  24297.    *p = 'x';          /* cause an exception, output should be in _scmhdl.out */
  24298.    if (-1 == close(fh)) {
  24299.       perror("Unable to close _scmhdl.out.");
  24300.       exit(EXIT_FAILURE);
  24301.    }
  24302.    return 0;
  24303.  
  24304.    /****************************************************************************
  24305.       Running this program would cause an exception to occur,
  24306.       the file _scmhdl.out should contain the exception messages similar to :
  24307.  
  24308.       Exception = c0000005 occurred at EIP = 10068.
  24309.    ****************************************************************************/
  24310. }
  24311.  
  24312.  
  24313. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24314.  
  24315. Example of _set_crt_msg_handle 
  24316.  
  24317.      open - Open File 
  24318.      fileno - Determine File Handle 
  24319.      _sopen - Open Shared File 
  24320.      <stdio.h> 
  24321.  
  24322.  
  24323. ΓòÉΓòÉΓòÉ 4.238. setjmp - Preserve Environment ΓòÉΓòÉΓòÉ
  24324.  
  24325.  
  24326. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24327.  
  24328. #include <setjmp.h>
  24329. int setjmp(jmp_buf env);
  24330.  
  24331.  
  24332. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24333.  
  24334. Language Level: ANSI, SAA, POSIX, XPG4 
  24335.  
  24336. setjmp saves a stack environment that can subsequently be restored by longjmp. 
  24337. setjmp and longjmp provide a way to perform a nonlocal goto. They are often 
  24338. used in signal handlers. 
  24339.  
  24340. A call to setjmp causes it to save the current stack environment in env.  A 
  24341. subsequent call to longjmp restores the saved environment and returns control 
  24342. to a point corresponding to the setjmp call.  The values of all variables 
  24343. (except register variables) accessible to the function receiving control 
  24344. contain the values they had when longjmp was called. The values of variables 
  24345. that are allocated to registers by the compiler are unpredictable. Because any 
  24346. auto variable could be allocated to a register in optimized code, you should 
  24347. consider the values of all auto variables to be unpredictable after a longjmp 
  24348. call. 
  24349.  
  24350. C++ Considerations  When you call setjmp in a C++ program, ensure that the same 
  24351. part of the program does not also create C++ objects that need to be destroyed. 
  24352. When you call longjmp, objects existing at the time of the setjmp call will 
  24353. still exist, but any destructors called after setjmp are not called. Click here 
  24354. for an example. 
  24355.  
  24356. Return Value 
  24357. setjmp returns the value 0 after saving the stack environment. If setjmp 
  24358. returns as a result of a longjmp call, it returns the value argument of 
  24359. longjmp, or 1 if the value argument of longjmp is 0. There is no error return 
  24360. value. 
  24361.  
  24362.  
  24363. ΓòÉΓòÉΓòÉ <hidden> Example of setjmp ΓòÉΓòÉΓòÉ
  24364.  
  24365. /************************************************************************
  24366.  
  24367. This example stores the stack environment at the statement 
  24368.  
  24369.   if(setjmp(mark) != 0) ...
  24370.  
  24371. When the system first performs the if statement, it saves the environment in 
  24372. mark and sets the condition to FALSE because setjmp returns a 0 when it saves 
  24373. the environment. The program prints the message 
  24374.  
  24375.   setjmp has been called
  24376.  
  24377. The subsequent call to function p tests for a local error condition, which can 
  24378. cause it to perform the longjmp function. Then, control returns to the original 
  24379. setjmp function using the environment saved in mark. This time, the condition 
  24380. is TRUE because -1 is the return value from the longjmp function. The program 
  24381. then performs the statements in the block and prints 
  24382.  
  24383.   longjmp has been called
  24384.  
  24385. Then the program calls the recover function and exits. 
  24386.  
  24387. ************************************************************************/
  24388.  
  24389. #include <stdio.h>
  24390. #include <stdlib.h>
  24391. #include <setjmp.h>
  24392.  
  24393. jmp_buf mark;
  24394.  
  24395. void p(void)
  24396. {
  24397.    int error = 0;
  24398.  
  24399.    error = 9;
  24400.  
  24401.    if (error != 0)
  24402.       longjmp(mark, -1);
  24403. }
  24404.  
  24405. void recover(void)
  24406. {
  24407. }
  24408.  
  24409. int main(void)
  24410. {
  24411.    if (setjmp(mark) != 0) {
  24412.       printf("longjmp has been called\n");
  24413.       recover();
  24414.       return 0;
  24415.    }
  24416.    printf("setjmp has been called\n");
  24417.  
  24418.    p();
  24419.  
  24420.    return 0;
  24421.  
  24422.    /****************************************************************************
  24423.       The output should be:
  24424.  
  24425.       setjmp has been called
  24426.       longjmp has been called
  24427.    ****************************************************************************/
  24428. }
  24429.  
  24430.  
  24431. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24432.  
  24433. Example of setjmp 
  24434.  
  24435.      longjmp - Restore Stack Environment 
  24436.      goto in the Language Reference 
  24437.      <setjmp.h> 
  24438.  
  24439.  
  24440. ΓòÉΓòÉΓòÉ 4.239. setlocale - Set Locale ΓòÉΓòÉΓòÉ
  24441.  
  24442.  
  24443. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24444.  
  24445. #include <locale.h>
  24446. char *setlocale(int category, const char *locale);
  24447.  
  24448.  
  24449. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24450.  
  24451. Language Level:  ANSI, SAA, POSIX, XPG4 
  24452.  
  24453. setlocale sets or queries the specified category of the program's locale. A 
  24454. locale is the complete definition of that part of a program that depends on 
  24455. language and cultural conventions. 
  24456.  
  24457. The default VisualAge for C++ locale is the POSIX C locale definition, 
  24458. represented as "C" or "POSIX". This locale is standard for all ANSI-conforming 
  24459. and POSIX-conforming compilers. You can accept the default, or you can use 
  24460. setlocale to set the locale to one of the supplied locales listed in 
  24461. "Introduction to Locale" in the Programming Guide. Windows supports two classes 
  24462. of code pages: ANSI and OEM. If you want the locale that is bound to the ANSI 
  24463. code page, you should specify the fully qualified name that identifies the code 
  24464. page by name as shown in the following example. 
  24465.  
  24466.       "En_GB.IBM-1252" (English, Great Britain, code page 1252) 
  24467.       "Fr_CA.IBM-1252" (French, Canada, code page 1252) 
  24468.  
  24469.  If you want the locale that is bound to the OEM code page, you should specify 
  24470.  only the language country as shown in the following example. 
  24471.  
  24472.       "En_GB.IBM-850" (English, Great Britain, code page 850 or code page 437) 
  24473.       "Fr_CA.IBM-850" (French, Canada, code page 850) 
  24474.  
  24475.  You may also use the fully qualified name as shown in the following example. 
  24476.  
  24477.       "En_GB" (English, Great Britain, code page 850) 
  24478.       "Fr_CA" (French, Canada, code page 850) 
  24479.  
  24480.  The result of setlocale depends on the arguments you specify: 
  24481.  
  24482.      To set a category to a specific locale, specify both the category and 
  24483.       locale names.  For example: 
  24484.  
  24485.                setlocale(LC_CTYPE, "POSIX");
  24486.       sets the LC_CTYPE category according to the "POSIX" locale. The category 
  24487.       names and their purpose are described in Locale Categories for setlocale 
  24488.  
  24489.       If you specify a null string ("") for locale, setlocale checks 
  24490.       locale-related environment variables in the program's environment to find 
  24491.       a locale name or names to use for category.  If category is not LC_ALL, 
  24492.       setlocale gets the locale name from: 
  24493.  
  24494.         1. LC_ALL, if it is defined and not null 
  24495.         2. The environment variable with the same name as category, if it is 
  24496.            defined and not null 
  24497.         3. LANG, if it is defined and not null 
  24498.         4. If none of these variables is defined to a valid locale name, 
  24499.            setlocale uses the "C" locale. 
  24500.  
  24501.       If category is LC_ALL and locale is a null string, setlocale checks the 
  24502.       environment variables in the same order listed above.  However, it checks 
  24503.       the variable for each category and sets the category to the locale 
  24504.       specified, which could be different for each category.  (By contrast, if 
  24505.       you specified LC_ALL and a specific locale name, all categories would be 
  24506.       set to the same locale that you specify.) The string returned lists all 
  24507.       the locales for all the categories. 
  24508.  
  24509.      To query the locale for a category, specify a null pointer for locale. 
  24510.       setlocale then returns a string indicating the locale setting for that 
  24511.       category, without changing it. For example: 
  24512.  
  24513.                char *s = setlocale(LC_CTYPE, NULL);
  24514.       returns the current locale for the LC_CTYPE category. 
  24515.  
  24516.  Return Value: 
  24517.  setlocale returns a string that specifies the locale for the category.  If you 
  24518.  specified "" for locale, the string names the current locale; otherwise, it 
  24519.  indicates the new locale that the category was set to. 
  24520.  
  24521.  If you specified LC_ALL for category, the returned string can be either a 
  24522.  single locale name or, if the individual categories have different locales, a 
  24523.  list of the locale names for each category in the following order: 
  24524.  
  24525.    1. LC_COLLATE 
  24526.    2. LC_CTYPE 
  24527.    3. LC_MONETARY 
  24528.    4. LC_NUMERIC 
  24529.    5. LC_TIME 
  24530.    6. LC_TOD 
  24531.    7. LC_MESSAGES 
  24532.    8. LC_SYNTAX 
  24533.  
  24534.  The string can be used on a subsequent call to restore that part of the 
  24535.  program's locale. Because the returned string can be overwritten by subsequent 
  24536.  calls to setlocale, you should copy the string if you plan to use it later. 
  24537.  
  24538.  If an error occurs, setlocale returns NULL and does not alter the program's 
  24539.  locale.  Errors can occur if the category or locale is not valid, or if the 
  24540.  value of the environment variable for a category does not contain a valid 
  24541.  locale. 
  24542.  
  24543.  
  24544. ΓòÉΓòÉΓòÉ <hidden> Example 1 of setlocale ΓòÉΓòÉΓòÉ
  24545.  
  24546. /************************************************************************
  24547.  
  24548. This example sets the locale of the program to be "fr_fr.ibm-850" and prints 
  24549. the string that is associated with the locale. 
  24550.  
  24551. ************************************************************************/
  24552.  
  24553. #include <stdio.h>
  24554. #include <stdlib.h>
  24555. #include <locale.h>
  24556.  
  24557. #if (1 == __TOS_OS2__)
  24558.    #define LOCNAME "fr_fr.ibm-850"     /* OS/2 name        */
  24559. #else
  24560.    #define LOCNAME "fr_fr.ibm-1252"    /* Windows name     */
  24561. #endif
  24562.  
  24563. int main(void)
  24564. {
  24565.    char *string;
  24566.  
  24567.    if (NULL == (string = setlocale(LC_ALL, LOCNAME)))
  24568.       printf("Locale \"%s\" could not be loaded\n", LOCNAME);
  24569.    else
  24570.       printf("The current locale is set to %s.\n", string);
  24571.    return 0;
  24572.  
  24573.    /****************************************************************************
  24574.       The OS/2 output should be similar to :
  24575.  
  24576.       The current locale is set to fr_fr.ibm-850.
  24577.    ****************************************************************************/
  24578. }
  24579.  
  24580.  
  24581. ΓòÉΓòÉΓòÉ <hidden> Example 2 of setlocale ΓòÉΓòÉΓòÉ
  24582.  
  24583. /************************************************************************
  24584.  
  24585. This example uses setenv to set the value of the environment variable LC_TIME 
  24586. to FRAN, calls setlocale to set all categories to default values, then query 
  24587. all categories, and uses printf to print results. 
  24588.  
  24589. ************************************************************************/
  24590.  
  24591. #include <locale.h>
  24592. #include <stdio.h>
  24593. #include <stdlib.h>
  24594.  
  24595. #if (1 == __TOS_OS2__)
  24596.    #define LOCSTR "LC_TIME=fr_fr.ibm-437"     /* OS/2 name        */
  24597. #else
  24598.    #define LOCSTR "LC_TIME=fr_fr.ibm-1252"    /* Windows name     */
  24599. #endif
  24600.  
  24601. int main(void)
  24602. {
  24603.    char *string;
  24604.  
  24605.    _putenv(LOCSTR);
  24606.    if (NULL == (string = setlocale(LC_ALL, ""))) {
  24607.       printf("setlocale(LC_ALL, \"\") failed.\n");
  24608.       exit(1);
  24609.    } else
  24610.       printf("The current locale categories are: \"%s\"\n", string);
  24611.    return 0;
  24612.  
  24613.    /****************************************************************************
  24614.       The OS/2 output should be similar to :
  24615.  
  24616.       The current locale categories are: "C,C,C,C,fr_fr.ibm-437,C,C,C"
  24617.    ****************************************************************************/
  24618. }
  24619.  
  24620.  
  24621. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24622.  
  24623. setlocale Example 1 
  24624.  
  24625. setlocale Example 2 
  24626.  
  24627.      Locale Categories for setlocale 
  24628.      "Introduction to Locale" in the Programming Guide 
  24629.      getenv - Search for Environment Variables 
  24630.      localeconv - Retrieve Information from the Environment 
  24631.      <locale.h> 
  24632.  
  24633.  
  24634. ΓòÉΓòÉΓòÉ 4.239.1. Locale Categories for setlocale ΓòÉΓòÉΓòÉ
  24635.  
  24636. You can set the category argument of setlocale to one of these values: 
  24637.  
  24638.  Category Purpose 
  24639.  
  24640.  LC_ALL 
  24641.     Specifies all categories associated with the program's locale. 
  24642.  
  24643.  LC_COLLATE 
  24644.     Defines the collation sequence, that is, the relative order of collation 
  24645.     elements (characters and multicharacter collation elements) in the 
  24646.     program's locale. The collation sequence definition is used by regular 
  24647.     expression, pattern matching, and sorting functions. Affects the regular 
  24648.     expression functions regcomp and regexec; the string functions strcoll, 
  24649.     strxfrm, wcscoll, and wcsxfrm. 
  24650.  
  24651.     Note:  Because both LC_CTYPE and LC_COLLATE modify the same storage area, 
  24652.     setting LC_CTYPE and LC_COLLATE to different categories causes 
  24653.     unpredictable results. 
  24654.  
  24655.  LC_CTYPE 
  24656.     Defines character classification and case conversion for characters in the 
  24657.     program's locale. Affects the behavior of character-handling functions 
  24658.     defined in the <ctype.h> header file: csid, isalnum, isalpha, isblank, 
  24659.     iswblank iscntrl, isdigit, isgraph, islower, isprint, ispunct, isspace, 
  24660.     isupper, iswalnum, iswalpha, iswcntrl, iswctype, iswdigit, iswgraph, 
  24661.     iswlower, iswprint, iswpunct, iswspace, iswupper, iswxdigit, isxdigit, 
  24662.     tolower, toupper, towlower, towupper, wcsid, and wctype. 
  24663.  
  24664.     Affects behavior of the printf and scanf families of functions: fprintf, 
  24665.     printf, sprintf, swprintf, vfprintf, vprintf, vsprintf, vswprintf; fscanf, 
  24666.     scanf, sscanf, and swscanf. 
  24667.  
  24668.     Affects the behavior of wide character input/output functions: fgetwc, 
  24669.     fgetws, getwc, getwchar, fputwc, fputws, putwc, putwchar, and ungetwc. 
  24670.  
  24671.     Affects the behavior of multibyte and wide character conversion functions: 
  24672.     mblen, mbrlen, mbrtowc, mbsrtowcs, mbstowcs, mbtowc, wcrtomb, wcsrtombs, 
  24673.     wcstod, wcstol, wcstombs, wcstoul, wcswidth, wctomb, and wcwidth. 
  24674.  
  24675.     Note:  Because both LC_CTYPE and LC_COLLATE modify the same storage area, 
  24676.     setting LC_CTYPE and LC_COLLATE to different categories causes 
  24677.     unpredictable results. 
  24678.  
  24679.  LC_MESSAGES 
  24680.     Under VisualAge for C++, affects the values returned by nl_langinfo and 
  24681.     also defines affirmative and negative response patterns, which affect 
  24682.     rpmatch. 
  24683.  
  24684.     LC_MESSAGES does not affect the messages for the following functions: 
  24685.     perror, strerror, _strerror, and regerror. 
  24686.  
  24687.  LC_MONETARY 
  24688.     Affects monetary information returned by localeconv and strfmon. It defines 
  24689.     the rules and symbols used to format monetary numeric information in the 
  24690.     program's locale. The formatting rules and symbols are strings. localeconv 
  24691.     returns pointers to these strings with names found in the <locale.h> header 
  24692.     file. 
  24693.  
  24694.  LC_NUMERIC 
  24695.     Affects the decimal-point character for the formatted input/output and 
  24696.     string conversion functions, and the nonmonetary formatting information 
  24697.     returned by the localeconv function, specifically: 
  24698.  
  24699.         printf family of functions 
  24700.         scanf family of functions 
  24701.         strtod 
  24702.         atof. 
  24703.  
  24704.  LC_TIME 
  24705.     Defines time and date format information in the program's locale, affecting 
  24706.     the strftime strptime, and wcsftime functions. 
  24707.  
  24708.  LC_SYNTAX 
  24709.     Affects the values that can be retrieved by the getsyntx function. It does 
  24710.     not affect the behavior of functions that are dependent on the encoded 
  24711.     values for formatting characters, as it may do on other platforms. 
  24712.  
  24713.  LC_TOD 
  24714.     Affects the behavior of the functions related to time zone and Daylight 
  24715.     Savings Time information in the program's locale. ctime, localtime, mktime, 
  24716.     setlocale, and strftime call the tzset function to override the LC_TOD 
  24717.     category information when TZ is defined and valid. 
  24718.  
  24719.  
  24720. ΓòÉΓòÉΓòÉ 4.240. _setmode - Set File Translation Mode ΓòÉΓòÉΓòÉ
  24721.  
  24722.  
  24723. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24724.  
  24725. #include <fcntl.h>
  24726. #include <io.h>
  24727. int _setmode(int handle, int mode);
  24728.  
  24729.  
  24730. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24731.  
  24732. Language Level: Extension 
  24733.  
  24734. _setmode sets the translation mode of the file given by handle to mode. The 
  24735. mode must be one of the values in the following table: 
  24736.  
  24737.  Value          Meaning 
  24738.  O_TEXT         Sets the translated text mode.  Carriage-return line-feed 
  24739.                 combinations are translated into a single line feed on input. 
  24740.                 Line-feed characters are translated into carriage-return 
  24741.                 line-feed combinations on output. 
  24742.  O_BINARY       Sets the binary (untranslated) mode.  The above translations 
  24743.                 are suppressed. 
  24744.  
  24745.  Use _setmode to change the translation mode of a file handle. The translation 
  24746.  mode only affects the read and write functions. _setmode does not affect the 
  24747.  translation mode of streams. 
  24748.  
  24749.  If a file handle is acquired other than by a call to open, creat, _sopen or 
  24750.  fileno, you should call _setmode for that file handle before using it within 
  24751.  the read or write functions. 
  24752.  
  24753.  Return Value 
  24754.  _setmode returns the previous translation mode if successful. A return value 
  24755.  of -1 indicates an error, and errno is set to one of the following values: 
  24756.  
  24757.  Value          Meaning 
  24758.  EBADF          The file handle is not a handle for an open file. 
  24759.  EINVAL         Incorrect mode (neither O_TEXT nor O_BINARY) 
  24760.  
  24761.  
  24762. ΓòÉΓòÉΓòÉ <hidden> Example of _setmode ΓòÉΓòÉΓòÉ
  24763.  
  24764. /************************************************************************
  24765.  
  24766. This example uses open to create the file setmode.dat and writes to it.  The 
  24767. program then uses _setmode to change the translation mode of setmode.dat from 
  24768. binary to text. 
  24769.  
  24770. ************************************************************************/
  24771.  
  24772. #include <stdio.h>
  24773. #include <stdlib.h>
  24774. #include <fcntl.h>
  24775. #include <io.h>
  24776. #include <sys\stat.h>
  24777.  
  24778. #define  FILENAME      "setmode.dat"
  24779.  
  24780. /* routine to validate return codes                                           */
  24781.  
  24782. void ckrc(int rc)
  24783. {
  24784.    if (-1 == rc) {
  24785.       printf("Unexpected return code = -1\n");
  24786.       remove(FILENAME);
  24787.       exit(EXIT_FAILURE);
  24788.    }
  24789. }
  24790.  
  24791. int main(void)
  24792. {
  24793.    int h;
  24794.    int xfer;
  24795.    int mode;
  24796.    char rbuf[256];
  24797.    char wbuf[] = "123\n456\n";
  24798.  
  24799.    ckrc(h = open(FILENAME, O_CREAT|O_RDWR|O_TRUNC|O_TEXT, S_IREAD|S_IWRITE));
  24800.    ckrc(write(h, wbuf, sizeof(wbuf)));     /* write the file (text)           */
  24801.    ckrc(lseek(h, 0, SEEK_SET));         /* seek back to the start of the file */
  24802.    ckrc(xfer = read(h, rbuf, 5));           /* read the file text             */
  24803.    printf("Read in %d characters (4 expected)\n", xfer);
  24804.    ckrc(mode = _setmode(h, O_BINARY));
  24805.    if (O_TEXT == mode)
  24806.       printf("Mode changed from binary to text\n");
  24807.    else
  24808.       printf("Previous mode was not text (unexpected)\n");
  24809.    ckrc(xfer = read(h, rbuf, 5));           /* read the file (binary)         */
  24810.    printf("Read in %d characters (5 expected)\n", xfer);
  24811.    ckrc(close(h));
  24812.    remove(FILENAME);
  24813.    return 0;
  24814.  
  24815.    /****************************************************************************
  24816.       The output should be:
  24817.  
  24818.       Read in 4 characters (4 expected)
  24819.       Mode changed from binary to text
  24820.       Read in 5 characters (5 expected)
  24821.    ****************************************************************************/
  24822. }
  24823.  
  24824.  
  24825. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24826.  
  24827. Example of _setmode 
  24828.  
  24829.      creat - Create New File 
  24830.      open - Open File 
  24831.      _sopen - Open Shared File 
  24832.      read - Read Into Buffer 
  24833.      write - Writes from Buffer to File 
  24834.      <fcntl.h> 
  24835.      <io.h> 
  24836.      <share.h> 
  24837.      <sys\stat.h> 
  24838.  
  24839.  
  24840. ΓòÉΓòÉΓòÉ 4.241. setvbuf - Control Buffering ΓòÉΓòÉΓòÉ
  24841.  
  24842.  
  24843. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24844.  
  24845. #include <stdio.h>
  24846. int setvbuf(FILE *stream, char *buf, int type, size_t size);
  24847.  
  24848.  
  24849. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24850.  
  24851. Language Level: ANSI, SAA, XPG4 
  24852.  
  24853. setvbuf allows control over the buffering strategy and buffer size for a 
  24854. specified stream. The stream must refer to a file that has been opened, but not 
  24855. read or written to. 
  24856.  
  24857. The array pointed to by buf designates an area that you provide that the C 
  24858. library may choose to use as a buffer for the stream.  A buf value of NULL 
  24859. indicates that no such area is supplied and that the C library is to assume 
  24860. responsibility for managing its own buffers for the stream.  If you supply a 
  24861. buffer, it must exist until the stream is closed. 
  24862.  
  24863. The type must be one of the following: 
  24864.  
  24865.  Value       Meaning 
  24866.  _IONBF      No buffer is used. 
  24867.  _IOFBF      Full buffering is used for input and output. Use buf as the buffer 
  24868.              and size as the size of the buffer. 
  24869.  _IOLBF      Line buffering is used.  The buffer is flushed when a new-line 
  24870.              character is written, when the buffer is full, or when input is 
  24871.              requested. 
  24872.  
  24873.  If type is _IOFBF or _IOLBF, size is the size of the supplied buffer.  If buf 
  24874.  is NULL, the C library takes size as the suggested size for its own buffer. 
  24875.  If type is _IONBF, both buf and size are ignored. 
  24876.  
  24877.  The value for size must be greater than 0. 
  24878.  
  24879.  Return Value 
  24880.  setvbuf returns 0 if successful. It returns nonzero if an invalid value was 
  24881.  specified in the parameter list, or if the request cannot be performed. 
  24882.  
  24883.  Note:  The array used as the buffer must still exist when the specified stream 
  24884.  is closed. For example, if the buffer is declared within the scope of a 
  24885.  function block, the stream must be closed before the function is terminated 
  24886.  and frees the storage allocated to the buffer. 
  24887.  
  24888.  
  24889. ΓòÉΓòÉΓòÉ <hidden> Example of setvbuf ΓòÉΓòÉΓòÉ
  24890.  
  24891. /************************************************************************
  24892.  
  24893. This example sets up a buffer of buf for stream1 and specifies that input to 
  24894. stream2 is to be unbuffered. 
  24895.  
  24896. ************************************************************************/
  24897.  
  24898. #include <stdio.h>
  24899. #include <stdlib.h>
  24900.  
  24901. #define  BUF_SIZE      1024
  24902. #define  FILE1         "setvbuf1.dat"
  24903. #define  FILE2         "setvbuf2.dat"
  24904.  
  24905. char buf[BUF_SIZE];
  24906. FILE *stream1,*stream2;
  24907.  
  24908. int main(void)
  24909. {
  24910.    int flag = EXIT_SUCCESS;
  24911.  
  24912.    stream1 = fopen(FILE1, "r");
  24913.    stream2 = fopen(FILE2, "r");
  24914.  
  24915.    /* stream1 uses a user-assigned buffer of BUF_SIZE bytes                   */
  24916.  
  24917.    if (setvbuf(stream1, buf, _IOFBF, sizeof(buf)) != 0) {
  24918.       printf("Incorrect type or size of buffer\n");
  24919.       flag = EXIT_FAILURE;
  24920.    }
  24921.  
  24922.    /* stream2 is unbuffered                                                   */
  24923.  
  24924.    if (setvbuf(stream2, NULL, _IONBF, 0) != 0) {
  24925.       printf("Incorrect type or size of buffer\n");
  24926.       flag = EXIT_FAILURE;
  24927.    }
  24928.  
  24929.    fclose(stream1);
  24930.    fclose(stream2);
  24931.    return  flag;
  24932. }
  24933.  
  24934.  
  24935. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24936.  
  24937. Example of setvbuf 
  24938.  
  24939.      fclose - Close Stream 
  24940.      fflush - Write Buffer to File 
  24941.      _flushall - Write Buffers to Files 
  24942.      fopen - Open Files 
  24943.      setbuf - Control Buffering 
  24944.      <stdio.h> 
  24945.  
  24946.  
  24947. ΓòÉΓòÉΓòÉ 4.242. signal - Handle Interrupt Signals ΓòÉΓòÉΓòÉ
  24948.  
  24949.  
  24950. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24951.  
  24952. #include <signal.h>
  24953. void ( *signal(int sig, void (*sig_handler)(int)) )(int);
  24954.  
  24955.  
  24956. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24957.  
  24958. Language Level:  ANSI, SAA, XPG4, Extension 
  24959.  
  24960. signal function assigns the signal handler sig_handler to handle the interrupt 
  24961. signal sig. Signals can be reported as a result of a machine interrupt (for 
  24962. example, division by zero) or by an explicit request to report a signal by 
  24963. using the raise function. 
  24964.  
  24965. The sig argument must be one of the signal constants defined in <signal.h>: 
  24966.  
  24967.  Value           Meaning 
  24968.  SIGABRT         Abnormal termination signal sent by abort. Default action: end 
  24969.                  the program. 
  24970.  SIGBREAK        Ctrl-Break signal. Default action: end the program. 
  24971.  SIGFPE          Floating-point exceptions that are not masked, such as 
  24972.                  overflow, division by zero, and invalid operation.  Default 
  24973.                  action: end the program and provide an error message. If 
  24974.                  machine-state dumps are enabled (with the /Tx compiler 
  24975.                  option), a dump is also provided. 
  24976.  SIGILL          Instruction not allowed.  Default action: end the program and 
  24977.                  provide an error message. If machine-state dumps are enabled 
  24978.                  (with the /Tx compiler option), a dump is also provided. 
  24979.  SIGINT          Ctrl-C signal. Default action: end the program. 
  24980.  SIGSEGV         Access to memory not valid. Default action: end the program 
  24981.                  and provide an error message. If machine-state dumps are 
  24982.                  enabled (with the /Tx compiler option), a dump is also 
  24983.                  provided. 
  24984.  SIGTERM         Program termination signal sent by the user. Default action: 
  24985.                  end the program. 
  24986.  SIGUSR1         Defined by the user. Default action: ignore the signal. 
  24987.  SIGUSR2         Defined by the user. Default action: ignore the signal. 
  24988.  SIGUSR3         Defined by the user. Default action: ignore the signal. 
  24989.  
  24990.  For sig_handler, you must specify either the SIG_DFL or SIG_IGN constant (also 
  24991.  defined in <signal.h>), or the address of a function that takes an integer 
  24992.  argument (the signal). 
  24993.  
  24994.  The action taken when the interrupt signal is received depends on the value of 
  24995.  sig_handler: 
  24996.  
  24997.  Value           Meaning 
  24998.  
  24999.  SIG_DFL         Perform the default action. This is the initial setting for 
  25000.                  all signals. The default actions are described in the list of 
  25001.                  signals above. All files controlled by the process are closed, 
  25002.                  but buffers are not flushed. 
  25003.  
  25004.  SIG_IGN         Ignore the interrupt signal. 
  25005.  
  25006.  sig_handler     Call the function sig_handler, which you provide, to handle 
  25007.                  the signal specified. 
  25008.  
  25009.  Your signal handler function (sig_handler) must take two integer arguments. 
  25010.  The first argument is always the signal identifier. The second argument is 0, 
  25011.  unless the signal is SIG_FPE. For SIG_FPE signals, the second argument passed 
  25012.  is a floating-point error signal as defined in <float.h>. If your sig_handler 
  25013.  returns, the calling process resumes running immediately following the point 
  25014.  at which it received the interrupt signal. 
  25015.  
  25016.  After a signal is reported and the sig_handler is called, signal handling for 
  25017.  that signal is reset to the default. Depending on the purpose of the signal 
  25018.  handler, you may want to call signal inside sig_handler to reestablish 
  25019.  sig_handler as the signal handler. You can also reset the default handling at 
  25020.  any time by calling signal and specifying SIG_DFL. 
  25021.  
  25022.  Synchronous signals and signal handlers are not shared between threads. If you 
  25023.  do not establish a handler for a specific signal within a thread, the default 
  25024.  signal handling is used regardless of what handlers you may have established 
  25025.  in other concurrent threads. However, asynchronous signals are global for the 
  25026.  process. 
  25027.  
  25028.  Note:  If an exception occurs in a math or critical library function, it is 
  25029.  handled by the VisualAge for C++ exception handler.  Your sig_handler will not 
  25030.  be called. For more information about signals and exceptions, refer to Signal 
  25031.  and Windows Exception Handling in the Programming Guide. 
  25032.  
  25033.  Return Value 
  25034.  All calls to signal return the address of the previous handler for the 
  25035.  re-assigned signal. 
  25036.  
  25037.  A return value of SIG_ERR (defined in <signal.h>) indicates an error, and 
  25038.  errno is set to EINVAL. The possible causes of the error are an incorrect sig 
  25039.  value or an undefined value for sig_handler. 
  25040.  
  25041.  
  25042. ΓòÉΓòÉΓòÉ <hidden> Example of signal ΓòÉΓòÉΓòÉ
  25043.  
  25044. /************************************************************************
  25045.  
  25046. In the following example, the call to signal in main establishes the function 
  25047. handler to process the interrupt signal raised by abort. The handler prints a 
  25048. message and returns to the system. 
  25049.  
  25050. ************************************************************************/
  25051.  
  25052. #if  (1 == __TOS_OS2__)
  25053.       #define  INCL_DOSFILEMGR                /*  For OS/2  */
  25054.       #include <os2.h>
  25055. #else
  25056.       #include <windows.h>                    /*  For Windows  */
  25057. #endif
  25058. #include <signal.h>
  25059. #include <stdio.h>
  25060. #include <stdlib.h>
  25061. #include <string.h>
  25062.  
  25063. void handler(int sig)
  25064. {
  25065. #if  (1 == __TOS_OS2__)
  25066.    UCHAR FileData[100];
  25067.    ULONG Wrote;
  25068.  
  25069.    strcpy((char *)FileData, "Signal occurred.\n\r");
  25070.    DosWrite(2,  (PVOID)FileData, strlen((const char*)FileData), &Wrote);
  25071. #else
  25072.    UCHAR FileData[100] = "Signal occurred.";
  25073.    DWORD Wrote;
  25074.    WriteFile(GetStdHandle(STD_ERROR_HANDLE), FileData, strlen(FileData),
  25075.              &Wrote, NULL);
  25076. #endif
  25077.  
  25078. }
  25079.  
  25080. int main(void)
  25081. {
  25082.    if (SIG_ERR == signal(SIGABRT, handler)) {
  25083.       perror("Could not set SIGABRT");
  25084.       return EXIT_FAILURE;
  25085.    }
  25086.    abort();                             /* signal raised by abort             */
  25087.    return 0;                            /* code should not reach here         */
  25088.  
  25089.    /****************************************************************************
  25090.       The output should be:
  25091.  
  25092.       Signal occurred.
  25093.    ****************************************************************************/
  25094. }
  25095.  
  25096.  
  25097. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25098.  
  25099. Example of signal 
  25100.  
  25101.      abort - Stop a Program 
  25102.      atexit - Record Program Termination Function 
  25103.      exit - End Program 
  25104.      _exit - End Process 
  25105.      _fpreset - Reset Floating-Point Unit 
  25106.      raise - Send Signal 
  25107.      _spawnl - _spawnvpe - Start and Run Child Processes 
  25108.      Signal and Windows Exception Handling in the Programming Guide 
  25109.      <signal.h> 
  25110.  
  25111.  
  25112. ΓòÉΓòÉΓòÉ 4.243. sin - Calculate Sine ΓòÉΓòÉΓòÉ
  25113.  
  25114.  
  25115. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25116.  
  25117. #include <math.h>
  25118. double sin(double x);
  25119.  
  25120.  
  25121. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25122.  
  25123. Language Level: ANSI, SAA, POSIX, XPG4 
  25124.  
  25125. sin calculates the sine of x, with x expressed in radians. If x is too large, a 
  25126. partial loss of significance in the result may occur. 
  25127.  
  25128. Return Value 
  25129. sin returns the value of the sine of x. 
  25130.  
  25131.  
  25132. ΓòÉΓòÉΓòÉ <hidden> Example of sin ΓòÉΓòÉΓòÉ
  25133.  
  25134. /************************************************************************
  25135.  
  25136. This example computes y as the sine of pi/2. 
  25137.  
  25138. ************************************************************************/
  25139.  
  25140. #include <stdio.h>
  25141. #include <math.h>
  25142.  
  25143. int main(void)
  25144. {
  25145.    double pi,x,y;
  25146.  
  25147.    pi = 3.1415926535;
  25148.    x = pi/2;
  25149.    y = sin(x);
  25150.    printf("sin( %lf ) = %lf\n", x, y);
  25151.    return 0;
  25152.  
  25153.    /****************************************************************************
  25154.       The output should be:
  25155.  
  25156.       sin( 1.570796 ) = 1.000000
  25157.    ****************************************************************************/
  25158. }
  25159.  
  25160.  
  25161. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25162.  
  25163. Example of sin 
  25164.  
  25165.      asin - Calculate Arcsine 
  25166.      cos - Calculate Cosine 
  25167.      _fasin - Calculate Arcsine 
  25168.      _fcossin - Calculate Cosine and Sine 
  25169.      _fsin - Calculate Sine 
  25170.      _fsincos - Calculate Sine and Cosine 
  25171.      sinh - Calculate Hyperbolic Sine 
  25172.      tan - Calculate Tangent 
  25173.      <math.h> 
  25174.  
  25175.  
  25176. ΓòÉΓòÉΓòÉ 4.244. sinh - Calculate Hyperbolic Sine ΓòÉΓòÉΓòÉ
  25177.  
  25178.  
  25179. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25180.  
  25181. #include <math.h>
  25182. double sinh(double x);
  25183.  
  25184.  
  25185. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25186.  
  25187. Language Level: ANSI, SAA, POSIX, XPG4 
  25188.  
  25189. sinh calculates the hyperbolic sine of x, with x expressed in radians. 
  25190.  
  25191. Return Value 
  25192. sinh returns the value of the hyperbolic sine of x. If the result is too large, 
  25193. sinh sets errno to ERANGE and returns the value HUGE_VAL (positive or negative, 
  25194. depending on the value of x). 
  25195.  
  25196.  
  25197. ΓòÉΓòÉΓòÉ <hidden> Example of sinh ΓòÉΓòÉΓòÉ
  25198.  
  25199. /************************************************************************
  25200.  
  25201. This example computes y as the hyperbolic sine of pi/2. 
  25202.  
  25203. ************************************************************************/
  25204.  
  25205. #include <stdio.h>
  25206. #include <math.h>
  25207.  
  25208. int main(void)
  25209. {
  25210.    double pi,x,y;
  25211.  
  25212.    pi = 3.1415926535;
  25213.    x = pi/2;
  25214.    y = sinh(x);
  25215.    printf("sinh( %lf ) = %lf\n", x, y);
  25216.    return 0;
  25217.  
  25218.    /****************************************************************************
  25219.       The output should be:
  25220.  
  25221.       sinh( 1.570796 ) = 2.301299
  25222.    ****************************************************************************/
  25223. }
  25224.  
  25225.  
  25226. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25227.  
  25228. Example of sinh 
  25229.  
  25230.      asin - Calculate Arcsine 
  25231.      cosh - Calculate Hyperbolic Cosine 
  25232.      _fasin - Calculate Arcsine 
  25233.      _fcossin - Calculate Cosine and Sine 
  25234.      _fsin - Calculate Sine 
  25235.      _fsincos - Calculate Sine and Cosine 
  25236.      sin - Calculate Sine 
  25237.      tanh - Calculate Hyperbolic Tangent 
  25238.      <math.h> 
  25239.  
  25240.  
  25241. ΓòÉΓòÉΓòÉ 4.245. _sopen - Open Shared File ΓòÉΓòÉΓòÉ
  25242.  
  25243.  
  25244. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25245.  
  25246. #include <fcntl.h>
  25247. #include <sys\stat.h>
  25248. #include <share.h>
  25249. #include <io.h>
  25250. int _sopen(char *pathname, int oflag, int shflag , int pmode);
  25251.  
  25252.  
  25253. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25254.  
  25255. Language Level:  Extension 
  25256.  
  25257. _sopen opens the file specified by pathname and prepares the file for 
  25258. subsequent shared reading or writing as defined by oflag and shflag. The oflag 
  25259. is an integer expression formed by combining one or more of the constants 
  25260. defined in <fcntl.h>. When more than one constant is given, the constants are 
  25261. joined with the OR operator (|). 
  25262.  
  25263.  Oflag          Meaning 
  25264.  O_APPEND       Reposition the file pointer to the end of the file before every 
  25265.                 write operation. 
  25266.  O_CREAT        Create and open a new file.  This flag has no effect if the 
  25267.                 file specified by pathname exists. 
  25268.  O_EXCL         Return an error value if the file specified by pathname exists. 
  25269.                 This flag applies only when used with O_CREAT. 
  25270.  O_RDONLY       Open the file for reading only.  If this flag is given, neither 
  25271.                 O_RDWR nor O_WRONLY can be given. 
  25272.  O_RDWR         Open the file for both reading and writing.  If this flag is 
  25273.                 given, neither O_RDONLY nor O_WRONLY can be given. 
  25274.  O_TRUNC        Open and truncate an existing file to 0 length. The file must 
  25275.                 have write permission. The contents of the file are destroyed. 
  25276.                 Do not specify O_TRUNC with O_RDONLY. 
  25277.  O_WRONLY       Open the file for writing only.  If this flag is given, neither 
  25278.                 O_RDONLY nor O_RDWR can be given. 
  25279.  O_BINARY       Open the file in binary (untranslated) mode. 
  25280.  O_TEXT         Open the file in text (translated) mode. (See "Stream 
  25281.                 Processing" in the Programming Guide for a description of text 
  25282.                 and binary mode.) 
  25283.  
  25284.  The shflag argument is one of the following constants, defined in <share.h>: 
  25285.  
  25286.  Shflag          Meaning 
  25287.  SH_DENYRW       Deny read and write access to file. 
  25288.  SH_DENYWR       Deny write access to file. 
  25289.  SH_DENYRD       Deny read access to file. 
  25290.  SH_DENYNO       Permit read and write access. 
  25291.  
  25292.  There is no default value for the shflag. 
  25293.  
  25294.  The pmode argument is required only when you specify O_CREAT. If the file does 
  25295.  not exist, pmode specifies the permission settings of the file, which are set 
  25296.  when the new file is closed for the first time. If the file exists, the value 
  25297.  of pmode is ignored. The pmode must be one of the following values, defined in 
  25298.  <sys\stat.h>: 
  25299.  
  25300.  Value                   Meaning 
  25301.  S_IWRITE                Writing permitted 
  25302.  S_IREAD                 Reading permitted 
  25303.  S_IREAD | S_IWRITE      Reading and writing permitted. 
  25304.  
  25305.  If write permission is not given, the file is read-only. On the Windows 
  25306.  operating system, all files are readable; you cannot give write-only 
  25307.  permission.  Thus, the modes S_IWRITE and S_IREAD | S_IWRITE are equivalent. 
  25308.  Specifying a pmode of S_IREAD is similar to making a file read-only with the 
  25309.  ATTRIB system command. 
  25310.  
  25311.  _sopen applies the current file permission mask to pmode before setting the 
  25312.  permissions. (See umask - Sets File Mask of Current Process for information on 
  25313.  file permission masks.) 
  25314.  
  25315.  _sopen returns a file handle for the opened file. A return value of -1 
  25316.  indicates an error, and errno is set to one of the following values: 
  25317.  
  25318.  Value         Meaning 
  25319.  EACCESS       The given path name is a directory, but the file is read-only 
  25320.                and an attempt was made to open it for writing, or a sharing 
  25321.                violation occurred. 
  25322.  EEXIST        The O_CREAT and O_EXCL flags are specified, but the named file 
  25323.                already exists. 
  25324.  EMFILE        No more file handles are available. 
  25325.  ENOENT        The file or path name was not found. 
  25326.  EINVAL        An incorrect argument was passed. 
  25327.  EOS2ERR       The call to the operating system was not successful. 
  25328.  
  25329.  
  25330. ΓòÉΓòÉΓòÉ <hidden> Example of _sopen ΓòÉΓòÉΓòÉ
  25331.  
  25332. /************************************************************************
  25333.  
  25334. This example opens the file sopen.dat for shared reading and writing using 
  25335. _sopen. It then opens the file for shared reading. 
  25336.  
  25337. ************************************************************************/
  25338.  
  25339. #include <io.h>
  25340. #include <stdio.h>
  25341. #include <stdlib.h>
  25342. #include <fcntl.h>
  25343. #include <share.h>
  25344.  
  25345. #define FILENAME "sopen.dat"
  25346.  
  25347. int main(void)
  25348. {
  25349.    int fh1,fh2;
  25350.  
  25351.    printf("Creating file.\n");
  25352.    system("echo Sample Program > " FILENAME);
  25353.  
  25354.    /* share open the file for reading and writing                            */
  25355.    if (-1 == (fh1 = _sopen(FILENAME, O_RDWR, SH_DENYNO))) {
  25356.       perror("sopen failed");
  25357.       remove(FILENAME);
  25358.       return EXIT_FAILURE;
  25359.    }
  25360.    /* share open the file for reading only                                   */
  25361.    if (-1 == (fh2 = _sopen(FILENAME, O_RDONLY, SH_DENYNO))) {
  25362.       perror("sopen failed");
  25363.       close(fh1);
  25364.       remove(FILENAME);
  25365.       return EXIT_FAILURE;
  25366.    }
  25367.    printf("File successfully opened for sharing.\n");
  25368.    close(fh1);
  25369.    close(fh2);
  25370.    remove(FILENAME);
  25371.    return 0;
  25372.  
  25373.    /****************************************************************************
  25374.       The output should be:
  25375.  
  25376.       Creating file.
  25377.       File successfully opened for sharing.
  25378.    ****************************************************************************/
  25379. }
  25380.  
  25381.  
  25382. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25383.  
  25384. Example of _sopen 
  25385.  
  25386.      close - Close File Associated with Handle 
  25387.      creat - Create New File 
  25388.      open - Open File 
  25389.      fdopen - Associates Input Or Output With File 
  25390.      fopen - Open Files 
  25391.      _sopen - Open Shared File 
  25392.      umask - Sets File Mask of Current Process 
  25393.      <fcntl.h> 
  25394.      <io.h> 
  25395.      <share.h> 
  25396.      <sys\stat.h> 
  25397.  
  25398.  
  25399. ΓòÉΓòÉΓòÉ 4.246. _spawnl - _spawnvpe - Start and Run Child Processes ΓòÉΓòÉΓòÉ
  25400.  
  25401.  
  25402. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25403.  
  25404. #include <process.h>
  25405. int _spawnl(int modeflag, char *pathname, char *arg0, char *arg1, ...,
  25406.               char *argn, NULL);
  25407. int _spawnlp(int modeflag, char *pathname, char *arg0, char *arg1, ...,
  25408.               char *argn, NULL);
  25409. int _spawnle(int modeflag, char *pathname, char *arg0, char *arg1, ...,
  25410.               char *argn, NULL, char *envp[ ]);
  25411. int _spawnlpe(int modeflag, char *pathname, char *arg0, char *arg1, ...,
  25412.               char *argn, NULL, char *envp[ ]);
  25413. int _spawnv(int modeflag, char *pathname, char *argv[ ]);
  25414. int _spawnvp(int modeflag, char *pathname, char *argv[ ]);
  25415. int _spawnve(int modeflag, char *pathname, char *argv[ ], char *envp[ ]);
  25416. int _spawnvpe(int modeflag, char *pathname, char *argv[ ], char *envp[ ])
  25417.  
  25418.  
  25419. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25420.  
  25421. Language Level:  Extension 
  25422.  
  25423. Each of the _spawn functions creates and runs a new child process. Enough 
  25424. storage must be available for loading and running the child process. All of the 
  25425. _spawn functions are versions of the same routine; the letters at the end 
  25426. determine the specific variation: 
  25427.  
  25428.  Letter    Variation 
  25429.   p        Uses PATH environment variable to find the file to be run 
  25430.   l        Lists command-line arguments separately 
  25431.   v        Passes to the child process an array of pointers to command-line 
  25432.            arguments 
  25433.   e        Passes to the child process an array of pointers to environment 
  25434.            strings. 
  25435.  
  25436.  The modeflag argument determines the action taken by the parent process before 
  25437.  and during the _spawn. The values for modeflag are defined in <process.h>: 
  25438.  
  25439.  Value          Meaning 
  25440.  P_WAIT         Suspend the parent process until the child process is complete. 
  25441.  P_NOWAIT       Continue to run the parent process concurrently. 
  25442.  P_OVERLAY      Start the child process, and then, if successful, end the 
  25443.                 parent process.  (This has the same effect as exec calls.) 
  25444.  
  25445.  The pathname argument specifies the file to run as the child process.  The 
  25446.  pathname can specify a full path (from the root), a partial path (from the 
  25447.  current working directory), or just a file name.  If pathname does not have a 
  25448.  file-name extension or end with a period, the _spawn functions add the 
  25449.  extension .EXE and search for the file. If pathname has an extension, only 
  25450.  that extension is used.  If pathname ends with a period, the _spawn functions 
  25451.  search for pathname with no extension. The _spawnlp, _spawnlpe, _spawnvp, and 
  25452.  _spawnvpe functions search for pathname (using the same procedures) in the 
  25453.  directories specified by the PATH environment variable. 
  25454.  
  25455.  You pass arguments to the child process by giving one or more pointers to 
  25456.  character strings as arguments in the _spawn routine.  These character strings 
  25457.  form the argument list for the child process. 
  25458.  
  25459.  The argument pointers can be passed as separate arguments (_spawnl, _spawnle, 
  25460.  _spawnlp, and _spawnlpe) or as an array of pointers (_spawnv, _spawnve, 
  25461.  _spawnvp, and _spawnvpe).  At least one argument, either arg0 or argv[0], must 
  25462.  be passed to the child process.  By convention, this argument is a copy of the 
  25463.  pathname argument.  However, a different value will not produce an error. 
  25464.  
  25465.  Use the _spawnl, _spawnle, _spawnlp, and _spawnlpe functions where you know 
  25466.  the number of arguments. The arg0 is usually a pointer to pathname. The arg1 
  25467.  through argn arguments are pointers to the character strings forming the new 
  25468.  argument list. Following argn, a NULL pointer must mark the end of the 
  25469.  argument list. 
  25470.  
  25471.  The _spawnv, _spawnve, _spawnvp, and _spawnvpe functions are useful when the 
  25472.  number of arguments to the child process is variable.  Pointers to the 
  25473.  arguments are passed as an array, argv.  The argv[0] argument is usually a 
  25474.  pointer to the pathname. The argv[1] through argv[n] arguments are pointers to 
  25475.  the character strings forming the new argument list. The argv[n+1] argument 
  25476.  must be a NULL pointer to mark the end of the argument list. 
  25477.  
  25478.  Files that are open when a _spawn call is made remain open in the child 
  25479.  process.  In the _spawnl, _spawnlp, _spawnv, and _spawnvp calls, the child 
  25480.  process inherits the environment of the parent. The _spawnle, _spawnlpe, 
  25481.  _spawnve, and _spawnvpe functions let you alter the environment for the child 
  25482.  process by passing a list of environment settings through the envp argument. 
  25483.  The envp argument is an array of character pointers, each element of which 
  25484.  points to a null-terminated string, that defines an environment variable. 
  25485.  Such a string has the form: 
  25486.  
  25487.      NAME=value
  25488.  
  25489.  where NAME is the name of an environment variable, and value is the string 
  25490.  value to which that variable is set.  (Notice that value is not enclosed in 
  25491.  double quotation marks.) The final element of the envp array should be NULL. 
  25492.  When envp itself is NULL, the child process inherits the environment settings 
  25493.  of the parent process. 
  25494.  
  25495.  Note:  Signal settings are not preserved in child processes created by calls 
  25496.  to _spawn functions. The signal settings are reset to the default in the child 
  25497.  process. 
  25498.  
  25499.  Return Value 
  25500.  The return from a spawn function has one of two different meanings.  The 
  25501.  return value of a synchronous spawn is the exit status of the child process. 
  25502.  The return value of an asynchronous spawn is the process identification of the 
  25503.  child process.  You can use wait or _cwait to get the child process exit code 
  25504.  if an asynchronous spawn was done. 
  25505.  
  25506.  A return value of -1 indicates an error (the child process is not started), 
  25507.  and errno is set to one of the following values: 
  25508.  
  25509.  Value       Meaning 
  25510.  EAGAIN      The limit of the number of processes that the operating system 
  25511.              permits has been reached. 
  25512.  EINVAL      The modeflag argument is incorrect. 
  25513.  ENOENT      The file or path name was not found or was not specified 
  25514.              correctly. 
  25515.  ENOEXEC     The specified file is not executable or has an incorrect 
  25516.              executable file format. 
  25517.  ENOMEM      Not enough storage is available to run the child process. 
  25518.  
  25519.  
  25520. ΓòÉΓòÉΓòÉ <hidden> Example of _spawnl - _spawnvpe ΓòÉΓòÉΓòÉ
  25521.  
  25522. /************************************************************************
  25523.  
  25524. This example calls four of the eight _spawn routines. When called without 
  25525. arguments from the command line, the program first runs the code for case 
  25526. PARENT. It spawns a copy of itself, waits for its child process to run, and 
  25527. then spawns a second child process. The instructions for the child process are 
  25528. blocked to run only if argv[0] and one parameter were passed (case CHILD). In 
  25529. its turn, each child process spawns a grandchild as a copy of the same program. 
  25530. The grandchild instructions are blocked by the existence of two passed 
  25531. parameters. The grandchild process can overlay the child process. Each of the 
  25532. processes prints a message identifying itself. 
  25533.  
  25534. ************************************************************************/
  25535.  
  25536.  #include  <stdio.h>
  25537.  #include  <process.h>
  25538.  
  25539.  #define   PARENT        1
  25540.  #define   CHILD         2
  25541.  #define   GRANDCHILD    3
  25542.  
  25543.  int main(int argc, char **argv, char **envp)
  25544.  {
  25545.     int    result;
  25546.     char   *args[4];
  25547.     switch(argc)
  25548.     {
  25549.        case PARENT:     /* no argument was passed:  spawn child and wait */
  25550.           result = spawnle(P_WAIT, argv[0], argv[0], "one", NULL, envp);
  25551.           if (result)
  25552.               abort();
  25553.           args[0] = argv[0];
  25554.           args[1] = "two";
  25555.           args[2] = NULL;
  25556.           /* spawn another child, and wait for it */
  25557.           result = spawnve(P_WAIT, argv[0], args, envp);
  25558.           if (result)
  25559.               abort();
  25560.           printf("Parent process ended\n");
  25561.           exit(0);
  25562.        case CHILD:     /* one argument passed:  allow grandchild to overlay */
  25563.           printf("child process %s began\n", argv[1]);
  25564.           if (*argv[1] == 'o')            /* child one? */
  25565.           {
  25566.              spawnl(P_OVERLAY, argv[0], argv[0], "one", "two", NULL);
  25567.              abort();       /* not executed because child was overlaid */
  25568.           }
  25569.           if (*argv[1] == 't')            /* child two? */
  25570.           {
  25571.               args[0] = argv[0];
  25572.               args[1] = "two";
  25573.               args[2] = "one";
  25574.               args[3] = NULL;
  25575.  
  25576.               spawnv(P_OVERLAY, argv[0], args);
  25577.  
  25578.               abort();       /* not executed because child was overlaid */
  25579.           }
  25580.           abort();       /* argument not valid */
  25581.       case GRANDCHILD:   /* two arguments passed */
  25582.          printf("grandchild %s ran\n", argv[1]);
  25583.          exit(0);
  25584.     }
  25585.  /*  The output should be similar to:
  25586.      child process one began
  25587.      grandchild one ran
  25588.      child process two began
  25589.      Parent process ended
  25590.      grandchild two ran
  25591.  */
  25592.  }
  25593.  
  25594.  
  25595. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25596.  
  25597. Example of _spawnl - _spawnvpe 
  25598.  
  25599.      abort - Stop a Program 
  25600.      _cwait - Wait for Child Process 
  25601.      execl - _execvpe - Load and Run Child Process 
  25602.      exit - End Program 
  25603.      _exit - End Process 
  25604.      wait - Wait for Child Process 
  25605.      <process.h> 
  25606.  
  25607.  
  25608. ΓòÉΓòÉΓòÉ 4.247. _splitpath - Decompose Path Name ΓòÉΓòÉΓòÉ
  25609.  
  25610.  
  25611. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25612.  
  25613. #include <stdlib.h>
  25614. void _splitpath(char *path, char *drive, char *dir,
  25615.                     char *fname, char *ext);
  25616.  
  25617.  
  25618. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25619.  
  25620. Language Level:  Extension 
  25621.  
  25622. _splitpath decomposes an existing path name path into its four components. The 
  25623. path should point to a buffer containing the complete path name. 
  25624.  
  25625. The maximum size necessary for each buffer is specified by the _MAX_DRIVE, 
  25626. _MAX_DIR, _MAX_FNAME, and _MAX_EXT constants defined in <stdlib.h>.  The other 
  25627. arguments point to the following buffers used to store the path name elements: 
  25628.  
  25629.  Buffer    Description 
  25630.  drive     Contains the drive letter followed by a colon (:) if a drive is 
  25631.            specified in path. 
  25632.  dir       Contains the path of subdirectories, if any, including the trailing 
  25633.            slash.  Slashes (/), backslashes (\), or both may be present in 
  25634.            path. 
  25635.  fname     Contains the base file name without any extensions. 
  25636.  ext       Contains the file name extension, if any, including the leading 
  25637.            period (.). 
  25638.  
  25639.  You can specify NULL for any of the buffer pointers to indicate that you do 
  25640.  not want the string for that component returned. 
  25641.  
  25642.  The return parameters contain empty strings for any path name components not 
  25643.  found in path. 
  25644.  
  25645.  Return Value 
  25646.  There is no return value. 
  25647.  
  25648.  
  25649. ΓòÉΓòÉΓòÉ <hidden> Example of _splitpath ΓòÉΓòÉΓòÉ
  25650.  
  25651. /************************************************************************
  25652.  
  25653. This example builds a file name path from the specified components, and then 
  25654. extracts the individual components. 
  25655.  
  25656. ************************************************************************/
  25657.  
  25658. #include <stdio.h>
  25659. #include <stdlib.h>
  25660.  
  25661. int main(void)
  25662. {
  25663.    char path_buffer[_MAX_PATH];
  25664.    char drive[_MAX_DRIVE];
  25665.    char dir[_MAX_DIR];
  25666.    char fname[_MAX_FNAME];
  25667.    char ext[_MAX_EXT];
  25668.  
  25669.    _makepath(path_buffer, "c", "qc\\bob\\eclibref\\e", "makepath", "c");
  25670.    printf("Path created with _makepath: %s\n\n", path_buffer);
  25671.    _splitpath(path_buffer, drive, dir, fname, ext);
  25672.    printf("Path extracted with _splitpath:\n");
  25673.    printf("drive: %s\n", drive);
  25674.    printf("directory: %s\n", dir);
  25675.    printf("file name: %s\n", fname);
  25676.    printf("extension: %s\n", ext);
  25677.    return 0;
  25678.  
  25679.    /****************************************************************************
  25680.       The output should be:
  25681.  
  25682.       Path created with _makepath: c:qc\bob\eclibref\e\makepath.c
  25683.  
  25684.       Path extracted with _splitpath:
  25685.       drive: c:
  25686.       directory: qc\bob\eclibref\e\
  25687.       file name: makepath
  25688.       extension: .c
  25689.    ****************************************************************************/
  25690. }
  25691.  
  25692.  
  25693. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25694.  
  25695. Example of _splitpath 
  25696.  
  25697.      _fullpath - Get Full Path Name of Partial Path 
  25698.      _getcwd - Get Path Name of Current Directory 
  25699.      _getdcwd - Get Full Path Name of Current Directory 
  25700.      _makepath - Create Path 
  25701.      <stdlib.h> 
  25702.  
  25703.  
  25704. ΓòÉΓòÉΓòÉ 4.248. sprintf - Print Formatted Data to Buffer ΓòÉΓòÉΓòÉ
  25705.  
  25706.  
  25707. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25708.  
  25709. #include <stdio.h>
  25710. int sprintf(char *buffer, const char *format-string, argument-list);
  25711.  
  25712.  
  25713. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25714.  
  25715. Language Level: ANSI, SAA, POSIX, XPG4, Extension 
  25716.  
  25717. sprintf formats and stores a series of characters and values in the array 
  25718. buffer. Any argument-list is converted and put out according to the 
  25719. corresponding format specification in the format-string. 
  25720.  
  25721. The format-string consists of ordinary characters and has the same form and 
  25722. function as the format-string argument for the printf function. See printf for 
  25723. a description of the format-string and arguments. 
  25724.  
  25725. In extended mode, sprintf also converts floating-point values of NaN and 
  25726. infinity to the strings "NAN" or "nan" and "INFINITY" or "infinity". The case 
  25727. and sign of the string is determined by the format specifiers.  See Infinity 
  25728. and NaN Support for more information on infinity and NaN values. 
  25729.  
  25730. If you specify a null string for the %s or %ls format specifier, sprintf prints 
  25731. (null). (In previous releases of VisualAge C++, sprintf produced no output for 
  25732. a null string.) 
  25733.  
  25734. Return Value 
  25735. sprintf returns the number of bytes written in the array, not counting the 
  25736. ending null character. 
  25737.  
  25738.  
  25739. ΓòÉΓòÉΓòÉ <hidden> Example of sprintf ΓòÉΓòÉΓòÉ
  25740.  
  25741. /************************************************************************
  25742.  
  25743. This example uses sprintf to format and print various data. 
  25744.  
  25745. ************************************************************************/
  25746.  
  25747. #include <stdio.h>
  25748.  
  25749. char buffer[200];
  25750. int i,j;
  25751. double fp;
  25752. char *s = "baltimore";
  25753. char c;
  25754.  
  25755. int main(void)
  25756. {
  25757.    c = 'l';
  25758.    i = 35;
  25759.    fp = 1.7320508;
  25760.  
  25761.     /* Format and print various data                                          */
  25762.  
  25763.    j = sprintf(buffer, "%s\n", s);
  25764.    j += sprintf(buffer+j, "%c\n", c);
  25765.    j += sprintf(buffer+j, "%d\n", i);
  25766.    j += sprintf(buffer+j, "%f\n", fp);
  25767.    printf("string:\n%s\ncharacter count = %d\n", buffer, j);
  25768.    return 0;
  25769.  
  25770.    /****************************************************************************
  25771.       The output should be:
  25772.  
  25773.       string:
  25774.       baltimore
  25775.       l
  25776.       35
  25777.       1.732051
  25778.  
  25779.       character count = 24
  25780.    ****************************************************************************/
  25781. }
  25782.  
  25783.  
  25784. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25785.  
  25786. Example of sprintf 
  25787.  
  25788.      Infinity and NaN Support 
  25789.      _cprintf - Print Characters to Screen 
  25790.      fprintf - Write Formatted Data to a Stream 
  25791.      printf - Print Formatted Characters 
  25792.      sscanf - Read Data 
  25793.      swprintf - Format and Write Wide Characters to Buffer 
  25794.      vfprintf - Print Argument Data to Stream 
  25795.      vprintf - Print Argument Data 
  25796.      vsprintf - Print Argument Data to Buffer 
  25797.      vswprintf - Format and Write Wide Characters to Buffer 
  25798.      <stdio.h> 
  25799.  
  25800.  
  25801. ΓòÉΓòÉΓòÉ 4.249. sqrt - Calculate Square Root ΓòÉΓòÉΓòÉ
  25802.  
  25803.  
  25804. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25805.  
  25806. #include <math.h>
  25807. double sqrt(double x);
  25808.  
  25809.  
  25810. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25811.  
  25812. Language Level: ANSI, SAA, POSIX, XPG4 
  25813.  
  25814. sqrt calculates the nonnegative value of the square root of x. 
  25815.  
  25816. Return Value 
  25817. sqrt returns the square root result.  If x is negative, the function sets errno 
  25818. to EDOM, and returns 0. 
  25819.  
  25820.  
  25821. ΓòÉΓòÉΓòÉ <hidden> Example of sqrt ΓòÉΓòÉΓòÉ
  25822.  
  25823. /************************************************************************
  25824.  
  25825. This example computes the square root of the quantity passed as the first 
  25826. argument to main. It prints an error message if you pass a negative value. 
  25827.  
  25828. ************************************************************************/
  25829.  
  25830. #include <stdio.h>
  25831. #include <stdlib.h>
  25832. #include <math.h>
  25833.  
  25834. int main(int argc,char **argv)
  25835. {
  25836.    double value = 45.0;
  25837.  
  25838.    printf("sqrt( %f ) = %f\n", value, sqrt(value));
  25839.    return 0;
  25840.  
  25841.    /****************************************************************************
  25842.       The output should be:
  25843.  
  25844.       sqrt( 45.000000 ) = 6.708204
  25845.    ****************************************************************************/
  25846. }
  25847.  
  25848.  
  25849. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25850.  
  25851. Example of sqrt 
  25852.  
  25853.      exp - Calculate Exponential Function 
  25854.      _fsqrt -  Calculate Square Root 
  25855.      hypot - Calculate Hypotenuse 
  25856.      log - Calculate Natural Logarithm 
  25857.      log10 - Calculate Base 10 Logarithm 
  25858.      pow - Compute Power 
  25859.      <math.h> 
  25860.  
  25861.  
  25862. ΓòÉΓòÉΓòÉ 4.250. srand - Set Seed for rand Function ΓòÉΓòÉΓòÉ
  25863.  
  25864.  
  25865. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25866.  
  25867. #include <stdlib.h>
  25868. void srand(unsigned int seed);
  25869.  
  25870.  
  25871. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25872.  
  25873. Language Level: ANSI, SAA, POSIX, XPG4 
  25874.  
  25875. srand sets the starting point for producing a series of pseudo-random integers. 
  25876. If srand is not called, the rand seed is set as if srand(1) were called at 
  25877. program start.  Any other value for seed sets the generator to a different 
  25878. starting point. 
  25879.  
  25880. The rand function generates the pseudo-random numbers. 
  25881.  
  25882. Return Value 
  25883. There is no return value. 
  25884.  
  25885.  
  25886. ΓòÉΓòÉΓòÉ <hidden> Example of srand ΓòÉΓòÉΓòÉ
  25887.  
  25888. /************************************************************************
  25889.  
  25890. This example first calls srand with a value other than 1 to initiate the random 
  25891. value sequence.  Then the program computes five pseudo-random values for the 
  25892. array of integers called ranvals. 
  25893.  
  25894. ************************************************************************/
  25895.  
  25896. #include <stdlib.h>
  25897. #include <stdio.h>
  25898.  
  25899. int main(void)
  25900. {
  25901.    int i,ranvals[5];
  25902.  
  25903.    srand(17);
  25904.    for (i = 0; i < 5; i++) {
  25905.       ranvals[i] = rand();
  25906.       printf("Iteration %d ranvals [%d] = %d\n", i+1, i, ranvals[i]);
  25907.    }
  25908.    return 0;
  25909.  
  25910.    /****************************************************************************
  25911.       The output should be similar to:
  25912.  
  25913.       Iteration 1 ranvals [0] = 24107
  25914.       Iteration 2 ranvals [1] = 16552
  25915.       Iteration 3 ranvals [2] = 12125
  25916.       Iteration 4 ranvals [3] = 9427
  25917.       Iteration 5 ranvals [4] = 13152
  25918.    ****************************************************************************/
  25919. }
  25920.  
  25921.  
  25922. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25923.  
  25924. Example of srand 
  25925.  
  25926.      rand - Generate Random Number 
  25927.      <stdlib.h> 
  25928.  
  25929.  
  25930. ΓòÉΓòÉΓòÉ 4.251. _srotl - _srotr - Rotate Bits of Unsigned Short Value ΓòÉΓòÉΓòÉ
  25931.  
  25932.  
  25933. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25934.  
  25935. #include <stdlib.h>   /* also in <builtin.h> */
  25936.  
  25937. unsigned short _srotl(unsigned short value, int shift);
  25938. unsigned short _srotr(unsigned short value, int shift);
  25939.  
  25940.  
  25941. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25942.  
  25943. Language Level:  Extension 
  25944.  
  25945. The _srotl and _srotr functions rotate the unsigned short integer value by 
  25946. shift bits. The _srotl function rotates to the left, and _srotr to the right. 
  25947.  
  25948. Note:  Both _srotl and _srotr are built-in functions, which means they are 
  25949.        implemented as inline instructions and have no backing code in the 
  25950.        library. For this reason: 
  25951.  
  25952.      You cannot take the address of these functions. 
  25953.      You cannot parenthesize a call to either function. (Parentheses specify a 
  25954.       call to the function's backing code, and these functions have none.) 
  25955.  
  25956.  Return Value 
  25957.  
  25958.  Both functions return the rotated value. There is no error return value. 
  25959.  
  25960.  
  25961. ΓòÉΓòÉΓòÉ <hidden> Example of _srotl - _srotr ΓòÉΓòÉΓòÉ
  25962.  
  25963. /************************************************************************
  25964. *
  25965.  
  25966. This example uses _srotl and _srotr with different shift values to rotate the 
  25967. character value: 
  25968.  
  25969.                                                                         *
  25970. ************************************************************************/
  25971.  
  25972. #include <stdio.h>
  25973. #include <stdlib.h>
  25974.  
  25975. int main(void)
  25976. {
  25977.    unsigned short val = 0X0123;
  25978.  
  25979.    printf("The value of 0x%4.4x rotated 4 bits to the left is 0x%4.4x\n", val,
  25980.       _srotl(val, 4));
  25981.    printf("The value of 0x%4.4x rotated 8 bits to the right is 0x%4.4x\n",
  25982.       val, _srotr(val, 8));
  25983.    return 0;
  25984.  
  25985.    /****************************************************************************
  25986.       The output should be:
  25987.  
  25988.       The value of 0x0123 rotated 4 bits to the left is 0x1230
  25989.       The value of 0x0123 rotated 8 bits to the right is 0x2301
  25990.    ****************************************************************************/
  25991. }
  25992.  
  25993.  
  25994. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25995.  
  25996. Example 
  25997.  
  25998.      _crotl - _crotr - Rotate Bits of Character Value 
  25999.      _lrotl - _lrotr - Rotate Bits of Unsigned Long Value 
  26000.      _rotl - _rotr - Rotate Bits of Unsigned Integer 
  26001.      <stdlib.h> 
  26002.      <builtin.h> 
  26003.  
  26004.  
  26005. ΓòÉΓòÉΓòÉ 4.252. sscanf - Read Data ΓòÉΓòÉΓòÉ
  26006.  
  26007.  
  26008. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26009.  
  26010. #include <stdio.h>
  26011. int sscanf(const char *buffer, const char *format, argument-list);
  26012.  
  26013.  
  26014. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26015.  
  26016. Language Level: ANSI, SAA, POSIX, XPG4, Extension 
  26017.  
  26018. sscanf reads data from buffer into the locations given by argument-list.  Each 
  26019. argument must be a pointer to a variable with a type that corresponds to a type 
  26020. specifier in the format-string. See scanf for a description of the 
  26021. format-string. 
  26022.  
  26023. In extended mode, sscanf also reads in the strings "INFINITY", "INF", and "NAN" 
  26024. (in upper or lowercase) and converts them to the corresponding floating-point 
  26025. value.  The sign of the value is determined by the format specification. See 
  26026. Infinity and NaN Support for more information on infinity and NaN values. 
  26027.  
  26028. Return Value 
  26029. sscanf returns the number of fields that were successfully converted and 
  26030. assigned.  The return value does not include fields that were read but not 
  26031. assigned. 
  26032.  
  26033. The return value is EOF when the end of the string is encountered before 
  26034. anything is converted. 
  26035.  
  26036.  
  26037. ΓòÉΓòÉΓòÉ <hidden> Example of sscanf ΓòÉΓòÉΓòÉ
  26038.  
  26039. /************************************************************************
  26040.  
  26041. This example uses sscanf to read various data from the string tokenstring, and 
  26042. then displays that data. 
  26043.  
  26044. ************************************************************************/
  26045.  
  26046. #include <stdio.h>
  26047.  
  26048. #define  SIZE          81
  26049.  
  26050. char *tokenstring = "15 12 14";
  26051. int i;
  26052. float fp;
  26053. char s[SIZE];
  26054. char c;
  26055.  
  26056. int main(void)
  26057. {
  26058.  
  26059.     /* Input various data                                                     */
  26060.  
  26061.    sscanf(tokenstring, "%s %c%d%f", s, &c, &i, &fp);
  26062.  
  26063.     /* If there were no space between %s and %c,                              */
  26064.     /* sscanf would read the first character following                        */
  26065.     /* the string, which is a blank space.                                    */
  26066.     /* Display the data                                                       */
  26067.  
  26068.    printf("string = %s\n", s);
  26069.    printf("character = %c\n", c);
  26070.    printf("integer = %d\n", i);
  26071.    printf("floating-point number = %f\n", fp);
  26072.    return 0;
  26073.  
  26074.    /****************************************************************************
  26075.       The output should be:
  26076.  
  26077.       string = 15
  26078.       character = 1
  26079.       integer = 2
  26080.       floating-point number = 14.000000
  26081.    ****************************************************************************/
  26082. }
  26083. /*****************  Output should be similar to:  ***************** */ 
  26084.  
  26085.  
  26086. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26087.  
  26088. Example of sscanf 
  26089.  
  26090.      Infinity and NaN Support 
  26091.      _cscanf - Read Data from Keyboard 
  26092.      fscanf - Read Formatted Data 
  26093.      scanf - Read Data 
  26094.      sprintf - Print Formatted Data to Buffer 
  26095.      swscanf - Read Wide Characters from Buffer 
  26096.      <stdio.h> 
  26097.  
  26098.  
  26099. ΓòÉΓòÉΓòÉ 4.253. stat - Get Information about File or Directory ΓòÉΓòÉΓòÉ
  26100.  
  26101.  
  26102. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26103.  
  26104. #include <sys\types.h>
  26105. #include <sys\stat.h>
  26106. int stat(const char *pathname, struct stat *buffer)    ;
  26107.  
  26108.  
  26109. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26110.  
  26111. Language Level:  XPG4, Extension 
  26112.  
  26113. stat stores information about the file or directory specified by pathname in 
  26114. the structure to which buffer points.  The stat structure, defined in 
  26115. <sys\stat.h>, contains the following fields: 
  26116.  
  26117.  Field          Value 
  26118.  
  26119.  st_mode        Bit mask for file-mode information. The S_IFDIR bit is set if 
  26120.                 pathname specifies a directory. The S_IFREG bit is set if 
  26121.                 pathname specifies an ordinary file.  User read/write bits are 
  26122.                 set according to the permission mode of the file. The S_IEXEC 
  26123.                 bit is set using the file name extension. The other bits are 
  26124.                 undefined. 
  26125.  
  26126.  st_dev         Drive number of the disk containing the file. 
  26127.  
  26128.  st_rdev        Drive number of the disk containing the file (same as st_dev). 
  26129.  
  26130.  st_nlink       Always 1. 
  26131.  
  26132.  st_size        Size of the file in bytes. 
  26133.  
  26134.  st_atime       Time of last access of file. 
  26135.  
  26136.  st_mtime       Time of last modification of file. 
  26137.  
  26138.  st_ctime       Time of file creation. 
  26139.  
  26140.  Note:  If the given pathname specifies only a device (for example C:\), time 
  26141.  information is not available. 
  26142.  
  26143.  Note:  In earlier releases of VisualAge C++, stat began with an underscore 
  26144.  (_stat). Because it is defined by the X/Open standard, the underscore has been 
  26145.  removed. For compatibility, VisualAge for C++ will map _stat to stat for you. 
  26146.  
  26147.  Return Value 
  26148.  stat returns the value 0 if the file status information is obtained.  A return 
  26149.  value of -1 indicates an error, and errno is set to ENOENT, indicating that 
  26150.  the file name or path name could not be found. 
  26151.  
  26152.  
  26153. ΓòÉΓòÉΓòÉ <hidden> Example of stat ΓòÉΓòÉΓòÉ
  26154.  
  26155. /************************************************************************
  26156.  
  26157. This example requests that the status information for the file test.exe be 
  26158. placed into the structure buf.  If the request is successful and the file is 
  26159. executable, the example runs test.exe. 
  26160.  
  26161. ************************************************************************/
  26162.  
  26163. #include <sys\types.h>
  26164. #include <sys\stat.h>
  26165. #include <process.h>
  26166. #include <stdio.h>
  26167.  
  26168. int main(void)
  26169. {
  26170.    struct stat buf;
  26171.  
  26172.    if (0 == stat("test.exe", &buf)) {
  26173.       if ((buf.st_mode&S_IFREG) && (buf.st_mode&S_IEXEC))
  26174.          execl("test.exe", "test", NULL);         /* file is executable       */
  26175.    }
  26176.    else
  26177.       printf("File could not be found\n");
  26178.    return 0;
  26179.  
  26180.    /****************************************************************************
  26181.       The source for test.exe is:
  26182.  
  26183.       #include <stdio.h>
  26184.       int main(void)
  26185.       {
  26186.           puts("test.exe is an executable file");
  26187.       }
  26188.  
  26189.       The output should be:
  26190.  
  26191.       test.exe is an executable file
  26192.    ****************************************************************************/
  26193. }
  26194.  
  26195.  
  26196. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26197.  
  26198. Example of stat 
  26199.  
  26200.      fstat - Information about Open File 
  26201.      <sys\stat.h> 
  26202.      <sys\types.h> 
  26203.  
  26204.  
  26205. ΓòÉΓòÉΓòÉ 4.254. _status87 - Get Floating-Point Status Word ΓòÉΓòÉΓòÉ
  26206.  
  26207.  
  26208. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26209.  
  26210. #include <float.h>  /* also in <builtin.h> */
  26211. unsigned int _status87(void);
  26212.  
  26213.  
  26214. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26215.  
  26216. Language Level:  Extension 
  26217.  
  26218. _status87 gets the current floating-point status word. The floating-point 
  26219. status word is a combination of the numeric coprocessor status word and other 
  26220. conditions detected by the numeric exception handler, such as floating-point 
  26221. stack underflow and overflow. 
  26222.  
  26223. Return Value 
  26224. The bits in the value returned reflect the floating-point status for the 
  26225. current thread only before the call was made. These bits are defined in the 
  26226. <float.h> include file. _status87 does not affect any other threads that may be 
  26227. processing. 
  26228.  
  26229.  
  26230. ΓòÉΓòÉΓòÉ <hidden> Example of _status87 ΓòÉΓòÉΓòÉ
  26231.  
  26232. /************************************************************************
  26233.  
  26234. This example uses _status87 to get the value of the floating-point status word. 
  26235.  
  26236. ************************************************************************/
  26237.  
  26238. #include <stdio.h>
  26239. #include <float.h>
  26240.  
  26241. double a = 1e-40,b;
  26242. float x,y;
  26243.  
  26244. int main(void)
  26245. {
  26246.    printf("status = 0x%.4x - clear\n", _status87());
  26247.  
  26248.    /* change control word to mask all exceptions                              */
  26249.  
  26250.    _control87(0x037f, 0xffff);
  26251.    y = a;                     /* store into y is inexact and causes underflow */
  26252.    printf("status = 0x%.4X - inexact, underflow\n", _status87());
  26253.  
  26254.    /* reinitialize the floating point unit                                    */
  26255.  
  26256.    _fpreset();
  26257.  
  26258.    /* change control word to mask all exceptions                              */
  26259.  
  26260.    _control87(0x037f, 0xffff);
  26261.    b = y;                                                 /* y is denormal    */
  26262.    printf("status = 0x%.4X - denormal\n", _status87());
  26263.  
  26264.    /* reinitialize the floating point unit                                    */
  26265.  
  26266.    _fpreset();
  26267.    return 0;
  26268.  
  26269.    /****************************************************************************
  26270.       The output should be:
  26271.  
  26272.       status = 0x0000 - clear
  26273.       status = 0x0030 - inexact, underflow
  26274.       status = 0x0002 - denormal
  26275.    ****************************************************************************/
  26276. }
  26277.  
  26278.  
  26279. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26280.  
  26281. Example of _status87 
  26282.  
  26283.      _clear87 - Clear Floating-Point Status Word 
  26284.      _control87 - Set Floating-Point Control Word 
  26285.      _fpreset - Reset Floating-Point Unit 
  26286.      <float.h> 
  26287.  
  26288.  
  26289. ΓòÉΓòÉΓòÉ 4.255. strcat - Concatenate Strings ΓòÉΓòÉΓòÉ
  26290.  
  26291.  
  26292. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26293.  
  26294. #include <string.h>
  26295. char *strcat(char *string1, const char *string2);
  26296.  
  26297.  
  26298. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26299.  
  26300. Language Level: ANSI, SAA, POSIX, XPG4 
  26301.  
  26302. strcat concatenates string2 to string1 and ends the resulting string with the 
  26303. null character. 
  26304.  
  26305. strcat operates on null-terminated strings. The string arguments to the 
  26306. function should contain a null character (\0) marking the end of the string. No 
  26307. length checking is performed. You should not use a literal string for a string1 
  26308. value, although string2 may be a literal string. 
  26309.  
  26310. If the storage of string1 overlaps the storage of string2, the behavior is 
  26311. undefined. 
  26312.  
  26313. Return Value 
  26314. strcat returns a pointer to the concatenated string (string1). 
  26315.  
  26316.  
  26317. ΓòÉΓòÉΓòÉ <hidden> Example of strcat ΓòÉΓòÉΓòÉ
  26318.  
  26319. /************************************************************************
  26320.  
  26321. This example creates the string "computer program" using strcat. 
  26322.  
  26323. ************************************************************************/
  26324.  
  26325. #include <stdio.h>
  26326. #include <string.h>
  26327.  
  26328. #define  SIZE          40
  26329.  
  26330. int main(void)
  26331. {
  26332.    char buffer1[SIZE] = "computer";
  26333.    char *ptr;
  26334.  
  26335.    ptr = strcat(buffer1, " program");
  26336.    printf("buffer1 = %s\n", buffer1);
  26337.    return 0;
  26338.  
  26339.    /****************************************************************************
  26340.       The output should be:
  26341.  
  26342.       buffer1 = computer program
  26343.    ****************************************************************************/
  26344. }
  26345.  
  26346.  
  26347. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26348.  
  26349. Example of strcat 
  26350.  
  26351.      strchr - Search for Character 
  26352.      strcmp - Compare Strings 
  26353.      strcpy - Copy Strings 
  26354.      strcspn - Compare Strings for Substrings 
  26355.      strncat - Concatenate Strings 
  26356.      wcscat - Concatenate Wide-Character Strings 
  26357.      wcsncat - Concatenate Wide-Character Strings 
  26358.      <string.h> 
  26359.  
  26360.  
  26361. ΓòÉΓòÉΓòÉ 4.256. strchr - Search for Character ΓòÉΓòÉΓòÉ
  26362.  
  26363.  
  26364. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26365.  
  26366. #include <string.h>
  26367. char *strchr(const char *string, int c);
  26368.  
  26369.  
  26370. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26371.  
  26372. Language Level: ANSI, SAA, POSIX, XPG4 
  26373.  
  26374. strchr finds the first occurrence of a character in a string. The character c 
  26375. can be the null character (\0); the ending null character of string is included 
  26376. in the search. 
  26377.  
  26378. The strchr function operates on null-terminated strings. The string arguments 
  26379. to the function should contain a null character (\0) marking the end of the 
  26380. string. 
  26381.  
  26382. Return Value 
  26383. strchr returns a pointer to the first occurrence of c converted to a character 
  26384. in string. The function returns NULL if the specified character is not found. 
  26385.  
  26386.  
  26387. ΓòÉΓòÉΓòÉ <hidden> Example of strchr ΓòÉΓòÉΓòÉ
  26388.  
  26389. /************************************************************************
  26390.  
  26391. This example finds the first occurrence of the character p in "computer 
  26392. program". 
  26393.  
  26394. ************************************************************************/
  26395.  
  26396. #include <stdio.h>
  26397. #include <string.h>
  26398.  
  26399. #define  SIZE          40
  26400.  
  26401. int main(void)
  26402. {
  26403.    char buffer1[SIZE] = "computer program";
  26404.    char *ptr;
  26405.    int ch = 'p';
  26406.  
  26407.    ptr = strchr(buffer1, ch);
  26408.    printf("The first occurrence of %c in '%s' is '%s'\n", ch, buffer1, ptr);
  26409.    return 0;
  26410.  
  26411.    /****************************************************************************
  26412.       The output should be:
  26413.  
  26414.       The first occurrence of p in 'computer program' is 'puter program'
  26415.    ****************************************************************************/
  26416. }
  26417.  
  26418.  
  26419. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26420.  
  26421. Example of strchr 
  26422.  
  26423.      strcmp - Compare Strings 
  26424.      strcspn - Compare Strings for Substrings 
  26425.      strncmp - Compare Strings 
  26426.      strpbrk - Find Characters in String 
  26427.      strrchr - Find Last Occurrence of Character in String 
  26428.      strspn - Search Strings 
  26429.      wcschr - Search for Wide Character 
  26430.      wcsspn - Search Wide-Character Strings 
  26431.      <string.h> 
  26432.  
  26433.  
  26434. ΓòÉΓòÉΓòÉ 4.257. strcmp - Compare Strings ΓòÉΓòÉΓòÉ
  26435.  
  26436.  
  26437. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26438.  
  26439. #include <string.h>
  26440. int strcmp(const char *string1, const char *string2);
  26441.  
  26442.  
  26443. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26444.  
  26445. Language Level: ANSI, SAA, POSIX, XPG4 
  26446.  
  26447. strcmp compares string1 and string2. The function operates on null-terminated 
  26448. strings. The string arguments to the function should contain a null character 
  26449. (\0) marking the end of the string. 
  26450.  
  26451. Return Value 
  26452. strcmp returns a value indicating the relationship between the two strings, as 
  26453. follows: 
  26454.  
  26455.  Value             Meaning 
  26456.  Less than 0       string1 less than string2 
  26457.  0                 string1 identical to string2 
  26458.  Greater than 0    string1 greater than string2. 
  26459.  
  26460.  If count is greater than the length of string1 or string2, characters that 
  26461.  follow a null character are not compared. 
  26462.  
  26463.  
  26464. ΓòÉΓòÉΓòÉ <hidden> Example of strcmp ΓòÉΓòÉΓòÉ
  26465.  
  26466. /************************************************************************
  26467.  
  26468. This example compares the two strings passed to main using strcmp. 
  26469.  
  26470. ************************************************************************/
  26471.  
  26472. #include <stdio.h>
  26473. #include <string.h>
  26474.  
  26475. int main(int argc,char **argv)
  26476. {
  26477.    int result;
  26478.  
  26479.    if (argc != 3) {
  26480.       printf("Usage: %s string1 string2\n", argv[0]);
  26481.    }
  26482.    else {
  26483.       result = strcmp(argv[1], argv[2]);
  26484.       if (0 == result)
  26485.          printf("\"%s\" is identical to \"%s\"\n", argv[1], argv[2]);
  26486.       else
  26487.          if (result < 0)
  26488.             printf("\"%s\" is less than \"%s\"\n", argv[1], argv[2]);
  26489.          else
  26490.             printf("\"%s\" is greater than \"%s\"\n", argv[1], argv[2]);
  26491.    }
  26492.    return 0;
  26493.  
  26494.    /****************************************************************************
  26495.       If the following arguments are passed to this program:
  26496.  
  26497.       "is this first?" "is this before that one?"
  26498.  
  26499.       The output should be:
  26500.  
  26501.       "is this first?" is greater than "is this before that one?"
  26502.    ****************************************************************************/
  26503. }
  26504.  
  26505.  
  26506. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26507.  
  26508. Example of strcmp 
  26509.  
  26510.      strcmpi - Compare Strings Without Case Sensitivity 
  26511.      strcoll - Compare Strings Using Collation Rules 
  26512.      strcspn - Compare Strings for Substrings 
  26513.      stricmp - Compare Strings as Lowercase 
  26514.      strncmp - Compare Strings 
  26515.      strnicmp - Compare Strings Without Case Sensitivity 
  26516.      wcscmp - Compare Wide-Character Strings 
  26517.      wcsncmp - Compare Wide-Character Strings 
  26518.      <string.h> 
  26519.  
  26520.  
  26521. ΓòÉΓòÉΓòÉ 4.258. strcmpi - Compare Strings Without Case Sensitivity ΓòÉΓòÉΓòÉ
  26522.  
  26523.  
  26524. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26525.  
  26526. #include <string.h>
  26527. int strcmpi(const char *string1, const char *string2);
  26528.  
  26529.  
  26530. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26531.  
  26532. Language Level:  Extension 
  26533.  
  26534. strcmpi compares string1 and string2 without sensitivity to case.  All 
  26535. alphabetic characters in the two arguments string1 and string2 are converted to 
  26536. lowercase before the comparison. 
  26537.  
  26538. The function operates on null-ended strings. The string arguments to the 
  26539. function are expected to contain a null character (\0) marking the end of the 
  26540. string. 
  26541.  
  26542. Return Value 
  26543. strcmpi returns a value indicating the relationship between the two strings, as 
  26544. follows: 
  26545.  
  26546.  Value             Meaning 
  26547.  Less than 0       string1 less than string2 
  26548.  0                 string1 equivalent to string2 
  26549.  Greater than 0    string1 greater than string2. 
  26550.  
  26551.  If n is greater than the length of string1 or string2, characters that follow 
  26552.  a null character are not compared. 
  26553.  
  26554.  
  26555. ΓòÉΓòÉΓòÉ <hidden> Example of strcmpi ΓòÉΓòÉΓòÉ
  26556.  
  26557. /************************************************************************
  26558.  
  26559. This example uses strcmpi to compare two strings. 
  26560.  
  26561. ************************************************************************/
  26562.  
  26563. #include <stdio.h>
  26564. #include <string.h>
  26565.  
  26566. int main(void)
  26567. {
  26568.  
  26569.    /* Compare two strings without regard to case                              */
  26570.  
  26571.    if (0 == strcmpi("hello", "HELLO"))
  26572.       printf("The strings are equivalent.\n");
  26573.    else
  26574.       printf("The strings are not equivalent.\n");
  26575.    return 0;
  26576.  
  26577.    /****************************************************************************
  26578.       The output should be:
  26579.  
  26580.       The strings are equivalent.
  26581.    ****************************************************************************/
  26582. }
  26583.  
  26584.  
  26585. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26586.  
  26587. Example of strcmpi 
  26588.  
  26589.      strcoll - Compare Strings Using Collation Rules 
  26590.      strcspn - Compare Strings for Substrings 
  26591.      strdup - Duplicate String 
  26592.      stricmp - Compare Strings as Lowercase 
  26593.      strncmp - Compare Strings 
  26594.      strnicmp - Compare Strings Without Case Sensitivity 
  26595.      wcscmp - Compare Wide-Character Strings 
  26596.      wcsncmp - Compare Wide-Character Strings 
  26597.      <string.h> 
  26598.  
  26599.  
  26600. ΓòÉΓòÉΓòÉ 4.259. strcoll - Compare Strings Using Collation Rules ΓòÉΓòÉΓòÉ
  26601.  
  26602.  
  26603. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26604.  
  26605. #include <string.h>
  26606. int strcoll(const char *string1, const char *string2);
  26607.  
  26608.  
  26609. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26610.  
  26611. Language Level:  ANSI, SAA, XPG4 
  26612.  
  26613. strcoll compares the string pointed to by string1 against the string pointed to 
  26614. by string2, both interpreted according to the information in the LC_COLLATE 
  26615. category of the current locale. 
  26616.  
  26617. strcoll differs from the strcmp function. strcoll performs a comparison between 
  26618. two character strings based on language collation rules as controlled by the 
  26619. LC_COLLATE category. In contrast, strcmp performs a character to character 
  26620. comparison. 
  26621.  
  26622. Return Value 
  26623. strcoll returns an integer value indicating the relationship between the 
  26624. strings, as listed below: 
  26625.  
  26626.  Value             Meaning 
  26627.  Less than 0       string1 is less than string2 
  26628.  0                 string1 is equivalent to string2 
  26629.  Greater than 0    string1 is greater than string2 
  26630.  
  26631.  Note: 
  26632.  
  26633.    1. strcoll might need to allocate additional memory to perform the 
  26634.       comparison algorithm specified in the LC_COLLATE. If the memory request 
  26635.       cannot be satisfied (by malloc), then strcoll fails. 
  26636.  
  26637.    2. If the locale supports double-byte characters (MB_CUR_MAX specified as 
  26638.       2), strcoll validates the multibyte characters. (Previously, strcoll did 
  26639.       not validate the string.) strcoll will fail if the string contains 
  26640.       invalid multibyte characters. 
  26641.  
  26642.    3. If MB_CUR_MAX is specified as 2, but the charmap file does not specify 
  26643.       the DBCS characters, the DBCS characters will collate after the 
  26644.       single-byte characters. 
  26645.  
  26646.  
  26647. ΓòÉΓòÉΓòÉ <hidden> Example of strcoll ΓòÉΓòÉΓòÉ
  26648.  
  26649. /************************************************************************
  26650.  
  26651. This example compares the two strings passed to main. 
  26652.  
  26653. ************************************************************************/
  26654.  
  26655. #include <stdio.h>
  26656. #include <string.h>
  26657.  
  26658. int main(int argc,char **argv)
  26659. {
  26660.    int result;
  26661.  
  26662.    if (argc != 3) {
  26663.       printf("Usage: %s string1 string2\n", argv[0]);
  26664.    }
  26665.    else {
  26666.       result = strcoll(argv[1], argv[2]);
  26667.       if (0 == result)
  26668.          printf("\"%s\" is identical to \"%s\"\n", argv[1], argv[2]);
  26669.       else
  26670.          if (result < 0)
  26671.             printf("\"%s\" is less than \"%s\"\n", argv[1], argv[2]);
  26672.          else
  26673.             printf("\"%s\" is greater than \"%s\"\n", argv[1], argv[2]);
  26674.    }
  26675.    return 0;
  26676.  
  26677.    /****************************************************************************
  26678.       If the program is passed the following arguments:
  26679.  
  26680.       "firststring" "secondstring"
  26681.  
  26682.       The output should be:
  26683.  
  26684.       "firststring" is less than "secondstring"
  26685.    ****************************************************************************/
  26686. }
  26687.  
  26688.  
  26689. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26690.  
  26691. Example of strcoll 
  26692.  
  26693.      setlocale - Set Locale 
  26694.      strcmp - Compare Strings 
  26695.      strcmpi - Compare Strings Without Case Sensitivity 
  26696.      strncmp - Compare Strings 
  26697.      wcscoll - Compare Wide-Character Strings 
  26698.      <string.h> 
  26699.  
  26700.  
  26701. ΓòÉΓòÉΓòÉ 4.260. strcpy - Copy Strings ΓòÉΓòÉΓòÉ
  26702.  
  26703.  
  26704. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26705.  
  26706. #include <string.h>
  26707. char *strcpy(char *string1, const char *string2);
  26708.  
  26709.  
  26710. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26711.  
  26712. Language Level: ANSI, SAA, POSIX, XPG4 
  26713.  
  26714. strcpy copies string2, including the ending null character, to the location 
  26715. specified by string1. 
  26716.  
  26717. strcpy operates on null-terminated strings. The string arguments to the 
  26718. function should contain a null character (\0) marking the end of the string. No 
  26719. length checking is performed. You should not use a literal string for a string1 
  26720. value, although string2 may be a literal string. 
  26721.  
  26722. Return Value 
  26723. strcpy returns a pointer to the copied string (string1.). 
  26724.  
  26725.  
  26726. ΓòÉΓòÉΓòÉ <hidden> Example of strcpy ΓòÉΓòÉΓòÉ
  26727.  
  26728. /************************************************************************
  26729.  
  26730. This example copies the contents of source to destination. 
  26731.  
  26732. ************************************************************************/
  26733.  
  26734. #include <stdio.h>
  26735. #include <string.h>
  26736.  
  26737. #define  SIZE          40
  26738.  
  26739. int main(void)
  26740. {
  26741.    char source[SIZE] = "123456789";
  26742.    char source1[SIZE] = "123456789";
  26743.    char destination[SIZE] = "abcdefg";
  26744.    char destination1[SIZE] = "abcdefg";
  26745.    char *return_string;
  26746.    int index = 5;
  26747.  
  26748.    /* This is how strcpy works                                                */
  26749.  
  26750.    printf("destination is originally = '%s'\n", destination);
  26751.    return_string = strcpy(destination, source);
  26752.    printf("After strcpy, destination becomes '%s'\n\n", destination);
  26753.  
  26754.    /* This is how strncpy works                                               */
  26755.  
  26756.    printf("destination1 is originally = '%s'\n", destination1);
  26757.    return_string = strncpy(destination1, source1, index);
  26758.    printf("After strncpy, destination1 becomes '%s'\n", destination1);
  26759.    return 0;
  26760.  
  26761.    /****************************************************************************
  26762.       The output should be:
  26763.  
  26764.       destination is originally = 'abcdefg'
  26765.       After strcpy, destination becomes '123456789'
  26766.  
  26767.       destination1 is originally = 'abcdefg'
  26768.       After strncpy, destination1 becomes '12345fg'
  26769.    ****************************************************************************/
  26770. }
  26771.  
  26772.  
  26773. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26774.  
  26775. Example of strcpy 
  26776.  
  26777.      strcat - Concatenate Strings 
  26778.      strdup - Duplicate String 
  26779.      strncpy - Copy Strings 
  26780.      wcscpy - Copy Wide-Character Strings 
  26781.      wcsncpy - Copy Wide-Character Strings 
  26782.      <string.h> 
  26783.  
  26784.  
  26785. ΓòÉΓòÉΓòÉ 4.261. strcspn - Compare Strings for Substrings ΓòÉΓòÉΓòÉ
  26786.  
  26787.  
  26788. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26789.  
  26790. #include <string.h>
  26791. size_t strcspn(const char *string1, const char *string2);
  26792.  
  26793.  
  26794. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26795.  
  26796. Language Level: ANSI, SAA, POSIX, XPG4 
  26797.  
  26798. strcspn finds the first occurrence of a character in string1 that belongs to 
  26799. the set of characters specified by string2. Ending null characters are not 
  26800. considered in the search. 
  26801.  
  26802. The strcspn function operates on null-terminated strings. The string arguments 
  26803. to the function should contain a null character (\0) marking the end of the 
  26804. string. 
  26805.  
  26806. Return Value 
  26807. strcspn returns the index of the first character found. This value is 
  26808. equivalent to the length of the initial substring of string1 that consists 
  26809. entirely of characters not in string2. 
  26810.  
  26811.  
  26812. ΓòÉΓòÉΓòÉ <hidden> Example of strcspn ΓòÉΓòÉΓòÉ
  26813.  
  26814. /************************************************************************
  26815.  
  26816. This example uses strcspn to find the first occurrence of any of the characters 
  26817. a, x, l or e in string. 
  26818.  
  26819. ************************************************************************/
  26820.  
  26821. #include <stdio.h>
  26822. #include <string.h>
  26823.  
  26824. #define  SIZE          40
  26825.  
  26826. int main(void)
  26827. {
  26828.    char string[SIZE] = "This is the source string";
  26829.    char *substring = "axle";
  26830.  
  26831.    printf("The first %i characters in the string \"%s\" are not in the "
  26832.       "string \"%s\" \n", strcspn(string, substring), string, substring);
  26833.    return 0;
  26834.  
  26835.    /****************************************************************************
  26836.       The output should be:
  26837.  
  26838.       The first 10 characters in the string "This is the source string" are not
  26839.       in the string "axle"
  26840.    ****************************************************************************/
  26841. }
  26842.  
  26843.  
  26844. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26845.  
  26846. Example of strcspn 
  26847.  
  26848.      strchr - Search for Character 
  26849.      strcmp - Compare Strings 
  26850.      strcmpi - Compare Strings Without Case Sensitivity 
  26851.      stricmp - Compare Strings as Lowercase 
  26852.      strncmp - Compare Strings 
  26853.      strnicmp - Compare Strings Without Case Sensitivity 
  26854.      strpbrk - Find Characters in String 
  26855.      strspn - Search Strings 
  26856.      wcscmp - Compare Wide-Character Strings 
  26857.      wcsncmp - Compare Wide-Character Strings 
  26858.      <string.h> 
  26859.  
  26860.  
  26861. ΓòÉΓòÉΓòÉ 4.262. _strdate - Copy Current Date ΓòÉΓòÉΓòÉ
  26862.  
  26863.  
  26864. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26865.  
  26866. #include <time.h>
  26867. char *_strdate(char *date);
  26868.  
  26869.  
  26870. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26871.  
  26872. Language Level:  Extension 
  26873.  
  26874. _strdate stores the current date as a string in the buffer pointed to by date 
  26875. in the following format: 
  26876.  
  26877.    mm/dd/yy
  26878.  
  26879. The two digits mm represent the month, the digits dd represent the day of the 
  26880. month, and the digits yy represent the year.  For example, the string 10/08/91 
  26881. represents October 8, 1991. The buffer must be at least 9 bytes. 
  26882.  
  26883. Note:  The time and date functions begin at 00:00:00 Coordinated Universal 
  26884. Time, January 1, 1970. 
  26885.  
  26886. Return Value 
  26887. _strdate returns a pointer to the buffer containing the date string.  There is 
  26888. no error return. 
  26889.  
  26890.  
  26891. ΓòÉΓòÉΓòÉ <hidden> Example of _strdate ΓòÉΓòÉΓòÉ
  26892.  
  26893. /************************************************************************
  26894.  
  26895. This example prints the current date. 
  26896.  
  26897. ************************************************************************/
  26898.  
  26899. #include <stdio.h>
  26900. #include <time.h>
  26901.  
  26902. int main(void)
  26903. {
  26904.    char buffer[9];
  26905.  
  26906.    printf("The current date is %s \n", _strdate(buffer));
  26907.    return 0;
  26908.  
  26909.    /****************************************************************************
  26910.       The output should be similar to:
  26911.  
  26912.       The current date is 01/02/95
  26913.    ****************************************************************************/
  26914. }
  26915.  
  26916.  
  26917. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26918.  
  26919. Example of _strdate 
  26920.  
  26921.      asctime - Convert Time to Character String 
  26922.      ctime - Convert Time to Character String 
  26923.      _ftime - Store Current Time 
  26924.      gmtime - Convert Time 
  26925.      localtime - Convert Time 
  26926.      mktime - Convert Local Time 
  26927.      time - Determine Current Time 
  26928.      tzset - Assign Values to Locale Information 
  26929.      <time.h> 
  26930.  
  26931.  
  26932. ΓòÉΓòÉΓòÉ 4.263. strdup - Duplicate String ΓòÉΓòÉΓòÉ
  26933.  
  26934.  
  26935. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26936.  
  26937. #include <string.h>
  26938. char *strdup(const char *string);
  26939.  
  26940.  
  26941. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26942.  
  26943. Language Level:  XPG4, Extension 
  26944.  
  26945. strdup reserves storage space for a copy of string by calling malloc. The 
  26946. string argument to this function is expected to contain a null character (\0) 
  26947. marking the end of the string. Remember to free the storage reserved with the 
  26948. call to strdup. 
  26949.  
  26950. Return Value 
  26951. strdup returns a pointer to the storage space containing the copied string. If 
  26952. it cannot reserve storage strdup returns NULL. 
  26953.  
  26954.  
  26955. ΓòÉΓòÉΓòÉ <hidden> Example of strdup ΓòÉΓòÉΓòÉ
  26956.  
  26957. /************************************************************************
  26958.  
  26959. This example uses strdup to duplicate a string and print the copy. 
  26960.  
  26961. ************************************************************************/
  26962.  
  26963. #include <stdio.h>
  26964. #include <string.h>
  26965.  
  26966. int main(void)
  26967. {
  26968.    char *string = "this is a copy";
  26969.    char *newstr;
  26970.  
  26971.    /* Make newstr point to a duplicate of string                              */
  26972.  
  26973.    if ((newstr = strdup(string)) != NULL)
  26974.       printf("The new string is: %s\n", newstr);
  26975.    return 0;
  26976.  
  26977.    /****************************************************************************
  26978.       The output should be:
  26979.  
  26980.       The new string is: this is a copy
  26981.    ****************************************************************************/
  26982. }
  26983.  
  26984.  
  26985. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26986.  
  26987. Example of strdup 
  26988.  
  26989.      strcpy - Copy Strings 
  26990.      strncpy - Copy Strings 
  26991.      wcscpy - Copy Wide-Character Strings 
  26992.      wcsncpy - Copy Wide-Character Strings 
  26993.      <string.h> 
  26994.  
  26995.  
  26996. ΓòÉΓòÉΓòÉ 4.264. strerror - Set Pointer to Runtime Error Message ΓòÉΓòÉΓòÉ
  26997.  
  26998.  
  26999. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  27000.  
  27001. #include <string.h>
  27002. char *strerror(int errnum);
  27003.  
  27004.  
  27005. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  27006.  
  27007. Language Level:  ANSI, SAA, XPG4 
  27008.  
  27009. strerror maps the error number in errnum to an error message string. 
  27010.  
  27011. Return Value 
  27012. strerror returns a pointer to the string. It does not use the program locale in 
  27013. any way. 
  27014.  
  27015. The value of errno may be set to: 
  27016.  
  27017.  EILSEQ  An encoding error has occurred converting a multibyte character. 
  27018.  E2BIG   The output buffer is too small. 
  27019.  
  27020.  
  27021. ΓòÉΓòÉΓòÉ <hidden> Example of strerror ΓòÉΓòÉΓòÉ
  27022.  
  27023. /************************************************************************
  27024.  
  27025. This example opens a file and prints a runtime error message if an error 
  27026. occurs. 
  27027.  
  27028. ************************************************************************/
  27029.  
  27030. #include <stdio.h>
  27031. #include <string.h>
  27032. #include <errno.h>
  27033.  
  27034. #define FILENAME "strerror.dat"
  27035.  
  27036. int main(void)
  27037. {
  27038.    FILE *stream;
  27039.  
  27040.    if (NULL == (stream = fopen(FILENAME, "r")))
  27041.       printf(" %s \n", strerror(errno));
  27042.    return 0;
  27043. }
  27044.  
  27045.  
  27046. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27047.  
  27048. Example of strerror 
  27049.  
  27050.      clearerr - Reset Error Indicators 
  27051.      ferror - Test for Read/Write Errors 
  27052.      perror - Print Error Message 
  27053.      _strerror - Set Pointer to System Error String 
  27054.      <string.h> 
  27055.  
  27056.  
  27057. ΓòÉΓòÉΓòÉ 4.265. _strerror - Set Pointer to System Error String ΓòÉΓòÉΓòÉ
  27058.  
  27059.  
  27060. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  27061.  
  27062. #include <string.h>
  27063. char *_strerror(char *string);
  27064.  
  27065.  
  27066. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  27067.  
  27068. Language Level:  Extension 
  27069.  
  27070. _strerror tests for system error. It gets the system error message for the last 
  27071. library call that produced an error and prefaces it with your string message. 
  27072.  
  27073. Your string message can be a maximum of 94 bytes. 
  27074.  
  27075. Unlike perror, _strerror by itself does not print a message.  To print the 
  27076. message returned by _strerror to stdout, use a printf statement similar to the 
  27077. following: 
  27078.  
  27079.    if ((access("datafile",2)) == -1)
  27080.       printf(stderr,_strerror(NULL));
  27081.  
  27082. You could also print the message with an fprintf statement. 
  27083.  
  27084. To produce accurate results, call _strerror immediately after a library 
  27085. function returns with an error. Otherwise, subsequent calls might write over 
  27086. the errno value. 
  27087.  
  27088. Return Value 
  27089. If string is equal to NULL, _strerror returns a pointer to a string containing 
  27090. the system error message for the last library call that produced an error, 
  27091. ended by a new-line character (\n). 
  27092.  
  27093. If string is not equal to NULL, _strerror returns a pointer to a string 
  27094. containing: 
  27095.  
  27096.      Your string message 
  27097.      A colon 
  27098.      A space 
  27099.      The system error message for the last library call producing an error 
  27100.      A new-line character (\n). 
  27101.  
  27102.  
  27103. ΓòÉΓòÉΓòÉ <hidden> Example of _strerror ΓòÉΓòÉΓòÉ
  27104.  
  27105. /************************************************************************
  27106.  
  27107. This example shows how _strerror can be used with the fopen function. 
  27108.  
  27109. ************************************************************************/
  27110.  
  27111. #include <string.h>
  27112. #include <stdio.h>
  27113.  
  27114. #define INFILE    "_strerro.in"
  27115. #define OUTFILE   "_strerro.out"
  27116.  
  27117. int main(void)
  27118. {
  27119.    FILE *fh1,*fh2;
  27120.  
  27121.    fh1 = fopen(INFILE, "r");
  27122.    if (NULL == fh1)
  27123.      /*  the error message goes through stdout not stderr                     */
  27124.       printf(_strerror("Open failed on input file"));
  27125.    fh2 = fopen(OUTFILE, "w+");
  27126.    if (NULL == fh2)
  27127.       printf(_strerror("Open failed on output file"));
  27128.    else
  27129.       printf("Open on output file was successful.\n");
  27130.    if (fh1 != NULL)
  27131.       fclose(fh1);
  27132.    if (fh2 != NULL)
  27133.       fclose(fh2);
  27134.    remove(OUTFILE);
  27135.    return 0;
  27136.  
  27137.    /****************************************************************************
  27138.       The output should be:
  27139.  
  27140.       Open failed on input file: The file cannot be found.
  27141.       Open on output file was successful.
  27142.    ****************************************************************************/
  27143. }
  27144.  
  27145.  
  27146. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27147.  
  27148. Example of _strerror 
  27149.  
  27150.      clearerr - Reset Error Indicators 
  27151.      ferror - Test for Read/Write Errors 
  27152.      perror - Print Error Message 
  27153.      strerror - Set Pointer to Runtime Error Message 
  27154.      <string.h> 
  27155.  
  27156.  
  27157. ΓòÉΓòÉΓòÉ 4.266. strfmon - Convert Monetary Value to String ΓòÉΓòÉΓòÉ
  27158.  
  27159.  
  27160. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  27161.  
  27162. #include <monetary.h>
  27163. int strfmon(char *s, size_t maxsize, const char *format, ...);
  27164.  
  27165.  
  27166. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  27167.  
  27168. Language Level:  XPG4 
  27169.  
  27170. strfmon places characters into the array pointed to by s, as controlled by the 
  27171. string pointed to by format. No more than maxsize characters are placed into 
  27172. the array. 
  27173.  
  27174. The character string format contains two types of objects: 
  27175.  
  27176.      Plain characters, which are copied to the output array. 
  27177.      Directives, each of which results in the fetching of zero or more 
  27178.       arguments that are converted and formatted. 
  27179.  
  27180.  The results are undefined if there are insufficient arguments for the format. 
  27181.  If the format is exhausted while arguments remain, the excess arguments are 
  27182.  simply ignored. If objects pointed to by s and format overlap, the behavior is 
  27183.  undefined. 
  27184.  
  27185.  The directive (conversion specification) consists of the following sequence. 
  27186.  
  27187.    1. A % character 
  27188.  
  27189.    2. Optional flags, described below: =f, ^, then +, C, (, then ! 
  27190.  
  27191.    3. Optional field width (may be preceded by -) 
  27192.  
  27193.    4. Optional left precision: #n 
  27194.  
  27195.    5. Optional right precision: .p 
  27196.  
  27197.    6. Required conversion character to indicate what conversion should be 
  27198.       performed: i or n. 
  27199.  
  27200.  Each directive is replaced by the appropriate characters, as described in the 
  27201.  following list: 
  27202.  
  27203.  %i          The double argument is formatted according to the locale's 
  27204.              international currency format (for example, in USA: USD 1,234.56). 
  27205.  
  27206.  %n          The double argument is formatted according to the locale's 
  27207.              national currency format (for example, in USA: $1,234.56). 
  27208.  
  27209.  %% is replaced by %. No argument is converted. 
  27210.  
  27211.  You can give optional conversion specifications immediately after the initial 
  27212.  % of a directive in the following order: 
  27213.  
  27214.  Specifier   Meaning 
  27215.  
  27216.  =f          Specifies f as the numeric fill character. This flag is used in 
  27217.              conjunction with the maximum digits specification #n (see below). 
  27218.              The default numeric fill character is the space character. This 
  27219.              option does not affect the other fill operations that always use a 
  27220.              space as the fill character. 
  27221.  
  27222.  ^           Formats the currency amount without thousands grouping characters. 
  27223.              The default is to insert the grouping characters if defined for 
  27224.              the current locale. 
  27225.  
  27226.  + | C | (   Specifies the style of representing positive and negative currency 
  27227.              amounts. You can specify only one of +, C, or (. The + specifies 
  27228.              to use the locale's equivalent of + and -. C specifies to use the 
  27229.              locale's equivalent of DB for negative and CR for positive. The ( 
  27230.              specifies to use the locale's equivalent of enclosing negative 
  27231.              amounts within parenthesis. If this option is not included, a 
  27232.              default specified by the current locale is used. 
  27233.  
  27234.  !           Suppresses the currency symbol from the output conversion. 
  27235.  
  27236.  [-]w        A decimal digit string that specifies a minimum field width in 
  27237.              which the result of the conversion is right-justified (or 
  27238.              left-justified if the - flag is specified). 
  27239.  
  27240.  #n          A decimal digit string that specifies a maximum number of digits 
  27241.              expected to be formatted to the left of the radix character. You 
  27242.              can use this option to keep the formatted output from multiple 
  27243.              calls to strfmon aligned in the same columns. You can also use it 
  27244.              to fill unused positions with a special character, as in 
  27245.              $***123.45. This option causes an amount to be formatted as if it 
  27246.              has the number of digits specified by n. If more digit positions 
  27247.              are required than specified, this conversion specification is 
  27248.              ignored. Digit positions in excess of those actually required are 
  27249.              filled with the numeric fill character. (See the =f specification 
  27250.              above). 
  27251.  
  27252.              If thousands grouping is enabled, the behavior is: 
  27253.  
  27254.                1. Format the number as if it is an n digit number. 
  27255.  
  27256.                2. Insert fill characters to the left of the leftmost digit (for 
  27257.                   example, $0001234.56 or $***1234.56). 
  27258.  
  27259.                3. Insert the separator character (for example, $0,001,234.56 or 
  27260.                   $*,**1,234.56). 
  27261.  
  27262.                4. If the fill character is not the digit zero, the separators 
  27263.                   are replaced by the fill character (for example, 
  27264.                   $****1,234.56). 
  27265.  
  27266.              To ensure alignment, any characters appearing before or after the 
  27267.              number in the formatted output, such as currency or sign symbols, 
  27268.              are padded with space characters to make their positive and 
  27269.              negative formats an equal length. 
  27270.  
  27271.  .p          A decimal digit string that specifies the number of digits after 
  27272.              the radix character. If the value of the precision p is 0, no 
  27273.              radix character appears. If this option is not included, a default 
  27274.              specified by the current locale is used. The amount being 
  27275.              formatted is rounded to the specified number of digits prior to 
  27276.              formatting. 
  27277.  
  27278.  The LC_MONETARY category of the program's locale affects the behavior of this 
  27279.  function, including the monetary radix character (which is different from the 
  27280.  numeric radix character affected by the LC_NUMERIC category), the thousands 
  27281.  (or alternate grouping) separator, the currency symbols, and formats. The 
  27282.  international currency symbol should be in accordance with those specified in 
  27283.  ISO 4217 Codes for the representation of currencies and funds. 
  27284.  
  27285.  Return Value 
  27286.  If the total number of resulting bytes including the terminating null 
  27287.  character is not more than maxsize, strfmon returns the number of bytes placed 
  27288.  into the array pointed to by s, not including the terminating null character. 
  27289.  Otherwise, strfmon returns -1 and the contents of the array are indeterminate. 
  27290.  
  27291.  
  27292. ΓòÉΓòÉΓòÉ <hidden> Example of strfmon ΓòÉΓòÉΓòÉ
  27293.  
  27294. /************************************************************************
  27295.  
  27296. This example uses strfmon to format the monetary value for money, then prints 
  27297. the resulting string. 
  27298.  
  27299. ************************************************************************/
  27300.  
  27301. #include <monetary.h>
  27302. #include <locale.h>
  27303. #include <stdio.h>
  27304. #include <stdlib.h>
  27305.  
  27306. #if (1 == __TOS_OS2__)
  27307.    #define LOCNAME "en_us.ibm-437"     /* OS/2 name        */
  27308. #else
  27309.    #define LOCNAME "en_us.ibm-1252"    /* Windows name     */
  27310. #endif
  27311.  
  27312. int main(void)
  27313. {
  27314.    char   string[100];     /* hold the string returned from strfmon() */
  27315.    double money = 1234.56;
  27316.  
  27317.    if (NULL == setlocale(LC_ALL, LOCNAME)) {
  27318.       printf("Locale \"%s\" could not be loaded\n", LOCNAME);
  27319.       exit(1);
  27320.    }
  27321.    strfmon(string, 100, "%i", money);
  27322.    printf("International currency format = \"%s\"\n", string);
  27323.    strfmon(string, 100, "%n", money);
  27324.    printf("National currency format      = \"%s\"\n", string);
  27325.    return 0;
  27326.  
  27327.    /****************************************************************************
  27328.       The output should be similar to :
  27329.  
  27330.       International currency format = "USD 1,234.56"
  27331.       National currency format      = "$1,234.56"
  27332.    ****************************************************************************/
  27333. }
  27334.  
  27335.  
  27336. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27337.  
  27338. Example of strfmon 
  27339.  
  27340.      strftime - Convert to Formatted Time 
  27341.      <monetary.h> 
  27342.  
  27343.  
  27344. ΓòÉΓòÉΓòÉ 4.267. strftime - Convert to Formatted Time ΓòÉΓòÉΓòÉ
  27345.  
  27346.  
  27347. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  27348.  
  27349. #include <time.h>
  27350. size_t strftime(char *dest, size_t maxsize,
  27351.                 const char *format, const struct tm *timeptr);
  27352.  
  27353.  
  27354. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  27355.  
  27356. Language Level:  ANSI, SAA, XPG4, POSIX 
  27357.  
  27358. strftime converts the time and date specification in the timeptr structure into 
  27359. a character string.  It then stores the null-terminated string in the array 
  27360. pointed to by dest according to the format string pointed to by format. maxsize 
  27361. specifies the maximum number of characters that can be copied into the array. 
  27362.  
  27363. The format string is a multibyte character string containing: 
  27364.  
  27365.      Conversion specification characters, preceded by a % sign. 
  27366.      Ordinary multibyte characters, which are copied into the array unchanged. 
  27367.  
  27368.  If data has the form of a conversion specifier, but is not one of the accepted 
  27369.  specifiers, the characters following the % are copied to the output. 
  27370.  
  27371.  The characters that are converted are determined by the LC_TIME category of 
  27372.  the current locale and by the values in the time structure pointed to by 
  27373.  timeptr. The time structure pointed to by timeptr is usually obtained by 
  27374.  calling the gmtime or localtime function. 
  27375.  
  27376.  When objects to be copied overlap, the behavior is undefined. 
  27377.  
  27378.  strftime obtains time zone information from an internal structure. You can set 
  27379.  the values in this structure by calling tzset which sets the structure 
  27380.  according to the information in the TZ environment variable. If you do not set 
  27381.  the values by calling this function, the defaults used are EST for time zone 
  27382.  name, EDT for Daylight Savings time zone name, and 300 minutes for the 
  27383.  difference between the standard time zone and the coordinated universal time. 
  27384.  
  27385.  Return Value 
  27386.  If the total number of characters in the resulting string, including the 
  27387.  terminating null character, does not exceed maxsize, strftime returns the 
  27388.  number of characters (bytes) placed into dest, not including the terminating 
  27389.  null character. Otherwise, strftime returns 0 and the content of the string is 
  27390.  indeterminate. 
  27391.  
  27392.  
  27393. ΓòÉΓòÉΓòÉ <hidden> Example of strftime ΓòÉΓòÉΓòÉ
  27394.  
  27395. /************************************************************************
  27396.  
  27397. This example gets the time and date from localtime, calls strftime to format 
  27398. it, and prints the resulting string. 
  27399.  
  27400. ************************************************************************/
  27401.  
  27402. #include <stdio.h>
  27403. #include <time.h>
  27404.  
  27405. int main(void)
  27406. {
  27407.    char dest[70];
  27408.    int ch;
  27409.    time_t temp;
  27410.    struct tm *timeptr;
  27411.  
  27412.    temp = time(NULL);
  27413.    timeptr = localtime(&temp);
  27414.    ch = strftime(dest, sizeof(dest)-1, "Today is %A,"" %b %d. \n Time: %I:%M %p"
  27415.       , timeptr);
  27416.    printf("%d characters placed in string to make: \n \n %s", ch, dest);
  27417.    return 0;
  27418.  
  27419.    /****************************************************************************
  27420.       The output should be similar to:
  27421.  
  27422.       41 characters placed in string to make:
  27423.        Today is Monday, Sep 16.
  27424.        Time: 06:31 pm
  27425.    ****************************************************************************/
  27426. }
  27427.  
  27428.  
  27429. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27430.  
  27431. Example of strftime 
  27432.  
  27433.      Conversion Specifiers Used by strftime 
  27434.      asctime - Convert Time to Character String 
  27435.      ctime - Convert Time to Character String 
  27436.      gmtime - Convert Time 
  27437.      localtime - Convert Time 
  27438.      setlocale - Set Locale 
  27439.      strptime - Convert to Formatted Date and Time 
  27440.      time - Determine Current Time 
  27441.      wcsftime - Convert to Formatted Date and Time 
  27442.      <time.h> 
  27443.  
  27444.  
  27445. ΓòÉΓòÉΓòÉ 4.267.1. Conversion Specifiers Used by strftime ΓòÉΓòÉΓòÉ
  27446.  
  27447. The following table lists the strftime conversion specifiers: 
  27448.  
  27449. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  27450. Γöé SPECIFIER     Γöé MEANING                          Γöé
  27451. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27452. Γöé %a        Γöé Replace with abbreviated weekday name of locale.      Γöé
  27453. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27454. Γöé %A        Γöé Replace with full weekday name of locale.         Γöé
  27455. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27456. Γöé %b        Γöé Replace with abbreviated month name of locale.       Γöé
  27457. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27458. Γöé %B        Γöé Replace with full month name of locale.          Γöé
  27459. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27460. Γöé %c        Γöé Replace with date and time of locale.           Γöé
  27461. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27462. Γöé %C        Γöé Replace with locale's century number (year divided by 100 Γöé
  27463. Γöé          Γöé and truncated)                       Γöé
  27464. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27465. Γöé %d        Γöé Replace with day of the month (01-31).           Γöé
  27466. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27467. Γöé %D        Γöé Insert date in mm/dd/yy form, regardless of locale.    Γöé
  27468. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27469. Γöé %e        Γöé Insert month of the year as a decimal number ("01"-"12"). Γöé
  27470. Γöé          Γöé                              Γöé
  27471. Γöé          Γöé Under POSIX, it's a 2-character, right-justified, blank-  Γöé
  27472. Γöé          Γöé filled field.                       Γöé
  27473. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27474. Γöé %E[cCxXyY]    Γöé If the alternate date/time format is not available, the  Γöé
  27475. Γöé          Γöé %E descriptors are mapped to their unextended counter-   Γöé
  27476. Γöé          Γöé parts.  For example, %EC is mapped to %C.         Γöé
  27477. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27478. Γöé %Ec        Γöé Replace with the locale's alternative date and time rep-  Γöé
  27479. Γöé          Γöé resentation.                        Γöé
  27480. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27481. Γöé %EC        Γöé Replace with the name of the base year (period) in the   Γöé
  27482. Γöé          Γöé locale's alternate representation.             Γöé
  27483. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27484. Γöé %Ex        Γöé Replace with the locale's alternative date represen-    Γöé
  27485. Γöé          Γöé tation.                          Γöé
  27486. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27487. Γöé %EX        Γöé Replace with the locale's alternative time represen-    Γöé
  27488. Γöé          Γöé tation.                          Γöé
  27489. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27490. Γöé %Ey        Γöé Replace with the offset from %EC (year only) in the    Γöé
  27491. Γöé          Γöé locale's alternate representation.             Γöé
  27492. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27493. Γöé %EY        Γöé Replace with the full alternative year representation.   Γöé
  27494. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27495. Γöé %h        Γöé Replace with locale's abbreviated month name. This is the Γöé
  27496. Γöé          Γöé same as %b.                        Γöé
  27497. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27498. Γöé %H        Γöé Replace with hour (24-hour clock) as a decimal number   Γöé
  27499. Γöé          Γöé (00-23).                          Γöé
  27500. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27501. Γöé %I        Γöé Replace with hour (12-hour clock) as a decimal number   Γöé
  27502. Γöé          Γöé (01-12).                          Γöé
  27503. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27504. Γöé %j        Γöé Replace with day of the year (001-366).          Γöé
  27505. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27506. Γöé %m        Γöé Replace with month (01-12).                Γöé
  27507. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27508. Γöé %M        Γöé Replace with minute (00-59).                Γöé
  27509. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27510. Γöé %n        Γöé Replace with a new line.                  Γöé
  27511. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27512. Γöé %O[deHImMSUwWy]  Γöé                              Γöé
  27513. Γöé          Γöé                              Γöé
  27514. Γöé          Γöé If the alternative date/time format is not available, the Γöé
  27515. Γöé          Γöé %O descriptors are mapped to their unextended counter-   Γöé
  27516. Γöé          Γöé parts.  For example, %Od is mapped to %d.         Γöé
  27517. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27518. Γöé %Od        Γöé Replace with the day of month, using the locale's alter-  Γöé
  27519. Γöé          Γöé native numeric symbols, filled as needed with leading   Γöé
  27520. Γöé          Γöé zeroes if there is any alternative symbol for zero; oth-  Γöé
  27521. Γöé          Γöé erwise fill with leading spaces.              Γöé
  27522. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27523. Γöé %Oe        Γöé Replace with the day of the month, using the locale's   Γöé
  27524. Γöé          Γöé alternative numeric symbols, filled as needed with     Γöé
  27525. Γöé          Γöé leading spaces.                      Γöé
  27526. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27527. Γöé %OH        Γöé Replace with the hour (24-hour clock), using the locale's Γöé
  27528. Γöé          Γöé alternative numeric symbols.                Γöé
  27529. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27530. Γöé %OI        Γöé Replace with the hour (12-hour clock), using the locale's Γöé
  27531. Γöé          Γöé alternative numeric symbols.                Γöé
  27532. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  27533. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  27534. Γöé %Om        Γöé Replace with the month, using the locale's alternative   Γöé
  27535. Γöé          Γöé numeric symbols.                      Γöé
  27536. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27537. Γöé %OM        Γöé Replace with the minutes, using the locale's alternative  Γöé
  27538. Γöé          Γöé numeric symbols.                      Γöé
  27539. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27540. Γöé %OS        Γöé Replace with the seconds, using the locale's alternative  Γöé
  27541. Γöé          Γöé numeric symbols.                      Γöé
  27542. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27543. Γöé %Ou        Γöé Replace with the weekday as a decimal number (1 to 7),   Γöé
  27544. Γöé          Γöé with 1 representing Monday, using the locale's alterna-  Γöé
  27545. Γöé          Γöé tive numeric symbols.                   Γöé
  27546. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27547. Γöé %OU        Γöé Replace with the week number of the year (00-53), where  Γöé
  27548. Γöé          Γöé Sunday is the first day of the week, using the locale's  Γöé
  27549. Γöé          Γöé alternative numeric symbols.                Γöé
  27550. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27551. Γöé %OV        Γöé Replace with week number of the year (01-53), where    Γöé
  27552. Γöé          Γöé Monday is the first day of the week, using the locale's  Γöé
  27553. Γöé          Γöé alternative numeric symbols.                Γöé
  27554. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27555. Γöé %Ow        Γöé Replace with the weekday (Sunday=0), using the locale's  Γöé
  27556. Γöé          Γöé alternative numeric symbols.                Γöé
  27557. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27558. Γöé %OW        Γöé Replace with the week number of the year (01-53), where  Γöé
  27559. Γöé          Γöé Monday is the first day of the week, using the locale's  Γöé
  27560. Γöé          Γöé alternative numeric symbols.                Γöé
  27561. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27562. Γöé %Oy        Γöé Replace with the year (offset from %C) in the locale's   Γöé
  27563. Γöé          Γöé alternative representation, using the locale's alterna-  Γöé
  27564. Γöé          Γöé tive numeric symbols.                   Γöé
  27565. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27566. Γöé %p        Γöé Replace with the locale's equivalent of AM or PM.     Γöé
  27567. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27568. Γöé %r        Γöé Replace with a string equivalent to %I:%M:%S %p; or use  Γöé
  27569. Γöé          Γöé "t_fmt_ampm" from LC_TIME, if present.           Γöé
  27570. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27571. Γöé %R        Γöé Replace with time in 24 hour notation (%H:%M)       Γöé
  27572. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27573. Γöé %S        Γöé Replace with second (00-61).                Γöé
  27574. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27575. Γöé %t        Γöé Replace with a tab.                    Γöé
  27576. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27577. Γöé %T        Γöé Replace with a string equivalent to %H:%M:%S.       Γöé
  27578. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27579. Γöé %u        Γöé Replace with the weekday as a decimal number (1 to 7),   Γöé
  27580. Γöé          Γöé with 1 representing Monday.                Γöé
  27581. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27582. Γöé %U        Γöé Replace with week number of the year (00-53), where    Γöé
  27583. Γöé          Γöé Sunday is the first day of the week.            Γöé
  27584. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27585. Γöé %V        Γöé Replace with week number of the year (01-53), where    Γöé
  27586. Γöé          Γöé Monday is the first day of the week.            Γöé
  27587. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27588. Γöé %w        Γöé Replace with weekday (0-6), where Sunday is 0.       Γöé
  27589. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27590. Γöé %W        Γöé Replace with week number of the year (00-53), where    Γöé
  27591. Γöé          Γöé Monday is the first day of the week.            Γöé
  27592. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27593. Γöé %x        Γöé Replace with date representation of locale.        Γöé
  27594. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27595. Γöé %X        Γöé Replace with time representation of locale.        Γöé
  27596. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27597. Γöé %y        Γöé Replace with year without the century (00-99).       Γöé
  27598. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27599. Γöé %Y        Γöé Replace with year including the century.          Γöé
  27600. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27601. Γöé %Z        Γöé Replace with name of time zone, or no characters if time  Γöé
  27602. Γöé          Γöé zone is not available.                   Γöé
  27603. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  27604. Γöé %%        Γöé Replace with %.                      Γöé
  27605. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  27606.  
  27607. For %Z, the tm_isdst flag in the tm structure passed to strftime specifies 
  27608. whether the time zone is standard or Daylight Savings time. 
  27609.  
  27610. If data has the form of a directive, but is not one of the above, the 
  27611. characters following the % are copied to the output. 
  27612.  
  27613.  
  27614. ΓòÉΓòÉΓòÉ 4.268. stricmp - Compare Strings as Lowercase ΓòÉΓòÉΓòÉ
  27615.  
  27616.  
  27617. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  27618.  
  27619. #include <string.h>
  27620. int stricmp(const char *string1, const char *string2);
  27621.  
  27622.  
  27623. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  27624.  
  27625. Language Level:  Extension 
  27626.  
  27627. stricmp compares string1 and string2 without sensitivity for case. All 
  27628. alphabetic characters in the arguments string1 and string2 are converted to 
  27629. lowercase before the comparison. stricmp operates on null-terminated strings. 
  27630.  
  27631. Return Value 
  27632. stricmp returns a value that indicates the following relationship between the 
  27633. two strings: 
  27634.  
  27635.  Value             Meaning 
  27636.  Less than 0       string1 less than string2 
  27637.  0                 string1 identical to string2 
  27638.  Greater than 0    string1 greater than string2. 
  27639.  
  27640.  
  27641. ΓòÉΓòÉΓòÉ <hidden> Example of stricmp ΓòÉΓòÉΓòÉ
  27642.  
  27643. /************************************************************************
  27644.  
  27645. This example uses stricmp to compare two strings. 
  27646.  
  27647. ************************************************************************/
  27648.  
  27649. #include <stdio.h>
  27650. #include <string.h>
  27651.  
  27652. int main(void)
  27653. {
  27654.    char *str1 = "this is a string";
  27655.    char *str2 = "THIS IS A STRING";
  27656.  
  27657.    /* Compare two strings without regard to case                              */
  27658.  
  27659.    if (stricmp(str1, str2))
  27660.       printf("str1 is not the same as str2\n");
  27661.    else
  27662.       printf("str1 is the same as str2\n");
  27663.    return 0;
  27664.  
  27665.    /****************************************************************************
  27666.       The output should be:
  27667.  
  27668.       str1 is the same as str2
  27669.    ****************************************************************************/
  27670. }
  27671.  
  27672.  
  27673. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27674.  
  27675. Example of stricmp 
  27676.  
  27677.      strcmp - Compare Strings 
  27678.      strcmpi - Compare Strings Without Case Sensitivity 
  27679.      strcspn - Compare Strings for Substrings 
  27680.      strncmp - Compare Strings 
  27681.      strnicmp - Compare Strings Without Case Sensitivity 
  27682.      wcscmp - Compare Wide-Character Strings 
  27683.      wcsncmp - Compare Wide-Character Strings 
  27684.      <string.h> 
  27685.  
  27686.  
  27687. ΓòÉΓòÉΓòÉ 4.269. strlen - Determine String Length ΓòÉΓòÉΓòÉ
  27688.  
  27689.  
  27690. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  27691.  
  27692. #include <string.h>
  27693. size_t strlen(const char *string);
  27694.  
  27695.  
  27696. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  27697.  
  27698. Language Level: ANSI, SAA, POSIX, XPG4 
  27699.  
  27700. strlen determines the length of string excluding the terminating null 
  27701. character. 
  27702.  
  27703. Return Value 
  27704. strlen returns the length of string. 
  27705.  
  27706.  
  27707. ΓòÉΓòÉΓòÉ <hidden> Example of strlen ΓòÉΓòÉΓòÉ
  27708.  
  27709. /************************************************************************
  27710.  
  27711. This example determines the length of the string that is a constant within 
  27712. main. 
  27713.  
  27714. ************************************************************************/
  27715.  
  27716. #include <stdio.h>
  27717. #include <string.h>
  27718.  
  27719. int main(int argc,char **argv)
  27720. {
  27721.    char *String = "How long is this string?";
  27722.  
  27723.    printf("Length of string \"%s\" is %i.\n", String, strlen(String));
  27724.    return 0;
  27725.  
  27726.    /****************************************************************************
  27727.       The output should be:
  27728.  
  27729.       Length of string "How long is this string?" is 24.
  27730.    ****************************************************************************/
  27731. }
  27732.  
  27733.  
  27734. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27735.  
  27736. Example of strlen 
  27737.  
  27738.      mblen - Determine Length of Multibyte Character 
  27739.      strrev - Reverse String 
  27740.      wcslen - Calculate Length of Wide-Character String 
  27741.      <string.h> 
  27742.  
  27743.  
  27744. ΓòÉΓòÉΓòÉ 4.270. strlwr - Convert Uppercase to Lowercase ΓòÉΓòÉΓòÉ
  27745.  
  27746.  
  27747. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  27748.  
  27749. #include <string.h>
  27750. char *strlwr(char *string);
  27751.  
  27752.  
  27753. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  27754.  
  27755. Language Level:  Extension 
  27756.  
  27757. strlwr converts any uppercase letters in the given null-terminated string to 
  27758. lowercase.  Other characters are not affected. 
  27759.  
  27760. Return Value 
  27761. strlwr returns a pointer to the converted string. There is no error return. 
  27762.  
  27763.  
  27764. ΓòÉΓòÉΓòÉ <hidden> Example of strlwr ΓòÉΓòÉΓòÉ
  27765.  
  27766. /************************************************************************
  27767.  
  27768. This example makes a copy in all lowercase of the string "General Assembly", 
  27769. and then prints the copy. 
  27770.  
  27771. ************************************************************************/
  27772.  
  27773. #include <string.h>
  27774. #include <stdio.h>
  27775.  
  27776. int main(void)
  27777. {
  27778.    char *string = "General Assembly";
  27779.    char *copy;
  27780.  
  27781.    copy = strlwr(strdup(string));
  27782.    printf("Expected result: general assembly\n");
  27783.    printf("strlwr returned: %s\n", copy);
  27784.    return 0;
  27785.  
  27786.    /****************************************************************************
  27787.       The output should be:
  27788.  
  27789.       Expected result: general assembly
  27790.       strlwr returned: general assembly
  27791.    ****************************************************************************/
  27792. }
  27793.  
  27794.  
  27795. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27796.  
  27797. Example of strlwr 
  27798.  
  27799.      strupr - Convert Lowercase to Uppercase 
  27800.      _toascii - _tolower - _toupper - Convert Character 
  27801.      tolower() - toupper() - Convert Character Case 
  27802.      towlower - towupper - Convert Wide Character Case 
  27803.      <string.h> 
  27804.  
  27805.  
  27806. ΓòÉΓòÉΓòÉ 4.271. strncat - Concatenate Strings ΓòÉΓòÉΓòÉ
  27807.  
  27808.  
  27809. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  27810.  
  27811. #include <string.h>
  27812. char *strncat(char *string1, const char *string2, size_t count);
  27813.  
  27814.  
  27815. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  27816.  
  27817. Language Level: ANSI, SAA, POSIX, XPG4 
  27818.  
  27819. strncat appends the first count characters of string2 to string1 and ends the 
  27820. resulting string with a null character (\0). If count is greater than the 
  27821. length of string2, the length of string2 is used in place of count. 
  27822.  
  27823. The strncat function operates on null-terminated strings. The string argument 
  27824. to the function should contain a null character (\0) marking the end of the 
  27825. string. 
  27826.  
  27827. Return Value 
  27828. strncat returns a pointer to the joined string (string1). 
  27829.  
  27830.  
  27831. ΓòÉΓòÉΓòÉ <hidden> Example of strncat ΓòÉΓòÉΓòÉ
  27832.  
  27833. /************************************************************************
  27834.  
  27835. This example demonstrates the difference between strcat and strncat. strcat 
  27836. appends the entire second string to the first, whereas strncat appends only the 
  27837. specified number of characters in the second string to the first. 
  27838.  
  27839. ************************************************************************/
  27840.  
  27841. #include <stdio.h>
  27842. #include <string.h>
  27843.  
  27844. #define  SIZE          40
  27845.  
  27846. int main(void)
  27847. {
  27848.    char buffer1[SIZE] = "computer";
  27849.    char *ptr;
  27850.  
  27851.    /* Call strcat with buffer1 and " program"                                 */
  27852.  
  27853.    ptr = strcat(buffer1, " program");
  27854.    printf("strcat : buffer1 = \"%s\"\n", buffer1);
  27855.  
  27856.    /* Reset buffer1 to contain just the string "computer" again               */
  27857.  
  27858.    memset(buffer1, '\0', sizeof(buffer1));
  27859.    ptr = strcpy(buffer1, "computer");
  27860.  
  27861.    /* Call strncat with buffer1 and " program"                                */
  27862.  
  27863.    ptr = strncat(buffer1, " program", 3);
  27864.    printf("strncat: buffer1 = \"%s\"\n", buffer1);
  27865.    return 0;
  27866.  
  27867.    /****************************************************************************
  27868.       The output should be:
  27869.  
  27870.       strcat : buffer1 = "computer program"
  27871.       strncat: buffer1 = "computer pr"
  27872.    ****************************************************************************/
  27873. }
  27874.  
  27875.  
  27876. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27877.  
  27878. Example of strncat 
  27879.  
  27880.      strcat - Concatenate Strings 
  27881.      strnicmp - Compare Strings Without Case Sensitivity 
  27882.      wcscat - Concatenate Wide-Character Strings 
  27883.      wcsncat - Concatenate Wide-Character Strings 
  27884.      <string.h> 
  27885.  
  27886.  
  27887. ΓòÉΓòÉΓòÉ 4.272. strncmp - Compare Strings ΓòÉΓòÉΓòÉ
  27888.  
  27889.  
  27890. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  27891.  
  27892. #include <string.h>
  27893. int strncmp(const char *string1, const char *string2, size_t count);
  27894.  
  27895.  
  27896. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  27897.  
  27898. Language Level: ANSI, SAA, POSIX, XPG4 
  27899.  
  27900. strncmp compares the first count characters of string1 and string2. If count is 
  27901. greater than the length of string1 or string2, characters that follow a null 
  27902. character are not compared. 
  27903.  
  27904. Return Value 
  27905. strncmp returns a value indicating the relationship between the substrings, as 
  27906. follows: 
  27907.  
  27908.  Value             Meaning 
  27909.  Less than 0       substring1 less than substring2 
  27910.  0                 substring1 equivalent to substring2 
  27911.  Greater than 0    substring1 greater than substring2 
  27912.  
  27913.  
  27914. ΓòÉΓòÉΓòÉ <hidden> Example of strncmp ΓòÉΓòÉΓòÉ
  27915.  
  27916. /************************************************************************
  27917.  
  27918. This example demonstrates the difference between strcmp and strncmp. 
  27919.  
  27920. ************************************************************************/
  27921.  
  27922. #include <stdio.h>
  27923. #include <string.h>
  27924.  
  27925. #define  SIZE          10
  27926.  
  27927. int main(void)
  27928. {
  27929.    int result;
  27930.    int index = 3;
  27931.    char buffer1[SIZE] = "abcdefg";
  27932.    char buffer2[SIZE] = "abcfg";
  27933.    void print_result(int, char *, char *);
  27934.  
  27935.    result = strcmp(buffer1, buffer2);
  27936.    printf("Comparison of each character\n");
  27937.    printf("  strcmp: ");
  27938.    print_result(result, buffer1, buffer2);
  27939.    result = strncmp(buffer1, buffer2, index);
  27940.    printf("\nComparison of only the first %i characters\n", index);
  27941.    printf("  strncmp: ");
  27942.    print_result(result, buffer1, buffer2);
  27943.    return 0;
  27944.    /****************************************************************************
  27945.       The output should be:
  27946.  
  27947.       Comparison of each character
  27948.         strcmp: "abcdefg" is less than "abcfg"
  27949.  
  27950.       Comparison of only the first 3 characters
  27951.         strncmp: "abcdefg" is identical to "abcfg"
  27952.    ****************************************************************************/
  27953. }
  27954.  
  27955. void print_result(int res,char *p_buffer1,char *p_buffer2)
  27956. {
  27957.    if (0 == res)
  27958.       printf("\"%s\" is identical to \"%s\"\n", p_buffer1, p_buffer2);
  27959.    else
  27960.       if (res < 0)
  27961.          printf("\"%s\" is less than \"%s\"\n", p_buffer1, p_buffer2);
  27962.       else
  27963.          printf("\"%s\" is greater than \"%s\"\n", p_buffer1, p_buffer2);
  27964. }
  27965.  
  27966.  
  27967. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27968.  
  27969. Example of strncmp 
  27970.  
  27971.      strcmp - Compare Strings 
  27972.      strcmpi - Compare Strings Without Case Sensitivity 
  27973.      strcoll - Compare Strings Using Collation Rules 
  27974.      strcspn - Compare Strings for Substrings 
  27975.      stricmp - Compare Strings as Lowercase 
  27976.      strnicmp - Compare Strings Without Case Sensitivity 
  27977.      wcscmp - Compare Wide-Character Strings 
  27978.      wcsncmp - Compare Wide-Character Strings 
  27979.      <string.h> 
  27980.  
  27981.  
  27982. ΓòÉΓòÉΓòÉ 4.273. strncpy - Copy Strings ΓòÉΓòÉΓòÉ
  27983.  
  27984.  
  27985. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  27986.  
  27987. #include <string.h>
  27988. char *strncpy(char *string1, const char *string2, size_t count);
  27989.  
  27990.  
  27991. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  27992.  
  27993. Language Level: ANSI, SAA, POSIX, XPG4 
  27994.  
  27995. strncpy copies count characters of string2 to string1. If count is less than or 
  27996. equal to the length of string2, a null character (\0) is not appended to the 
  27997. copied string. If count is greater than the length of string2, the string1 
  27998. result is padded with null characters (\0) up to length count. 
  27999.  
  28000. Return Value 
  28001. strncpy returns a pointer to string1. 
  28002.  
  28003.  
  28004. ΓòÉΓòÉΓòÉ <hidden> Example of strncpy ΓòÉΓòÉΓòÉ
  28005.  
  28006. /************************************************************************
  28007.  
  28008. This example demonstrates the difference between strcpy and strncpy. 
  28009.  
  28010. ************************************************************************/
  28011.  
  28012. #include <stdio.h>
  28013. #include <string.h>
  28014.  
  28015. #define  SIZE          40
  28016.  
  28017. int main(void)
  28018. {
  28019.    char source[SIZE] = "123456789";
  28020.    char source1[SIZE] = "123456789";
  28021.    char destination[SIZE] = "abcdefg";
  28022.    char destination1[SIZE] = "abcdefg";
  28023.    char *return_string;
  28024.    int index = 5;
  28025.  
  28026.    /* This is how strcpy works                                                */
  28027.  
  28028.    printf("destination is originally = '%s'\n", destination);
  28029.    return_string = strcpy(destination, source);
  28030.    printf("After strcpy, destination becomes '%s'\n\n", destination);
  28031.  
  28032.    /* This is how strncpy works                                               */
  28033.  
  28034.    printf("destination1 is originally = '%s'\n", destination1);
  28035.    return_string = strncpy(destination1, source1, index);
  28036.    printf("After strncpy, destination1 becomes '%s'\n", destination1);
  28037.    return 0;
  28038.  
  28039.    /****************************************************************************
  28040.       The output should be:
  28041.  
  28042.       destination is originally = 'abcdefg'
  28043.       After strcpy, destination becomes '123456789'
  28044.  
  28045.       destination1 is originally = 'abcdefg'
  28046.       After strncpy, destination1 becomes '12345fg'
  28047.    ****************************************************************************/
  28048. }
  28049.  
  28050.  
  28051. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  28052.  
  28053. Example of strncpy 
  28054.  
  28055.      strcpy - Copy Strings 
  28056.      strdup - Duplicate String 
  28057.      strnicmp - Compare Strings Without Case Sensitivity 
  28058.      <string.h> 
  28059.  
  28060.  
  28061. ΓòÉΓòÉΓòÉ 4.274. strnicmp - Compare Strings Without Case Sensitivity ΓòÉΓòÉΓòÉ
  28062.  
  28063.  
  28064. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  28065.  
  28066. #include <string.h>
  28067. int strnicmp(const char *string1, const char *string2, int n);
  28068.  
  28069.  
  28070. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  28071.  
  28072. Language Level:  Extension 
  28073.  
  28074. strnicmp compares, at most, the first n characters of string1 and string2. It 
  28075. operates on null-terminated strings. 
  28076.  
  28077. strnicmp is case insensitive; the uppercase and lowercase forms of a letter are 
  28078. considered equivalent. 
  28079.  
  28080. Return Value 
  28081. strnicmp returns a value indicating the relationship between the substrings, as 
  28082. listed below: 
  28083.  
  28084.  Value             Meaning 
  28085.  Less than 0       substring1 less than substring2 
  28086.  0                 substring1 equivalent to substring2 
  28087.  Greater than 0    substring1 greater than substring2. 
  28088.  
  28089.  
  28090. ΓòÉΓòÉΓòÉ <hidden> Example of strnicmp ΓòÉΓòÉΓòÉ
  28091.  
  28092. /************************************************************************
  28093.  
  28094. This example uses strnicmp to compare two strings. 
  28095.  
  28096. ************************************************************************/
  28097.  
  28098. #include <string.h>
  28099. #include <stdio.h>
  28100.  
  28101. int main(void)
  28102. {
  28103.    char *str1 = "THIS IS THE FIRST STRING";
  28104.    char *str2 = "This is the second string";
  28105.    int numresult;
  28106.  
  28107.      /* Compare the first 11 characters of str1 and str2
  28108.         without regard to case                                                */
  28109.  
  28110.    numresult = strnicmp(str1, str2, 11);
  28111.    if (numresult < 0)
  28112.       printf("String 1 is less than string2.\n");
  28113.    else
  28114.       if (numresult > 0)
  28115.          printf("String 1 is greater than string2.\n");
  28116.       else
  28117.          printf("The two strings are equivalent.\n");
  28118.    return 0;
  28119.  
  28120.    /****************************************************************************
  28121.       The output should be:
  28122.  
  28123.       The two strings are equivalent.
  28124.    ****************************************************************************/
  28125. }
  28126.  
  28127.  
  28128. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  28129.  
  28130. Example of strnicmp 
  28131.  
  28132.      strcmp - Compare Strings 
  28133.      strcmpi - Compare Strings Without Case Sensitivity 
  28134.      stricmp - Compare Strings as Lowercase 
  28135.      strncmp - Compare Strings 
  28136.      wcscmp - Compare Wide-Character Strings 
  28137.      wcsncmp - Compare Wide-Character Strings 
  28138.      <string.h> 
  28139.  
  28140.  
  28141. ΓòÉΓòÉΓòÉ 4.275. strnset - strset - Set Characters in String ΓòÉΓòÉΓòÉ
  28142.  
  28143.  
  28144. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  28145.  
  28146. #include <string.h>
  28147. char *strnset(char *string, int c, size_t n);
  28148. char *strset(char *string, int c);
  28149.  
  28150.  
  28151. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  28152.  
  28153. Language Level:  Extension 
  28154.  
  28155. strnset sets, at most, the first n characters of string to c (converted to a 
  28156. char). If n is greater than the length of string, the length of string is used 
  28157. in place of n. strset sets all characters of string, except the ending null 
  28158. character (\0), to c (converted to a char). 
  28159.  
  28160. For both functions, the string is a null-terminated string. 
  28161.  
  28162. Return Value 
  28163. Both strset and strnset return a pointer to the altered string. There is no 
  28164. error return value. 
  28165.  
  28166.  
  28167. ΓòÉΓòÉΓòÉ <hidden> Example of strnset and strset ΓòÉΓòÉΓòÉ
  28168.  
  28169. /************************************************************************
  28170.  
  28171. In this example, strnset sets not more than four characters of a string to the 
  28172. character 'x'. Then the strset function changes any non-null characters of the 
  28173. string to the character 'k'. 
  28174.  
  28175. ************************************************************************/
  28176.  
  28177. #include <stdio.h>
  28178. #include <string.h>
  28179.  
  28180. int main(void)
  28181. {
  28182.    char str[] = "abcdefghi";
  28183.  
  28184.    printf("This is the string: %s\n", str);
  28185.    printf("This is the string after strnset: %s\n", strnset((char*)str, 'x', 4));
  28186.    printf("This is the string after strset: %s\n", strset((char*)str, 'k'));
  28187.    return 0;
  28188.  
  28189.    /****************************************************************************
  28190.       The output should be:
  28191.  
  28192.       This is the string: abcdefghi
  28193.       This is the string after strnset: xxxxefghi
  28194.       This is the string after strset: kkkkkkkkk
  28195.    ****************************************************************************/
  28196. }
  28197.  
  28198.  
  28199. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  28200.  
  28201. Example of strnset and strset 
  28202.  
  28203.      strchr - Search for Character 
  28204.      strpbrk - Find Characters in String 
  28205.      wcschr - Search for Wide Character 
  28206.      wcspbrk - Locate Wide Characters in String 
  28207.      <string.h> 
  28208.  
  28209.  
  28210. ΓòÉΓòÉΓòÉ 4.276. strpbrk - Find Characters in String ΓòÉΓòÉΓòÉ
  28211.  
  28212.  
  28213. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  28214.  
  28215. #include <string.h>
  28216. char *strpbrk(const char *string1, const char *string2);
  28217.  
  28218.  
  28219. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  28220.  
  28221. Language Level: ANSI, SAA, POSIX, XPG4 
  28222.  
  28223. strpbrk locates the first occurrence in the string pointed to by string1 of any 
  28224. character from the string pointed to by string2. 
  28225.  
  28226. Return Value 
  28227. strpbrk returns a pointer to the character. If string1 and string2 have no 
  28228. characters in common, a NULL pointer is returned. 
  28229.  
  28230.  
  28231. ΓòÉΓòÉΓòÉ <hidden> Example of strpbrk ΓòÉΓòÉΓòÉ
  28232.  
  28233. /************************************************************************
  28234.  
  28235. This example returns a pointer to the first occurrence in the array string of 
  28236. either a or b. 
  28237.  
  28238. ************************************************************************/
  28239.  
  28240. #include <stdio.h>
  28241. #include <string.h>
  28242.  
  28243. int main(void)
  28244. {
  28245.    char *result,*string = "A Blue Danube";
  28246.    char *chars = "ab";
  28247.  
  28248.    result = strpbrk(string, chars);
  28249.    printf("The first occurrence of any of the characters \"%s\" in "
  28250.       "\"%s\" is \"%s\"\n", chars, string, result);
  28251.    return 0;
  28252.  
  28253.    /****************************************************************************
  28254.       The output should be:
  28255.  
  28256.       The first occurrence of any of the characters "ab" in
  28257.       "A Blue Danube" is "anube"
  28258.    ****************************************************************************/
  28259. }
  28260.  
  28261.  
  28262. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  28263.  
  28264. Example of strpbrk 
  28265.  
  28266.      strchr - Search for Character 
  28267.      strcspn - Compare Strings for Substrings 
  28268.      strrchr - Find Last Occurrence of Character in String 
  28269.      strspn - Search Strings 
  28270.      wcschr - Search for Wide Character 
  28271.      wcscspn - Find Offset of First Wide-Character Match 
  28272.      wcspbrk - Locate Wide Characters in String 
  28273.      wcsrchr - Locate Wide Character in String 
  28274.      wcswcs - Locate Wide-Character Substring 
  28275.      <string.h> 
  28276.  
  28277.  
  28278. ΓòÉΓòÉΓòÉ 4.277. strptime - Convert to Formatted Date and Time ΓòÉΓòÉΓòÉ
  28279.  
  28280.  
  28281. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  28282.  
  28283. #include <time.h>
  28284. char *strptime(const char *buf, const char *fmt, struct tm *tm);
  28285.  
  28286.  
  28287. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  28288.  
  28289. Language Level:  XPG4 
  28290.  
  28291. strptime uses the format specified by fmt to convert the character string 
  28292. pointed to by buf to values that are stored in the structure pointed to by tm. 
  28293.  
  28294. The *fmt is composed of zero or more directives. Each directive is composed of 
  28295. one of the following: 
  28296.  
  28297.      One or more white-space characters (as specified by the isspace function) 
  28298.      An ordinary character (neither % nor a white-space character) 
  28299.      A conversion specifier. 
  28300.  
  28301.  Each conversion specifier consists of a % character followed by a conversion 
  28302.  character that specifies the replacement required. There must be white-space 
  28303.  or other non-alphanumeric characters between any two conversion specifiers. 
  28304.  See  Conversion Specifiers Used by strptime for a list of conversion 
  28305.  specifiers. 
  28306.  
  28307.  For a directive composed of white-space characters, strptime scans input up to 
  28308.  the first character that is not white space (which remains unscanned), or 
  28309.  until no more characters can be scanned. 
  28310.  
  28311.  For a directive that is an ordinary character, strptime scans the next 
  28312.  character from the buffer. If the scanned character differs from the one 
  28313.  comprising the directive, the directive fails and the differing and subsequent 
  28314.  characters remain unscanned. 
  28315.  
  28316.  For a series of directives composed of %n, %t, white-space characters, or any 
  28317.  combination, strptime scans up to the first character that is not white space 
  28318.  (which remains unscanned), or until no more characters can be scanned. 
  28319.  
  28320.  For any other conversion specification, strptime scans characters until a 
  28321.  character matching the next directive is scanned, or until no more characters 
  28322.  can be scanned. It then compares these characters, excepting the one matching 
  28323.  the next directive, to the locale values associated with the conversion 
  28324.  specifier. If a match is found, strptime sets the appropriate tm structure 
  28325.  members to values corresponding to the locale information. Case is ignored 
  28326.  when items in buf are matched, such as month or weekday names. If no match is 
  28327.  found, strptime fails and no more characters are scanned. 
  28328.  
  28329.  Return Value 
  28330.  If successful, strptime returns a pointer to the character following the last 
  28331.  character parsed. Otherwise, a null pointer is returned. 
  28332.  
  28333.  
  28334. ΓòÉΓòÉΓòÉ <hidden> Example of strptime ΓòÉΓòÉΓòÉ
  28335.  
  28336. /************************************************************************
  28337.  
  28338. This example uses strptime to convert a string to the structure xmas, then 
  28339. prints the contents of the structure. 
  28340.  
  28341. ************************************************************************/
  28342.  
  28343. #include <time.h>
  28344. #include <stdio.h>
  28345. #include <stdlib.h>
  28346.  
  28347. int main(void)
  28348. {
  28349.    struct tm xmas;
  28350.  
  28351.    if (NULL == strptime("12/25/94 12:01", "%D %T", &xmas)) {
  28352.       printf("strptime() failed.\n");
  28353.       exit(EXIT_FAILURE);
  28354.    }
  28355.    printf("tm_sec  = %3d\n", xmas.tm_sec );
  28356.    printf("tm_min  = %3d\n", xmas.tm_min );
  28357.    printf("tm_hour = %3d\n", xmas.tm_hour);
  28358.    printf("tm_mday = %3d\n", xmas.tm_mday);
  28359.    printf("tm_mon  = %3d\n", xmas.tm_mon );
  28360.    printf("tm_year = %3d\n", xmas.tm_year);
  28361.    return 0;
  28362.  
  28363.    /****************************************************************************
  28364.       The output should be similar to :
  28365.  
  28366.       tm_sec  =   1
  28367.       tm_min  =   0
  28368.       tm_hour =  11
  28369.       tm_mday =  25
  28370.       tm_mon  =  12
  28371.       tm_year =  94
  28372.    ****************************************************************************/
  28373. }
  28374.  
  28375.  
  28376. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  28377.  
  28378. Example of strptime 
  28379.  
  28380.      Conversion Specifiers Used by strptime 
  28381.      strftime - Convert to Formatted Time 
  28382.      wcsftime - Convert to Formatted Date and Time 
  28383.      <time.h> 
  28384.  
  28385.  
  28386. ΓòÉΓòÉΓòÉ 4.277.1. Conversion Specifiers Used by strptime ΓòÉΓòÉΓòÉ
  28387.  
  28388. The following tables list the conversion specifiers for strptime. 
  28389.  
  28390. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  28391. Γöé SPECIFIER   Γöé MEANING                     Γöé
  28392. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28393. Γöé %a       Γöé Day of week, using locale's abbreviated or full Γöé
  28394. Γöé        Γöé weekday name.                  Γöé
  28395. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28396. Γöé %A       Γöé Day of week, using locale's abbreviated or full Γöé
  28397. Γöé        Γöé weekday name.                  Γöé
  28398. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28399. Γöé %b       Γöé Month, using locale's abbreviated or full month Γöé
  28400. Γöé        Γöé name.                      Γöé
  28401. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28402. Γöé %B       Γöé Month, using locale's abbreviated or full month Γöé
  28403. Γöé        Γöé name.                      Γöé
  28404. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28405. Γöé %c       Γöé Date and time, using locale's date and time.   Γöé
  28406. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28407. Γöé %C       Γöé Century number (year divided by 100 and trun-  Γöé
  28408. Γöé        Γöé cated to an integer)               Γöé
  28409. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28410. Γöé %d       Γöé Day of the month (1-31; leading zeros permitted Γöé
  28411. Γöé        Γöé but not required).                Γöé
  28412. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28413. Γöé %D       Γöé Date as %m/%d/%y.                Γöé
  28414. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28415. Γöé %e       Γöé Day of the month (1-31; leading zeros permitted Γöé
  28416. Γöé        Γöé but not required).                Γöé
  28417. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28418. Γöé %h       Γöé Month, using locale's abbreviated or full month Γöé
  28419. Γöé        Γöé name.                      Γöé
  28420. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28421. Γöé %H       Γöé Hour (0-23; leading zeros permitted but not   Γöé
  28422. Γöé        Γöé required).                    Γöé
  28423. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28424. Γöé %I       Γöé Hour (0-12; leading zeros permitted but not   Γöé
  28425. Γöé        Γöé required).                    Γöé
  28426. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28427. Γöé %j       Γöé Day number of the year (001-366).        Γöé
  28428. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28429. Γöé %m       Γöé Month number (1-12; leading zeros permitted but Γöé
  28430. Γöé        Γöé not required).                  Γöé
  28431. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28432. Γöé %M       Γöé Minute (0-59; leading zeros permitted but not  Γöé
  28433. Γöé        Γöé required).                    Γöé
  28434. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28435. Γöé %n       Γöé Newline character.                Γöé
  28436. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28437. Γöé %p       Γöé Locale's equivalent of AM or PM.         Γöé
  28438. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28439. Γöé %r       Γöé Time as %I:%M:%S a.m. or %I:%M:%S p.m.      Γöé
  28440. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28441. Γöé %R       Γöé Time in 24 hour notation (%H%M)         Γöé
  28442. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28443. Γöé %S       Γöé Seconds (0-61; leading zeros permitted but not  Γöé
  28444. Γöé        Γöé required).                    Γöé
  28445. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28446. Γöé %t       Γöé Tab character.                  Γöé
  28447. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28448. Γöé %T       Γöé Time as %H:%M:%S.                Γöé
  28449. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28450. Γöé %U       Γöé Week number of the year (0-53; where Sunday is  Γöé
  28451. Γöé        Γöé the first day of the week; leading zeros per-  Γöé
  28452. Γöé        Γöé mitted but not required).            Γöé
  28453. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28454. Γöé %w       Γöé Weekday (0-6; where Sunday is 0; leading zeros  Γöé
  28455. Γöé        Γöé permitted but not required).           Γöé
  28456. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28457. Γöé %W       Γöé Week number of the year (0-53; where Monday is  Γöé
  28458. Γöé        Γöé the first day of the week; leading zeros per-  Γöé
  28459. Γöé        Γöé mitted but not required).            Γöé
  28460. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28461. Γöé %x       Γöé Date, using locale's date format.        Γöé
  28462. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28463. Γöé %X       Γöé Time, using locale's time format.        Γöé
  28464. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28465. Γöé %y       Γöé Year within century (0-99; leading zeros per-  Γöé
  28466. Γöé        Γöé mitted but not required).            Γöé
  28467. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28468. Γöé %Y       Γöé Year, including century.             Γöé
  28469. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28470. Γöé %Z       Γöé Time zone name                  Γöé
  28471. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28472. Γöé %%       Γöé Replace with %.                 Γöé
  28473. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  28474.  
  28475. Some directives can be modified by the E or O modifier characters to indicate 
  28476. that an alternative format or specification should be used rather than the one 
  28477. normally used by the unmodified directive. If the alternative format or 
  28478. specification does not exist in the current locale, the behavior will be as if 
  28479. the unmodified directive were used. 
  28480.  
  28481. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  28482. Γöé SPECIFIER   Γöé MEANING                     Γöé
  28483. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28484. Γöé %Ec      Γöé Replace with the locale's alternative date and  Γöé
  28485. Γöé        Γöé time representation.               Γöé
  28486. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28487. Γöé %EC      Γöé Replace with the name of the base year (period) Γöé
  28488. Γöé        Γöé in the locale's alternative representation.   Γöé
  28489. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28490. Γöé %Ex      Γöé Replace with the locale's alternative date rep- Γöé
  28491. Γöé        Γöé resentation.                   Γöé
  28492. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28493. Γöé %EX      Γöé Replace with the locale's alternative time rep- Γöé
  28494. Γöé        Γöé resentation.                   Γöé
  28495. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28496. Γöé %Ey      Γöé Replace with the offset from %EC (year only) in Γöé
  28497. Γöé        Γöé the locale's alternative representation.     Γöé
  28498. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28499. Γöé %EY      Γöé Replace with the full alternative year repre-  Γöé
  28500. Γöé        Γöé sentation.                    Γöé
  28501. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28502. Γöé %Od      Γöé Replace with the day of month, using the     Γöé
  28503. Γöé        Γöé locale's alternative numeric symbols, filled as Γöé
  28504. Γöé        Γöé needed with leading zeroes if there is any    Γöé
  28505. Γöé        Γöé alternative symbol for zero; otherwise, fill   Γöé
  28506. Γöé        Γöé with leading spaces.               Γöé
  28507. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28508. Γöé %Oe      Γöé Replace with the day of the month, using the   Γöé
  28509. Γöé        Γöé locale's alternative numeric symbols, filled as Γöé
  28510. Γöé        Γöé needed with leading spaces.           Γöé
  28511. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28512. Γöé %OH      Γöé Replace with the hour (24-hour clock), using   Γöé
  28513. Γöé        Γöé the locale's alternative numeric symbols.    Γöé
  28514. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28515. Γöé %OI      Γöé Replace with the hour (12-hour clock), using   Γöé
  28516. Γöé        Γöé the locale's alternative numeric symbols.    Γöé
  28517. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28518. Γöé %Om      Γöé Replace with the month, using the locale's    Γöé
  28519. Γöé        Γöé alternative numeric symbols.           Γöé
  28520. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28521. Γöé %OM      Γöé Replace with the minutes, using the locale's   Γöé
  28522. Γöé        Γöé alternative numeric symbols.           Γöé
  28523. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28524. Γöé %OS      Γöé Replace with the seconds, using the locale's   Γöé
  28525. Γöé        Γöé alternative numeric symbols.           Γöé
  28526. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28527. Γöé %OU      Γöé Replace with the week number of the year     Γöé
  28528. Γöé        Γöé (Sunday as the first day of the week, rules   Γöé
  28529. Γöé        Γöé corresponding to %U), using the locale's alter- Γöé
  28530. Γöé        Γöé native numeric symbols.             Γöé
  28531. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28532. Γöé %Ow      Γöé Replace with the weekday (Sunday=0), using the  Γöé
  28533. Γöé        Γöé locale's alternative numeric symbols.      Γöé
  28534. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28535. Γöé %OW      Γöé Replace with the week number of the year     Γöé
  28536. Γöé        Γöé (Monday as the first day of the week), using   Γöé
  28537. Γöé        Γöé the locale's alternative numeric symbols.    Γöé
  28538. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  28539. Γöé %Oy      Γöé Replace with the year (offset from %C) in the  Γöé
  28540. Γöé        Γöé locale's alternative representation, using the  Γöé
  28541. Γöé        Γöé locale's alternative numeric symbols.      Γöé
  28542. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  28543.  
  28544.  
  28545. ΓòÉΓòÉΓòÉ 4.278. strrchr - Find Last Occurrence of Character in String ΓòÉΓòÉΓòÉ
  28546.  
  28547.  
  28548. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  28549.  
  28550. #include <string.h>
  28551. char *strrchr(const char *string, int c);
  28552.  
  28553.  
  28554. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  28555.  
  28556. Language Level: ANSI, SAA, POSIX, XPG4 
  28557.  
  28558. strrchr finds the last occurrence of c (converted to a character) in string. 
  28559. The ending null character is considered part of the string. 
  28560.  
  28561. Return Value 
  28562. strrchr returns a pointer to the last occurrence of c in string. If the given 
  28563. character is not found, a NULL pointer is returned. 
  28564.  
  28565.  
  28566. ΓòÉΓòÉΓòÉ <hidden> Example of strrchr ΓòÉΓòÉΓòÉ
  28567.  
  28568. /************************************************************************
  28569.  
  28570. This example compares the use of strchr and strrchr.  It searches the string 
  28571. for the first and last occurrence of p in the string. 
  28572.  
  28573. ************************************************************************/
  28574.  
  28575. #include <stdio.h>
  28576. #include <string.h>
  28577.  
  28578. #define  SIZE          40
  28579.  
  28580. int main(void)
  28581. {
  28582.    char buf[SIZE] = "computer program";
  28583.    char *ptr;
  28584.    int ch = 'p';
  28585.  
  28586.    /* This illustrates strchr                                                 */
  28587.  
  28588.    ptr = strchr(buf, ch);
  28589.    printf("The first occurrence of %c in '%s' is '%s'\n", ch, buf, ptr);
  28590.  
  28591.    /* This illustrates strrchr                                                */
  28592.  
  28593.    ptr = strrchr(buf, ch);
  28594.    printf("The last occurrence of %c in '%s' is '%s'\n", ch, buf, ptr);
  28595.    return 0;
  28596.  
  28597.    /****************************************************************************
  28598.       The output should be:
  28599.  
  28600.       The first occurrence of p in 'computer program' is 'puter program'
  28601.       The last occurrence of p in 'computer program' is 'program'
  28602.    ****************************************************************************/
  28603. }
  28604.  
  28605.  
  28606. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  28607.  
  28608. Example of strrchr 
  28609.  
  28610.      strchr - Search for Character 
  28611.      strcspn - Compare Strings for Substrings 
  28612.      strpbrk - Find Characters in String 
  28613.      strspn - Search Strings 
  28614.      wcschr - Search for Wide Character 
  28615.      wcspbrk - Locate Wide Characters in String 
  28616.      wcsrchr - Locate Wide Character in String 
  28617.      wcswcs - Locate Wide-Character Substring 
  28618.      <string.h> 
  28619.  
  28620.  
  28621. ΓòÉΓòÉΓòÉ 4.279. strrev - Reverse String ΓòÉΓòÉΓòÉ
  28622.  
  28623.  
  28624. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  28625.  
  28626. #include <string.h>
  28627. char *strrev(char *string);
  28628.  
  28629.  
  28630. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  28631.  
  28632. Language Level:  Extension 
  28633.  
  28634. strrev reverses the order of the characters in the given string.  The ending 
  28635. null character (\0) remains in place. 
  28636.  
  28637. Return Value 
  28638. strrev returns a pointer to the altered string.  There is no error return 
  28639. value. 
  28640.  
  28641.  
  28642. ΓòÉΓòÉΓòÉ <hidden> Example of strrev ΓòÉΓòÉΓòÉ
  28643.  
  28644. /************************************************************************
  28645.  
  28646. This example determines whether a string is a palindrome.  A palindrome is a 
  28647. string that reads the same forward and backward. 
  28648.  
  28649. ************************************************************************/
  28650.  
  28651. #include <stdio.h>
  28652. #include <stdlib.h>
  28653. #include <string.h>
  28654.  
  28655. int palindrome(char *string)
  28656. {
  28657.    char *string2;
  28658.  
  28659.    /* Duplicate string for comparison                                         */
  28660.  
  28661.    if (NULL == (string2 = strdup(string))) {
  28662.       printf("Storage could not be reserved for string\n");
  28663.       exit(EXIT_FAILURE);
  28664.    }
  28665.  
  28666.    /* If result equals 0, the string is a palindrome                          */
  28667.  
  28668.    return (strcmp(string, strrev(string2)));
  28669. }
  28670.  
  28671. int main(void)
  28672. {
  28673.    char string[81];
  28674.  
  28675.    printf("Please enter a string.\n");
  28676.    scanf("%80s", string);
  28677.    if (palindrome(string))
  28678.       printf("The string is not a palindrome.\n");
  28679.    else
  28680.       printf("The string is a palindrome.\n");
  28681.    return 0;
  28682.  
  28683.    /****************************************************************************
  28684.       Sample output from program:
  28685.  
  28686.       Please enter a string.
  28687.       level
  28688.       The string is a palindrome.
  28689.       ... or ...
  28690.       Please enter a string.
  28691.       levels
  28692.       The string is not a palindrome.
  28693.    ****************************************************************************/
  28694. }
  28695.  
  28696.  
  28697. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  28698.  
  28699. Example of strrev 
  28700.  
  28701.      strcat - Concatenate Strings 
  28702.      strcmp - Compare Strings 
  28703.      strcpy - Copy Strings 
  28704.      strdup - Duplicate String 
  28705.      strnset - strset - Set Characters in String 
  28706.      <string.h> 
  28707.  
  28708.  
  28709. ΓòÉΓòÉΓòÉ 4.280. strspn - Search Strings ΓòÉΓòÉΓòÉ
  28710.  
  28711.  
  28712. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  28713.  
  28714. #include <string.h>
  28715. size_t strspn(const char *string1, const char *string2);
  28716.  
  28717.  
  28718. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  28719.  
  28720. Language Level: ANSI, SAA, POSIX, XPG4 
  28721.  
  28722. strspn finds the first occurrence of a character in string1 that is not 
  28723. contained in the set of characters specified by string2. The null character 
  28724. (\0) that ends string2 is not considered in the matching process. 
  28725.  
  28726. Return Value 
  28727. strspn returns the index of the first character found. This value is equal to 
  28728. the length of the initial substring of string1 that consists entirely of 
  28729. characters from string2. If string1 begins with a character not in string2, 
  28730. strspn returns 0. If all the characters in string1 are found in string2, the 
  28731. length of string1 is returned. 
  28732.  
  28733.  
  28734. ΓòÉΓòÉΓòÉ <hidden> Example of strspn ΓòÉΓòÉΓòÉ
  28735.  
  28736. /************************************************************************
  28737.  
  28738. This example finds the first occurrence in the array string of a character that 
  28739. is not an a, b, or c.  Because the string in this example is cabbage, strspn 
  28740. returns 5, the length of the segment of cabbage before a character that is not 
  28741. an a, b, or c. 
  28742.  
  28743. ************************************************************************/
  28744.  
  28745. #include <stdio.h>
  28746. #include <string.h>
  28747.  
  28748. int main(void)
  28749. {
  28750.    char *string = "cabbage";
  28751.    char *source = "abc";
  28752.    int index;
  28753.  
  28754.    index = strspn(string, "abc");
  28755.    printf("The first %d characters of \"%s\" are found in \"%s\"\n", index,
  28756.       string, source);
  28757.    return 0;
  28758.  
  28759.    /****************************************************************************
  28760.       The output should be:
  28761.  
  28762.       The first 5 characters of "cabbage" are found in "abc"
  28763.    ****************************************************************************/
  28764. }
  28765.  
  28766.  
  28767. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  28768.  
  28769. Example of strspn 
  28770.  
  28771.      strchr - Search for Character 
  28772.      strcspn - Compare Strings for Substrings 
  28773.      strpbrk - Find Characters in String 
  28774.      strrchr - Find Last Occurrence of Character in String 
  28775.      wcschr - Search for Wide Character 
  28776.      wcscspn - Find Offset of First Wide-Character Match 
  28777.      wcspbrk - Locate Wide Characters in String 
  28778.      wcsrchr - Locate Wide Character in String 
  28779.      wcsspn - Search Wide-Character Strings 
  28780.      wcswcs - Locate Wide-Character Substring 
  28781.      <string.h> 
  28782.  
  28783.  
  28784. ΓòÉΓòÉΓòÉ 4.281. strstr - Locate Substring ΓòÉΓòÉΓòÉ
  28785.  
  28786.  
  28787. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  28788.  
  28789. #include <string.h>
  28790. char *strstr(const char *string1, const char *string2);
  28791.  
  28792.  
  28793. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  28794.  
  28795. Language Level: ANSI, SAA, POSIX, XPG4 
  28796.  
  28797. strstr finds the first occurrence of string2 in string1. The function ignores 
  28798. the null character (\0) that ends string2 in the matching process. 
  28799.  
  28800. Return Value 
  28801. strstr returns a pointer to the beginning of the first occurrence of string2 in 
  28802. string1. If string2 does not appear in string1, strstr returns NULL. If string2 
  28803. points to a string with zero length, strstr returns string1. 
  28804.  
  28805.  
  28806. ΓòÉΓòÉΓòÉ <hidden> Example of strstr ΓòÉΓòÉΓòÉ
  28807.  
  28808. /************************************************************************
  28809.  
  28810. This example locates the string haystack in the string "needle in a haystack". 
  28811.  
  28812. ************************************************************************/
  28813.  
  28814. #include <stdio.h>
  28815. #include <string.h>
  28816.  
  28817. int main(void)
  28818. {
  28819.    char *string1 = "needle in a haystack";
  28820.    char *string2 = "haystack";
  28821.    char *result;
  28822.  
  28823.    result = strstr(string1, string2);
  28824.  
  28825.    /* Result = a pointer to "haystack"                                        */
  28826.  
  28827.    printf("%s\n", result);
  28828.    return 0;
  28829.  
  28830.    /****************************************************************************
  28831.       The output should be:
  28832.  
  28833.       haystack
  28834.    ****************************************************************************/
  28835. }
  28836.  
  28837.  
  28838. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  28839.  
  28840. Example of strstr 
  28841.  
  28842.      strchr - Search for Character 
  28843.      strcspn - Compare Strings for Substrings 
  28844.      strpbrk - Find Characters in String 
  28845.      strrchr - Find Last Occurrence of Character in String 
  28846.      strspn - Search Strings 
  28847.      wcschr - Search for Wide Character 
  28848.      wcscspn - Find Offset of First Wide-Character Match 
  28849.      wcspbrk - Locate Wide Characters in String 
  28850.      wcsrchr - Locate Wide Character in String 
  28851.      wcsspn - Search Wide-Character Strings 
  28852.      wcswcs - Locate Wide-Character Substring 
  28853.      <string.h> 
  28854.  
  28855.  
  28856. ΓòÉΓòÉΓòÉ 4.282. _strtime - Copy Time ΓòÉΓòÉΓòÉ
  28857.  
  28858.  
  28859. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  28860.  
  28861. #include <time.h>
  28862. char *_strtime(char *time);
  28863.  
  28864.  
  28865. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  28866.  
  28867. Language Level:  Extension 
  28868.  
  28869. _strtime copies the current time into the buffer that time points to.  The 
  28870. format is: 
  28871.  
  28872.    hh:mm:ss
  28873.  
  28874. where 
  28875.  
  28876.       hh represents the hour in 24-hour notation, 
  28877.       mm represents the minutes past the hour, 
  28878.       ss represents the number of seconds. 
  28879.  
  28880.  For example, the string 18:23:44 represents 23 minutes and 44 seconds past 6 
  28881.  p.m. 
  28882.  
  28883.  The buffer must be at least 9 bytes. 
  28884.  
  28885.  Return Value 
  28886.  _strtime returns a pointer to the buffer. There is no error return. 
  28887.  
  28888.  
  28889. ΓòÉΓòÉΓòÉ <hidden> Example of _strtime ΓòÉΓòÉΓòÉ
  28890.  
  28891. /************************************************************************
  28892.  
  28893. This example prints the current time: 
  28894.  
  28895. ************************************************************************/
  28896.  
  28897. #include <stdio.h>
  28898. #include <time.h>
  28899.  
  28900. int main(void)
  28901. {
  28902.    char buffer[9];
  28903.  
  28904.    printf("The current time is %s \n", _strtime(buffer));
  28905.    return 0;
  28906.  
  28907.    /****************************************************************************
  28908.       The output should be similar to:
  28909.  
  28910.       The current time is 16:22
  28911.    ****************************************************************************/
  28912. }
  28913.  
  28914.  
  28915. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  28916.  
  28917. Example of _strtime 
  28918.  
  28919.      asctime - Convert Time to Character String 
  28920.      ctime - Convert Time to Character String 
  28921.      gmtime - Convert Time 
  28922.      localtime - Convert Time 
  28923.      mktime - Convert Local Time 
  28924.      time - Determine Current Time 
  28925.      tzset - Assign Values to Locale Information 
  28926.      <time.h> 
  28927.  
  28928.  
  28929. ΓòÉΓòÉΓòÉ 4.283. strtod - Convert Character String to Double ΓòÉΓòÉΓòÉ
  28930.  
  28931.  
  28932. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  28933.  
  28934. #include <stdlib.h>
  28935. double strtod(const char *nptr, char **endptr);
  28936.  
  28937.  
  28938. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  28939.  
  28940. Language Level:  ANSI, SAA, XPG4 
  28941.  
  28942. strtod converts a character string to a double-precision value. The parameter 
  28943. nptr points to a sequence of characters that can be interpreted as a numerical 
  28944. value of the type double. When it reads a character that it does not recognize 
  28945. as part of a number, strtod stops reading the string at that character, and 
  28946. sets endptr to point to the remainder of nptr. The character at which strtod 
  28947. stops reading the string may be the null character at the end of that string. 
  28948. The strtod function expects nptr to point to a string with the following form: 
  28949.  
  28950. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  28951. Γöé                                        Γöé
  28952. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ>         Γöé
  28953. Γöé   ΓööΓöÇwhite-spaceΓöÇΓöÿ  Γö£ΓöÇ+ΓöÇΓöñ  Γö£ΓöÇdigitsΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöñ           Γöé
  28954. Γöé            ΓööΓöÇΓö┤ΓöÇΓöÿ  Γöé     ΓööΓöÇ.ΓöÇΓöÿ  ΓööΓöÇdigitsΓöÇΓöÿ Γöé           Γöé
  28955. Γöé               ΓööΓöÇ.ΓöÇΓöÇdigitsΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ           Γöé
  28956. Γöé                                        Γöé
  28957. Γöé >ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><                        Γöé
  28958. Γöé   ΓööΓöÇΓö¼ΓöÇeΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdigitsΓöÇΓöÿ                          Γöé
  28959. Γöé    ΓööΓöÇEΓöÇΓöÿ  Γö£ΓöÇ+ΓöÇΓöñ                               Γöé
  28960. Γöé       ΓööΓöÇΓö┤ΓöÇΓöÿ                               Γöé
  28961. Γöé                                        Γöé
  28962. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  28963.  
  28964. Note:  The character used for the decimal point (shown as . in the above 
  28965. diagram) depends on the LC_NUMERIC category of the current locale. 
  28966.  
  28967. The first character that does not fit this form stops the scan. 
  28968.  
  28969. Return Value 
  28970. strtod returns the value of the floating-point number, except when the 
  28971. representation causes an underflow or overflow. For an overflow, it returns 
  28972. -HUGE_VAL or +HUGE_VAL; for an underflow, it returns 0. 
  28973.  
  28974. In both cases, errno is set to ERANGE, depending on the base of the value. If 
  28975. the string pointed to by nptr does not have the expected form, no conversion is 
  28976. performed and the value of nptr is stored in the object pointed to by endptr, 
  28977. provided that endptr is not a NULL pointer. 
  28978.  
  28979. strtod does not fail if a character other than a digit follows an E or e read 
  28980. in as an exponent. For example, 100elf will be converted to the floating-point 
  28981. value 100.0. 
  28982.  
  28983.  
  28984. ΓòÉΓòÉΓòÉ <hidden> Example of strtod ΓòÉΓòÉΓòÉ
  28985.  
  28986. /************************************************************************
  28987.  
  28988. This example converts the strings to a double value.  It prints out the 
  28989. converted value and the substring that stopped the conversion. 
  28990.  
  28991. ************************************************************************/
  28992.  
  28993. #include <stdlib.h>
  28994. #include <stdio.h>
  28995.  
  28996. int main(void)
  28997. {
  28998.    char *string,*stopstring;
  28999.    double x;
  29000.  
  29001.    string = "3.1415926This stopped it";
  29002.    x = strtod(string, &stopstring);
  29003.    printf("string = %s\n", string);
  29004.    printf("   strtod = %f\n", x);
  29005.    printf("   Stopped scan at %s\n\n", stopstring);
  29006.    string = "100ergs";
  29007.    x = strtod(string, &stopstring);
  29008.    printf("string = \"%s\"\n", string);
  29009.    printf("   strtod = %f\n", x);
  29010.    printf("   Stopped scan at \"%s\"\n\n", stopstring);
  29011.    return 0;
  29012.  
  29013.    /****************************************************************************
  29014.       The output should be:
  29015.  
  29016.       string = 3.1415926This stopped it
  29017.          strtod = 3.141593
  29018.          Stopped scan at This stopped it
  29019.  
  29020.       string = "100ergs"
  29021.          strtod = 100.000000
  29022.          Stopped scan at "ergs"
  29023.    ****************************************************************************/
  29024. }
  29025.  
  29026.  
  29027. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  29028.  
  29029. Example of strtod 
  29030.  
  29031.      atof - Convert Character String to Float 
  29032.      atoi - Convert Character String to Integer 
  29033.      atol - Convert Character String to Long Integer 
  29034.      _atold - Convert Character String to Long Double 
  29035.      strtol - Convert Character String to Long Integer 
  29036.      strtold - Convert String to Long Double 
  29037.      strtoul - Convert String Segment to Unsigned Integer 
  29038.      wcstod - Convert Wide-Character String to Double 
  29039.      wcstol - Convert Wide-Character to Long Integer 
  29040.      wcstoul - Convert Wide-Character String to Unsigned Long 
  29041.      <stdlib.h> 
  29042.  
  29043.  
  29044. ΓòÉΓòÉΓòÉ 4.284. strtok - Tokenize String ΓòÉΓòÉΓòÉ
  29045.  
  29046.  
  29047. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  29048.  
  29049. #include <string.h>
  29050. char *strtok(char *string1, const char *string2);
  29051.  
  29052.  
  29053. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  29054.  
  29055. Language Level: ANSI, SAA, POSIX, XPG4 
  29056.  
  29057. strtok reads string1 as a series of zero or more tokens, and string2 as the set 
  29058. of characters serving as delimiters of the tokens in string1. The tokens in 
  29059. string1 can be separated by one or more of the delimiters from string2. The 
  29060. tokens in string1 can be located by a series of calls to strtok. 
  29061.  
  29062. In the first call to strtok for a given string1, strtok searches for the first 
  29063. token in string1, skipping over leading delimiters.  A pointer to the first 
  29064. token is returned. 
  29065.  
  29066. To read the next token from string1, call strtok with a NULL string1 argument. 
  29067. A NULL string1 argument causes strtok to search for the next token in the 
  29068. previous token string. Each delimiter is replaced by a null character.  The set 
  29069. of delimiters can vary from call to call, so string2 can take any value. 
  29070.  
  29071. Return Value 
  29072. The first time strtok is called, it returns a pointer to the first token in 
  29073. string1.  In later calls with the same token string, strtok returns a pointer 
  29074. to the next token in the string.  A NULL pointer is returned when there are no 
  29075. more tokens.  All tokens are null-terminated. 
  29076.  
  29077.  
  29078. ΓòÉΓòÉΓòÉ <hidden> Example of strtok ΓòÉΓòÉΓòÉ
  29079.  
  29080. /************************************************************************
  29081.  
  29082. Using a loop, this example gathers tokens, separated by commas, from a string 
  29083. until no tokens are left.  After processing the tokens (not shown), the example 
  29084. returns the pointers to the tokens a string, of, tokens and a blank. The next 
  29085. call to strtok returns NULL, and the loop ends. 
  29086.  
  29087. ************************************************************************/
  29088.  
  29089. #pragma strings(writable)
  29090. #include <stdio.h>
  29091. #include <string.h>
  29092.  
  29093. int main(void)
  29094. {
  29095.    char *token,string[] = "a string, of, ,tokens\0,after null terminator";
  29096.  
  29097.     /* the string pointed to by string is broken up into the tokens
  29098.        "a string", " of", " ", and "tokens" ; the null terminator (\0)
  29099.        is encountered and execution stops after the token "tokens"            */
  29100.  
  29101.    token = strtok((char*)string, ",");
  29102.    do {
  29103.       printf("token: %s\n", token);
  29104.    }  while (token = strtok(NULL, ","));
  29105.    return 0;
  29106.  
  29107.    /****************************************************************************
  29108.       The output should be:
  29109.  
  29110.       token: a string
  29111.       token:  of
  29112.       token:
  29113.       token: tokens
  29114.    ****************************************************************************/
  29115. }
  29116.  
  29117.  
  29118. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  29119.  
  29120. Example of strtok 
  29121.  
  29122.      strcat - Concatenate Strings 
  29123.      strchr - Search for Character 
  29124.      strcmp - Compare Strings 
  29125.      strcpy - Copy Strings 
  29126.      strcspn - Compare Strings for Substrings 
  29127.      strspn - Search Strings 
  29128.      wcstok - Tokenize Wide-Character String 
  29129.      <string.h> 
  29130.  
  29131.  
  29132. ΓòÉΓòÉΓòÉ 4.285. strtol - Convert Character String to Long Integer ΓòÉΓòÉΓòÉ
  29133.  
  29134.  
  29135. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  29136.  
  29137. #include <stdlib.h>
  29138. long int strtol(const char *nptr, char **endptr, int base);
  29139.  
  29140.  
  29141. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  29142.  
  29143. Language Level: ANSI, SAA, XPG4 
  29144.  
  29145. strtol converts a character string to a long-integer value. The parameter nptr 
  29146. points to a sequence of characters that can be interpreted as a numerical value 
  29147. of the type long int. When it reads a character that it does not recognize as 
  29148. part of a number, strtol stops reading the string at that character, and sets 
  29149. endptr to point to the remainder of nptr. The character at which strtol stops 
  29150. reading the string may be the null character at the end of that string. The 
  29151. ending character can also be the first numeric character greater than or equal 
  29152. to the base. 
  29153.  
  29154. When you use the strtol function, nptr should point to a string with the 
  29155. following form: 
  29156.  
  29157. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  29158. Γöé                                        Γöé
  29159. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><              Γöé
  29160. Γöé   ΓööΓöÇwhite-spaceΓöÇΓöÿ  Γö£ΓöÇ+ΓöÇΓöñ  Γö£ΓöÇ0ΓöÇΓöÇΓöñ  ΓööΓöÇdigitsΓöÇΓöÿ                Γöé
  29161. Γöé            ΓööΓöÇΓö┤ΓöÇΓöÿ  Γö£ΓöÇ0xΓöÇΓöñ                      Γöé
  29162. Γöé               ΓööΓöÇ0XΓöÇΓöÿ                      Γöé
  29163. Γöé                                        Γöé
  29164. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  29165.  
  29166. If base is in the range of 2 through 36, it becomes the base of the number. If 
  29167. base is 0, the prefix determines the base (8, 16, or 10):  the prefix 0 means 
  29168. base 8 (octal);  the prefix 0x or 0X means base 16 (hexadecimal); using any 
  29169. other digit without a prefix means decimal. 
  29170.  
  29171. Return Value 
  29172. strtol returns the value represented in the string, except when the 
  29173. representation causes an overflow. For an overflow, it returns LONG_MAX or 
  29174. LONG_MIN, according to the sign of the value and errno is set to ERANGE. If 
  29175. base is not a valid number, strtol sets errno to EDOM. 
  29176.  
  29177. If the string pointed to by nptr does not have the expected form, no conversion 
  29178. is performed and the value of nptr is stored in the object pointed to by 
  29179. endptr, provided that endptr is not a NULL pointer. 
  29180.  
  29181.  
  29182. ΓòÉΓòÉΓòÉ <hidden> Example of strtol ΓòÉΓòÉΓòÉ
  29183.  
  29184. /************************************************************************
  29185.  
  29186. This example converts the strings to a long value.  It prints out the converted 
  29187. value and the substring that stopped the conversion. 
  29188.  
  29189. ************************************************************************/
  29190.  
  29191. #include <stdlib.h>
  29192. #include <stdio.h>
  29193.  
  29194. int main(void)
  29195. {
  29196.    char *string,*stopstring;
  29197.    long l;
  29198.    int bs;
  29199.  
  29200.    string = "10110134932";
  29201.    printf("string = %s\n", string);
  29202.    for (bs = 2; bs <= 8; bs *= 2) {
  29203.       l = strtol(string, &stopstring, bs);
  29204.       printf("   strtol = %ld (base %d)\n", l, bs);
  29205.       printf("   Stopped scan at %s\n\n", stopstring);
  29206.    }
  29207.    return 0;
  29208.  
  29209.    /****************************************************************************
  29210.       The output should be:
  29211.  
  29212.       string = 10110134932
  29213.          strtol = 45 (base 2)
  29214.          Stopped scan at 34932
  29215.  
  29216.       strtol = 4423 (base 4)
  29217.       Stopped scan at 4932
  29218.  
  29219.       strtol = 2134108 (base 8)
  29220.       Stopped scan at 932
  29221.    ****************************************************************************/
  29222. }
  29223.  
  29224.  
  29225. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  29226.  
  29227. Example of strtol 
  29228.  
  29229.      atof - Convert Character String to Float 
  29230.      atoi - Convert Character String to Integer 
  29231.      atol - Convert Character String to Long Integer 
  29232.      _atold - Convert Character String to Long Double 
  29233.      _ltoa - Convert Long Integer to String 
  29234.      strtod - Convert Character String to Double 
  29235.      strtold - Convert String to Long Double 
  29236.      strtoll - Convert Character String to Long Long Integer 
  29237.      strtoul - Convert String Segment to Unsigned Integer 
  29238.      wcstod - Convert Wide-Character String to Double 
  29239.      wcstol - Convert Wide-Character to Long Integer 
  29240.      wcstoul - Convert Wide-Character String to Unsigned Long 
  29241.      <stdlib.h> 
  29242.  
  29243.  
  29244. ΓòÉΓòÉΓòÉ 4.286. strtold - Convert String to Long Double ΓòÉΓòÉΓòÉ
  29245.  
  29246.  
  29247. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  29248.  
  29249. #include <stdlib.h>
  29250. long double strtold(const char *nptr, char **endptr);
  29251.  
  29252.  
  29253. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  29254.  
  29255. Language Level:  Extension 
  29256.  
  29257. strtold converts a character string to a long double value. The parameter nptr 
  29258. points to a sequence of characters that can be interpreted as a numerical value 
  29259. of the type long double. When it reads a character that it does not recognize 
  29260. as part of a number, strtold stops reading the string at that character, and 
  29261. sets endptr to point to the remainder of nptr. The character at which strtod 
  29262. stops reading the string may be the null character at the end of that string. 
  29263.  
  29264. The string pointed to by nptr must have the following format: 
  29265.  
  29266. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  29267. Γöé                                        Γöé
  29268. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ>       Γöé
  29269. Γöé   ΓööΓöÇwhitespaceΓöÇΓöÿ  ΓööΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇdigitsΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö¼ΓöÇΓöÿ        Γöé
  29270. Γöé            Γö£ΓöÇ + ΓöÇΓöñ  Γöé     ΓööΓöÇ.ΓöÇΓöÿ  ΓööΓöÇdigitsΓöÇΓöÿ Γöé         Γöé
  29271. Γöé            ΓööΓöÇ Γö┤ ΓöÇΓöÿ  ΓööΓöÇ.ΓöÇΓöÇdigitsΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ         Γöé
  29272. Γöé                                        Γöé
  29273. Γöé >ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><                      Γöé
  29274. Γöé   ΓööΓöÇΓö¼ΓöÇ e ΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdigitsΓöÇΓöÿ                        Γöé
  29275. Γöé    ΓööΓöÇ E ΓöÇΓöÿ  Γö£ΓöÇ + ΓöÇΓöñ                             Γöé
  29276. Γöé        ΓööΓöÇ Γö┤ ΓöÇΓöÿ                             Γöé
  29277. Γöé                                        Γöé
  29278. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  29279.  
  29280. The digits are one or more decimal digits.  If no digits appear before the 
  29281. decimal point, at least one digit must follow the decimal point.  An exponent 
  29282. expressed as a decimal integer can follow the digits.  The exponent can be 
  29283. signed. 
  29284.  
  29285. The value of nptr can also be one of the strings infinity, inf, or nan.  These 
  29286. strings are case insensitive, and can be preceded by a unary minus (-). They 
  29287. are converted to infinity and NaN values. See Infinity and NaN Support for more 
  29288. information about using infinity and NaN values. 
  29289.  
  29290. If the string pointed to by nptr does not have the expected form, no conversion 
  29291. is performed and endptr points to the value of nptr. 
  29292.  
  29293. Return Value 
  29294. If successful, strtold returns the value of the long double number.  If it 
  29295. fails, strtold returns 0.  For an underflow or overflow, it returns the 
  29296. following: 
  29297.  
  29298.  Condition           Return Value 
  29299.  Underflow           0 with errno set to ERANGE 
  29300.  Positive overflow   +_LHUGE_VAL 
  29301.  Negative overflow   -_LHUGE_VAL. 
  29302.  
  29303.  
  29304. ΓòÉΓòÉΓòÉ <hidden> Example of strtold ΓòÉΓòÉΓòÉ
  29305.  
  29306. /************************************************************************
  29307.  
  29308. This example uses strtold to convert two strings, "  -001234.5678e10end of 
  29309. string" and "NaNthis cannot be converted" to their corresponding long double 
  29310. values.  It also prints out the part of the string that cannot be converted. 
  29311.  
  29312. ************************************************************************/
  29313.  
  29314. #include <stdlib.h>
  29315. #include <stdio.h>
  29316.  
  29317. int main(void)
  29318. {
  29319.    char *nptr;
  29320.    char *endptr;
  29321.  
  29322.    nptr = "  -001234.5678e10end of string";
  29323.    printf("strtold = %.10Le\n", strtold(nptr, &endptr));
  29324.    printf("end pointer at = %s\n\n", endptr);
  29325.    nptr = "NaNthis cannot be converted";
  29326.    printf("strtold = %.10Le\n", strtold(nptr, &endptr));
  29327.    printf("end pointer at = %s\n\n", endptr);
  29328.    return 0;
  29329.  
  29330.    /****************************************************************************
  29331.       The output should be:
  29332.  
  29333.       strtold = -1.2345678000e+13
  29334.       end pointer at = end of string
  29335.  
  29336.       strtold = nan
  29337.       end pointer at = this cannot be converted
  29338.    ****************************************************************************/
  29339. }
  29340.  
  29341.  
  29342. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  29343.  
  29344. Example of strtold 
  29345.  
  29346.      atof - Convert Character String to Float 
  29347.      atoi - Convert Character String to Integer 
  29348.      atol - Convert Character String to Long Integer 
  29349.      _atold - Convert Character String to Long Double 
  29350.      strtod - Convert Character String to Double 
  29351.      strtol - Convert Character String to Long Integer 
  29352.      strtoul - Convert String Segment to Unsigned Integer 
  29353.      wcstod - Convert Wide-Character String to Double 
  29354.      wcstol - Convert Wide-Character to Long Integer 
  29355.      wcstoul - Convert Wide-Character String to Unsigned Long 
  29356.      Infinity and NaN Support 
  29357.      <stdlib.h> 
  29358.  
  29359.  
  29360. ΓòÉΓòÉΓòÉ 4.287. strtoll - Convert Character String to Long Long Integer ΓòÉΓòÉΓòÉ
  29361.  
  29362.  
  29363. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  29364.  
  29365. #include <stdlib.h>
  29366. long long strtoll(const char *nptr, char **endptr, int base);
  29367.  
  29368.  
  29369. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  29370.  
  29371. Language Level: Extension 
  29372.  
  29373. strtoll converts a character string to a long long value. The parameter nptr 
  29374. points to a sequence of characters that can be interpreted as a numerical value 
  29375. of type long long int. This function stops reading the string at the first 
  29376. character that it cannot recognize as part of a number. This character can be 
  29377. the null character (\0) at the end of the string. The ending character can also 
  29378. be the first numeric character greater than or equal to the base. 
  29379.  
  29380. When you use the strtoll function, nptr should point to a string with the 
  29381. following form: 
  29382.  
  29383. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  29384. Γöé                                        Γöé
  29385. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><              Γöé
  29386. Γöé   ΓööΓöÇwhite-spaceΓöÇΓöÿ  Γö£ΓöÇ+ΓöÇΓöñ  Γö£ΓöÇ0ΓöÇΓöÇΓöñ  ΓööΓöÇdigitsΓöÇΓöÿ                Γöé
  29387. Γöé            ΓööΓöÇΓö┤ΓöÇΓöÿ  Γö£ΓöÇ0xΓöÇΓöñ                      Γöé
  29388. Γöé               ΓööΓöÇ0XΓöÇΓöÿ                      Γöé
  29389. Γöé                                        Γöé
  29390. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  29391.  
  29392. If base is in the range of 2 through 36, it becomes the base of the number. If 
  29393. base is 0, the prefix determines the base (8, 16, or 10):  the prefix 0 means 
  29394. base 8 (octal);  the prefix 0x or 0X means base 16 (hexadecimal); using any 
  29395. other digit without a prefix means decimal. 
  29396.  
  29397. Return Value 
  29398. strtoll returns the value represented in the string, except when the 
  29399. representation causes an overflow. For an overflow, it returns LONGLONG_MAX or 
  29400. LONGLONG_MIN, according to the sign of the value and errno is set to ERANGE. If 
  29401. base is not a valid number, strtoll sets errno to EDOM. 
  29402.  
  29403. errno is set to ERANGE for the exceptional cases, depending on the base of the 
  29404. value.  If the string pointed to by nptr does not have the expected form, no 
  29405. conversion is performed and the value of nptr is stored in the object pointed 
  29406. to by endptr, provided that endptr is not a NULL pointer. 
  29407.  
  29408.  
  29409. ΓòÉΓòÉΓòÉ <hidden> Example of strtoll ΓòÉΓòÉΓòÉ
  29410.  
  29411. /************************************************************************
  29412.  
  29413. This example converts the strings to a long long value.  It prints out the 
  29414. converted value and the substring that stopped the conversion. 
  29415.  
  29416. ************************************************************************/
  29417.  
  29418. #include <stdlib.h>
  29419. #include <stdio.h>
  29420.  
  29421. int main(void)
  29422. {
  29423.    char *string,*stopstring;
  29424.    long long ll;
  29425.    int bs;
  29426.  
  29427.    string = "10110134932";
  29428.    printf("string = %s\n\n", string);
  29429.    for (bs = 2; bs <= 8; bs *= 2) {
  29430.       ll = strtoll(string, &stopstring, bs);
  29431.       printf("   strtoll = %lld (base %d)\n", ll, bs);
  29432.       printf("   Scan stopped at %s\n\n", stopstring);
  29433.    }
  29434.    return 0;
  29435.  
  29436.    /****************************************************************************
  29437.       The output should be:
  29438.  
  29439.       string = 10110134932
  29440.  
  29441.          strtoll = 45 (base 2)
  29442.          Scan stopped at 34932
  29443.  
  29444.          strtoll = 4423 (base 4)
  29445.          Scan stopped at 4932
  29446.  
  29447.          strtoll = 2134108 (base 8)
  29448.          Scan stopped at 932
  29449.    ****************************************************************************/
  29450. }
  29451.  
  29452.  
  29453. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  29454.  
  29455. Example of strtoll 
  29456.  
  29457.      atof - Convert Character String to Float 
  29458.      atoi - Convert Character String to Integer 
  29459.      atol - Convert Character String to Long Integer 
  29460.      _atold - Convert Character String to Long Double 
  29461.      _ltoa - Convert Long Integer to String 
  29462.      strtod - Convert Character String to Double 
  29463.      strtol - Convert Character String to Long Integer 
  29464.      strtold - Convert String to Long Double 
  29465.      strtoul - Convert String Segment to Unsigned Integer 
  29466.      strtoull - Convert String Segment to Unsigned Long Long Integer 
  29467.      wcstod - Convert Wide-Character String to Double 
  29468.      wcstol - Convert Wide-Character to Long Integer 
  29469.      wcstoul - Convert Wide-Character String to Unsigned Long 
  29470.      <stdlib.h> 
  29471.  
  29472.  
  29473. ΓòÉΓòÉΓòÉ 4.288. strtoul - Convert String Segment to Unsigned Integer ΓòÉΓòÉΓòÉ
  29474.  
  29475.  
  29476. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  29477.  
  29478. #include <stdlib.h>
  29479. unsigned long int strtoul(const char *string1, char **string2, int base);
  29480.  
  29481.  
  29482. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  29483.  
  29484. Language Level: ANSI, SAA, XPG4 
  29485.  
  29486. strtoul converts a character string to an unsigned long integer value. The 
  29487. input string1 is a sequence of characters that can be interpreted as a 
  29488. numerical value of the type unsigned long int. strtoul stops reading the string 
  29489. at the first character that it cannot recognize as part of a number. This 
  29490. character can be the first numeric character greater than or equal to the base. 
  29491. strtoul  sets string2 to point to the resulting output string if a conversion 
  29492. is performed, and provided that string2 is not a NULL pointer. 
  29493.  
  29494. When you use strtoul, string1 should point to a string with the following form: 
  29495.  
  29496. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  29497. Γöé                                        Γöé
  29498. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><              Γöé
  29499. Γöé   ΓööΓöÇwhite-spaceΓöÇΓöÿ  Γö£ΓöÇ+ΓöÇΓöñ  Γö£ΓöÇ0ΓöÇΓöÇΓöñ  ΓööΓöÇdigitsΓöÇΓöÿ                Γöé
  29500. Γöé            ΓööΓöÇΓö┤ΓöÇΓöÿ  Γö£ΓöÇ0xΓöÇΓöñ                      Γöé
  29501. Γöé               ΓööΓöÇ0XΓöÇΓöÿ                      Γöé
  29502. Γöé                                        Γöé
  29503. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  29504.  
  29505. If base is in the range of 2 through 36, it becomes the base of the number.  If 
  29506. base is 0, the prefix determines the base (8, 16, or 10): the prefix 0 means 
  29507. base 8 (octal); the prefix 0x or 0X means base 16 (hexadecimal);  using any 
  29508. other digit without a prefix means decimal. 
  29509.  
  29510. Return Value 
  29511. strtoul returns the value represented in the string, or 0 if no conversion 
  29512. could be performed. For an overflow, strtoul returns ULONG_MAX and sets errno 
  29513. to ERANGE.  If base is not a valid number, strtoul sets errno to EDOM. 
  29514.  
  29515.  
  29516. ΓòÉΓòÉΓòÉ <hidden> Example of strtoul ΓòÉΓòÉΓòÉ
  29517.  
  29518. /************************************************************************
  29519.  
  29520. This example converts the string to an unsigned long value.  It prints out the 
  29521. converted value and the substring that stopped the conversion. 
  29522.  
  29523. ************************************************************************/
  29524.  
  29525. #include <stdio.h>
  29526. #include <stdlib.h>
  29527.  
  29528. #define  BASE          2
  29529.  
  29530. int main(void)
  29531. {
  29532.    char *string,*stopstring;
  29533.    unsigned long ul;
  29534.  
  29535.    string = "1000e13 e";
  29536.    printf("string = %s\n", string);
  29537.    ul = strtoul(string, &stopstring, BASE);
  29538.    printf("   strtoul = %ld (base %d)\n", ul, BASE);
  29539.    printf("   Stopped scan at %s\n\n", stopstring);
  29540.    return 0;
  29541.  
  29542.    /****************************************************************************
  29543.       The output should be:
  29544.  
  29545.       string = 1000e13 e
  29546.          strtoul = 8 (base 2)
  29547.          Stopped scan at e13 e
  29548.    ****************************************************************************/
  29549. }
  29550.  
  29551.  
  29552. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  29553.  
  29554. Example of strtoul 
  29555.  
  29556.      atof - Convert Character String to Float 
  29557.      atoi - Convert Character String to Integer 
  29558.      atol - Convert Character String to Long Integer 
  29559.      _atold - Convert Character String to Long Double 
  29560.      strtod - Convert Character String to Double 
  29561.      strtol - Convert Character String to Long Integer 
  29562.      strtold - Convert String to Long Double 
  29563.      strtoll - Convert Character String to Long Long Integer 
  29564.      strtoull - Convert String Segment to Unsigned Long Long Integer 
  29565.      _ultoa - Convert Unsigned Long Integer to String 
  29566.      wcstod - Convert Wide-Character String to Double 
  29567.      wcstol - Convert Wide-Character to Long Integer 
  29568.      wcstoul - Convert Wide-Character String to Unsigned Long 
  29569.      <stdlib.h> 
  29570.  
  29571.  
  29572. ΓòÉΓòÉΓòÉ 4.289. strtoull - Convert String Segment to Unsigned Long Long Integer ΓòÉΓòÉΓòÉ
  29573.  
  29574.  
  29575. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  29576.  
  29577. #include <stdlib.h>
  29578. unsigned long long int strtoull(const char *string1, char **string2, int base);
  29579.  
  29580.  
  29581. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  29582.  
  29583. Language Level: Extension 
  29584.  
  29585. strtoull converts a character string to an unsigned long long integer value. 
  29586. The input string1 is a sequence of characters that can be interpreted as a 
  29587. numerical value of the type unsigned long long int. strtoull stops reading the 
  29588. string at the first character that it cannot recognize as part of a number. 
  29589. This character can be the first numeric character greater than or equal to the 
  29590. base. strtoull  sets string2 to point to the resulting output string if a 
  29591. conversion is performed, and provided that string2 is not a NULL pointer. 
  29592.  
  29593. When you use strtoull, string1 should point to a string with the following 
  29594. form: 
  29595.  
  29596. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  29597. Γöé                                        Γöé
  29598. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><              Γöé
  29599. Γöé   ΓööΓöÇwhite-spaceΓöÇΓöÿ  Γö£ΓöÇ+ΓöÇΓöñ  Γö£ΓöÇ0ΓöÇΓöÇΓöñ  ΓööΓöÇdigitsΓöÇΓöÿ                Γöé
  29600. Γöé            ΓööΓöÇΓö┤ΓöÇΓöÿ  Γö£ΓöÇ0xΓöÇΓöñ                      Γöé
  29601. Γöé               ΓööΓöÇ0XΓöÇΓöÿ                      Γöé
  29602. Γöé                                        Γöé
  29603. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  29604.  
  29605. If base is in the range of 2 through 36, it becomes the base of the number.  If 
  29606. base is 0, the prefix determines the base (8, 16, or 10): the prefix 0 means 
  29607. base 8 (octal); the prefix 0x or 0X means base 16 (hexadecimal);  using any 
  29608. other digit without a prefix means decimal. 
  29609.  
  29610. Return Value 
  29611. strtoull returns the value represented in the string, or 0 if no conversion 
  29612. could be performed. For an overflow, strtoull returns ULONGLONG_MAX and sets 
  29613. errno to ERANGE.  If base is not a valid number, strtoull sets errno to EDOM. 
  29614.  
  29615.  
  29616. ΓòÉΓòÉΓòÉ <hidden> Example of strtoull ΓòÉΓòÉΓòÉ
  29617.  
  29618. /************************************************************************
  29619.  
  29620. This example converts the string to an unsigned long long value.  It prints out 
  29621. the converted value and the substring that stopped the conversion. 
  29622.  
  29623. ************************************************************************/
  29624.  
  29625. #include <stdio.h>
  29626. #include <stdlib.h>
  29627.  
  29628. #define  BASE          2
  29629.  
  29630. int main(void)
  29631. {
  29632.    char *string,*stopstring;
  29633.    unsigned long long ull;
  29634.  
  29635.    string = "1000e13 e";
  29636.    printf("string = %s\n", string);
  29637.    ull = strtoull(string, &stopstring, BASE);
  29638.    printf("   strtoull = %lld (base %d)\n", ull, BASE);
  29639.    printf("   Scan stopped at %s\n\n", stopstring);
  29640.    return 0;
  29641.  
  29642.    /****************************************************************************
  29643.       The output should be:
  29644.  
  29645.       string = 1000e13 e
  29646.          strtoul = 8 (base 2)
  29647.          Scan stopped at e13 e
  29648.    ****************************************************************************/
  29649. }
  29650.  
  29651.  
  29652. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  29653.  
  29654. Example of strtoull 
  29655.  
  29656.      atof - Convert Character String to Float 
  29657.      atoi - Convert Character String to Integer 
  29658.      atol - Convert Character String to Long Integer 
  29659.      _atold - Convert Character String to Long Double 
  29660.      strtod - Convert Character String to Double 
  29661.      strtol - Convert Character String to Long Integer 
  29662.      strtoll - Convert Character String to Long Long Integer 
  29663.      strtold - Convert String to Long Double 
  29664.      _ultoa - Convert Unsigned Long Integer to String 
  29665.      wcstod - Convert Wide-Character String to Double 
  29666.      wcstol - Convert Wide-Character to Long Integer 
  29667.      wcstoul - Convert Wide-Character String to Unsigned Long 
  29668.      <stdlib.h> 
  29669.  
  29670.  
  29671. ΓòÉΓòÉΓòÉ 4.290. strupr - Convert Lowercase to Uppercase ΓòÉΓòÉΓòÉ
  29672.  
  29673.  
  29674. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  29675.  
  29676. #include <string.h>
  29677. char *strupr(char *string);
  29678.  
  29679.  
  29680. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  29681.  
  29682. Language Level:  Extension 
  29683.  
  29684. strupr converts any lowercase letters in string to uppercase. Other characters 
  29685. are not affected. 
  29686.  
  29687. Return Value 
  29688. strupr returns a pointer to the converted string. There is no error return. 
  29689.  
  29690.  
  29691. ΓòÉΓòÉΓòÉ <hidden> Example of strupr ΓòÉΓòÉΓòÉ
  29692.  
  29693. /************************************************************************
  29694.  
  29695. This example makes a copy in all-uppercase of the string "Win32", and then 
  29696. prints the copy. 
  29697.  
  29698. ************************************************************************/
  29699.  
  29700. #include <string.h>
  29701. #include <stdio.h>
  29702.  
  29703. int main(void)
  29704. {
  29705.    char *string = "Hello World!";
  29706.    char *copy;
  29707.  
  29708.    copy = strupr(strdup(string));
  29709.    printf("This is a copy of the string with all letters capitalized: %s\n",
  29710.           copy);
  29711.    return 0;
  29712.  
  29713.    /****************************************************************************
  29714.       The output should be:
  29715.  
  29716.       This is a copy of the string with all letters capitalized: HELLO WORLD!
  29717.    ****************************************************************************/
  29718. }
  29719.  
  29720.  
  29721. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  29722.  
  29723. Example of strupr 
  29724.  
  29725.      strlwr - Convert Uppercase to Lowercase 
  29726.      _toascii - _tolower - _toupper - Convert Character 
  29727.      tolower() - toupper() - Convert Character Case 
  29728.      towlower - towupper - Convert Wide Character Case 
  29729.      <string.h> 
  29730.  
  29731.  
  29732. ΓòÉΓòÉΓòÉ 4.291. strxfrm - Transform String ΓòÉΓòÉΓòÉ
  29733.  
  29734.  
  29735. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  29736.  
  29737. #include <string.h>
  29738. size_t strxfrm(char *str1, const char *str2, size_t n);
  29739.  
  29740.  
  29741. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  29742.  
  29743. Language Level:  ANSI, SAA, XPG4 
  29744.  
  29745. strxfrm transforms the string pointed to by str2 and places the resulting 
  29746. string into the array pointed to by str1. The transformation is determined by 
  29747. the program's locale. The transformed string may not be displayable or 
  29748. printable, but can be used with the strcmp or strncmp functions. 
  29749.  
  29750. The result of applying  strcoll to two separate strings before their 
  29751. transformation is equal to the result of applying strcmp, or strncmp, to the 
  29752. same two strings after their transformation. 
  29753.  
  29754. No more than n bytes are placed into the area pointed to by str1, including the 
  29755. terminating null byte. If n is 0, str1 can be a null pointer. 
  29756.  
  29757. Return Value 
  29758. strxfrm returns the length of the transformed string (excluding the null byte). 
  29759. When n is 0 and str1 is a null pointer, the length returned is one less than 
  29760. the number of bytes required to contain the transformed string. If an error 
  29761. occurs, strxfrm function returns (size_t)-1 and sets errno to indicate the 
  29762. error. 
  29763.  
  29764. Note: 
  29765.  
  29766.    1. The string returned by strxfrm contains the weights for each order of the 
  29767.       characters within the string. As a result, the string returned may be 
  29768.       longer than the input string; it does not contain printable characters. 
  29769.  
  29770.    2. strxfrm calls malloc when the LC_COLLATE category specifies backward on 
  29771.       the order_start keyword, the substitute keyword is specified, or the 
  29772.       locale has one-to-many mapping. If malloc fails, strxfrm also fails. 
  29773.  
  29774.    3. If the locale supports double-byte characters (MB_CUR_MAX specified as 
  29775.       2), strxfrm validates the multibyte characters. (Previously it did not 
  29776.       validate the string.) strxfrm will fail if the string contains invalid 
  29777.       multibyte characters. 
  29778.  
  29779.    4. If MB_CUR_MAX is defined as 2, and no collation is defined for DBCS chars 
  29780.       in the current locale, the DBCS characters will collate after the 
  29781.       single-byte characters. 
  29782.  
  29783.  
  29784. ΓòÉΓòÉΓòÉ <hidden> Example of strxfrm ΓòÉΓòÉΓòÉ
  29785.  
  29786. /************************************************************************
  29787.  
  29788. This example uses strxfrm to transform two different strings that have the same 
  29789. collating weight. It then calls strcmp to compare the new strings. 
  29790.  
  29791. ************************************************************************/
  29792.  
  29793. #include <stdlib.h>
  29794. #include <stdio.h>
  29795. #include <locale.h>
  29796. #include <string.h>
  29797.  
  29798. #if (1 == __TOS_OS2__)
  29799.    #define LOCNAME "da_dk.ibm-865"     /* OS/2 name        */
  29800.    char *string1 = "str\xA0ng1a";
  29801.    char *string2 = "strang1\x83";
  29802. #else
  29803.    #define LOCNAME "da_dk.ibm-1252"    /* Windows name     */
  29804.    char *string1 = "str\xE0ng1a";
  29805.    char *string2 = "strang1\xE2";
  29806. #endif
  29807.  
  29808. int main(void)
  29809. {
  29810.    char *newstring1, *newstring2;
  29811.    size_t length1, length2, pw1, pw2;
  29812.  
  29813.    if (NULL == setlocale(LC_ALL, LOCNAME)) {
  29814.       printf("Locale \"%s\" could not be loaded\n", LOCNAME);
  29815.       exit(1);
  29816.    }
  29817.    length1 = strxfrm(NULL, string1, 0);
  29818.    pw1 = strlen(string1);
  29819.    length2 = strxfrm(NULL, string2, 0);
  29820.    pw2 = strlen(string2);
  29821.    if (NULL == (newstring1 =(char*) calloc(length1 + 1, 1)) ||
  29822.        NULL == (newstring2 =(char*) calloc(length2 + 1, 1))) {
  29823.       printf("insufficient memory\n");
  29824.       exit(1);
  29825.    }
  29826.    /* Get primary weight of each string                                       */
  29827.    if ((strxfrm(newstring1, string1, pw1 + 1) != length1) ||
  29828.        (strxfrm(newstring2, string2, pw2 + 1) != length2)) {
  29829.       printf("error in string processing\n");
  29830.       exit(1);
  29831.    }
  29832.    if (0 != strcmp(newstring1, newstring2))
  29833.       printf("wrong results\n");
  29834.    else
  29835.       printf("correct results\n");
  29836.    return 0;
  29837.  
  29838.    /****************************************************************************
  29839.       The output should be similar to :
  29840.  
  29841.       correct results
  29842.    ****************************************************************************/
  29843. }
  29844.  
  29845.  
  29846. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  29847.  
  29848. Example of strxfrm 
  29849.  
  29850.      localeconv - Retrieve Information from the Environment 
  29851.      setlocale - Set Locale 
  29852.      strcmp - Compare Strings 
  29853.      strcoll - Compare Strings Using Collation Rules 
  29854.      strncmp - Compare Strings 
  29855.      wcsxfrm - Transform Wide-Character String 
  29856.      <string.h> 
  29857.  
  29858.  
  29859. ΓòÉΓòÉΓòÉ 4.292. swab - Swap Adjacent Bytes ΓòÉΓòÉΓòÉ
  29860.  
  29861.  
  29862. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  29863.  
  29864. #include <stdlib.h>
  29865. void swab(char *source, char *destination, int n);
  29866.  
  29867.  
  29868. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  29869.  
  29870. Language Level:  Extension 
  29871.  
  29872. swab copies n bytes from source, swaps each pair of adjacent bytes, and stores 
  29873. the result at destination.  The integer n should be an even number to allow for 
  29874. swapping. If n is an odd number, a null character (\0) is added after the last 
  29875. byte. 
  29876.  
  29877. swab is typically used to prepare binary data for transfer to a machine that 
  29878. uses a different byte order. 
  29879.  
  29880. Note:  In earlier releases of VisualAge C++, swab began with an underscore 
  29881. (_swab). Because it is defined by the X/Open standard, the underscore has been 
  29882. removed. For compatibility, VisualAge for C++ will map _swab to swab for you. 
  29883.  
  29884. Return Value 
  29885. There is no return value. 
  29886.  
  29887.  
  29888. ΓòÉΓòÉΓòÉ <hidden> Example of swab ΓòÉΓòÉΓòÉ
  29889.  
  29890. /************************************************************************
  29891.  
  29892. This example copies n bytes from one location to another, swapping each pair of 
  29893. adjacent bytes. In the output x is replaced with null character. 
  29894.  
  29895. ************************************************************************/
  29896.  
  29897. #include <stdlib.h>
  29898. #include <stdio.h>
  29899.  
  29900. int main(void)
  29901. {
  29902.    char from[21] = "hTsii  s atsirgn..x ";
  29903.    char to[21];
  29904.  
  29905.    swab(from, to, 19);  /* swap bytes */
  29906.    printf("%s\n", to);
  29907.  
  29908.    return 0;
  29909.  
  29910.    /****************************************************************************
  29911.       The output should be:
  29912.  
  29913.       This is a string..
  29914.    ****************************************************************************/
  29915. }
  29916.  
  29917.  
  29918. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  29919.  
  29920. Example of swab 
  29921.  
  29922.      fgetc - Read a Character 
  29923.      fputc - Write Character 
  29924.      <stdlib.h> 
  29925.  
  29926.  
  29927. ΓòÉΓòÉΓòÉ 4.293. swprintf - Format and Write Wide Characters to Buffer ΓòÉΓòÉΓòÉ
  29928.  
  29929.  
  29930. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  29931.  
  29932. #include <wchar.h>
  29933. int swprintf(wchar_t *wcsbuffer, size_t n,
  29934.              const wchar_t *format, argument-list);
  29935.  
  29936.  
  29937. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  29938.  
  29939. Language Level:  ANSI 93 
  29940.  
  29941. swprintf formats and stores a series of wide characters and values into the 
  29942. wide-character buffer wcsbuffer. swprintf is equivalent to sprintf, except that 
  29943. it operates on wide characters. 
  29944.  
  29945. The value n specifies the maximum number of wide characters to be written, 
  29946. including the terminating null character. 
  29947.  
  29948. swprintf converts each entry in the argument-list according to the 
  29949. corresponding wide-character format specifier in format. The format has the 
  29950. same form and function as the format string for printf, with the following 
  29951. exceptions: 
  29952.  
  29953.      %c (without an l prefix) converts an integer argument to wchar_t, as if 
  29954.       by calling mbtowc. 
  29955.      %lc converts a wint_t to wchar_t. 
  29956.      %s (without an l prefix) converts an array of multibyte characters to an 
  29957.       array of wchar_t, as if by calling mbrtowc. The array is written up to, 
  29958.       but not including, the terminating null character, unless the precision 
  29959.       specifies a shorter output. 
  29960.      %ls writes an array of wchar_t. The array is written up to, but not 
  29961.       including, the terminating null character, unless the precision specifies 
  29962.       a shorter output. 
  29963.  
  29964.  If you specify a null string for the %s or %ls format specifier, swprintf 
  29965.  prints (null). 
  29966.  
  29967.  For a complete description of format specifiers, see printf - Print Formatted 
  29968.  Characters. 
  29969.  
  29970.  A null wide character is added to the end of the wide characters written; the 
  29971.  null wide character is not counted as part of the returned value. If copying 
  29972.  takes place between objects that overlap, the behavior is undefined. 
  29973.  
  29974.  In extended mode, swprintf also converts floating-point values of NaN and 
  29975.  infinity to the strings "NAN" or "nan" and "INFINITY" or "infinity". The case 
  29976.  and sign of the string is determined by the format specifiers.  See Infinity 
  29977.  and NaN Support for more information on infinity and NaN values. 
  29978.  
  29979.  Return Value 
  29980.  swprintf returns the number of bytes written in the array, not counting the 
  29981.  terminating null wide character. 
  29982.  
  29983.  
  29984. ΓòÉΓòÉΓòÉ <hidden> Example of swprintf ΓòÉΓòÉΓòÉ
  29985.  
  29986. /************************************************************************
  29987.  
  29988. This example uses swprintf to format and print several values to buffer. 
  29989.  
  29990. ************************************************************************/
  29991.  
  29992. #include <wchar.h>
  29993. #include <stdio.h>
  29994.  
  29995. #define BUF_SIZE 100
  29996.  
  29997. int main(void)
  29998. {
  29999.    wchar_t wcsbuf[BUF_SIZE];
  30000.    wchar_t wstring[] = L"ABCDE";
  30001.    int     num;
  30002.  
  30003.    num = swprintf(wcsbuf, BUF_SIZE, L"%s", "xyz");
  30004.    num += swprintf(wcsbuf + num, BUF_SIZE - num, L"%ls", wstring);
  30005.    num += swprintf(wcsbuf + num, BUF_SIZE - num, L"%i", 100);
  30006.    printf("The array wcsbuf contains: \"%ls\"\n", wcsbuf);
  30007.    return 0;
  30008.  
  30009.    /****************************************************************************
  30010.       The output should be similar to :
  30011.  
  30012.       The array wcsbuf contains: "xyzABCDE100"
  30013.    ****************************************************************************/
  30014. }
  30015.  
  30016.  
  30017. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  30018.  
  30019. Example of swprintt 
  30020.  
  30021.      printf - Print Formatted Characters 
  30022.      sprintf - Print Formatted Data to Buffer 
  30023.      swscanf - Read Wide Characters from Buffer 
  30024.      vswprintf - Format and Write Wide Characters to Buffer 
  30025.      <wchar.h> 
  30026.  
  30027.  
  30028. ΓòÉΓòÉΓòÉ 4.294. swscanf - Read Wide Characters from Buffer ΓòÉΓòÉΓòÉ
  30029.  
  30030.  
  30031. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  30032.  
  30033. #include <wchar.h>
  30034. int swscanf(const wchar_t *wcsbuffer, const wchar_t *format,
  30035.             argument-list);
  30036.  
  30037.  
  30038. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  30039.  
  30040. Language Level:  ANSI 93 
  30041.  
  30042. swscanf reads wide data from wcsbuffer into the locations given by 
  30043. argument-list. swscanf is equivalent to sscanf, except that it operates on wide 
  30044. characters. 
  30045.  
  30046. Each argument in the argument-list must point to a variable with a type that 
  30047. corresponds to a type specifier in format. The format has the same form and 
  30048. function as the format string for scanf, with the following exceptions: 
  30049.  
  30050.      %c (with no l prefix) converts one or more wchar_t characters (depending 
  30051.       on precision) to multibyte characters, as if by calling wcrtomb. 
  30052.      %lc converts one or more wchar_t characters (depending on precision) to 
  30053.       an array of wchar_t. 
  30054.      %s (with no l prefix) converts a sequence of non-white-space wchar_t 
  30055.       characters to multibyte characters, as if by calling wcrtomb. The array 
  30056.       includes the terminating null character. 
  30057.      %ls copies an array of wchar_t, including the terminating null wide 
  30058.       character, to an array of wchar_t. 
  30059.  
  30060.  For a complete description of format specifiers, see scanf Format 
  30061.  Specification Fields. 
  30062.  
  30063.  When swscanf reaches the end of the wide character string, it stops parsing 
  30064.  and returns a value as indicated below (this behavior is the same as sscanf). 
  30065.  If copying takes place between objects that overlap, the behavior is 
  30066.  undefined. 
  30067.  
  30068.  Return Value 
  30069.  swscanf returns the number of input items that were successfully converted and 
  30070.  assigned.  The value does not include fields that were read but not assigned. 
  30071.  If an input failure (such as the end of the string) is encountered before any 
  30072.  conversion, swscanf returns EOF. 
  30073.  
  30074.  
  30075. ΓòÉΓòÉΓòÉ <hidden> Example of swscanf ΓòÉΓòÉΓòÉ
  30076.  
  30077. /************************************************************************
  30078.  
  30079. This example uses swscanf to scan in wide characters, and then prints them. 
  30080.  
  30081. ************************************************************************/
  30082.  
  30083. #include <wchar.h>
  30084. #include <stdio.h>
  30085.  
  30086. int main(void)
  30087. {
  30088.    wchar_t *tokenstring = L"xyz ╨ôA╨ôB╨ôC╨ôD╨ôEΓöÇa 1234";
  30089.    char    string[20];
  30090.    wchar_t wstring[20];
  30091.    wchar_t wc;
  30092.    int     i;
  30093.    int     num;
  30094.  
  30095.    num = swscanf(tokenstring, L"%s %ls %lc %d", string, wstring, &wc, &i);
  30096.    printf("string   = %s\n",  string );
  30097.    printf("wstring  = %ls\n", wstring );
  30098.    printf("wc       = %lc\n", wc );
  30099.    printf("i        = %d\n",  i );
  30100.    printf("total number of fields scanned: %i\n", num);
  30101.    return 0;
  30102.  
  30103.    /****************************************************************************
  30104.       The output should be similar to :
  30105.  
  30106.       string   = xyz
  30107.       wstring  = ╨ôA╨ôB╨ôC╨ôD╨ôEΓöÇa
  30108.       wc       = 1
  30109.       i        = 234
  30110.       total number of fields scanned: 4
  30111.    ****************************************************************************/
  30112. }
  30113.  
  30114.  
  30115. ΓòÉΓòÉΓòÉ <hidden> Related I