home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / HELP / DDE4CLIB.INF (.txt) < prev    next >
OS/2 Help File  |  1993-10-13  |  754KB  |  27,501 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. How to Use the Online C Library Reference ΓòÉΓòÉΓòÉ
  3.  
  4. The C/C++ Tools Online C Library Reference is a library reference guide for C 
  5. and C++ programmers.  It provides information about the C/C++ Tools 
  6. implementation of the C language library, including code examples, to enable 
  7. you to write C and C++ programs. 
  8.  
  9. This document is a reference rather than a tutorial.  It assumes you are 
  10. already familiar with C programming concepts. 
  11.  
  12. Information applies to the C language, but many of the functions and macros can 
  13. be called from C++ language applications 
  14.  
  15. Before you begin to use this information, it would be helpful to understand how 
  16. you can: 
  17.  
  18. o Expand the Contents to see all available topics 
  19. o Obtain additional information for a highlighted word or phrase 
  20. o Use action bar choices 
  21.  
  22. How to Use the Contents 
  23.  
  24. When the Contents window first appears, some topics have a plus (+) sign beside 
  25. them. The plus sign indicates that additional topics are available. 
  26.  
  27. To expand the Contents if you are using a mouse, click on the plus sign.  If 
  28. you are using the keyboard, use the Up or Down Arrow key to highlight the 
  29. topic, and press the plus (+) key.  For example, Preprocessor Directives has a 
  30. plus sign beside it.  To see additional topics for that heading, click on the 
  31. plus sign or highlight that topic and press the plus (+) key. 
  32.  
  33. To view a topic, double-click on the topic (or press the Up or Down Arrow key 
  34. to highlight the topic, and then press the Enter key). 
  35.  
  36. How to Obtain Additional Information 
  37.  
  38. After you select a topic, the information for that topic appears in a window. 
  39. Highlighted words or phrases indicate that additional information is available. 
  40. You will notice that certain words and phrases are highlighted in green 
  41. letters, or in white letters on a black background. These are called hypertext 
  42. terms.  If you are using a mouse, double-click on the highlighted word.  If you 
  43. are using a keyboard, press the Tab key to move to the highlighted word, and 
  44. then press the Enter key.  Additional information then appears in a window. 
  45.  
  46. How to Use Action Bar Choices 
  47.  
  48. Several choices are available for managing information presented in the 
  49. C/C++Tools Online Language Reference. There are three pull-down menus on the 
  50. action bar:  the Services menu, the Options menu, and the Help menu. 
  51.  
  52. The actions that are selectable from the Services menu operate on the active 
  53. window currently displayed on the screen. These actions include the following: 
  54.  
  55. Bookmark 
  56.   Allows you to set a placeholder so you can retrieve information of interest 
  57.   to you. 
  58.  
  59.   When you place a bookmark on a topic, it is added to a list of bookmarks you 
  60.   have previously set.  You can view the list, and you can remove one or all 
  61.   bookmarks from the list.  If you have not set any bookmarks, the list is 
  62.   empty. 
  63.  
  64.   To set a bookmark, do the following: 
  65.  
  66.     1. Select a topic from the Contents. 
  67.     2. When that topic appears, choose the Bookmark option from the Services 
  68.        pull-down. 
  69.     3. If you want to change the name used for the bookmark, type the new name 
  70.        in the field. 
  71.     4. Click on the Place radio button (or press the Up or Down Arrow key to 
  72.        select it). 
  73.     5. Click on OK (or select it and press Enter). The bookmark is then added 
  74.        to the bookmark list. 
  75. Search 
  76.   Allows you to find occurrences of a word or phrase in the current topic, 
  77.   selected topics, or all topics. 
  78.  
  79.   You can specify a word or phrase to be searched.  You can also limit the 
  80.   search to a set of topics by first marking the topics in the Contents list. 
  81.  
  82.   To search for a word or phrase in all topics, do the following: 
  83.  
  84.     1. Choose the Search option from the Services pull-down. 
  85.     2. Type the word or words to be searched for. 
  86.     3. Click on All sections (or press the 
  87.  
  88.                Up or Down Arrow keys to select it).
  89.  
  90.     4. Click on Search (or select it and press Enter) to begin the search. 
  91.     5. The list of topics where the word or phrase appears is displayed. 
  92. Print 
  93.   Allows you to print one or more topics. You can also print a set of topics by 
  94.   first marking the topics in the Contents list. 
  95.  
  96.   To print the document Contents list, do the following: 
  97.  
  98.     1. Choose Print from the Services pull-down. 
  99.     2. Click on Contents (or press the Up or Down Arrow key to select it). 
  100.     3. Click on Print (or select it and press Enter). 
  101.     4. The Contents list is printed on your printer. 
  102. Copy 
  103.   Allows you to copy a topic that you are viewing to the System Clipboard or to 
  104.   a file that you can edit. This is particularly useful for copying syntax 
  105.   definitions and program samples into the application that you are developing. 
  106.  
  107.   You can copy a topic that you are viewing in two ways: 
  108.  
  109.    o Copy copies the topic that you are viewing into the System Clipboard.  If 
  110.      you are using a Presentation Manager* (PM) editor (for example, the 
  111.      Enhanced Editor) that copies or cuts (or both) to the System Clipboard, 
  112.      and pastes to the System Clipboard, you can easily add the copied 
  113.      information to your program source module. 
  114.  
  115.    o Copy to file copies the topic that you are viewing into a temporary file 
  116.      named TEXT.TMP.  You can later edit that file by using any editor. 
  117.      TEXT.TMP is placed in the directory where your viewable document resides. 
  118.  
  119.   To copy a topic, do the following: 
  120.  
  121.     1. Expand the Contents list and select a topic. 
  122.     2. When the topic appears, choose Copy to file from the Services pull-down. 
  123.     3. The system puts the text pertaining to that topic into the temporary 
  124.        file TEXT.TMP. 
  125.  
  126.   For information on any of the choices in the Services pull-down, highlight 
  127.   the choice and press the F1 key. 
  128.  
  129.   The actions that are selectable from the Options menu allow you to change the 
  130.   way your Contents list is displayed. To expand the Contents and show all 
  131.   levels for all topics, choose Expand all from the Options pull-down. You can 
  132.   also press the Ctrl and * keys together. 
  133.  
  134.   For information on any of the choices in the Options pull-down, highlight the 
  135.   choice and press the F1 key. 
  136.  
  137.   The actions that are selectable from the Help menu allow you to select 
  138.   different types of help information. You can also press the F1 key for help 
  139.   information about the Information Presentation Facility (IPF). 
  140.  
  141.  
  142. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  143.  
  144. o Copyright 
  145. o Edition Notice 
  146. o Notices 
  147. o Trademarks and Service Marks 
  148.  
  149.  
  150. ΓòÉΓòÉΓòÉ 1.1. Copyright ΓòÉΓòÉΓòÉ
  151.  
  152. Copyright International Business Machines Corporation, 1993. All rights 
  153. reserved. 
  154.  
  155. Note to U.S. Government Users - Documentation related to restricted rights - 
  156. Use, duplication, or disclosure is subject to restrictions set forth in GSA ADP 
  157. Schedule Contract with IBM* Corp. 
  158.  
  159.  
  160. ΓòÉΓòÉΓòÉ 1.2. Edition Notice ΓòÉΓòÉΓòÉ
  161.  
  162. Second Edition, November 1993. 
  163.  
  164. This edition applies to Version 2.01 of IBM C/C++ Tools (82G3733, 82G3735, 
  165. 82G3736) and to all subsequent releases and modifications until otherwise 
  166. indicated in new editions.  This publication could include technical 
  167. inaccuracies or typographical errors.  Changes are periodically made to the 
  168. information herein; any such changes will be reported in subsequent revisions. 
  169.  
  170. Requests for publications and for technical information about IBM* products 
  171. should be made to your IBM Authorized Dealer or your IBM Marketing 
  172. Representative. 
  173.  
  174. When you send information to IBM, you grant IBM a nonexclusive right to use or 
  175. distribute the information in any ways it believes appropriate without 
  176. incurring any obligation to you. 
  177.  
  178.  
  179. ΓòÉΓòÉΓòÉ 1.3. Notices ΓòÉΓòÉΓòÉ
  180.  
  181. References in this publication to IBM* products, programs, or services do not 
  182. imply that IBM intends to make these available in all countries in which IBM 
  183. operates. Any reference to an IBM product, program, or service is not intended 
  184. to state or imply that only IBM's product, program, or service may be used. Any 
  185. functionally equivalent product, program, or service that does not infringe any 
  186. of IBM's intellectual property rights may be used instead of the IBM product, 
  187. program, or service. Evaluation and verification of operation in conjunction 
  188. with other products, programs, or services, except those expressly designated 
  189. by IBM, are the user's responsibility. 
  190.  
  191. IBM may have patents or pending patent applications covering subject matter in 
  192. this document.  The furnishing of this document does not give you any license 
  193. to these patents.  You can send license inquiries, in writing, to the IBM 
  194. Director of Commercial Relations, IBM Corporation, Purchase, NY 10577. 
  195.  
  196.  
  197. ΓòÉΓòÉΓòÉ 1.4. Trademarks and Service Marks ΓòÉΓòÉΓòÉ
  198.  
  199. The following terms, denoted by an asterisk (*) in this publication, are 
  200. trademarks or service marks of IBM* Corporation in the United States or other 
  201. countries: 
  202.  
  203. C/2 
  204. C Set/2 
  205. C Set ++ 
  206. Common User Access 
  207. CUA 
  208. IBM 
  209. Operating System/2 
  210. OS/2 
  211. Personal System/2 
  212. Presentation Manager 
  213. PS/2 
  214. SAA 
  215. Systems Application Architecture 
  216. WorkFrame/2 
  217.  
  218. The following terms, denoted by a double asterisk (**) in this publication, are 
  219. trademarks of another county as follows: 
  220.  
  221. AT&T      AT&T Corporation 
  222.  
  223.  
  224. ΓòÉΓòÉΓòÉ <hidden> IBM Trademark ΓòÉΓòÉΓòÉ
  225.  
  226. Trademark of the IBM Corporation. 
  227.  
  228.  
  229. ΓòÉΓòÉΓòÉ <hidden> Non-IBM Trademarks ΓòÉΓòÉΓòÉ
  230.  
  231. AT&T is a trademark of AT&T Corporation. 
  232.  
  233.  
  234. ΓòÉΓòÉΓòÉ 2. The C Library ΓòÉΓòÉΓòÉ
  235.  
  236. This section summarizes the available C library functions. Each library 
  237. function is listed according to the type of function it performs. 
  238.  
  239. o Error Handling 
  240. o Process Control 
  241. o File and Directory Management 
  242. o Searching and Sorting 
  243. o Mathematical 
  244. o Floating-Point Unit Control 
  245. o Time Manipulation 
  246. o Type Conversion 
  247. o Stream Input/Output 
  248. o Low-Level Input/Output 
  249. o Handling Argument Lists 
  250. o Pseudorandom Numbers 
  251. o Dynamic Memory Management 
  252. o Memory Objects 
  253. o Environment Interaction 
  254. o String Operations 
  255. o Character Testing 
  256. o Character Case Mapping 
  257. o Multibyte Character Manipulation 
  258. o C/C++ Tools Extensions 
  259. o Intrinsic Functions 
  260.  
  261.  
  262. ΓòÉΓòÉΓòÉ 2.1. Error Handling ΓòÉΓòÉΓòÉ
  263.  
  264. o assert  - Verify Condition 
  265. o atexit  - Record Program Termination Function 
  266. o _matherr - Process Math Library Errors 
  267. o perror  - Print Error Message 
  268. o raise  - Send Signal 
  269. o _set_crt_msg_handle - Change Runtime Message Output Handle 
  270. o signal Install Interrupt Handlers 
  271. o strerror  - Set Pointer to Runtime Error Message 
  272. o _strerror - Set Pointer to System Error String 
  273.  
  274.  
  275. ΓòÉΓòÉΓòÉ 2.2. Process Control ΓòÉΓòÉΓòÉ
  276.  
  277. o _beginthread - Create New Thread 
  278. o _cwait - Wait for Child Process 
  279. o _disable - Disable Interrupts 
  280. o _enable - Enable Interrupts 
  281. o _endthread - Terminate Current Thread 
  282. o _execl - _execvp - Load and Run Child Process 
  283. o _exit - End Process 
  284. o _freemod - Free User DLL 
  285. o _getpid - Get Process Identifier 
  286. o _getTIBvalue - Get TIB Value 
  287. o _interrupt - Call Interrupt  Procedure 
  288. o _loadmod - Load User DLL 
  289. o _onexit - Record Termination Function 
  290. o _putenv - Modify Environment Variables 
  291. o _searchenv - Search for File 
  292. o _spawnl -_spawnvpe -Start and Run Child Processes 
  293. o _threadstore - Access Thread-Specific Storage 
  294.  
  295.  
  296. ΓòÉΓòÉΓòÉ 2.3. File and Directory Management ΓòÉΓòÉΓòÉ
  297.  
  298. o _chdir - Change Current Working Directory 
  299. o _chdrive - Change Current Working Drive 
  300. o _fstat - Information about Open File 
  301. o _fullpath - Get Full Path Name of Partial Path 
  302. o _getcwd - Get Path Name of Current Directory 
  303. o _getdcwd - Get Full Path Name of Current Directory 
  304. o _getdrive - Get Current Working Drive 
  305. o _makepath - Create Path 
  306. o _mkdir - Create New Directory 
  307. o _rmdir - Remove Directory 
  308. o _splitpath - Decompose Path Name 
  309. o _stat - Get Information about File or Directory 
  310.  
  311.  
  312. ΓòÉΓòÉΓòÉ 2.4. Searching and Sorting ΓòÉΓòÉΓòÉ
  313.  
  314. o bsearch  - Search Arrays 
  315. o _lfind - _lsearch - Find Key in Array 
  316. o _lfind - _lsearch - Find Key in Array 
  317. o qsort  - Sort Array 
  318.  
  319.  
  320. ΓòÉΓòÉΓòÉ 2.5. Mathematical ΓòÉΓòÉΓòÉ
  321.  
  322. o abs  - Calculate Integer Absolute Value 
  323. o acos  - Calculate Arccosine 
  324. o asin  - Calculate Arcsine 
  325. o atan - atan2  - Calculate Arctangent 
  326. o _cabs - Calculate Absolute Value of Complex Number 
  327. o ceil - Integer >= Argument 
  328. o cos  - Calculate Cosine 
  329. o cosh  - Calculate Hyperbolic Cosine 
  330. o div  - Calculate Quotient and Remainder 
  331. o erf  - Calculate Error Functions 
  332. o exp  - Exponential Function 
  333. o fabs  - Calculate Floating-Point Absolute Value 
  334. o _facos - Calculate Arccosine 
  335. o _fasin - Calculate Arcsine 
  336. o _fcos - Calculate Cosine 
  337. o _fcossin - Calculate Cosine and Sine 
  338. o floor - Integer <= Argument 
  339. o fmod  - Floating-Point Remainder 
  340. o _fpatan - Calculate Arctangent 
  341. o _fptan - Calculate Tangent 
  342. o frexp  - Separate Floating-Point Value 
  343. o _fsin - Calculate Sine 
  344. o _fsincos - Calculate Sine and Cosine 
  345. o _fsqrt -  Calculate Square Root 
  346. o _fyl2x - Calculate y * log2(x) 
  347. o _fyl2xp1 -  Calculate y * log2(x + 1) 
  348. o _f2xm1 -  Calculate (2**x) - 1 
  349. o gamma  - Gamma Function 
  350. o hypot  - Calculate Hypotenuse 
  351. o labs  - Calculate long Absolute Value 
  352. o ldexp  - Multiply by a Power of Two 
  353. o ldiv  - Long Division 
  354. o log  - Calculate Natural Logarithm 
  355. o log10  - Calculate Base 10 Logarithm 
  356. o _lrotl - _lrotr - Rotate Bits 
  357. o _lrotl - _lrotr - Rotate Bits 
  358. o max - Return Larger of Two Values 
  359. o min - Return Lesser of Two Values 
  360. o modf  - Separate Floating-Point Value 
  361. o pow  - Compute Power 
  362. o _rotl - _rotr - Bit Rotation 
  363. o _rotl - _rotr - Bit Rotation 
  364. o sin  - Calculate Sine 
  365. o sinh  - Calculate Hyperbolic Sine 
  366. o sqrt  - Calculate Square Root 
  367. o tan  - Calculate Tangent 
  368. o tanh  - Calculate Hyperbolic Tangent 
  369. o Bessel Functions 
  370.  
  371.  
  372. ΓòÉΓòÉΓòÉ 2.6. Floating-Point Unit Control ΓòÉΓòÉΓòÉ
  373.  
  374. o _clear87 - Clear Floating-Point Status Word 
  375. o _control87 - Set Floating-Point Status Word 
  376. o _fpreset - Reset Floating-Point Unit 
  377. o _status87 - Get Floating-Point Status Word 
  378.  
  379.  
  380. ΓòÉΓòÉΓòÉ 2.7. Time Manipulation ΓòÉΓòÉΓòÉ
  381.  
  382. o asctime  - Convert Time 
  383. o clock  - Determine Processor Time 
  384. o ctime  - Convert Time 
  385. o difftime  - Compute Time Difference 
  386. o _ftime - Store Current Time 
  387. o gmtime  - Convert Time 
  388. o localtime  - Convert Time 
  389. o mktime  - Convert Local Time 
  390. o _strdate - Copy Current Date 
  391. o strftime  - Convert to Formatted Time 
  392. o _strtime - Copy Time 
  393. o time  - Determine Current Time 
  394. o _tzset - Assign Values to Locale Information 
  395. o _utime - Set Modification Time 
  396.  
  397.  
  398. ΓòÉΓòÉΓòÉ 2.8. Type Conversion ΓòÉΓòÉΓòÉ
  399.  
  400. o atof  - Convert Character Strings 
  401. o atoi  - Convert Character Strings 
  402. o atol  - Convert Character Strings 
  403. o _atold - Convert ASCII String to Long Double 
  404. o _ecvt - Convert Floating-Point to Character 
  405. o _fcvt - Convert Floating-Point to String 
  406. o _gcvt - Convert Floating-Point to String 
  407. o _itoa - Convert Integer to String 
  408. o _ltoa - Convert Long Integer to String 
  409. o strtod  - Convert Character String to Numeric 
  410. o strtol  - Convert Character String to Numeric 
  411. o strtold - Convert String to Long Double 
  412. o strtoul  - Convert String Segment to Unsigned Integer 
  413. o _ultoa - Convert Unsigned Long Integer to String 
  414.  
  415.  
  416. ΓòÉΓòÉΓòÉ 2.9. Stream Input/Output ΓòÉΓòÉΓòÉ
  417.  
  418. Formatted Input/Output 
  419.  
  420. o fprintf  - Write Formatted Data 
  421. o fscanf  - Read Formatted Data 
  422. o printf  - Formatted Print 
  423. o scanf  - Read Data 
  424. o sprintf  - Formatted Print to Buffer 
  425. o sscanf  - Read Data 
  426. o vfprintf  - Print Argument Data 
  427. o vprintf  - Print Argument Data 
  428. o vsprintf  - Print Argument Data 
  429.  
  430. Character and String Input/Output 
  431.  
  432. o fgetc  - Read a Character 
  433. o _fgetchar - Read Single Character from stdin 
  434. o fgets  - Read a String 
  435. o fputc  - Write a Character 
  436. o _fputchar - Write Character 
  437. o fputs  - Print Strings 
  438. o getc  - Read a Character 
  439. o gets  - Read a Line 
  440. o putc - putchar  - Write a Character 
  441. o putc - putchar  - Write a Character 
  442. o puts  - Write a String 
  443. o ungetc  - Push Character onto Input Stream 
  444.  
  445. Direct Input/Output 
  446.  
  447. o clearerr  - Reset Error Indicators 
  448. o feof  - Test End-of-File Indicator 
  449. o ferror  - Test for Read/Write Errors 
  450. o fread  - Read Items 
  451. o fwrite  - Write Items 
  452.  
  453. File Positioning 
  454.  
  455. o fgetpos  - Get File Position 
  456. o fseek  - Reposition File Position 
  457. o fsetpos  - Set File Position 
  458. o ftell  - Get Current Position 
  459. o _lseek - Move File Pointer 
  460. o rewind  - Adjust Current File Position 
  461.  
  462. File Access 
  463.  
  464. o fclose  - Close Stream 
  465. o _fcloseall - Close All Open Streams 
  466. o _fdopen - Associates Input Or Output With File 
  467. o fflush  - Write Buffer to File 
  468. o _flushall - Write Buffers to Files 
  469. o fopen  - Open Files 
  470. o freopen  - Redirect Open Files 
  471. o setbuf  - Control Buffering 
  472. o _setmode - Set File Translation Mode 
  473. o setvbuf  - Control Buffering 
  474.  
  475. File Operations 
  476.  
  477. o _fileno - Determine File Handle 
  478. o remove  - Delete File 
  479. o rename  - Rename File 
  480. o _rmtmp - Remove Temporary Files 
  481. o _tempnam - Produce Temporary File Name 
  482. o tmpfile  - Create Temporary File 
  483. o tmpnam  - Produce Temporary File Name 
  484. o _unlink - Delete File 
  485.  
  486.  
  487. ΓòÉΓòÉΓòÉ 2.10. Low-Level Input/Output ΓòÉΓòÉΓòÉ
  488.  
  489. o _inp - Read Byte from Input Port 
  490. o _inpd - Read Double Word from Input Port 
  491. o _inpw - Read Unsigned Short from Input Port 
  492. o _outp - Write Byte to Output Port 
  493. o _outpd - Write Double Word to Output Port 
  494. o _outpw - Write Word to Output Port 
  495. o _umask - Sets File Mask of Current Process 
  496.  
  497. Character and String Input/Output 
  498.  
  499. o _cgets - Read String of Characters from Keyboard 
  500. o _cprintf - Print Characters to Screen 
  501. o _cputs - Write String to Screen 
  502. o _cscanf - Read Data from Keyboard 
  503. o _getch - _getche - Read Character from Keyboard 
  504. o _kbhit - Test for Keystroke 
  505. o _putch - Write Character to Screen 
  506. o _ungetch - Push Character Back to Keyboard 
  507.  
  508. File Positioning 
  509.  
  510. o __eof - Determine End of File 
  511. o _tell - Get Pointer Position 
  512.  
  513. File Access 
  514.  
  515. o _access - Determine Access Mode 
  516. o _chmod - Change File Permission Setting 
  517. o _close - Closes File Associated with Handle 
  518. o _creat - Create New File 
  519. o _dup -Associate Second Handle with Open File 
  520. o _dup2 -Associate Second Handle with Open File 
  521. o _isatty - Test Handle for Character Device 
  522. o _open - Open File 
  523. o _read - Read Into Buffer 
  524. o _sopen - Open Shared File 
  525. o _read - Read Into Buffer 
  526.  
  527. File Operations 
  528.  
  529. o _chsize - Alter Length of File 
  530. o _filelength - Determine File Length 
  531.  
  532.  
  533. ΓòÉΓòÉΓòÉ 2.11. Handling Argument Lists ΓòÉΓòÉΓòÉ
  534.  
  535. o va_arg - va_end - va_start - Access Function Arguments 
  536.  
  537.  
  538. ΓòÉΓòÉΓòÉ 2.12. Pseudorandom Numbers ΓòÉΓòÉΓòÉ
  539.  
  540. o rand  - Generate Random Number 
  541. o srand  - Set Seed for rand Function 
  542.  
  543.  
  544. ΓòÉΓòÉΓòÉ 2.13. Dynamic Memory Management ΓòÉΓòÉΓòÉ
  545.  
  546. o _alloca - Temporarily Reserve Storage Block 
  547. o calloc  - Reserve and Initialize Storage 
  548. o _debug_calloc - Reserve and Initialize Storage 
  549. o _debug_free - Release Storage Blocks 
  550. o _debug_heapmin - Release Unused Memory in the Heap 
  551. o _debug_malloc - Reserve Storage Blocks 
  552. o _debug_realloc - Change Reserved Storage Block Size 
  553. o _dump_allocated - Get Information about Allocated Storage 
  554. o free  - Release Storage Blocks 
  555. o _heap_check - Validate Run-Time Storage Heap 
  556. o _heapmin - Release Unused Memory in the Heap 
  557. o malloc  - Reserve Storage Block 
  558. o _heap_check - Validate Run-Time Storage Heap 
  559. o realloc  - Change Reserved Storage Block Size 
  560. o _tcalloc - Reserve Tiled Storage Block 
  561. o _tfree - Free Tiled Storage Block 
  562. o _tmalloc - Reserve Tiled Storage Block 
  563. o _trealloc - Reallocate Tiled Storage Block 
  564.  
  565.  
  566. ΓòÉΓòÉΓòÉ 2.14. Memory Objects ΓòÉΓòÉΓòÉ
  567.  
  568. o memccpy - Copy Bytes 
  569. o memchr  - Search Buffer 
  570. o memcmp  - Compare Buffers 
  571. o memcpy  - Copy Bytes 
  572. o memicmp - Compare Bytes 
  573. o memmove  - Copy Bytes 
  574. o memset  - Set Bytes to Value 
  575. o _swab - Swap Adjacent Bytes 
  576.  
  577.  
  578. ΓòÉΓòÉΓòÉ 2.15. Environment Interaction ΓòÉΓòÉΓòÉ
  579.  
  580. o abort  - Stop a Program 
  581. o exit  - End Program 
  582. o getenv  - Search for Environment Variables 
  583. o localeconv  - Query Locale Conventions 
  584. o longjmp  - Restore Stack Environment 
  585. o __parmdwords - Get Number of dwords in Parameter List 
  586. o setjmp  - Preserve Environment 
  587. o setlocale  - Set Locale 
  588. o system - Invoke the Command Processor 
  589.  
  590.  
  591. ΓòÉΓòÉΓòÉ 2.16. String Operations ΓòÉΓòÉΓòÉ
  592.  
  593. o strcat  - Concatenate Strings 
  594. o strchr  - Search for Character 
  595. o strcmp  - Compare Strings 
  596. o strcmpi - Compare Strings 
  597. o strcoll  - Compare Strings 
  598. o strcpy  - Copy Strings 
  599. o strcspn  - Compare Strings 
  600. o strdup - Duplicate String 
  601. o stricmp - Compare Strings 
  602. o strlen  - Determine String Length 
  603. o strncat  - Concatenate Strings 
  604. o strncmp  - Compare Strings 
  605. o strncpy  - Copy Strings 
  606. o strnicmp - Compare Strings 
  607. o strnset - strset - Set Characters in String 
  608. o strpbrk  - Find Characters in String 
  609. o strrchr  - Find Last Occurrence of Character in String 
  610. o strrev - Reverse String 
  611. o strnset - strset - Set Characters in String 
  612. o strspn  - Search Strings 
  613. o strstr  - Locate Substring 
  614. o strtok  - Tokenize String 
  615. o strxfrm  - Transform Strings 
  616.  
  617.  
  618. ΓòÉΓòÉΓòÉ 2.17. Character Testing ΓòÉΓòÉΓòÉ
  619.  
  620. o isalnum to isxdigit  - Test Integer Value 
  621. o _isascii - Test Integer Values 
  622. o _iscsym - _iscsymf - Test Integer 
  623. o _iscsym - _iscsymf - Test Integer 
  624.  
  625.  
  626. ΓòÉΓòÉΓòÉ 2.18. Character Case Mapping ΓòÉΓòÉΓòÉ
  627.  
  628. o strlwr - Convert Uppercase to Lowercase 
  629. o strupr - Convert Lowercase to Uppercase 
  630. o tolower - toupper  - Convert Character Case 
  631. o tolower - toupper  - Convert Character Case 
  632. o tolower - toupper  - Convert Character Case 
  633. o tolower - toupper  - Convert Character Case 
  634.  
  635.  
  636. ΓòÉΓòÉΓòÉ 2.19. Multibyte Character Manipulation ΓòÉΓòÉΓòÉ
  637.  
  638. o mblen  - Multibyte String Length 
  639. o mbstowcs  - Convert Multibyte Characters to wchar_t Characters 
  640. o mbtowc  - Convert Multibyte Character to wchar_t 
  641. o wctomb  - Convert wchar_t Character to Multibyte Character 
  642. o wcstombs  - Convert wchar_t String to Multibyte Character String 
  643. o wcscat  - Append wchar_t Strings 
  644. o wcschr  - Search wchar_t String for Given wchar_t 
  645. o wcscmp  - Compare wchar_t Strings 
  646. o wcscpy  - Copy wchar_t Strings 
  647. o wcscspn  - Find Offset of First wchar_t Match 
  648. o wcslen  - Calculate Length of wchar_t String 
  649. o wcsncat  - Concatenate wchar_t Strings 
  650. o wcsncmp  - Compare wchar_t Strings 
  651. o wcsncpy  - Copy wchar_t Strings 
  652. o wcspbrk  - Locate wchar_t Characters in String 
  653. o wcsspn  - Search wchar_t Characters in String 
  654. o wcsrchr  - Locate wchar_t Character in String 
  655. o wcswcs  - Locate wchar_t Substring in wchar_t String 
  656.  
  657.  
  658. ΓòÉΓòÉΓòÉ 2.20. C/C++ Tools Extensions ΓòÉΓòÉΓòÉ
  659.  
  660. o _access - Determine Access Mode 
  661. o _alloca - Temporarily Reserve Storage Block 
  662. o _atold - Convert ASCII String to Long Double 
  663. o _beginthread - Create New Thread 
  664. o _cabs - Calculate Absolute Value of Complex Number 
  665. o _cgets - Read String of Characters from Keyboard 
  666. o _chdir - Change Current Working Directory 
  667. o _chdrive - Change Current Working Drive 
  668. o _chmod - Change File Permission Setting 
  669. o _chsize - Alter Length of File 
  670. o _clear87 - Clear Floating-Point Status Word 
  671. o _close - Closes File Associated with Handle 
  672. o _control87 - Set Floating-Point Status Word 
  673. o _cprintf - Print Characters to Screen 
  674. o _cputs - Write String to Screen 
  675. o _creat - Create New File 
  676. o _cscanf - Read Data from Keyboard 
  677. o _cwait - Wait for Child Process 
  678. o _dup -Associate Second Handle with Open File 
  679. o _dup2 -Associate Second Handle with Open File 
  680. o _ecvt - Convert Floating-Point to Character 
  681. o _endthread - Terminate Current Thread 
  682. o __eof - Determine End of File 
  683. o _execl - _execvp - Load and Run Child Process 
  684. o _exit - End Process 
  685. o _fcloseall - Close All Open Streams 
  686. o _fcvt - Convert Floating-Point to String 
  687. o _fdopen - Associates Input Or Output With File 
  688. o _filelength - Determine File Length 
  689. o _fileno - Determine File Handle 
  690. o _flushall - Write Buffers to Files 
  691. o _fpreset - Reset Floating-Point Unit 
  692. o _fputchar - Write Character 
  693. o _freemod - Free User DLL 
  694. o _fstat - Information about Open File 
  695. o _ftime - Store Current Time 
  696. o _fullpath - Get Full Path Name of Partial Path 
  697. o _gcvt - Convert Floating-Point to String 
  698. o _getch - _getche - Read Character from Keyboard 
  699. o _getcwd - Get Path Name of Current Directory 
  700. o _getdcwd - Get Full Path Name of Current Directory 
  701. o _getdrive - Get Current Working Drive 
  702. o _getpid - Get Process Identifier 
  703. o _heapmin - Release Unused Memory in the Heap 
  704. o _isascii - Test Integer Values 
  705. o _isatty - Test Handle for Character Device 
  706. o _iscsym - _iscsymf - Test Integer 
  707. o _itoa - Convert Integer to String 
  708. o _kbhit - Test for Keystroke 
  709. o _lfind - _lsearch - Find Key in Array 
  710. o _loadmod - Load User DLL 
  711. o _lrotl - _lrotr - Rotate Bits 
  712. o _lseek - Move File Pointer 
  713. o _ltoa - Convert Long Integer to String 
  714. o _makepath - Create Path 
  715. o _matherr - Process Math Library Errors 
  716. o max - Return Larger of Two Values 
  717. o memccpy - Copy Bytes 
  718. o memicmp - Compare Bytes 
  719. o min - Return Lesser of Two Values 
  720. o _mkdir - Create New Directory 
  721. o _msize - Return Number of Bytes Allocated 
  722. o _onexit - Record Termination Function 
  723. o _open - Open File 
  724. o __parmdwords - Get Number of dwords in Parameter List 
  725. o _putch - Write Character to Screen 
  726. o _putenv - Modify Environment Variables 
  727. o _read - Read Into Buffer 
  728. o _rmdir - Remove Directory 
  729. o _rmtmp - Remove Temporary Files 
  730. o _rotl - _rotr - Bit Rotation 
  731. o _searchenv - Search for File 
  732. o _setmode - Set File Translation Mode 
  733. o signal Install Interrupt Handlers 
  734. o _sopen - Open Shared File 
  735. o spawnl - spawnvpe - Start and Run Child Processes 
  736. o _splitpath - Decompose Path Name 
  737. o _stat - Get Information about File or Directory 
  738. o _status87 - Get Floating-Point Status Word 
  739. o strcmpi - Compare Strings 
  740. o _strdate - Copy Current Date 
  741. o strdup - Duplicate String 
  742. o _strerror - Set Pointer to System Error String 
  743. o stricmp - Compare Strings 
  744. o strlwr - Convert Uppercase to Lowercase 
  745. o strnicmp - Compare Strings 
  746. o strnset - strset - Set Characters in String 
  747. o strrev - Reverse String 
  748. o _strtime - Copy Time 
  749. o strtold - Convert String to Long Double 
  750. o strupr - Convert Lowercase to Uppercase 
  751. o _swab - Swap Adjacent Bytes 
  752. o system - Invoke the Command Processor 
  753. o _tell - Get Pointer Position 
  754. o _tempnam - Produce Temporary File Name 
  755. o _toascii - _tolower - _toupper - Convert Character 
  756. o _tzset - Assign Values to Locale Information 
  757. o _ultoa - Convert Unsigned Long Integer to String 
  758. o _umask - Sets File Mask of Current Process 
  759. o _ungetch - Push Character Back to Keyboard 
  760. o _unlink - Delete File 
  761. o _utime - Set Modification Time 
  762. o _wait - Wait for Child Process 
  763. o _write - Writes from Buffer to File 
  764.  
  765.  
  766. ΓòÉΓòÉΓòÉ 2.21. Intrinsic Functions ΓòÉΓòÉΓòÉ
  767.  
  768. When optimization is on, the C/C++ Tools compiler by default generates code 
  769. instead of a function call for the following C library functions: 
  770.  
  771. abs                 _clear87 
  772. _control87          fabs 
  773. labs                memchr 
  774. memcmp              memcpy 
  775. memmove             memset 
  776. _status87           strcat 
  777. strchr              strcmp 
  778. strcpy              strlen 
  779. strncat             strncmp 
  780. strncpy             strrchr 
  781.  
  782. When you #include the appropriate header file in which the function prototype 
  783. and the #define and #pragma statements for the function are found, the 
  784. C/C++Tools compiler generates code instead of a function call for these 
  785. functions. 
  786.  
  787. You can override the header either by undefining the macro or by placing the 
  788. name of the function in parentheses, thus disabling the processor substitution. 
  789. The function then remains a function call, and is not replaced by the code. The 
  790. size of your object module is reduced, but your application program runs more 
  791. slowly. 
  792.  
  793. Note:  The following functions are built-in functions, meaning they do not have 
  794.        any backing library functions, and are always inlined: 
  795.  
  796. _alloca             _disable 
  797. _enable             _facos 
  798. _fasin              _fcos 
  799. _fcossin            _fpatan 
  800. _fptan              _fsin 
  801. _fsincos            _fyl2x 
  802. _fyl2xp1            _f2xm1 
  803. _getTIBvalue        _inp 
  804. _inpd               _inpw 
  805. _interrupt          _outp 
  806. _outpd              _outpw 
  807. __parmdwords 
  808.  
  809. The built-in functions are all defined in <builtin.h>, in addition to the 
  810. standard header definitions. 
  811.  
  812.  
  813. ΓòÉΓòÉΓòÉ 3. Memory Management Functions ΓòÉΓòÉΓòÉ
  814.  
  815. This section describes two types of memory management functions: 
  816.  
  817. o Debug Memory Management Functions 
  818. o Tiled Memory Management Functions 
  819. These functions are extensions to the ANSI/SAA memory management functions that 
  820. you can use. 
  821.  
  822. A brief description is provided for each function, as well as a description of 
  823. how the functions are invoked and used. 
  824.  
  825.  
  826. ΓòÉΓòÉΓòÉ 3.1. Debug Memory Management Functions ΓòÉΓòÉΓòÉ
  827.  
  828. The C/C++ Tools compiler provides a set of seven functions to assist you in 
  829. debugging memory management problems associated with memory allocated by the 
  830. calloc, malloc, or realloc functions. The debug memory management functions are 
  831. provided in both the standard and subsystem development libraries, and can help 
  832. you find where memory is being allocated, written to, or freed incorrectly. 
  833.  
  834. This section describes the following debug memory management functions: 
  835.  
  836. o _debug_calloc, _debug_free, _debug_heapmin, _debug_malloc, _debug_realloc 
  837.  
  838.   These functions are variations of the calloc, free, _heapmin, malloc, and 
  839.   realloc functions respectively. They build internal data structures to allow 
  840.   checks to be made on the run-time heap. Each call to one of these functions 
  841.   also automatically calls the _heap_check function. 
  842.  
  843. o _heap_check 
  844.  
  845.   This function checks all memory blocks allocated or freed by the functions 
  846.   listed above to make sure that no overwriting has occurred outside the bounds 
  847.   of allocated blocks or in a free memory block. 
  848.  
  849. o _dump_allocated 
  850.  
  851.   This function prints out information about each memory block currently 
  852.   allocated by the functions listed above. 
  853.  
  854. All output from these functions is sent to the OS/2 file handle 2, which is 
  855. usually associated with stderr. 
  856.  
  857. Note:  The information provided by these functions is Diagnosis, Modification, 
  858.        and Tuning information only. It is not intended to be used as a 
  859.        programming interface. 
  860.  
  861.  
  862. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  863.  
  864. o Using the Debug Memory Management Functions 
  865. o Library Functions 
  866. o Tiled Memory Management Functions 
  867.  
  868.  
  869. ΓòÉΓòÉΓòÉ 3.1.1. Using the Debug Memory Management Functions ΓòÉΓòÉΓòÉ
  870.  
  871. To use the debug memory management functions: 
  872.  
  873.  1. Define the macro __DEBUG_ALLOC__ 
  874.  
  875.     This macro defines the malloc, calloc, realloc, free, and _heapmin 
  876.     functions to the corresponding debug memory management function. You can 
  877.     define the macro in your source files, or on the command line (using the /D 
  878.     option). 
  879.  
  880.  2. Include <stdlib.h> in each of your source files. 
  881.  
  882.     If you define __DEBUG_ALLOC__ in your source file, that definition must 
  883.     appear before the #include directive. 
  884.  
  885.  3. Place a #pragma strings(readonly) directive at the top of each source file. 
  886.  
  887.     This directive is not essential, but it ensures that the file name passed 
  888.     to the debug memory management functions cannot be overwritten, and that 
  889.     only one copy of the file name string is included in the object module. 
  890.  
  891. Once you have followed the above steps, the _debug_malloc, _debug_calloc, 
  892. _debug_realloc, _debug_free, and _debug_heapmin functions are automatically 
  893. called in place of the regular memory management functions in your code. Do not 
  894. parenthesize any calls to these functions, because parentheses will disable the 
  895. definition of the function name to the debug function name. 
  896.  
  897. The _heap_check function is also called automatically by each of these 
  898. functions, or you can call it explicitly. To use the _dump_allocated function, 
  899. you must explicitly call it in your code. 
  900.  
  901. Note: 
  902.  
  903. o To use the debug memory management functions, set the language level to 
  904.   extended. Specify the /Se option on the command line, or include the #pragma 
  905.   langlvl(extended) directive in your code. 
  906. o The debug memory management functions are not available if you are using 
  907.   tiled memory (with the /Gt compiler option). 
  908. o All memory blocks allocated by the _debug_malloc, _debug_calloc, and 
  909.   _debug_realloc functions must be freed using _debug_free, not the free 
  910.   function. If you do not use _debug_free, a message is generated and the 
  911.   process terminates. To ensure that _debug_free is used, define the 
  912.   __DEBUG_ALLOC__ macro in all your modules. 
  913. o If you copy the examples from the online help and compile and run them, the 
  914.   format of the output you will see will be the same as that shown in the 
  915.   sample output, but the values may be different. 
  916.  
  917.  
  918. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  919.  
  920. o #define 
  921. o #include 
  922. o malloc.h 
  923. o stdlib.h 
  924. o #pragma langlvl 
  925. o #pragma strings 
  926. o /D option 
  927. o /Gt option 
  928. o Debug Memory Management Functions 
  929. o Tiled Memory Management Functions 
  930.  
  931.  
  932. ΓòÉΓòÉΓòÉ 3.2. Tiled Memory Management Functions ΓòÉΓòÉΓòÉ
  933.  
  934. The C/C++ Tools compiler provides a set of four functions to allow you to 
  935. manipulate tiled memory. These functions are the 16-bit versions of the 
  936. C/C++Tools memory functions. 
  937.  
  938. This section describes the following tiled memory functions: 
  939.  
  940. o _tcalloc, _tfree, _tmalloc, _trealloc. 
  941.  
  942.   These functions are variations of the calloc, free, malloc, and realloc 
  943.   functions, respectively. They work exactly like the original functions, 
  944.   except that the memory allocated or freed is guaranteed not to cross 64K 
  945.   boundaries, allowing object to be used in 16-bit programs. 
  946.  
  947. The tiled memory functions should be used if you have applications that depend 
  948. on APIs or subroutines that are only available as 16-bit code. 
  949.  
  950. Note:  Data items larger than 64K in size can be allocated. They will be 
  951. aligned on 64K boundaries, but they will also cross 64K boundaries. 
  952.  
  953.  
  954. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  955.  
  956. o Using the Tiled Memory Functions 
  957. o Library Functions 
  958.  
  959.  
  960. ΓòÉΓòÉΓòÉ 3.2.1. Using the Tiled Memory Functions ΓòÉΓòÉΓòÉ
  961.  
  962. To use the tiled memory management functions: 
  963.  
  964.  1. Define the macro __TILED__ in your code. 
  965.  
  966.     This macro defines the malloc, calloc, free, and realloc functions to the 
  967.     corresponding tiled memory function. You can also define the macro on your 
  968.     command line by setting the /Gt+ compiler option. 
  969.  
  970.  2. Include <stdlib.h> in each of your source files. 
  971.  
  972.     If you define __TILED__ in your source file, that definition must appear 
  973.     before the #include directive. 
  974.  
  975. Once you have followed the above steps, the _tcalloc, _tfree, _tmalloc, and 
  976. _trealloc functions are automatically called in place of the regular memory 
  977. management functions in your code. Do not parenthesize any calls to these 
  978. functions, because parentheses will disable the definition of the function name 
  979. to the tiled memory function name. 
  980.  
  981. Note: 
  982.  
  983. o To use the tiled memory management functions, set the language level to 
  984.   extended. Specify the /Se option on the command line, or include the #pragma 
  985.   langlvl(extended) directive in your code. 
  986. o The debug memory management functions are not available if you are using 
  987.   tiled memory (with the /Gt compiler option). 
  988. o All memory blocks allocated by the _tcalloc, _tmalloc, and _trealloc 
  989.   functions must be freed using _tfree, not the free function. If you do not 
  990.   use _tfree, a message is generated and the process terminates. To ensure that 
  991.   _tfree is used, define the __TILED__ macro in all your modules. 
  992.  
  993.  
  994. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  995.  
  996. o #define 
  997. o #include 
  998. o malloc.h 
  999. o stdlib.h 
  1000. o /D option 
  1001. o /Gt option 
  1002. o Debug Memory Management Functions 
  1003.  
  1004.  
  1005. ΓòÉΓòÉΓòÉ 4. Infinity and NaN Support ΓòÉΓòÉΓòÉ
  1006.  
  1007. The C/C++ Tools compiler supports the use of infinity and NaN (not-a-number) 
  1008. values. Infinity is a value with an associated sign that is mathematically 
  1009. greater in magnitude than any binary floating-point number. A NaN is a value in 
  1010. floating-point computations that is not interpreted as a mathematical value, 
  1011. and that contains a mask state and a sequence of binary digits. 
  1012.  
  1013. The value of infinity can be computed from 1.0 / 0.0 . The value of a NaN can 
  1014. be computed from 0.0 / 0.0 . 
  1015.  
  1016. Depending on its bit pattern, a NaN can be either quiet (NaNQ) or signalling 
  1017. (NaNS), as defined in the ANSI/IEEE Standard for Binary Floating-Point 
  1018. Arithmetic (754-1982). A NaNQ is masked and never generates exceptions. A NaNS 
  1019. may be masked and may generate an exception, but does not necessarily do so. 
  1020. The C/C++ Tools compiler supports only quiet NaN values; all NaN values 
  1021. discussed below refer to quiet NaNs. 
  1022.  
  1023. NaN and infinity values are defined as macro constants in the <float.h> header 
  1024. file.  The macros are: 
  1025.  
  1026. Macro                Description 
  1027. _INFINITYF           Infinity of type float 
  1028. _INFINITY            Infinity of type double 
  1029. _INFINITYL           Infinity of type long double 
  1030.  
  1031. _INFF                Same as _INFINITYF 
  1032. _INF                 Same as _INFINITY 
  1033. _INFL                Same as _INFINITYL 
  1034.  
  1035. _NANF                Quiet NaN of type float 
  1036. _NAN                 Quiet NaN of type double 
  1037. _NANL                Quiet NaN of type long double. 
  1038.  
  1039. The corresponding negative values can be obtained by using the unary minus 
  1040. operator (for example, -_INF). 
  1041.  
  1042. Because these macros are actually references to constant variables, you cannot 
  1043. use them to initialize static variables. For example, the following statements 
  1044. are not allowed: 
  1045.  
  1046.    static double infval = _INF;
  1047.    static float nanval = 1.0 + _NANF;
  1048.  
  1049. However, you can initialize static variables to the numeric values of infinity 
  1050. and Nan: 
  1051.  
  1052.    static double infval = 1.0 / 0.0;
  1053.    static float nanval =  0.0 / 0.0;
  1054.  
  1055. Note:  While positive and negative infinities are specific bit patterns, NaNs 
  1056.        are not. A NaN value is not equal to itself or to any other value. For 
  1057.        example, if you assign a NaN value to a variable x, you cannot check the 
  1058.        value of x with the statement if (_NAN == x). Instead, use the statement 
  1059.        if (x != x). 
  1060.  
  1061. All relational and equality expressions involving NaN values always evaluate to 
  1062. FALSE or zero (0), with the exception of not equal (!=), which always evaluates 
  1063. to TRUE or one (1). 
  1064.  
  1065. For information on the bit mapping and storage mapping of NaN and infinity 
  1066. values, see the Programming Guide. 
  1067.  
  1068.  
  1069. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1070.  
  1071. o Infinity and NaN in Library Functions 
  1072. o Assignment Expression 
  1073. o Equality 
  1074. o Relational 
  1075. o float.h 
  1076.  
  1077.  
  1078. ΓòÉΓòÉΓòÉ 4.1. Infinity and NaN in Library Functions ΓòÉΓòÉΓòÉ
  1079.  
  1080. When the language level is set to extended (using the /Se option or the #pragma 
  1081. langlvl(extended) directive), which is the default, infinity and NaN values can 
  1082. be passed as arguments to the scanf and printf families of library functions, 
  1083. and to the string conversion and math functions. At other language levels, 
  1084. these functions work as described in this reference. 
  1085.  
  1086. The following sections describe how the library functions handle the infinity 
  1087. and NaN values: 
  1088.  
  1089. o scanf Family 
  1090. o printf Family 
  1091. o String Conversion Functions 
  1092. o Math Functions 
  1093.  
  1094.  
  1095. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1096.  
  1097. o Infinity and NaN Support 
  1098. o #pragma langlvl 
  1099. o /Se option. 
  1100.  
  1101.  
  1102. ΓòÉΓòÉΓòÉ 4.1.1. scanf Family ΓòÉΓòÉΓòÉ
  1103.  
  1104. The scanf family of functions includes the SAA functions scanf, fscanf, and 
  1105. sscanf. When reading in floating-point numbers, these functions convert the 
  1106. strings INFINITY, INF, and NAN (in upper-, lower-, or mixed case) to the 
  1107. corresponding floating-point value. The sign of the value is determined by the 
  1108. format specification. 
  1109.  
  1110. Given a string that consists of NAN, INF, or INFINITY, followed by other 
  1111. characters, the scanf functions read in only the NaN or infinity value, and 
  1112. consider the rest of the string to be a second input field. For example, Nancy 
  1113. would be scanned as two fields, Nan and cy. 
  1114.  
  1115. Note:  In the case of a string that begins with INF, the functions check the 
  1116.        fourth letter. If that letter is not I (in upper- or lowercase), INF is 
  1117.        read and converted and the rest of the string is left for the next 
  1118.        format specification. If the fourth letter is I, the functions continue 
  1119.        to scan for the full INFINITY string. If the string is other than 
  1120.        INFINITY, the entire string is discarded. 
  1121.  
  1122. Example of fscanf with NaN and Infinity Values 
  1123.  
  1124.  
  1125. ΓòÉΓòÉΓòÉ <hidden> Example of fscanf with NaN and Infinity Values ΓòÉΓòÉΓòÉ
  1126.  
  1127. /************************************************************************
  1128. *
  1129.  
  1130. In the following example, fscanf converts NaN and infinity strings to their 
  1131. numeric values. 
  1132.  
  1133.                                                                         *
  1134. ************************************************************************/
  1135.  
  1136. #include <stdio.h>
  1137.  
  1138. int main(void)
  1139. {
  1140.    int n, count;
  1141.    double d1, d2, d3;
  1142.    FILE *stream;
  1143.  
  1144.    stream = tmpfile();
  1145.  
  1146.    fputs(" INFINITY NAn INF", stream);
  1147.  
  1148.    rewind(stream);
  1149.  
  1150.    n = fscanf(stream, "%lF%lf%lF%n", &d1, &d2, &d3, &count);
  1151.  
  1152.    if (n != EOF)
  1153.    {
  1154.       printf("Number of fields converted = %d\n", n);
  1155.       printf("Number of characters read = %d\n", count);
  1156.       printf("Output = %f %F %F\n", d1, d2, d3);
  1157.    }
  1158.  
  1159.    return 0;
  1160.  
  1161.    /* The expected output is:
  1162.  
  1163.       Number of fields converted = 3
  1164.       Number of characters read = 17
  1165.       Output = infinity NAN INFINITY  */
  1166.  
  1167. }
  1168.  
  1169.  
  1170. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1171.  
  1172. o Infinity and NaN Support 
  1173. o fscanf  - Read Formatted Data 
  1174. o scanf  - Read Data 
  1175. o sscanf  - Read Data 
  1176.  
  1177.  
  1178. ΓòÉΓòÉΓòÉ 4.1.2. printf Family ΓòÉΓòÉΓòÉ
  1179.  
  1180. The printf family of functions includes the SAA functions printf, fprintf, 
  1181. sprintf, vfprintf, vprintf, and vsprintf. These functions convert 
  1182. floating-point values of infinity and NaN to the strings "INFINITY" or 
  1183. "infinity" and "NAN" or "nan". 
  1184.  
  1185. The case is determined by the format specification, as is the sign (positive or 
  1186. negative). When converting these values, the printf functions ignore the 
  1187. precision width given by the format specification. 
  1188.  
  1189. Example of printf with Nan and Infinity Values 
  1190.  
  1191.  
  1192. ΓòÉΓòÉΓòÉ <hidden> Example of printf with Nan and Infinity Values ΓòÉΓòÉΓòÉ
  1193.  
  1194. /************************************************************************
  1195. *
  1196.  
  1197. In the following example, printf converts the NaN and infinity values and 
  1198. prints out the corresponding string. 
  1199.  
  1200.                                                                         *
  1201. ************************************************************************/
  1202.  
  1203. #include <stdio.h>
  1204. #include <float.h>
  1205.  
  1206. int main(void)
  1207. {
  1208.    double infval = -(_INF);
  1209.    float nanval = _NANF;
  1210.  
  1211.    printf("-_INF is the same as %-15.30f\n", infval);
  1212.    printf("_NANF is the same as %-15.30F\n", nanval);
  1213.  
  1214.    return 0;
  1215.  
  1216.    /* The expected output is:
  1217.  
  1218.       -_INF is the same as -infinity
  1219.       _NANF is the same as NAN        */
  1220.  
  1221. }
  1222.  
  1223.  
  1224. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1225.  
  1226. o Infinity and NaN Support 
  1227. o fprintf  - Write Formatted Data 
  1228. o printf  - Formatted Print 
  1229. o sprintf  - Formatted Print to Buffer 
  1230. o vfprintf  - Print Argument Data 
  1231. o vprintf  - Print Argument Data 
  1232. o vsprintf  - Print Argument Data 
  1233.  
  1234.  
  1235. ΓòÉΓòÉΓòÉ 4.1.3. String Conversion Functions ΓòÉΓòÉΓòÉ
  1236.  
  1237. The string conversion functions include the SAA functions atof and strtod, and 
  1238. the C/C++ Tools standard extensions _atold, _ecvt, _fcvt, _gcvt, and strtold. 
  1239.  
  1240. The atof, _atold, strtod, and strtold functions accept the strings INFINITY, 
  1241. INF, and NAN (in upper-, lower-, or mixed case) as input, and convert these 
  1242. strings to the corresponding macro value defined in <float.h>. The _ecvt, 
  1243. _fcvt, and _gcvt functions convert infinity and NaN values to the strings 
  1244. INFINITY and NAN, respectively. 
  1245.  
  1246. Note:  If a signalling NaN string is passed to a string conversion function, a 
  1247. quiet NaN value is returned, and no signal is raised. 
  1248.  
  1249. Example of atof with NaN and Infinity Values 
  1250.  
  1251.  
  1252. ΓòÉΓòÉΓòÉ <hidden> Example of atof with NaN and Infinity Values ΓòÉΓòÉΓòÉ
  1253.  
  1254. /************************************************************************
  1255. *
  1256.  
  1257. The following example uses atof to convert the strings "naN" and "infinity" to 
  1258. the corresponding macro value. 
  1259.  
  1260.                                                                         *
  1261. ************************************************************************/
  1262.  
  1263. #include <stdlib.h>
  1264. #include <stdio.h>
  1265.  
  1266. int main(void)
  1267. {
  1268.    char *nanstr;
  1269.    char *infstr;
  1270.  
  1271.    nanstr = "naN";
  1272.    printf( "Result of atof = %.10e\n", atof(nanstr) );
  1273.  
  1274.    infstr = "inf";
  1275.    printf( "Result of atof = %.10E\n", atof(infstr) );
  1276.  
  1277.    return 0;
  1278.  
  1279.    /* The expected output is:
  1280.  
  1281.       Result of atof = nan
  1282.       Result of atof = INFINITY  */
  1283.  
  1284. }
  1285.  
  1286.  
  1287. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1288.  
  1289. o Infinity and NaN Support 
  1290. o atof  - Convert Character Strings 
  1291. o _atold - Convert ASCII String to Long Double 
  1292. o _ecvt - Convert Floating-Point to Character 
  1293. o _fcvt - Convert Floating-Point to String 
  1294. o _gcvt - Convert Floating-Point to String 
  1295. o strtod  - Convert Character String to Numeric 
  1296. o strtold - Convert String to Long Double 
  1297.  
  1298.  
  1299. ΓòÉΓòÉΓòÉ 4.1.4. Math Functions ΓòÉΓòÉΓòÉ
  1300.  
  1301. Most math functions accept infinity, negative infinity, and NaN values as 
  1302. input. (For information on those functions that do not accept these values, see 
  1303. Math Functions without Infinity and NaN Support.) In general, a NaN value as 
  1304. input will result in a NaN value as output, and infinity values as input 
  1305. usually result in infinity values. If the input value is outside the domain or 
  1306. range of the function, errno is set to EDOM or ERANGE, respectively. 
  1307.  
  1308. The following tables display the results of each math function when NaN or 
  1309. infinity values are input, and the associated errno value if one exists. The 
  1310. first table lists the functions that take only one argument; the second lists 
  1311. those that take two arguments. 
  1312.  
  1313. Note:  In some cases, infinity is always a valid input value for the function 
  1314. regardless of the language level (for example, atan). These cases do not appear 
  1315. in the tables. 
  1316.  
  1317. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  1318. Γöé      NaN and Infinity Values in Math Functions              Γöé
  1319. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1320. Γöé FUNCTION      Γöé INPUT       Γöé RESULT       Γöé "ERRNO" VALUE   Γöé
  1321. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1322. Γöé "         Γöé NaN        Γöé NaN "       Γöé          Γöé
  1323. Γöé acos        Γöé infinity      Γöé 0         Γöé EDOM       Γöé
  1324. Γöé asin "       Γöé -infinity     Γöé 0 "        Γöé EDOM       Γöé
  1325. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1326. Γöé "atan"       Γöé NaN        Γöé NaN        Γöé          Γöé
  1327. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1328. Γöé "         Γöé NaN        Γöé NaN        Γöé          Γöé
  1329. Γöé ceil        Γöé infinity      Γöé infinity      Γöé          Γöé
  1330. Γöé floor "      Γöé -infinity     Γöé -infinity     Γöé          Γöé
  1331. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1332. Γöé "         Γöé NaN        Γöé NaN        Γöé EDOM       Γöé
  1333. Γöé cos        Γöé infinity      Γöé NaN        Γöé ERANGE      Γöé
  1334. Γöé tan "       Γöé -infinity     Γöé NaN        Γöé ERANGE      Γöé
  1335. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1336. Γöé "cosh"       Γöé NaN        Γöé NaN        Γöé          Γöé
  1337. Γöé          Γöé infinity      Γöé infinity      Γöé ERANGE      Γöé
  1338. Γöé          Γöé -infinity     Γöé infinity      Γöé ERANGE      Γöé
  1339. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1340. Γöé "erf"       Γöé NaN        Γöé NaN "       Γöé EDOM       Γöé
  1341. Γöé          Γöé infinity      Γöé 1         Γöé          Γöé
  1342. Γöé          Γöé -infinity     Γöé -1 "        Γöé          Γöé
  1343. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1344. Γöé "erfc"       Γöé NaN        Γöé NaN "       Γöé EDOM       Γöé
  1345. Γöé          Γöé infinity      Γöé 0         Γöé          Γöé
  1346. Γöé          Γöé -infinity     Γöé 2 "        Γöé          Γöé
  1347. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1348. Γöé "exp"       Γöé NaN        Γöé NaN        Γöé          Γöé
  1349. Γöé          Γöé infinity      Γöé infinity "     Γöé ERANGE      Γöé
  1350. Γöé          Γöé -infinity     Γöé 0 "        Γöé ERANGE      Γöé
  1351. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1352. Γöé "fabs"       Γöé NaN        Γöé NaN        Γöé          Γöé
  1353. Γöé          Γöé infinity      Γöé infinity      Γöé          Γöé
  1354. Γöé          Γöé -infinity     Γöé infinity      Γöé          Γöé
  1355. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1356. Γöé "frexp"      Γöé NaN        Γöé NaN, "0"      Γöé EDOM       Γöé
  1357. Γöé          Γöé infinity      Γöé NaN, "0"      Γöé EDOM       Γöé
  1358. Γöé          Γöé -infinity     Γöé NaN, "0"      Γöé EDOM       Γöé
  1359. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1360. Γöé "gamma"      Γöé NaN        Γöé NaN        Γöé EDOM       Γöé
  1361. Γöé          Γöé infinity      Γöé infinity      Γöé ERANGE      Γöé
  1362. Γöé          Γöé -infinity     Γöé NaN        Γöé EDOM       Γöé
  1363. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1364. Γöé "         Γöé NaN        Γöé NaN        Γöé          Γöé
  1365. Γöé log        Γöé infinity "     Γöé infinity      Γöé          Γöé
  1366. Γöé log10 "      Γöé 0         Γöé -infinity     Γöé ERANGE      Γöé
  1367. Γöé          Γöé <0 "        Γöé NaN        Γöé EDOM       Γöé
  1368. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1369. Γöé "modf"       Γöé NaN        Γöé NaN, NaN      Γöé EDOM       Γöé
  1370. Γöé          Γöé infinity      Γöé NaN, infinity   Γöé EDOM       Γöé
  1371. Γöé          Γöé -infinity     Γöé NaN, -infinity   Γöé EDOM       Γöé
  1372. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1373. Γöé "sin"       Γöé NaN        Γöé NaN        Γöé EDOM       Γöé
  1374. Γöé          Γöé infinity      Γöé NaN        Γöé ERANGE      Γöé
  1375. Γöé          Γöé -infinity     Γöé NaN        Γöé ERANGE      Γöé
  1376. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1377. Γöé "sinh"       Γöé NaN        Γöé NaN        Γöé EDOM       Γöé
  1378. Γöé          Γöé infinity      Γöé infinity      Γöé ERANGE      Γöé
  1379. Γöé          Γöé -infinity     Γöé -infinity     Γöé ERANGE      Γöé
  1380. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1381. Γöé "sqrt"       Γöé NaN        Γöé NaN        Γöé          Γöé
  1382. Γöé          Γöé infinity      Γöé infinity "     Γöé          Γöé
  1383. Γöé          Γöé -infinity     Γöé 0 "        Γöé EDOM       Γöé
  1384. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1385. Γöé "tanh"       Γöé NaN        Γöé NaN "       Γöé EDOM       Γöé
  1386. Γöé          Γöé infinity      Γöé 1         Γöé          Γöé
  1387. Γöé          Γöé -infinity     Γöé -1 "        Γöé          Γöé
  1388. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  1389.  
  1390. The functions in the following table take two arguments. The results from NaN 
  1391. and infinity values vary depending on which argument they are passed as. 
  1392.  
  1393. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  1394. Γöé      Infinity and NaN Values in Math Functions              Γöé
  1395. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1396. Γöé FUNCTION    Γöé ARGUMENT 1   Γöé ARGUMENT 2   Γöé RESULT     Γöé "ERRNO"    Γöé
  1397. Γöé        Γöé        Γöé        Γöé        Γöé VALUE     Γöé
  1398. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1399. Γöé "atan2"    Γöé NaN      Γöé any number   Γöé NaN      Γöé EDOM     Γöé
  1400. Γöé        Γöé any number   Γöé NaN      Γöé NaN      Γöé        Γöé
  1401. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1402. Γöé "fmod"     Γöé NaN      Γöé any number   Γöé NaN      Γöé EDOM     Γöé
  1403. Γöé        Γöé any number   Γöé NaN      Γöé NaN      Γöé EDOM     Γöé
  1404. Γöé        Γöé ╤æinfinity   Γöé any number   Γöé 0       Γöé EDOM     Γöé
  1405. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1406. Γöé "ldexp"    Γöé infinity    Γöé any number   Γöé infinity    Γöé ERANGE    Γöé
  1407. Γöé        Γöé -infinity   Γöé any number   Γöé -infinity   Γöé ERANGE    Γöé
  1408. Γöé        Γöé NaN      Γöé any number   Γöé NaN      Γöé EDOM     Γöé
  1409. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1410. Γöé "pow"     Γöé ╤æinfinity   Γöé "0"      Γöé NaN      Γöé EDOM     Γöé
  1411. Γöé        Γöé infinity    Γöé -infinity   Γöé NaN      Γöé EDOM     Γöé
  1412. Γöé        Γöé -infinity   Γöé ╤æinfinity   Γöé NaN      Γöé EDOM     Γöé
  1413. Γöé        Γöé -infinity   Γöé <-1      Γöé NaN      Γöé EDOM     Γöé
  1414. Γöé        Γöé -infinity   Γöé <1, >-1    Γöé NaN      Γöé EDOM     Γöé
  1415. Γöé        Γöé -infinity   Γöé >1       Γöé NaN      Γöé EDOM     Γöé
  1416. Γöé        Γöé NaN      Γöé any number   Γöé NaN      Γöé EDOM     Γöé
  1417. Γöé        Γöé any number   Γöé NaN      Γöé NaN      Γöé EDOM     Γöé
  1418. Γöé        Γöé =<0      Γöé infinity    Γöé NaN      Γöé EDOM     Γöé
  1419. Γöé        Γöé 1       Γöé ╤æinfinity   Γöé NaN      Γöé EDOM     Γöé
  1420. Γöé        Γöé ╤æinfinity   Γöé ╤æ1       Γöé 0       Γöé ERANGE    Γöé
  1421. Γöé        Γöé >0, <1     Γöé infinity    Γöé 0       Γöé ERANGE    Γöé
  1422. Γöé        Γöé >0, <1     Γöé -infinity   Γöé infinity    Γöé ERANGE    Γöé
  1423. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  1424.  
  1425. Note:  If a signalling NaN is passed to a math function, the behavior is 
  1426.        undefined. 
  1427.  
  1428.  
  1429. ΓòÉΓòÉΓòÉ 4.1.5. Math Functions without Infinity and NaN Support ΓòÉΓòÉΓòÉ
  1430.  
  1431. The following floating-point unit functions are not supported for use with 
  1432. infinity or NaN values. In general, a NaN or infinity value as input for these 
  1433. functions will result in an undefined value, an invalid operation exception, or 
  1434. both. These functions do not set errno. 
  1435.  
  1436. _facos      _fasin 
  1437. _fcos       _fcossin 
  1438. _fpatan     _fptan 
  1439. _fsin       _fsincos 
  1440. _fsqrt      _fyl2x 
  1441. _fyl2xp1    _f2xm1 
  1442.  
  1443. Note:  If you expect the return value of a math function to be infinity or NaN, 
  1444. you should use the functions that are supported for these values. The advantage 
  1445. in using the floating-point unit math functions is a reduction in the 
  1446. processing time. :enote. 
  1447.  
  1448.  
  1449. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1450.  
  1451. o Infinity and NaN Support 
  1452. o math.h 
  1453. o acos  - Calculate Arccosine 
  1454. o asin  - Calculate Arcsine 
  1455. o atan - atan2  - Calculate Arctangent 
  1456. o ceil - Integer >= Argument 
  1457. o cos  - Calculate Cosine 
  1458. o cosh  - Calculate Hyperbolic Cosine 
  1459. o erf  - Calculate Error Functions 
  1460. o exp  - Exponential Function 
  1461. o fabs  - Calculate Floating-Point Absolute Value 
  1462. o floor - Integer <= Argument 
  1463. o fmod  - Floating-Point Remainder 
  1464. o frexp  - Separate Floating-Point Value 
  1465. o gamma  - Gamma Function 
  1466. o ldexp  - Multiply by a Power of Two 
  1467. o log  - Calculate Natural Logarithm 
  1468. o log10  - Calculate Base 10 Logarithm 
  1469. o modf  - Separate Floating-Point Value 
  1470. o pow  - Compute Power 
  1471. o sin  - Calculate Sine 
  1472. o sinh  - Calculate Hyperbolic Sine 
  1473. o sqrt  - Calculate Square Root 
  1474. o tan  - Calculate Tangent 
  1475. o tanh  - Calculate Hyperbolic Tangent 
  1476.  
  1477.  
  1478. ΓòÉΓòÉΓòÉ 5. Using Low-Level I/O Functions ΓòÉΓòÉΓòÉ
  1479.  
  1480. The C/C++ Tools compiler supports both stream I/O and low-level I/O. The 
  1481. primary difference between the two types of I/O is that low-level I/O leaves 
  1482. the responsibility of buffering and formatting up to the user. 
  1483.  
  1484. In general, you should not mix input or output from low-level I/O with that 
  1485. from stream I/O. The only way to communicate between stream I/O and low-level 
  1486. I/O is by using the _fdopen or _fileno functions. 
  1487.  
  1488. The low-level I/O functions include: 
  1489.  
  1490. _access        _fstat 
  1491. _chmod         _isatty 
  1492. _chsize        _lseek 
  1493. _close         _open 
  1494. _creat         _read 
  1495. _dup           _setmode 
  1496. _dup2          _sopen 
  1497. __eof          _stat 
  1498. _fdopen        _tell 
  1499. _filelength    _umask 
  1500. _fileno        _write 
  1501.  
  1502. When you are using the low-level I/O functions, you should be aware of the 
  1503. following information: 
  1504.  
  1505. o A handle is a value created by the system and used by low-level I/O that 
  1506.   identifies a file. The conversion between C and OS/2 API handles is given by: 
  1507.  
  1508.        API_handle = C_handle
  1509.  
  1510.   Handles may be passed between library environments without restriction. 
  1511.  
  1512.   If a handle is acquired other than by using the C/C++ Tools library functions 
  1513.   _open, _creat, _sopen, or _fileno, the function _setmode must be run for that 
  1514.   handle before using it with the C/C++ Tools library functions. 
  1515.  
  1516. o The default open-sharing mode is SH_DENYWR. Use _sopen to obtain other 
  1517.   sharing modes. 
  1518.  
  1519. o Text mode will delete `\r' characters on input and will change `\n' to `\r\n' 
  1520.   on output. 
  1521.  
  1522. o In a multithread environment, it is your responsibility to ensure that two 
  1523.   threads do not attempt to perform low level I/O operations on the same file 
  1524.   at the same time. You must make sure that one I/O process is completed before 
  1525.   another begins. 
  1526.  
  1527. o Low level I/O uses a named shared memory segment, with a name of the form 
  1528.   \SHAREMEM\DDE4xxxx.xxx, where x may be any character other than blank. Using 
  1529.   a named shared memory segment of this form may cause low level I/O to operate 
  1530.   incorrectly. 
  1531.  
  1532. o If the file mode is text, the low-level I/O functions treat the character x1a 
  1533.   in the following ways: 
  1534.  
  1535.    - The character x1a is treated as end of file on input if it is detected in 
  1536.      a nonseekable file. It is only treated as end of file if it is the last 
  1537.      character of a seekable file. 
  1538.  
  1539.    - If a file is opened as text with either the O_APPEND or O_RDWR flags, and 
  1540.      x1a is the last character of the file, the last character of the file is 
  1541.      deleted. 
  1542.  
  1543.  
  1544. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1545.  
  1546. o Low-Level Input/Output 
  1547.  
  1548.  
  1549. ΓòÉΓòÉΓòÉ 6. Library Functions ΓòÉΓòÉΓòÉ
  1550.  
  1551. The C/C++ Tools libraries are divided into two parts: 
  1552.  
  1553. o Standard libraries, which define the SAA features and the C/C++ Tools 
  1554.   standard extensions to SAA 
  1555.  
  1556. o Subsystem libraries, which are a subset of the standard library, and are used 
  1557.   for subsystem development. 
  1558.  
  1559. This section lists alphabetically and describes all the functions that the 
  1560. C/C++Tools product offers, including the extensions to the SAA C definition. 
  1561. For information on the subsystem libraries and the functions in them, see the 
  1562. chapter called "Developing Subsystems" in the Programming Guide. 
  1563.  
  1564. Each function description includes the following subsections: 
  1565.  
  1566. Format 
  1567.       The prototyped declaration of the function and the header file in which 
  1568.       it is found.  You do not need to include the declaration in your code; it 
  1569.       is included with the header file. 
  1570. Language Level 
  1571.       The C language standard that each function belongs to. The standard is 
  1572.       one of the following: 
  1573.  
  1574.    ANSI      Functions defined in the ANSI C standard. 
  1575.    SAA       Functions defined in the SAA C standard. 
  1576.    POSIX     Functions defined in the POSIX C standard. 
  1577.    Extension Functions offered by the C/C++ Tools product as extensions to the 
  1578.              above standards. 
  1579. Description 
  1580.       A brief description of what the function does, what parameters it takes, 
  1581.       and how to use the function. 
  1582. Example 
  1583.       A short example of how to use the function. 
  1584. Related Information 
  1585.       A list of other functions that are similar to or related to the function. 
  1586.  
  1587. You can use the Copy to File choice from the Services pull-down menu to copy 
  1588. any function example to a separate file (called TEXT.TMP by default).  You can 
  1589. then compile, link, and run the example. 
  1590.  
  1591.  
  1592. ΓòÉΓòÉΓòÉ 6.1. abort  - Stop a Program ΓòÉΓòÉΓòÉ
  1593.  
  1594.  
  1595. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  1596.  
  1597. #include <stdlib.h>
  1598.  
  1599. void abort(void);
  1600.  
  1601.  
  1602. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  1603.  
  1604. Language Level: ANSI, SAA, Extension 
  1605.  
  1606. The abort function causes an abnormal program termination and returns control 
  1607. to the host environment.  The abort function is similar to exit, except that 
  1608. abort does not flush buffers and close open files before ending the program. 
  1609. Calls to abort raise the SIGABRT signal. 
  1610.  
  1611. Example of abort 
  1612.  
  1613.  
  1614. ΓòÉΓòÉΓòÉ <hidden> Example of abort ΓòÉΓòÉΓòÉ
  1615.  
  1616. /************************************************************************
  1617. *
  1618.  
  1619. This example tests for successful opening of the file myfile. If an error 
  1620. occurs, an error message is printed and the program ends with a call to the 
  1621. abort function. 
  1622.  
  1623.                                                                         *
  1624. ************************************************************************/
  1625.  
  1626. #include <stdio.h>
  1627. #include <stdlib.h>
  1628.  
  1629. int main(void)
  1630. {
  1631.  
  1632.    FILE *stream;
  1633.  
  1634.    if ((stream = fopen("myfile.dat", "r")) == NULL)
  1635.    {
  1636.       perror("Could not open data file");
  1637.       abort();
  1638.    }
  1639. }
  1640.  
  1641.  
  1642. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1643.  
  1644. o exit  - End Program 
  1645. o _exit - End Process 
  1646. o signal Install Interrupt Handlers 
  1647. o stdlib.h 
  1648.  
  1649.  
  1650. ΓòÉΓòÉΓòÉ 6.2. abs  - Calculate Integer Absolute Value ΓòÉΓòÉΓòÉ
  1651.  
  1652.  
  1653. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  1654.  
  1655. #include <stdlib.h>
  1656.  
  1657. int abs(int n);
  1658.  
  1659.  
  1660. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  1661.  
  1662. Language Level: ANSI, SAA 
  1663.  
  1664. The abs function returns the absolute value of an integer argument n. 
  1665.  
  1666. There is no error return value.  The result is undefined when the absolute 
  1667. value of the argument cannot be represented as an integer.  The value of the 
  1668. minimum allowable integer is defined by INT_MIN in the <limits.h> include file. 
  1669.  
  1670. Example of abs 
  1671.  
  1672.  
  1673. ΓòÉΓòÉΓòÉ <hidden> Example of abs ΓòÉΓòÉΓòÉ
  1674.  
  1675. /************************************************************************
  1676. *
  1677.  
  1678. This example calculates the absolute value of an integer x and assigns it to y. 
  1679.  
  1680.                                                                         *
  1681. ************************************************************************/
  1682.  
  1683. #include <stdlib.h>
  1684. #include <stdio.h>
  1685.  
  1686. int main(void)
  1687. {
  1688.     int x = -4, y;
  1689.  
  1690.     y = abs(x);
  1691.  
  1692.     printf("The absolute value of x is %d.\n", y);
  1693.  
  1694.     /********************* Output **************************
  1695.             The absolute value of x is 4.
  1696.     */
  1697. }
  1698.  
  1699.  
  1700. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1701.  
  1702. o _cabs - Calculate Absolute Value of Complex Number 
  1703. o fabs  - Calculate Floating-Point Absolute Value 
  1704. o labs  - Calculate long Absolute Value 
  1705. o limits.h 
  1706. o stdlib.h 
  1707.  
  1708.  
  1709. ΓòÉΓòÉΓòÉ 6.3. _access - Determine Access Mode ΓòÉΓòÉΓòÉ
  1710.  
  1711.  
  1712. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  1713.  
  1714. #include <io.h>
  1715.  
  1716. int _access(char *pathname, int mode);
  1717.  
  1718.  
  1719. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  1720.  
  1721. Language Level: Extension 
  1722.  
  1723. The _access function determines whether the specified file exists and whether 
  1724. you can get access to it in the given mode.  The following list gives possible 
  1725. values for the mode and their meaning in the access call: 
  1726.  
  1727. Value    Meaning 
  1728.  06      Check for permission to read from and write to the file. 
  1729.  04      Check for permission to read from the file. 
  1730.  02      Check for permission to write to the file. 
  1731.  00      Check only for the existence of the file. 
  1732.  
  1733. The _access function returns the value 0 if you can get access to the file in 
  1734. the specified mode. A return value of -1 shows that the file does not exist or 
  1735. is inaccessible in the given mode, and the system sets errno to one of the 
  1736. following values: 
  1737.  
  1738. Value          Meaning 
  1739. EACCESS        Access is denied; the permission setting of the file does not 
  1740.                allow you to get access to the file in the specified mode. 
  1741. ENOENT         The system cannot find the file or the path that you specified, 
  1742.                or the file name was incorrect. 
  1743. EINVAL         The mode specified was not valid. 
  1744. EOS2ERR        The call to the operating system was not successful. 
  1745.  
  1746. Example of _access 
  1747.  
  1748.  
  1749. ΓòÉΓòÉΓòÉ <hidden> Example of _access ΓòÉΓòÉΓòÉ
  1750.  
  1751. /************************************************************************
  1752. *
  1753.  
  1754. This example checks for the existence of the file sample.dat. If the file does 
  1755. not exist, it is created. 
  1756.  
  1757.                                                                         *
  1758. ************************************************************************/
  1759.  
  1760. #include <io.h>
  1761. #include <stdio.h>
  1762. #include <stdlib.h>
  1763.  
  1764. int main(void)
  1765. {
  1766.  
  1767.    if (-1 == _access("sample.dat",00))
  1768.    {
  1769.       printf("File sample.dat does not exist.\n");
  1770.       printf("Creating sample.dat.\n");
  1771.       system("echo Sample Program > sample.dat");
  1772.       if (0 == _access("sample.dat",00))
  1773.          printf("File sample.dat created.\n");
  1774.    }
  1775.    else
  1776.       printf("File sample.dat exists.\n");
  1777.  
  1778.    return 0;
  1779.  
  1780. /****************  The output should be similar to:  ********************
  1781.  
  1782.       File sample.dat does not exist.
  1783.       Creating sample.dat.
  1784.       File sample.dat created.
  1785. */
  1786. }
  1787.  
  1788.  
  1789. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1790.  
  1791. o _chmod - Change File Permission Setting 
  1792. o _sopen - Open Shared File 
  1793. o _umask - Sets File Mask of Current Process 
  1794. o io.h 
  1795.  
  1796.  
  1797. ΓòÉΓòÉΓòÉ 6.4. acos  - Calculate Arccosine ΓòÉΓòÉΓòÉ
  1798.  
  1799.  
  1800. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  1801.  
  1802. #include <math.h>
  1803.  
  1804. double acos(double x);
  1805.  
  1806.  
  1807. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  1808.  
  1809. Language Level: ANSI, SAA 
  1810.  
  1811. The acos function calculates the arc cosine of x, expressed in radians, in the 
  1812. range 0 to ╤â. 
  1813.  
  1814. The value of x must be between -1 and 1 inclusive. If x is less than -1 or 
  1815. greater than 1, acos sets errno to EDOM and returns 0. 
  1816.  
  1817. Example of acos 
  1818.  
  1819.  
  1820. ΓòÉΓòÉΓòÉ <hidden> Example of acos ΓòÉΓòÉΓòÉ
  1821.  
  1822. /************************************************************************
  1823. *
  1824.  
  1825. This example prompts for a value for x.  It prints an error message if x is 
  1826. greater than 1 or less than -1;  otherwise, it assigns the arc cosine of x to 
  1827. y. 
  1828.  
  1829.                                                                         *
  1830. ************************************************************************/
  1831.  
  1832. #include <stdio.h>
  1833. #include <stdlib.h>
  1834. #include <math.h>
  1835.  
  1836. #define MAX  1.0
  1837. #define MIN -1.0
  1838.  
  1839. int main(void)
  1840. {
  1841.   double x, y;
  1842.  
  1843.   printf( "Enter x\n" );
  1844.   scanf( "%lf", &x );
  1845.  
  1846.   /* Output error if not in range */
  1847.   if ( x > MAX )
  1848.     printf( "Error: %lf too large for acos\n", x );
  1849.   else if ( x < MIN )
  1850.     printf( "Error: %lf too small for acos\n", x );
  1851.   else {
  1852.     y = acos( x );
  1853.     printf( "acos( %lf ) = %lf\n", x, y );
  1854.   }
  1855. }
  1856.  
  1857. /*******  Expected output if 0.4 is entered:  *********
  1858.  
  1859. Enter x
  1860. acos( 0.400000 ) = 1.159279
  1861. */
  1862.  
  1863.  
  1864. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1865.  
  1866. o asin  - Calculate Arcsine 
  1867. o atan - atan2  - Calculate Arctangent 
  1868. o cos  - Calculate Cosine 
  1869. o cosh  - Calculate Hyperbolic Cosine 
  1870. o _facos - Calculate Arccosine 
  1871. o _fcos - Calculate Cosine 
  1872. o _fcossin - Calculate Cosine and Sine 
  1873. o _fsincos - Calculate Sine and Cosine 
  1874. o sin  - Calculate Sine 
  1875. o sinh  - Calculate Hyperbolic Sine 
  1876. o tan  - Calculate Tangent 
  1877. o tanh  - Calculate Hyperbolic Tangent 
  1878. o math.h 
  1879.  
  1880.  
  1881. ΓòÉΓòÉΓòÉ 6.5. _alloca - Temporarily Reserve Storage Block ΓòÉΓòÉΓòÉ
  1882.  
  1883.  
  1884. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  1885.  
  1886. #include <stdlib.h>  /* also defined in <malloc.h> */
  1887.                      /*      and <builtin.h>       */
  1888.  
  1889. void *_alloca(size_t size);
  1890.  
  1891.  
  1892. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  1893.  
  1894. Language Level: Extended 
  1895.  
  1896. The _alloca function is a built-in function that temporarily allocates size 
  1897. bytes of storage space from the program's stack. The memory space is 
  1898. automatically freed when the function that called _alloca returns. 
  1899.  
  1900. Note:  The _alloca function is faster than other allocation functions such as 
  1901. malloc, but it has several limitations: 
  1902.  
  1903. o Because it is a built-in function and has no backing code in the library: 
  1904.  
  1905.    - You cannot take the address of _alloca. 
  1906.    - You cannot parenthesize an _alloca function call because parentheses 
  1907.      specify a call to the backing code for the function in the library, and 
  1908.      _alloca has no backing code. 
  1909.  
  1910. o Because _alloca automatically frees storage after the function that calls it 
  1911.   returns, you cannot pass the pointer value returned by _alloca as an argument 
  1912.   to the free function. 
  1913. o You cannot pass memory allocated by _alloca to 16-bit programs, because it is 
  1914.   never tiled. 
  1915.  
  1916. Because _alloca uses automatic storage, programs calling _alloca must not be 
  1917. compiled using the /Gs+ switch. This switch disables stack probes and does not 
  1918. guarantee that enough stack storage will be available. You should use the /Gs- 
  1919. switch, which is the default setting. 
  1920.  
  1921. The _alloca function returns a pointer to the reserved space. If _alloca cannot 
  1922. reserve the requested space, the program gets an out of stack exception. 
  1923.  
  1924. Example of _alloca 
  1925.  
  1926.  
  1927. ΓòÉΓòÉΓòÉ <hidden> Example of alloca ΓòÉΓòÉΓòÉ
  1928.  
  1929. /************************************************************************
  1930. *
  1931. This example uses srand to generate five random numbers.  The numbers determine 
  1932. how much space _alloca is to allocate for the array barstr.  The result is a 
  1933. ragged two-dimensional array of strings. 
  1934.  
  1935.                                                                         *
  1936. ************************************************************************/
  1937.  
  1938. #include <stdio.h>
  1939. #include <stdlib.h>
  1940. #include <time.h>
  1941.  
  1942. int main(void)
  1943. {
  1944.     char *fullbar = "1 2 3 4 5";
  1945.     int range, rval;
  1946.     char *barstr[5];
  1947.     int i;
  1948.  
  1949.     printf("Bar representation of 5 random numbers\n ");
  1950.     printf("(each generated from 1 to 5):\n\n");
  1951.  
  1952.     srand( (unsigned int)time(NULL) ); /* set seed for rand function  */
  1953.                                        /* using time in seconds       */
  1954.     for (i = 0; i < 5; i++)
  1955.     {
  1956.        rval = (rand() + 1) % 5; /* generate random number from 0 to 4  */
  1957.  
  1958.        /* for partial copy of fullbar, allocate space on stack
  1959.           for barstr from 2 to 10 characters long + one space for
  1960.           a null character */
  1961.        barstr[i] = _alloca( (rval * sizeof(char) << 1) + 3 );
  1962.        memset(barstr[i], '\0', (rval 8 sizeof(char) <<1) + 3);
  1963.  
  1964.        /* copy random sized portion of fullbar  */
  1965.        strncpy(barstr[i], fullbar, ((rval +1) * 2) );
  1966.  
  1967.        printf("%s\n", barstr[i]);    /*  print random length bar  */
  1968.     }
  1969.  
  1970.     return 0;
  1971.  
  1972.     /***************  Possible output could be:  ********************
  1973.  
  1974.        Bar representation of 5 random numbers
  1975.        (each generated from 1 to 5):
  1976.  
  1977.        1
  1978.        1 2 3 4
  1979.        1 2 3
  1980.        1 2 3 4 5
  1981.        1 2                                */
  1982. }
  1983.  
  1984.  
  1985. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  1986.  
  1987. o calloc  - Reserve and Initialize Storage 
  1988. o free  - Release Storage Blocks 
  1989. o malloc  - Reserve Storage Block 
  1990. o realloc  - Change Reserved Storage Block Size 
  1991. o /Gs option 
  1992. o malloc.h 
  1993. o stdlib.h 
  1994.  
  1995.  
  1996. ΓòÉΓòÉΓòÉ 6.6. asctime  - Convert Time ΓòÉΓòÉΓòÉ
  1997.  
  1998.  
  1999. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2000.  
  2001. #include <time.h>
  2002.  
  2003. char *asctime(const struct tm *time);
  2004.  
  2005.  
  2006. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2007.  
  2008. Language Level: ANSI, SAA 
  2009.  
  2010. The asctime function converts time stored as a structure pointed to by time to 
  2011. a character string.  The time value may be obtained from a call to gmtime or 
  2012. localtime;  either returns a pointer to a tm structure defined in <time.h>. See 
  2013. gmtime  - Convert Time for a description of the tm structure fields. 
  2014.  
  2015. The string result that asctime produces contains exactly 26 characters and has 
  2016. the format: 
  2017.  
  2018.    "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n"
  2019.  
  2020. See printf  - Formatted Print for a description of format specifications. The 
  2021. following are examples of the string returned: 
  2022.  
  2023.    Sat Jul 04 02:03:55 1991\n\0
  2024. or
  2025.    Sat Jul 04  2:03:55 1991\n\0
  2026.  
  2027. The asctime function uses a 24-hour-clock format.  The days are abbreviated to: 
  2028. Sun, Mon, Tue, Wed, Thu, Fri, and Sat.  The months are abbreviated to:  Jan, 
  2029. Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, and Dec.  All fields have 
  2030. constant width. Days with only one digit are preceded either with a zero or a 
  2031. blank space. The new-line character (\n) and the null character (\0) occupy the 
  2032. last two positions of the string. 
  2033.  
  2034. The time and date functions begin at 00:00:00 Universal Time, January 1, 1970. 
  2035.  
  2036. The asctime function returns a pointer to the resulting character string. 
  2037. There is no error return value. 
  2038.  
  2039. Note:  The asctime, ctime, and other time functions may use a common, 
  2040.        statically allocated buffer to hold the return string.  Each call to one 
  2041.        of these functions may destroy the result of the previous call. 
  2042.  
  2043. Example of asctime 
  2044.  
  2045.  
  2046. ΓòÉΓòÉΓòÉ <hidden> Example of asctime ΓòÉΓòÉΓòÉ
  2047.  
  2048. /************************************************************************
  2049. *
  2050.  
  2051. This example polls the system clock and prints a message giving the current 
  2052. time. 
  2053.  
  2054.                                                                         *
  2055. ************************************************************************/
  2056.  
  2057. #include <time.h>
  2058. #include <stdio.h>
  2059.  
  2060. int main(void)
  2061. {
  2062.     struct tm *newtime;
  2063.     time_t ltime;
  2064.  
  2065.         /* Get the time in seconds */
  2066.     time(<ime);
  2067.         /* Convert it to the structure tm */
  2068.     newtime = localtime(<ime);
  2069.  
  2070.         /* Print the local time as a string */
  2071.     printf("The current date and time are %s",
  2072.              asctime(newtime));
  2073. }
  2074.  
  2075. /****************  Output should be similar to:  ******************
  2076.  
  2077. The current date and time are Fri Mar 26 13:29:51 1993
  2078. */
  2079.  
  2080.  
  2081. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2082.  
  2083. o ctime  - Convert Time 
  2084. o gmtime  - Convert Time 
  2085. o localtime  - Convert Time 
  2086. o mktime  - Convert Local Time 
  2087. o strftime  - Convert to Formatted Time 
  2088. o time  - Determine Current Time 
  2089. o printf  - Formatted Print 
  2090. o time.h 
  2091.  
  2092.  
  2093. ΓòÉΓòÉΓòÉ 6.7. asin  - Calculate Arcsine ΓòÉΓòÉΓòÉ
  2094.  
  2095.  
  2096. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2097.  
  2098. #include <math.h>
  2099.  
  2100. double asin(double x);
  2101.  
  2102.  
  2103. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2104.  
  2105. Language Level: ANSI, SAA 
  2106.  
  2107. The asin function calculates the arc sine of x, in the range -╤â/2 to ╤â/2 
  2108. radians. 
  2109.  
  2110. The value of x must be between -1 and 1.  If x is less than -1 or greater than 
  2111. 1, asin sets errno to EDOM, and returns a value of 0. 
  2112.  
  2113. Example of asin 
  2114.  
  2115.  
  2116. ΓòÉΓòÉΓòÉ <hidden> Example of asin ΓòÉΓòÉΓòÉ
  2117.  
  2118. /************************************************************************
  2119. *
  2120.  
  2121. This example prompts for a value for x.  It prints an error message if x is 
  2122. greater than 1 or less than -1;  otherwise, it assigns the arc sine of x to y. 
  2123.  
  2124.                                                                         *
  2125. ************************************************************************/
  2126.  
  2127. #include <stdio.h>
  2128. #include <stdlib.h>
  2129. #include <math.h>
  2130.  
  2131. #define MAX  1.0
  2132. #define MIN -1.0
  2133.  
  2134. int main(void)
  2135. {
  2136.   double x, y;
  2137.  
  2138.   printf( "Enter x\n" );
  2139.   scanf( "%lf", &x );
  2140.  
  2141.   /* Output error if not in range */
  2142.   if ( x > MAX )
  2143.     printf( "Error: %lf too large for asin\n", x );
  2144.   else if ( x < MIN )
  2145.     printf( "Error: %lf too small for asin\n", x );
  2146.   else
  2147.   {
  2148.     y = asin( x );
  2149.     printf( "asin( %lf ) = %lf\n", x, y );
  2150.   }
  2151. }
  2152.  
  2153. /****************  Output should be similar to:  ******************
  2154.  
  2155. Enter x
  2156. asin( 0.200000 ) = 0.201358
  2157. */
  2158.  
  2159.  
  2160. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2161.  
  2162. o acos  - Calculate Arccosine 
  2163. o atan - atan2  - Calculate Arctangent 
  2164. o cos  - Calculate Cosine 
  2165. o cosh  - Calculate Hyperbolic Cosine 
  2166. o _fasin - Calculate Arcsine 
  2167. o _fcossin - Calculate Cosine and Sine 
  2168. o _fsin - Calculate Sine 
  2169. o _fsincos - Calculate Sine and Cosine 
  2170. o sin  - Calculate Sine 
  2171. o sinh  - Calculate Hyperbolic Sine 
  2172. o tan  - Calculate Tangent 
  2173. o tanh  - Calculate Hyperbolic Tangent 
  2174. o math.h 
  2175.  
  2176.  
  2177. ΓòÉΓòÉΓòÉ 6.8. assert  - Verify Condition ΓòÉΓòÉΓòÉ
  2178.  
  2179.  
  2180. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2181.  
  2182. #include <assert.h>
  2183.  
  2184. void assert(int expression);
  2185.  
  2186.  
  2187. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2188.  
  2189. Language Level: ANSI, SAA 
  2190.  
  2191. The assert function prints a diagnostic message to stderr and aborts the 
  2192. program if expression is false (zero). The diagnostic message has the format: 
  2193. Assertion failed: expression, file filename, line line-number. 
  2194.  
  2195. The assert function takes no action if the expression is true (nonzero). 
  2196.  
  2197. Use the assert function to identify program logic errors.  Choose an expression 
  2198. that holds true only if the program is operating as you intend.  After you have 
  2199. debugged the program, you can use the special no-debug identifier NDEBUG to 
  2200. remove the assert calls from the program.  If you define NDEBUG to any value 
  2201. with a #define directive, the C preprocessor expands all assert invocations to 
  2202. void expressions. If you use NDEBUG, you must define it before you include 
  2203. <assert.h> in the program. 
  2204.  
  2205. There is no return value. 
  2206.  
  2207. Note:  The assert function is a macro. Do not use the #undef directive with the 
  2208. assert function. 
  2209.  
  2210. Example of assert 
  2211.  
  2212.  
  2213. ΓòÉΓòÉΓòÉ <hidden> Example of assert ΓòÉΓòÉΓòÉ
  2214.  
  2215. /************************************************************************
  2216. *
  2217.  
  2218. In this example, the assert function tests the string argument for a null 
  2219. string and an empty string and verifies that the length argument is positive 
  2220. before processing these arguments. 
  2221.  
  2222.                                                                         *
  2223. ************************************************************************/
  2224.  
  2225. #include <stdio.h>
  2226. #include <assert.h>
  2227.  
  2228. void analyze (char *, int);
  2229.  
  2230. int main(void)
  2231. {
  2232.    char *string = "ABC";
  2233.    int length = 3;
  2234.  
  2235.    analyze(string, length);
  2236.    printf("The string %s is not null or empty, "
  2237.           "and has length %d \n", string, length);
  2238. }
  2239.  
  2240. void analyze(char *string, int length)
  2241. {
  2242.    assert(string != NULL);            /* cannot be NULL */
  2243.    assert(*string != '\0');    /* cannot be empty */
  2244.    assert(length > 0);          /* must be positive */
  2245. }
  2246.  
  2247. /****************  Output should be similar to:  ******************
  2248.  
  2249. The string ABC is not null or empty, and has length 3
  2250. */
  2251.  
  2252.  
  2253. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2254.  
  2255. o abort  - Stop a Program 
  2256. o assert.h 
  2257. o #define 
  2258. o #undef 
  2259.  
  2260.  
  2261. ΓòÉΓòÉΓòÉ 6.9. atan - atan2  - Calculate Arctangent ΓòÉΓòÉΓòÉ
  2262.  
  2263.  
  2264. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2265.  
  2266. #include <math.h>
  2267.  
  2268. double atan(double x);
  2269.  
  2270. double atan2(double y, double x);
  2271.  
  2272.  
  2273. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2274.  
  2275. Language Level: ANSI, SAA 
  2276.  
  2277. The atan and atan2 functions calculate the arc tangent of x and y/x, 
  2278. respectively. 
  2279.  
  2280. The atan function returns a value in the range -╤â/2 to ╤â/2 radians. The atan2 
  2281. function returns a value in the range -╤â to ╤â radians.  If both arguments of 
  2282. atan2 are zero, the function sets errno to EDOM, and returns a value of zero 
  2283. (0). 
  2284.  
  2285. Example of atan - atan2 
  2286.  
  2287.  
  2288. ΓòÉΓòÉΓòÉ <hidden> Example of atan - atan2 ΓòÉΓòÉΓòÉ
  2289.  
  2290. /************************************************************************
  2291. *
  2292.  
  2293. This example calculates arc tangents using the atan and atan2 functions. 
  2294.  
  2295.                                                                         *
  2296. ************************************************************************/
  2297.  
  2298. #include <math.h>
  2299. #include <stdio.h>
  2300.  
  2301. int main(void)
  2302. {
  2303.     double a,b,c,d;
  2304.  
  2305.     c = 0.45;
  2306.     d = 0.23;
  2307.  
  2308.     a = atan(c);
  2309.     b = atan2(c,d);
  2310.  
  2311.     printf("atan( %lf ) = %lf\n", c, a);
  2312.     printf("atan2( %lf, %lf ) = %lf\n", c, d, b);
  2313. }
  2314.  
  2315. /****************  Output should be similar to:  ******************
  2316.  
  2317. atan( 0.450000 ) = 0.422854
  2318. atan2( 0.450000, 0.230000 ) = 1.098299
  2319. */
  2320.  
  2321.  
  2322. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2323.  
  2324. o acos  - Calculate Arccosine 
  2325. o asin  - Calculate Arcsine 
  2326. o cos  - Calculate Cosine 
  2327. o cosh  - Calculate Hyperbolic Cosine 
  2328. o _fpatan - Calculate Arctangent 
  2329. o _fptan - Calculate Tangent 
  2330. o sin  - Calculate Sine 
  2331. o sinh  - Calculate Hyperbolic Sine 
  2332. o tan  - Calculate Tangent 
  2333. o tanh  - Calculate Hyperbolic Tangent 
  2334. o math.h 
  2335.  
  2336.  
  2337. ΓòÉΓòÉΓòÉ 6.10. atexit  - Record Program Termination Function ΓòÉΓòÉΓòÉ
  2338.  
  2339.  
  2340. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2341.  
  2342. #include <stdlib.h>
  2343.  
  2344. int atexit(void (*func)(void));
  2345.  
  2346.  
  2347. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2348.  
  2349. Language Level: ANSI, SAA 
  2350.  
  2351. The atexit function records a function, pointed to by func, that the system 
  2352. calls at normal program termination.  For portability, you should use atexit to 
  2353. register up to 32 functions only. The functions are executed in a last in, 
  2354. first out order. 
  2355.  
  2356. The atexit function returns zero (0) if it is successful, and nonzero if it 
  2357. fails. 
  2358.  
  2359. Example of atexit 
  2360.  
  2361.  
  2362. ΓòÉΓòÉΓòÉ <hidden> Example of atexit ΓòÉΓòÉΓòÉ
  2363.  
  2364. /************************************************************************
  2365. *
  2366.  
  2367. This example uses the atexit function to call the function goodbye at program 
  2368. termination. 
  2369.  
  2370.                                                                         *
  2371. ************************************************************************/
  2372.  
  2373. #include <stdlib.h>
  2374. #include <stdio.h>
  2375.  
  2376. int main(void)
  2377. {
  2378.    void goodbye(void);
  2379.    int rc;
  2380.  
  2381.    rc = atexit(goodbye);
  2382.    if (rc != 0)
  2383.       perror("Error in atexit");
  2384.    exit(0);
  2385. }
  2386.  
  2387. void goodbye(void)
  2388.    /* This function is called at normal program termination */
  2389. {
  2390.    printf("The function goodbye was called at program termination\n");
  2391. }
  2392.  
  2393. /****************  Output should be similar to:  ******************
  2394.  
  2395. The function goodbye was called at program termination
  2396. */
  2397.  
  2398.  
  2399. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2400.  
  2401. o exit  - End Program 
  2402. o _exit - End Process 
  2403. o _onexit - Record Termination Function 
  2404. o signal Install Interrupt Handlers 
  2405. o stdlib.h 
  2406.  
  2407.  
  2408. ΓòÉΓòÉΓòÉ 6.11. atof  - Convert Character Strings ΓòÉΓòÉΓòÉ
  2409.  
  2410.  
  2411. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2412.  
  2413. #include <stdlib.h>
  2414.  
  2415. double atof(const char *string);
  2416.  
  2417.  
  2418. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2419.  
  2420. Language Level: ANSI, SAA, Extension 
  2421.  
  2422. This function converts a character string to a double-precision floating-point 
  2423. value. 
  2424.  
  2425. The input string is a sequence of characters that can be interpreted as a 
  2426. numerical value of the specified return type.  The function stops reading the 
  2427. input string at the first character that it cannot recognize as part of a 
  2428. number;  this character can be the null character that ends the string. 
  2429.  
  2430. The atof function expects a string in the following form: 
  2431.  
  2432.  ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ
  2433.   Γöé        Γöé  Γöé    Γöé  Γöé                 Γöé
  2434.   ΓööΓöÇΓöÇwhitespaceΓöÇΓöÇΓöÿ  Γö£ΓöÇΓöÇ + ΓöÇΓöÇΓöñ  Γö£ΓöÇdigitsΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöñ
  2435.            Γöé    Γöé  Γöé      Γöé    Γöé  Γöé     Γöé  Γöé
  2436.            ΓööΓöÇΓöÇ - ΓöÇΓöÇΓöÿ  Γöé      ΓööΓöÇΓöÇ . ΓöÇΓöÿ  ΓööΓöÇdigitsΓöÇΓöÿ  Γöé
  2437.                  Γöé                 Γöé
  2438.                  ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ . ΓöÇΓöÇdigitsΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2439.  
  2440.  ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ
  2441.   Γöé              Γöé
  2442.   Γö£ΓöÇΓöÇeΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇdigitsΓöÇΓöÇΓöÿ
  2443.   Γöé   Γöé  Γöé   Γöé
  2444.   ΓööΓöÇΓöÇEΓöÇΓöÇΓöÿ  Γö£ΓöÇ + ΓöÇΓöñ
  2445.        Γöé   Γöé
  2446.        ΓööΓöÇ - ΓöÇΓöÿ
  2447.  
  2448. The white space consists of the same characters for which the isspace function 
  2449. is true, such as spaces and tabs.  The atof function ignores leading 
  2450. white-space characters. 
  2451.  
  2452. For the atof function, digits is one or more decimal digits;  if no digits 
  2453. appear before the decimal point, at least one digit must appear after the 
  2454. decimal point.  The decimal digits can precede an exponent, introduced by the 
  2455. letter e or E.  The exponent is a decimal integer, which may be signed. The 
  2456. string can also be "infinity", "inf", or "nan". These strings are case 
  2457. insensitive, and can be preceded by a unary minus (-). They are converted to 
  2458. infinity and NaN values. 
  2459.  
  2460. The atof function returns a double value produced by interpreting the input 
  2461. characters as a number.  The return value is 0 if the function cannot convert 
  2462. the input to a value of that type.  The return value is undefined in case of 
  2463. overflow. 
  2464.  
  2465. Example of atof 
  2466.  
  2467.  
  2468. ΓòÉΓòÉΓòÉ <hidden> Example of atof ΓòÉΓòÉΓòÉ
  2469.  
  2470. /************************************************************************
  2471. *
  2472.  
  2473. This example shows how to convert numbers stored as strings to numerical values 
  2474. using the atof function. 
  2475.  
  2476.                                                                         *
  2477. ************************************************************************/
  2478.  
  2479. #include <stdlib.h>
  2480.  
  2481. int main(void)
  2482. {
  2483.     double x;
  2484.     char *s;
  2485.  
  2486.     s = " -2309.12E-15";
  2487.     x = atof(s);     /* x = -2309.12E-15 */
  2488. }
  2489.  
  2490.  
  2491. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2492.  
  2493. o atoi  - Convert Character Strings 
  2494. o atol  - Convert Character Strings 
  2495. o _atold - Convert ASCII String to Long Double 
  2496. o strtod  - Convert Character String to Numeric 
  2497. o strtol  - Convert Character String to Numeric 
  2498. o strtold - Convert String to Long Double 
  2499. o Infinity and NaN Support 
  2500. o stdlib.h 
  2501.  
  2502.  
  2503. ΓòÉΓòÉΓòÉ 6.12. atoi  - Convert Character Strings ΓòÉΓòÉΓòÉ
  2504.  
  2505.  
  2506. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2507.  
  2508. #include <stdlib.h>
  2509.  
  2510. int atoi(const char *string);
  2511.  
  2512.  
  2513. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2514.  
  2515. Language Level: ANSI, SAA 
  2516.  
  2517. This function converts a character string to an integer value. 
  2518.  
  2519. The input string is a sequence of characters that can be interpreted as a 
  2520. numerical value of the specified return type.  The function stops reading the 
  2521. input string at the first character that it cannot recognize as part of a 
  2522. number;  this character can be the null character which ends the string. 
  2523.  
  2524. The atoi function does not recognize decimal points nor exponents.  The string 
  2525. argument for this function has the form: 
  2526.  
  2527. ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdigitsΓöÇΓöÇ
  2528.   Γöé        Γöé  Γöé    Γöé
  2529.   ΓööΓöÇΓöÇwhitespaceΓöÇΓöÇΓöÿ  Γö£ΓöÇΓöÇ + ΓöÇΓöÇΓöñ
  2530.            Γöé    Γöé
  2531.            ΓööΓöÇΓöÇ - ΓöÇΓöÇΓöÿ
  2532.  
  2533. where whitespace consists of the same characters for which the isspace function 
  2534. is true, such as spaces and tabs.  The atoi function ignores leading 
  2535. white-space characters. digits is one or more decimal digits. 
  2536.  
  2537. atoi returns an int value produced by interpreting the input characters as a 
  2538. number.  The return value is 0 if the function cannot convert the input to a 
  2539. value of that type.  The return value is undefined in the case of an overflow. 
  2540.  
  2541.  Example of atoi 
  2542.  
  2543.  
  2544. ΓòÉΓòÉΓòÉ <hidden> Example of atoi ΓòÉΓòÉΓòÉ
  2545.  
  2546. /************************************************************************
  2547. *
  2548.  
  2549. This example shows how to convert numbers stored as strings to numerical values 
  2550. using the atoi function. 
  2551.  
  2552.                                                                         *
  2553. ************************************************************************/
  2554.  
  2555. #include <stdlib.h>
  2556.  
  2557. int main(void)
  2558. {
  2559.     int i;
  2560.     char *s;
  2561.  
  2562.     s = " -9885";
  2563.     i = atoi(s);     /* i = -9885 */
  2564. }
  2565.  
  2566.  
  2567. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2568.  
  2569. o atof  - Convert Character Strings 
  2570. o atol  - Convert Character Strings 
  2571. o _atold - Convert ASCII String to Long Double 
  2572. o strtod  - Convert Character String to Numeric 
  2573. o strtol  - Convert Character String to Numeric 
  2574. o strtold - Convert String to Long Double 
  2575. o stdlib.h 
  2576.  
  2577.  
  2578. ΓòÉΓòÉΓòÉ 6.13. atol  - Convert Character Strings ΓòÉΓòÉΓòÉ
  2579.  
  2580.  
  2581. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2582.  
  2583. #include <stdlib.h>
  2584.  
  2585. long int atol(const char *string);
  2586.  
  2587.  
  2588. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2589.  
  2590. Language Level: ANSI, SAA 
  2591.  
  2592. This function converts a character string to a long value. 
  2593.  
  2594. The input string is a sequence of characters that can be interpreted as a 
  2595. numerical value of the specified return type.  The function stops reading the 
  2596. input string at the first character that it cannot recognize as part of a 
  2597. number;  this character can be the null character that ends the string. 
  2598.  
  2599. The atol function does not recognize decimal points nor exponents.  The string 
  2600. argument for this function has the form: 
  2601.  
  2602. ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdigitsΓöÇΓöÇ
  2603.   Γöé        Γöé  Γöé    Γöé
  2604.   ΓööΓöÇΓöÇwhitespaceΓöÇΓöÇΓöÿ  Γö£ΓöÇΓöÇ + ΓöÇΓöÇΓöñ
  2605.            Γöé    Γöé
  2606.            ΓööΓöÇΓöÇ - ΓöÇΓöÇΓöÿ
  2607.  
  2608. where whitespace consists of the same characters for which the isspace function 
  2609. is true, such as spaces and tabs.  The atol function ignores leading 
  2610. white-space characters. digits is one or more decimal digits. 
  2611.  
  2612. atol returns a long value produced by interpreting the input characters as a 
  2613. number.  The return value is 0L if the function cannot convert the input to a 
  2614. value of that type.  The return value is undefined in case of overflow. 
  2615.  
  2616. Example of atol 
  2617.  
  2618.  
  2619. ΓòÉΓòÉΓòÉ <hidden> Example of atol ΓòÉΓòÉΓòÉ
  2620.  
  2621. /************************************************************************
  2622. *
  2623.  
  2624. The example shows how to convert numbers stored as strings to numerical values 
  2625. using the atol function. 
  2626.  
  2627.                                                                         *
  2628. ************************************************************************/
  2629.  
  2630. #include <stdlib.h>
  2631.  
  2632. int main(void)
  2633. {
  2634.     long l;
  2635.     char *s;
  2636.  
  2637.     s = "98854 dollars";
  2638.     l = atol(s);     /* l = 98854 */
  2639. }
  2640.  
  2641.  
  2642. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2643.  
  2644. o atof  - Convert Character Strings 
  2645. o atoi  - Convert Character Strings 
  2646. o _atold - Convert ASCII String to Long Double 
  2647. o strtod  - Convert Character String to Numeric 
  2648. o strtol  - Convert Character String to Numeric 
  2649. o strtold - Convert String to Long Double 
  2650. o stdlib.h 
  2651.  
  2652.  
  2653. ΓòÉΓòÉΓòÉ 6.14. _atold - Convert ASCII String to Long Double ΓòÉΓòÉΓòÉ
  2654.  
  2655.  
  2656. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2657.  
  2658. #include <stdlib.h>    /* also defined in <math.h> */
  2659.  
  2660. long double _atold(const char *nptr);
  2661.  
  2662.  
  2663. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2664.  
  2665. Language Level: Extension 
  2666.  
  2667. The _atold function converts a character string pointed to by nptr to a long 
  2668. double value.  The function continues until it reads a character it does not 
  2669. recognize  as part of a number.  This character may be the ending null 
  2670. character. Except for its behavior on error, _atold is equivalent to 
  2671.  
  2672.    strtold(nptr, (char **)NULL)
  2673.  
  2674. The string pointed to by nptr must have the following format: 
  2675.  
  2676. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2677. Γöé                                        Γöé
  2678. Γöé >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ>       Γöé
  2679. Γöé   ΓööΓöÇwhitespaceΓöÇΓöÿ  ΓööΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇdigitsΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö¼ΓöÇΓöÿ        Γöé
  2680. Γöé            Γö£ΓöÇ + ΓöÇΓöñ  Γöé     ΓööΓöÇ.ΓöÇΓöÿ  ΓööΓöÇdigitsΓöÇΓöÿ Γöé         Γöé
  2681. Γöé            ΓööΓöÇ Γö┤ ΓöÇΓöÿ  ΓööΓöÇ.ΓöÇΓöÇdigitsΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ         Γöé
  2682. Γöé                                        Γöé
  2683. Γöé >ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><                      Γöé
  2684. Γöé   ΓööΓöÇΓö¼ΓöÇ e ΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdigitsΓöÇΓöÿ                        Γöé
  2685. Γöé    ΓööΓöÇ E ΓöÇΓöÿ  Γö£ΓöÇ + ΓöÇΓöñ                             Γöé
  2686. Γöé        ΓööΓöÇ Γö┤ ΓöÇΓöÿ                             Γöé
  2687. Γöé                                        Γöé
  2688. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2689.  
  2690. The digits are one or more decimal digits.  If no digits appear before the 
  2691. decimal point, at least one digit must follow the decimal point. You can place 
  2692. an exponent expressed as a decimal integer after the digits. The exponent can 
  2693. be signed. 
  2694.  
  2695. The value of nptr can also be one of the strings infinity, inf, or nan.  These 
  2696. strings are case insensitive, and can be preceded by a unary minus (-). They 
  2697. are converted to infinity and NaN values. For more information on NaN and 
  2698. infinity values, see Infinity and NaN Support. 
  2699.  
  2700. The _atold function ignores any whitespace characters, as defined by the 
  2701. isspace function. 
  2702.  
  2703. The _atold function returns the converted long double value. In the case of an 
  2704. underflow, it returns 0. In the case of a positive overflow, _atold returns 
  2705. positive _LHUGE_VAL, and negative _LHUGE_VAL for a negative overflow. 
  2706.  
  2707. Example of _atold 
  2708.  
  2709.  
  2710. ΓòÉΓòÉΓòÉ <hidden> Example of _atold ΓòÉΓòÉΓòÉ
  2711.  
  2712. /************************************************************************
  2713. *
  2714. This example uses _atold to convert two strings, "  -001234.5678e10end of 
  2715. string" and "NaNQ", to their corresponding long double values. 
  2716.  
  2717.                                                                         *
  2718. ************************************************************************/
  2719.  
  2720. #include <stdlib.h>
  2721. #include <stdio.h>
  2722.  
  2723. int main(void)
  2724. {
  2725.   char *string;
  2726.  
  2727.   string = "  -001234.5678e10end of string";
  2728.   printf("_atold = %.10Le\n", _atold(string) );
  2729.  
  2730.   string = "NaNQ";
  2731.   printf("_atold = %.10Le\n", _atold(string) );
  2732.  
  2733.   return 0;
  2734.  
  2735.   /* The expected output is:
  2736.  
  2737.      _atold = -1.2345678000e+13
  2738.      _atold = nan                */
  2739.  
  2740. }
  2741.  
  2742.  
  2743. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2744.  
  2745. o atof  - Convert Character Strings 
  2746. o atoi  - Convert Character Strings 
  2747. o atol  - Convert Character Strings 
  2748. o strtod  - Convert Character String to Numeric 
  2749. o strtol  - Convert Character String to Numeric 
  2750. o strtold - Convert String to Long Double 
  2751. o stdlib.h 
  2752. o math.h 
  2753.  
  2754.  
  2755. ΓòÉΓòÉΓòÉ 6.15. _beginthread - Create New Thread ΓòÉΓòÉΓòÉ
  2756.  
  2757.  
  2758. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2759.  
  2760. #include <stdlib.h>     /* also defined in <process.h> */
  2761.  
  2762. int _beginthread(void (*start_address) (void *),
  2763.                      (void *)stack,
  2764.                      unsigned stack_size,
  2765.                      void *arglist);
  2766.  
  2767.  
  2768. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2769.  
  2770. Language Level: Extension 
  2771.  
  2772. The _beginthread function creates a new thread. It takes the following 
  2773. arguments: 
  2774.  
  2775. start_address 
  2776.   This parameter is the address of the function that the newly created thread 
  2777.   will execute. When the thread returns from that function, it is terminated 
  2778.   automatically. You can also explicitly terminate the thread by calling 
  2779.   _endthread. 
  2780. stack 
  2781.   This parameter is ignored, but is retained to ease migration of C/2 programs. 
  2782.   The C/2 compiler requires the second parameter to be the address of the 
  2783.   bottom of the stack that the new thread will use. Because the OS/2 operating 
  2784.   system automatically takes care of stack allocation, the parameter is not 
  2785.   needed. 
  2786. stack_size 
  2787.   The size of the stack, in bytes, which is to be allocated for the new thread. 
  2788.   The stack size should be a nonzero multiple of 4K and a minimum of 8K. Memory 
  2789.   is used when needed, one page at a time. 
  2790. arglist 
  2791.   A parameter to be passed to the newly created thread. It is the size of a 
  2792.   pointer, and is usually the address of a data item to be passed to the new 
  2793.   thread, such as a char string. It provides _beginthread with a value to pass 
  2794.   to the child thread. NULL can be used as a placeholder. 
  2795.  
  2796. The function that the new thread will perform must be declared and compiled 
  2797. using _Optlink linkage. 
  2798.  
  2799. An alternative to this function is the OS/2 DosCreateThread API. If you use 
  2800. DosCreateThread, you must also use a #pragma handler statement for the thread 
  2801. function to ensure proper C exception handling. You should also call the 
  2802. _fpreset function at the start of the thread to preset the 387 control status 
  2803. word properly. The use of DosCreateThread requires the use of _endthread to 
  2804. terminate the thread. 
  2805.  
  2806. Note:  When using the _beginthread and _endthread functions, you must specify 
  2807. the /Gm+ compiler option to use the multithread libraries. 
  2808.  
  2809. If successful, _beginthread returns the thread ID number of the new thread. It 
  2810. returns -1 to indicate an error. 
  2811.  
  2812. Example of _beginthread 
  2813.  
  2814.  
  2815. ΓòÉΓòÉΓòÉ <hidden> Example of _beginthread ΓòÉΓòÉΓòÉ
  2816.  
  2817. /************************************************************************
  2818. *
  2819. This example uses _beginthread to start a new thread bonjour, which prints 
  2820. Bonjour! five times and then implicitly ends itself. The program then prints a 
  2821. statement indicating the thread identifier number for bonjour. 
  2822.  
  2823. Note:  To run this example, you must compile it using the /Gm+ compiler option. 
  2824.  
  2825.                                                                         *
  2826. ************************************************************************/
  2827.  
  2828. #define INCL_DOS
  2829. #include <os2.h>
  2830. #include <stdio.h>
  2831. #include <stdlib.h>
  2832.  
  2833. static int wait = 1;
  2834.  
  2835. void bonjour(void *arg)
  2836. {
  2837.    int i = 0;
  2838.  
  2839.    while (wait)
  2840.            /* wait until the thread id has been printed */
  2841.       DosSleep(0l);
  2842.  
  2843.    while ( i++ < 5 )
  2844.       printf("Bonjour!\n");
  2845. }
  2846.  
  2847. int main(void)
  2848. {
  2849.    unsigned long tid;
  2850.  
  2851.    tid = _beginthread(bonjour, NULL, 8192, NULL);
  2852.  
  2853.    if ( tid == -1 )
  2854.    {
  2855.       printf("Unable to start thread.\n");
  2856.       exit(-1);
  2857.    }
  2858.    else
  2859.    {
  2860.       printf("Thread started
  2861.               with thread identifier number %d.\n", tid);
  2862.       wait = 0;
  2863.    }
  2864.  
  2865.    DosWaitThread( &tid, DCWW_WAIT );
  2866.                /* wait for thread bonjour to end */
  2867.                /*  before ending main thread      */
  2868.  
  2869.    return 0;
  2870.  
  2871. /* The expected output
  2872.        (with possible thread id number) is:
  2873.  
  2874.       Thread started with thread identifier number 2.
  2875.       Bonjour!
  2876.       Bonjour!
  2877.       Bonjour!
  2878.       Bonjour!
  2879.       Bonjour!                                                  */
  2880.  
  2881. }
  2882.  
  2883.  
  2884. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2885.  
  2886. o _endthread - Terminate Current Thread 
  2887. o _threadstore - Access Thread-Specific Storage 
  2888. o /Gm+ option 
  2889. o stdlib.h 
  2890. o process.h 
  2891.  
  2892.  
  2893. ΓòÉΓòÉΓòÉ 6.16. Bessel Functions ΓòÉΓòÉΓòÉ
  2894.  
  2895.  
  2896. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2897.  
  2898. #include <math.h> /* SAA extensions to ANSI */
  2899.  
  2900. double _j0(double x);
  2901.  
  2902. double _j1(double x);
  2903.  
  2904. double _jn(int n, double x);
  2905.  
  2906. double _y0(double x);
  2907.  
  2908. double _y1(double x);
  2909.  
  2910. double _yn(int n, double x);
  2911.  
  2912.  
  2913. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2914.  
  2915. Language Level: SAA 
  2916.  
  2917. Bessel functions solve certain types of differential equations.  The _j0, _j1, 
  2918. and _jn functions are Bessel functions of the first kind for orders 0, 1, and 
  2919. n, respectively. 
  2920.  
  2921. The _y0, _y1, and _yn functions are Bessel functions of the second kind for 
  2922. orders 0, 1, and n, respectively.  The argument x must be positive.  The 
  2923. argument n should be greater than or equal to zero. If n is less than zero, it 
  2924. will be a negative exponent. 
  2925.  
  2926. For _j0, _j1, _y0, or _y1, if the absolute value of x is too large, the 
  2927. function sets errno to ERANGE, and returns 0.  For _y0, _y1, or _yn, if x is 
  2928. negative, the function sets errno to EDOM and returns the value -HUGE_VAL.  For 
  2929. _y0, _y1, or _yn, if x causes overflow, the function sets errno to ERANGE and 
  2930. returns the value -HUGE_VAL. 
  2931.  
  2932. Example of Bessel Functions 
  2933.  
  2934.  
  2935. ΓòÉΓòÉΓòÉ <hidden> Example of Bessel Functions ΓòÉΓòÉΓòÉ
  2936.  
  2937. /************************************************************************
  2938. *
  2939.  
  2940. This example computes y to be the order 0 Bessel function of the first kind for 
  2941. x and z to be the order 3 Bessel function of the second kind for x. 
  2942.  
  2943.                                                                         *
  2944. ************************************************************************/
  2945.  
  2946. #include <math.h>
  2947.  
  2948. int main(void)
  2949. {
  2950.     double x, y, z;
  2951.     x = 4.27;
  2952.  
  2953.     y = _j0(x);      /* y = -0.3660 is the order 0 bessel */
  2954.                      /* function of the first kind for x  */
  2955.     z = _yn(3,x);    /* z = -0.0875 is the order 3 bessel */
  2956.                      /* function of the second kind for x */
  2957. }
  2958.  
  2959.  
  2960. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  2961.  
  2962. o erf  - Calculate Error Functions 
  2963. o gamma  - Gamma Function 
  2964. o math.h 
  2965.  
  2966.  
  2967. ΓòÉΓòÉΓòÉ 6.17. bsearch  - Search Arrays ΓòÉΓòÉΓòÉ
  2968.  
  2969.  
  2970. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  2971.  
  2972. #include <stdlib.h>  /* also defined in <search.h> */
  2973.  
  2974. void *bsearch(const void *key, const void *base, size_t num,
  2975.               size_t size, int (*compare) (const void *element1,
  2976.               const void *element2));
  2977.  
  2978.  
  2979. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  2980.  
  2981. Language Level: ANSI, SAA, Extension 
  2982.  
  2983. The bsearch function performs a binary search of an array of num elements, each 
  2984. of size bytes The array must be sorted in ascending order by the function 
  2985. pointed to by compare.  The base is a pointer to the base of the array to 
  2986. search, and key is the value being sought. 
  2987.  
  2988. The compare variable is a pointer to a function you must supply that compares 
  2989. two array elements and returns a value specifying their relationship.  The 
  2990. bsearch function calls this function one or more times during the search, 
  2991. passing the key and the pointer to one array element on each call.  The 
  2992. function must compare the elements and then return one of the following values: 
  2993.  
  2994. Value             Meaning 
  2995. Less than 0       element1 less than element2 
  2996. 0                 element1 identical to element2 
  2997. Greater than 0    element1 greater than element2 
  2998.  
  2999. The bsearch function returns a pointer to key in the array to which base 
  3000. points.  If two keys are equal, which element key will point to is unspecified. 
  3001. If bsearch cannot find the key, it returns NULL. 
  3002.  
  3003. Example of bsearch 
  3004.  
  3005.  
  3006. ΓòÉΓòÉΓòÉ <hidden> Example of bsearch ΓòÉΓòÉΓòÉ
  3007.  
  3008. /************************************************************************
  3009. *
  3010.  
  3011. This example performs a binary search on the argv array of pointers to the 
  3012. program parameters and finds the position of the argument PATH. It first 
  3013. removes the program name from argv, and then sorts the array alphabetically 
  3014. before calling bsearch. The functions compare1 and compare2 compare the values 
  3015. pointed to by arg1 and arg2 and return the result to bsearch. 
  3016.  
  3017.                                                                         *
  3018. ************************************************************************/
  3019.  
  3020. #include <stdlib.h>
  3021. #include <stdio.h>
  3022. #include <string.h>
  3023.  
  3024. int compare1(const void *arg1, const void *arg2);
  3025. int compare2(const void *arg1, const void *arg2);
  3026.  
  3027. int main(int argc, char *argv[])
  3028. {
  3029.    char **result;
  3030.    char *key = "PATH";
  3031.    int i;
  3032.    argv++;
  3033.    argc--;
  3034.  
  3035.    qsort((char *)argv, argc, sizeof(char *), compare1);
  3036.  
  3037.    result = (char**)bsearch(key, argv, argc, sizeof(char *), compare2);
  3038.    if (result != NULL)
  3039.    {
  3040.       printf("result = <%s>\n",*result);
  3041.    }
  3042.    else printf("result is null\n");
  3043. }
  3044.  
  3045. int compare1(const void *arg1, const void *arg2)
  3046. {
  3047.    return (strcmp(*(char **)arg1, *(char **)arg2));
  3048. }
  3049.  
  3050. int compare2(const void *arg1, const void *arg2)
  3051. {
  3052.    return (strcmp((char *)arg1, *(char **)arg2));
  3053. }
  3054.  
  3055. /********************  Output should be similar to:  **************
  3056.  
  3057. progname where is PATH in this phrase?
  3058. result = <PATH>
  3059. */
  3060.  
  3061.  
  3062. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3063.  
  3064. o _lfind - _lsearch - Find Key in Array 
  3065. o qsort  - Sort Array 
  3066. o stdlib.h 
  3067.  
  3068.  
  3069. ΓòÉΓòÉΓòÉ 6.18. _cabs - Calculate Absolute Value of Complex Number ΓòÉΓòÉΓòÉ
  3070.  
  3071.  
  3072. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3073.  
  3074. #include <math.h>
  3075.  
  3076. double _cabs(struct complex z);
  3077.  
  3078.  
  3079. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3080.  
  3081. Language Level: Extension 
  3082.  
  3083. The _cabs function calculates the absolute value of a complex number.  This 
  3084. complex number is represented as a structure with the tag complex containing 
  3085. the real and imaginary parts.  The following type declaration is in <math.h>: 
  3086.  
  3087.    struct complex {double x,y;};
  3088.  
  3089. A call to _cabs is equivalent to: 
  3090.  
  3091.    sqrt(z.x * z.x + z.y * z.y)
  3092.  
  3093. Note:  For portability, use the SAA function hypot to replace _cabs. 
  3094.  
  3095. The _cabs function returns the absolute value as a double value.  If an 
  3096. overflow results, _cabs calls the _matherr routine and, if necessary, sets 
  3097. errno to ERANGE and returns the value HUGE_VAL. 
  3098.  
  3099. Example of _cabs 
  3100.  
  3101.  
  3102. ΓòÉΓòÉΓòÉ <hidden> Example of _cabs ΓòÉΓòÉΓòÉ
  3103.  
  3104. /************************************************************************
  3105. *                                                                          *
  3106. The following program computes the absolute value of the complex number (3.0, 
  3107. 4.0). 
  3108.  
  3109.                                                                         *
  3110. ************************************************************************/
  3111.  
  3112. #include <math.h>
  3113. #include <stdio.h>
  3114.  
  3115. int main(void)
  3116. {
  3117.     struct complex value;
  3118.     double d;
  3119.  
  3120.     value.x = 3.0;
  3121.     value.y = 4.0;
  3122.     d = _cabs(value);
  3123.     printf("The complex absolute value of %f and %f is
  3124.              %f\n", value.x, value.y, d);
  3125.  
  3126.     return 0;
  3127.  
  3128. /************  Output should be:  *******************************
  3129. /*                                                              */
  3130.    The complex absolute value of 3.000000 and 4.000000 is 5.000000 */
  3131. }
  3132.  
  3133.  
  3134. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3135.  
  3136. o abs  - Calculate Integer Absolute Value 
  3137. o fabs  - Calculate Floating-Point Absolute Value 
  3138. o hypot  - Calculate Hypotenuse 
  3139. o labs  - Calculate long Absolute Value 
  3140. o _matherr - Process Math Library Errors 
  3141. o sqrt  - Calculate Square Root 
  3142. o math.h 
  3143.  
  3144.  
  3145. ΓòÉΓòÉΓòÉ 6.19. calloc  - Reserve and Initialize Storage ΓòÉΓòÉΓòÉ
  3146.  
  3147.  
  3148. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3149.  
  3150. #include <stdlib.h>  /* also defined in <malloc.h> */
  3151.  
  3152. void *calloc(size_t num, size_t size);
  3153.  
  3154.  
  3155. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3156.  
  3157. Language Level: ANSI, SAA 
  3158.  
  3159. The calloc function reserves storage space for an array of num elements, each 
  3160. of length size bytes.  The calloc function then gives all the bits of each 
  3161. element an initial value of 0. 
  3162.  
  3163. The calloc function returns a pointer to the reserved space.  The storage space 
  3164. to which the return value points is guaranteed to be suitably aligned for 
  3165. storage of any type of object.  To get a pointer to a type, use a type cast on 
  3166. the return value.  The return value is NULL if there is not enough storage, or 
  3167. if num or size is 0. 
  3168.  
  3169. Example of calloc 
  3170.  
  3171.  
  3172. ΓòÉΓòÉΓòÉ <hidden> Example of calloc ΓòÉΓòÉΓòÉ
  3173.  
  3174. /************************************************************************
  3175. *
  3176.  
  3177. This example prompts for the number of array entries required and then reserves 
  3178. enough space in storage for the entries. If calloc is successful, the example 
  3179. prints out each entry;  otherwise, it prints out an error. 
  3180.  
  3181.                                                                         *
  3182. ************************************************************************/
  3183.  
  3184. #include <stdio.h>
  3185. #include <stdlib.h>
  3186.  
  3187. int main(void)
  3188. {
  3189.   long * array;                               /* start of the array */
  3190.   long * index;                               /* index variable     */
  3191.   int    i;                                   /* index variable     */
  3192.   int  num;                       /* number of entries of the array */
  3193.  
  3194.   printf( "Enter the size of the array\n" );
  3195.   scanf( "%i", &num );
  3196.  
  3197.                                             /* allocate num entries */
  3198.   if ( (index = array = calloc( num, sizeof( long ))) != NULL )
  3199.   {
  3200.  
  3201.     for ( i = 0; i < num; ++i )           /* put values in array    */
  3202.        *index++ = i;                      /* using pointer notation */
  3203.  
  3204.     for ( i = 0; i < num; ++i )           /* print the array out    */
  3205.       printf( "array[ %i ] = %i\n", i, array[i] );
  3206.   }
  3207.   else
  3208.   { /* out of storage */
  3209.     perror( "Out of storage" );
  3210.     abort();
  3211.   }
  3212. }
  3213.  
  3214. /******************  Output should be similar to:  **********************
  3215.  
  3216. Enter the size of the array
  3217. array[ 0 ] = 0
  3218. array[ 1 ] = 1
  3219. array[ 2 ] = 2
  3220. */
  3221.  
  3222.  
  3223. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3224.  
  3225. o _alloca - Temporarily Reserve Storage Block 
  3226. o _debug_calloc - Reserve and Initialize Storage 
  3227. o malloc  - Reserve Storage Block 
  3228. o _tcalloc - Reserve Tiled Storage Block 
  3229. o free  - Release Storage Blocks 
  3230. o malloc  - Reserve Storage Block 
  3231. o realloc  - Change Reserved Storage Block Size 
  3232. o malloc.h 
  3233. o stdlib.h 
  3234.  
  3235.  
  3236. ΓòÉΓòÉΓòÉ 6.20. ceil - Integer >= Argument ΓòÉΓòÉΓòÉ
  3237.  
  3238.  
  3239. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3240.  
  3241. #include <math.h>
  3242.  
  3243. double ceil(double x);
  3244.  
  3245.  
  3246. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3247.  
  3248. Language Level: ANSI, SAA 
  3249.  
  3250. The ceil function computes the smallest integer that is greater than or equal 
  3251. to x. 
  3252.  
  3253. The ceil function returns a double value. 
  3254.  
  3255. Example of ceil 
  3256.  
  3257.  
  3258. ΓòÉΓòÉΓòÉ <hidden> Example of ceil ΓòÉΓòÉΓòÉ
  3259.  
  3260. /************************************************************************
  3261. *
  3262.  
  3263. This example sets y to the smallest integer greater than 1.05, and then to the 
  3264. smallest integer greater than -1.05.  The results are 2. and -1., respectively. 
  3265.  
  3266.                                                                         *
  3267. ************************************************************************/
  3268.  
  3269. #include <math.h>
  3270.  
  3271. int main(void)
  3272. {
  3273.    double y, z;
  3274.  
  3275.    y = ceil(1.05);       /* y = 2.0 */
  3276.    z = ceil(-1.05);      /* z = -1.0 */
  3277. }
  3278.  
  3279.  
  3280. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3281.  
  3282. o floor - Integer <= Argument 
  3283. o fmod  - Floating-Point Remainder 
  3284. o math.h 
  3285.  
  3286.  
  3287. ΓòÉΓòÉΓòÉ 6.21. _cgets - Read String of Characters from Keyboard ΓòÉΓòÉΓòÉ
  3288.  
  3289.  
  3290. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3291.  
  3292. #include <conio.h>
  3293.  
  3294. char *_cgets(char *str);
  3295.  
  3296.  
  3297. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3298.  
  3299. Language Level: Extension 
  3300.  
  3301. The _cgets function reads a string of characters directly from the keyboard and 
  3302. stores the string and its length in the location pointed to by str. 
  3303.  
  3304. The _cgets function continues to read characters until it meets a 
  3305. carriage-return followed by a line-feed (CR-LF) or until it reads the specified 
  3306. number of characters. It stores the string starting at str[2]. If _cgets reads 
  3307. a CR-LF combination, it replaces this combination with a null character ('\0') 
  3308. before storing the string. The _cgets function then stores the actual length of 
  3309. the string in the second array element, str[1]. 
  3310.  
  3311. The str variable must be a pointer to a character array. The first element of 
  3312. the array, str[0], must contain the maximum length, in characters, of the 
  3313. string to be read.  The array must have enough elements to hold the string, a 
  3314. final null character, and 2 additional bytes. 
  3315.  
  3316. If successful, the _cgets function returns a pointer to the actual start of the 
  3317. string, str[2]. Otherwise, _cgets returns NULL. 
  3318.  
  3319. Example of _cgets 
  3320.  
  3321.  
  3322. ΓòÉΓòÉΓòÉ <hidden> Example of _cgets ΓòÉΓòÉΓòÉ
  3323.  
  3324. /************************************************************************
  3325. *                                                                          *
  3326.  
  3327. This example creates a buffer and initializes the first byte to the size of the 
  3328. buffer. The program then accepts an input string using cgetsand displays the 
  3329. size and text of that string. 
  3330.  
  3331.                                                                         *
  3332. ************************************************************************/
  3333.  
  3334.  
  3335. #include <conio.h>
  3336. #include <stdio.h>
  3337.  
  3338. void nothing(void)
  3339. {
  3340. }
  3341.  
  3342. int main(void)
  3343. {
  3344.     char buffer[82] = { 80, 0 };
  3345.     char * buffer2;
  3346.     int i;
  3347.  
  3348.     _cputs("\nPress any key to continue.");
  3349.     printf("\n");
  3350.  
  3351.     while (_kbhit() == 0)
  3352.     {
  3353.     nothing();
  3354.     }
  3355.  
  3356.     _getch();
  3357.     _cputs("\nEnter a line of text:");
  3358.     printf("\n");
  3359.  
  3360.     buffer2= _cgets(buffer);
  3361.     printf("\nText entered was: %s",buffer2);
  3362.  
  3363.     return 0;
  3364. }
  3365.  
  3366.  
  3367. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3368.  
  3369. o conio.h 
  3370. o _cputs - Write String to Screen 
  3371. o fgets  - Read a String 
  3372. o gets  - Read a Line 
  3373. o _getch - _getche - Read Character from Keyboard 
  3374.  
  3375.  
  3376. ΓòÉΓòÉΓòÉ 6.22. _chdir - Change Current Working Directory ΓòÉΓòÉΓòÉ
  3377.  
  3378.  
  3379. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3380.  
  3381. #include <direct.h>
  3382.  
  3383. int _chdir(char *pathname);
  3384.  
  3385.  
  3386. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3387.  
  3388. Language Level: Extension 
  3389.  
  3390. The _chdir function causes the current working directory to change to the 
  3391. directory specified by pathname.  The pathname must refer to an existing 
  3392. directory. 
  3393.  
  3394. Note:  This function can change the current working directory on any drive.  It 
  3395. cannot change the default drive.  For example, if A:\BIN is the current working 
  3396. directory and A: is the default drive, the following changes only the current 
  3397. working directory on drive C:. 
  3398.  
  3399.    _chdir ("c:\\emp");
  3400.  
  3401. A: is still the default drive. 
  3402.  
  3403. An alternative to this function is the DosSetCurrentDir API call. 
  3404.  
  3405. The _chdir function returns a value of 0 if the working directory was 
  3406. successfully changed. A return value of -1 indicates an error;  in this case, 
  3407. _chdir sets errno to ENOENT, showing that _chdir cannot find the specified path 
  3408. name.  No error occurs if pathname specifies the current working directory. 
  3409.  
  3410. Example of _chdir 
  3411.  
  3412.  
  3413. ΓòÉΓòÉΓòÉ <hidden> Example of _chdir ΓòÉΓòÉΓòÉ
  3414.  
  3415. /************************************************************************
  3416. *                                                                          *
  3417. This example changes the current working directory to the root directory, and 
  3418. then to the \red\green\blue directory: 
  3419.  
  3420.                                                                         *
  3421. ************************************************************************/
  3422.  
  3423. #include <direct.h>
  3424. #include <stdio.h>
  3425.  
  3426. int main(void)
  3427. {
  3428.  
  3429.     printf("Changing to the root directory.\n");
  3430.  
  3431.     if (_chdir("\\"))
  3432.        perror(NULL);
  3433.     else
  3434.        printf("Changed to the root directory.\n\n");
  3435.  
  3436.     printf("Changing to directory '\\red\\green\\blue'.\n");
  3437.  
  3438.     if (_chdir("\\red\\green\\blue"))
  3439.        perror(NULL);
  3440.     else
  3441.        printf("Changed to directory '\\red\\green\\blue'.\n");
  3442.  
  3443.     return 0;
  3444.  
  3445. /***********  The output should be similar to:  **********
  3446.  
  3447.   Changing to the root directory.
  3448.   Changed to the root directory.
  3449.  
  3450.   Changing to directory '\red\green\blue'.
  3451.   Changed to directory '\red\green\blue'.
  3452. */
  3453. }
  3454.  
  3455.  
  3456. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3457.  
  3458. o _chdrive - Change Current Working Drive 
  3459. o _getcwd - Get Path Name of Current Directory 
  3460. o _getdcwd - Get Full Path Name of Current Directory 
  3461. o _getdrive - Get Current Working Drive 
  3462. o system - Invoke the Command Processor 
  3463. o _mkdir - Create New Directory 
  3464. o _rmdir - Remove Directory 
  3465. o system - Invoke the Command Processor 
  3466. o direct.h 
  3467.  
  3468.  
  3469. ΓòÉΓòÉΓòÉ 6.23. _chdrive - Change Current Working Drive ΓòÉΓòÉΓòÉ
  3470.  
  3471.  
  3472. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3473.  
  3474. #include <direct.h>
  3475.  
  3476. int _chdrive(int drive);
  3477.  
  3478.  
  3479. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3480.  
  3481. Language Level: Extension 
  3482.  
  3483. The _chdrive function changes the current working drive to the drive specified. 
  3484. The drive variable is an integer value representing the number of the new 
  3485. working drive (A: is 1, B: is 2, and so on). 
  3486.  
  3487. To change the default drive, include <os2.h>, define INCL_DOSFILEMGR, and use 
  3488. DosSetDefaultDisk to pass the appropriate command to the operating system. You 
  3489. can also use DosQueryCurrentDisk to query the disk. For more information, refer 
  3490. to the OS/2 2.0 Toolkit documentation. 
  3491.  
  3492. If _chdrive is successful in changing the working drive, it returns 0.  A 
  3493. return value of -1 indicates an error; in this case, _chdrive sets errno to 
  3494. EOS2ERR. 
  3495.  
  3496. Example of _chdrive 
  3497.  
  3498.  
  3499. ΓòÉΓòÉΓòÉ <hidden> Example of _chdrive ΓòÉΓòÉΓòÉ
  3500.  
  3501. /************************************************************************
  3502. *
  3503. This example uses _chdrive to change the current working drive to C:. 
  3504.  
  3505.                                                                         *
  3506. ************************************************************************/
  3507.  
  3508. #include <direct.h>
  3509. #include <stdio.h>
  3510.  
  3511. int main(void)
  3512. {
  3513.     if (_chdrive(3))
  3514.          printf("Cannot change current working drive
  3515.                   to 'C' drive.\n");
  3516.     else
  3517.     {
  3518.          printf("Current working drive changed to ");
  3519.          printf("'%c' drive.\n", ('A'+_getdrive() - 1) );
  3520.     }
  3521.  
  3522.     return 0;
  3523.  
  3524.  
  3525. /**************  The output should be similar to:  **********************
  3526.  
  3527.    Current working drive changed to 'C' drive.
  3528. */
  3529. }
  3530.  
  3531.  
  3532. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3533.  
  3534. o _chdir - Change Current Working Directory 
  3535. o _getcwd - Get Path Name of Current Directory 
  3536. o _getdcwd - Get Full Path Name of Current Directory 
  3537. o _getdrive - Get Current Working Drive 
  3538. o _mkdir - Create New Directory 
  3539. o _rmdir - Remove Directory 
  3540. o direct.h 
  3541.  
  3542.  
  3543. ΓòÉΓòÉΓòÉ 6.24. _chmod - Change File Permission Setting ΓòÉΓòÉΓòÉ
  3544.  
  3545.  
  3546. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3547.  
  3548. #include <io.h>
  3549. #include <sys\stat.h>
  3550.  
  3551. int _chmod(char *pathname, int pmode);
  3552.  
  3553.  
  3554. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3555.  
  3556. Language Level: Extension 
  3557.  
  3558. The _chmod function changes the permission setting of the file specified by 
  3559. pathname. The permission setting controls access to the file for reading or 
  3560. writing. The pmode expression contains one or both of the constants S_IWRITE 
  3561. and S_IREAD, defined in <sys\stat.h>. You can use the _chmod function only if 
  3562. the file is closed. The meanings of the values of the pmode argument are: 
  3563.  
  3564. Value                   Meaning 
  3565. S_IREAD                 Reading permitted 
  3566. S_IWRITE                Writing permitted 
  3567. S_IREAD | S_IWRITE      Reading and writing permitted. 
  3568.  
  3569. If you do not give permission to write to the file, the _chmod function makes 
  3570. the file read-only. With the OS/2 operating system, all files are readable; you 
  3571. cannot give write-only permission. Thus, the modes S_IWRITE and S_IREAD | 
  3572. S_IWRITE set the same permission. 
  3573.  
  3574. Specifying a pmode of S_IREAD is similar to making a file read-only with the 
  3575. ATTRIB system command. 
  3576.  
  3577. The _chmod function returns the value 0 if it successfully changes the 
  3578. permission setting.  A return value of -1 shows an error; in this case, the 
  3579. _chmod function set errno to one of the following values: 
  3580.  
  3581. Value          Meaning 
  3582. ENOENT         The system cannot find the file or the path that you specified, 
  3583.                or the file name was incorrect. 
  3584. EOS2ERR        The call to the operating system was not successful. 
  3585. EINVAL         The mode specified was not valid. 
  3586.  
  3587. Example of _chmod 
  3588.  
  3589.  
  3590. ΓòÉΓòÉΓòÉ <hidden> Example of _chmod ΓòÉΓòÉΓòÉ
  3591.  
  3592. /************************************************************************
  3593. *
  3594.  
  3595. This example opens the file chmod.dat for writing after checking the file to 
  3596. see if writing is permissible. It then writes from the buffer to the opened 
  3597. file. This program takes file names passed as arguments and sets each to 
  3598. read-only. 
  3599.  
  3600.                                                                         *
  3601. ************************************************************************/
  3602.  
  3603. #include <sys\stat.h>
  3604. #include <io.h>
  3605. #include <stdio.h>
  3606. #include <stdlib.h>
  3607.  
  3608. int main(void)
  3609. {
  3610.    if (-1 == _access("chmod.dat",00))
  3611.                         /* Check if file exists. */
  3612.    {
  3613.       printf("\nCreating chmod.dat.\n");
  3614.       system("echo Sample Program > chmod.dat");
  3615.       printf("_chmod chmod.dat to be readonly.\n");
  3616.  
  3617.       if (-1 == _chmod("chmod.dat",S_IREAD))
  3618.          perror("_chmod failed");
  3619.  
  3620.       if (-1 == _access("chmod.dat",02))
  3621.          printf("File chmod.dat is now readonly.\n\n");
  3622.  
  3623.       printf("Run this program again to erase chmod.dat.\n\n");
  3624.    }
  3625.    else
  3626.    {
  3627.       printf("\nFile chmod.dat exist.\n");
  3628.       printf("_chmod chmod.dat to become writable.\n");
  3629.  
  3630.       if (-1 == _chmod("chmod.dat",S_IWRITE))
  3631.          perror("_chmod failed");
  3632.  
  3633.       system("erase  chmod.dat");
  3634.  
  3635.       printf("File chmod.dat removed.\n\n");
  3636.    }
  3637.    return 0;
  3638.  
  3639. /************  If chmod.dat does not exist,  ************************
  3640. *******  the output should be similar to:  ****************
  3641.  
  3642.       Creating chmod.dat.
  3643.       _chmod chmod.dat to be readonly.
  3644.       File chmod.dat is now readonly.
  3645.       Run this program again to erase chmod.dat.
  3646.  
  3647. **********************************************************/
  3648. }
  3649.  
  3650.  
  3651. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3652.  
  3653. o _access - Determine Access Mode 
  3654. o _sopen - Open Shared File 
  3655. o _umask - Sets File Mask of Current Process 
  3656. o sys\stat.h 
  3657. o io.h 
  3658.  
  3659.  
  3660. ΓòÉΓòÉΓòÉ 6.25. _chsize - Alter Length of File ΓòÉΓòÉΓòÉ
  3661.  
  3662.  
  3663. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3664.  
  3665. #include <io.h>
  3666.  
  3667. int _chsize(int handle, long size);
  3668.  
  3669.  
  3670. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3671.  
  3672. Language Level: Extension 
  3673.  
  3674. The _chsize function lengthens or cuts off the file associated with handle to 
  3675. the length specified by size. You must open the file in a mode that permits 
  3676. writing. The _chsize function adds null characters (\0) when it lengthens the 
  3677. file. When _chsize cuts off the file, it erases all data from the end of the 
  3678. shortened file to the end of the original file. 
  3679.  
  3680. The _chsize function returns the value 0 if it successfully changes the file 
  3681. size.  A return value of -1 shows an error, and _chsize sets errno to one of 
  3682. the following values: 
  3683.  
  3684. Value          Meaning 
  3685. EACCESS        The specified file is locked against access. 
  3686. EBADF          The file handle is not valid, or the file is not open for 
  3687.                writing. 
  3688. ENOSPC         There is no space left on the device. 
  3689. EOS2ERR        The call to the operating system was not successful. 
  3690.  
  3691. Example of _chsize 
  3692.  
  3693.  
  3694. ΓòÉΓòÉΓòÉ <hidden> Example of _chsize ΓòÉΓòÉΓòÉ
  3695.  
  3696. /************************************************************************
  3697. *
  3698.  
  3699. This example opens a file named sample.dat and returns the current length of 
  3700. that file. It then alters the size of sample.dat and returns the new length of 
  3701. that file. 
  3702.  
  3703.                                                                         *
  3704. ************************************************************************/
  3705.  
  3706. #include <io.h>
  3707. #include <stdio.h>
  3708. #include <stdlib.h>
  3709. #include <fcntl.h>
  3710.  
  3711. int main(void)
  3712. {
  3713.    long length;
  3714.    int  fh;
  3715.  
  3716.    printf("\nCreating sample.dat.\n");
  3717.    system("echo Sample Program > sample.dat");
  3718.  
  3719.    if (-1 == (fh = _open("sample.dat",O_RDWR | O_APPEND)))
  3720.    {
  3721.       printf("Unable to open sample.dat.\n");
  3722.       return 1;
  3723.    }
  3724.  
  3725.    if (-1 == (length = _filelength(fh)))
  3726.    {
  3727.       printf("Unable to determine length of sample.dat.\n");
  3728.       return 1;
  3729.    }
  3730.  
  3731.    printf("Current length of sample.dat is %d.\n",length);
  3732.    printf("Changing the length of sample.dat to 20.\n");
  3733.  
  3734.    if (-1 == (_chsize(fh,20)))
  3735.    {
  3736.       perror("_chsize failed");
  3737.       return 1;
  3738.    }
  3739.  
  3740.    if (-1 == (length = _filelength(fh)))
  3741.    {
  3742.       printf("Unable to determine length of sample.dat.\n");
  3743.       return 1;
  3744.    }
  3745.    printf("New length of sample.dat is %d.\n",length);
  3746.  
  3747.    _close(fh);
  3748.    return 0;
  3749.  
  3750. /*****  The output should be similar to:  ************
  3751.  
  3752.       Creating sample.dat.
  3753.       Current length of sample.dat is 17.
  3754.       Changing the length of sample.dat to 20.
  3755.       New length of sample.dat is 20.
  3756. */
  3757. }
  3758.  
  3759.  
  3760. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3761.  
  3762. o _filelength - Determine File Length 
  3763. o _lseek - Move File Pointer 
  3764. o io.h 
  3765.  
  3766.  
  3767. ΓòÉΓòÉΓòÉ 6.26. clearerr  - Reset Error Indicators ΓòÉΓòÉΓòÉ
  3768.  
  3769.  
  3770. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3771.  
  3772. #include <stdio.h>
  3773.  
  3774. void clearerr (FILE *stream);
  3775.  
  3776.  
  3777. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3778.  
  3779. Language Level: ANSI, SAA 
  3780.  
  3781. The clearerr function resets the error indicator and end-of-file indicator for 
  3782. the specified stream. Once set, the indicators for a specified stream remain 
  3783. set until your program calls clearerr or rewind. The fseek function also clears 
  3784. the end-of-file indicator. 
  3785.  
  3786. Example of clearerr 
  3787.  
  3788.  
  3789. ΓòÉΓòÉΓòÉ <hidden> Example of clearerr ΓòÉΓòÉΓòÉ
  3790.  
  3791. /************************************************************************
  3792. *
  3793.  
  3794. This example reads a data stream and then checks that a read error has not 
  3795. occurred. 
  3796.  
  3797.                                                                         *
  3798. ************************************************************************/
  3799.  
  3800. #include <stdio.h>
  3801. #include <stdlib.h>
  3802.  
  3803. FILE *stream;
  3804. int c;
  3805.  
  3806. int main(void)
  3807. {
  3808.    if ((stream = fopen("myfile.dat", "r")) != NULL)
  3809.    {
  3810.       if ((c=getc(stream)) == EOF)
  3811.       {
  3812.          if (ferror(stream))
  3813.          {
  3814.             perror("Read error");
  3815.             clearerr(stream);
  3816.          }
  3817.       }
  3818.    }
  3819.    else
  3820.       exit(0);
  3821. }
  3822.  
  3823.  
  3824. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3825.  
  3826. o feof  - Test End-of-File Indicator 
  3827. o ferror  - Test for Read/Write Errors 
  3828. o perror  - Print Error Message 
  3829. o rewind  - Adjust Current File Position 
  3830. o strerror  - Set Pointer to Runtime Error Message 
  3831. o _strerror - Set Pointer to System Error String 
  3832. o stdio.h 
  3833.  
  3834.  
  3835. ΓòÉΓòÉΓòÉ 6.27. _clear87 - Clear Floating-Point Status Word ΓòÉΓòÉΓòÉ
  3836.  
  3837.  
  3838. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3839.  
  3840. #include <float.h>  /* also defined in <builtin.h> */
  3841.  
  3842. unsigned int _clear87(void);
  3843.  
  3844.  
  3845. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3846.  
  3847. Language Level: Extension 
  3848.  
  3849. The _clear87 function gets the floating-point status word and then clears it. 
  3850. The floating-point status word is a combination of the numeric coprocessor 
  3851. status word and other conditions that the numeric exception handler detects, 
  3852. such as floating-point stack overflow and underflow. 
  3853.  
  3854. The _clear87 function only affects the current thread. It does not affect any 
  3855. other threads that may be processing. 
  3856.  
  3857. The bits in the value returned reflect the floating-point status before the 
  3858. call to _clear87 was made. 
  3859.  
  3860. Example of _clear87 
  3861.  
  3862.  
  3863. ΓòÉΓòÉΓòÉ <hidden> Example of _clear87 ΓòÉΓòÉΓòÉ
  3864.  
  3865. /************************************************************************
  3866. *
  3867. This example takes a number close to 0 as a double and assigns it to a float. 
  3868. The result is a loss of significance, y becomes a denormal number, and the 
  3869. underflow bit of the floating-point status word is set. The _clear87 function 
  3870. gets the current floating-point status word and then clears it, and the printf 
  3871. function prints it as immediate data. The result shows the change in the 
  3872. floating-point word because of the loss of significance. 
  3873.  
  3874. The program then assigns the denormal y to another variable, causing the 
  3875. denormal bit to be set in the floating-point status word.  Again, the _clear87 
  3876. gets the current status word and clears it, and printf prints it to the screen. 
  3877.  
  3878.                                                                         *
  3879. ************************************************************************/
  3880.  
  3881. #include <stdio.h>
  3882. #include <float.h>
  3883.  
  3884. double a = 1e-40;
  3885. double b;
  3886. float y;
  3887.  
  3888. int main(void)
  3889. {
  3890.    unsigned int statword;
  3891.    unsigned int old_cw;
  3892.  
  3893.    /*  change control word to mask all exceptions */
  3894.    _control87(0x037f,0xffff);
  3895.  
  3896.    /* Assignment of the double to the float y is inexact; */
  3897.    /*       the underflow bit is set.                     */
  3898.    y = a;
  3899.    statword = _clear87();
  3900.    printf("floating-point status = 0x%.4x after underflow\n",
  3901.            statword);
  3902.  
  3903.    statword = _status87();
  3904.    printf("cleared floating-point status word = 0x%.4x\n",
  3905.            statword);
  3906.  
  3907.    /*  reset floating point status word  */
  3908.    _fpreset();
  3909.  
  3910.    /*  change control word to mask all exception */
  3911.    _control87(0x037f,0xffff);
  3912.  
  3913.    /* Reassigning the denormal y to the double b */
  3914.    /*   causes the denormal bit to be set. */
  3915.    b = y;
  3916.    statword = _clear87();
  3917.    printf("floating-point status = 0x%.4x for denormal\n",
  3918.            statword);
  3919.  
  3920.    /*  reset floating point status word  */
  3921.    _fpreset();
  3922.  
  3923.    return 0;
  3924.  
  3925.  
  3926.    /* The expected output is:
  3927.  
  3928.       floating-point status = 0x0030 after underflow
  3929.       cleared floating-point status word = 0x0000
  3930.       floating-point status = 0x0002 for denormal  */
  3931. }
  3932.  
  3933.  
  3934. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  3935.  
  3936. o _control87 - Set Floating-Point Status Word 
  3937. o _status87 - Get Floating-Point Status Word 
  3938. o _fpreset - Reset Floating-Point Unit 
  3939. o float.h 
  3940.  
  3941.  
  3942. ΓòÉΓòÉΓòÉ 6.28. clock  - Determine Processor Time ΓòÉΓòÉΓòÉ
  3943.  
  3944.  
  3945. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  3946.  
  3947. #include <time.h>
  3948.  
  3949. clock_t clock(void);
  3950.  
  3951.  
  3952. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  3953.  
  3954. Language Level: ANSI, SAA 
  3955.  
  3956. The clock function returns an approximation of the processor time used by the 
  3957. program since the beginning of an implementation-defined time-period that is 
  3958. related to the program invocation. To obtain the time in seconds, divide the 
  3959. value returned by clock by the value of the macro CLOCKS_PER_SEC. 
  3960.  
  3961. If the value of the processor time is not available or cannot be represented, 
  3962. clock returns the value (clock_t)-1. 
  3963.  
  3964. To measure the time spent in a program, call the clock function at the start of 
  3965. the program, and subtract its return value from the value returned by 
  3966. subsequent calls to clock. 
  3967.  
  3968. Example of clock 
  3969.  
  3970.  
  3971. ΓòÉΓòÉΓòÉ <hidden> Example of clock ΓòÉΓòÉΓòÉ
  3972.  
  3973. /************************************************************************
  3974. *
  3975.  
  3976. This example prints the time elapsed since the program was invoked. 
  3977.  
  3978.                                                                         *
  3979. ************************************************************************/
  3980.  
  3981. #include <time.h>
  3982. #include <stdio.h>
  3983.  
  3984. double time1, timedif;/* use doubles to show small values */
  3985.  
  3986. int main(void)
  3987. {
  3988.     time1 = (double) clock();            /* get initial time */
  3989.     time1 = time1 / CLOCKS_PER_SEC;      /*    in seconds    */
  3990.    .
  3991.    .
  3992.    .
  3993.     /* call clock a second time */
  3994.     timedif = ( ((double) clock()) / CLOCKS_PER_SEC) - time1;
  3995.     printf("The elapsed time is %lf seconds\n", timedif);
  3996. }
  3997.  
  3998.  
  3999. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4000.  
  4001. o difftime  - Compute Time Difference 
  4002. o time  - Determine Current Time 
  4003. o time.h 
  4004.  
  4005.  
  4006. ΓòÉΓòÉΓòÉ 6.29. _control87 - Set Floating-Point Status Word ΓòÉΓòÉΓòÉ
  4007.  
  4008.  
  4009. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4010.  
  4011. #include <float.h>  /* also defined in <builtin.h> */
  4012.  
  4013. unsigned int _control87(unsigned int new, unsigned int mask);
  4014.  
  4015.  
  4016. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4017.  
  4018. Language Level: Extension 
  4019.  
  4020. The _control87 function gets the current floating-point control word and then 
  4021. sets it. The floating-point control word specifies the precision, rounding, and 
  4022. infinity modes of the floating-point chip. 
  4023.  
  4024. You can mask or unmask current floating-point exceptions using the _control87 
  4025. function. If the value for the mask is equal to 0, _control87 gets the 
  4026. floating-point control word. If the mask is nonzero, _control87 sets a new 
  4027. value for the control word in the manner described below, and returns the 
  4028. previous value of the control word. For any bit in the mask equal to 1, the 
  4029. corresponding bit in new updates the control word. This is equivalent to the 
  4030. expression: 
  4031.  
  4032.    fpcntrl = ((fpcntrl & ~ mask) Γöé (new & mask))
  4033.  
  4034. where fpcntrl is the floating-point control word. 
  4035.  
  4036. The _control87 function is used for the current thread only. It does not affect 
  4037. any other threads that may be processing. 
  4038.  
  4039. Warning: If you change the content of the floating-point control word: 
  4040.  
  4041. o The behavior of the math functions with regard to domain and range errors may 
  4042.   be undefined. 
  4043. o Math functions may not handle infinity and NaN values correctly. 
  4044. o Some floating-point exceptions may not occur, while other new ones may occur. 
  4045. o Resetting the EM_INEXACT bit may cause SIG_FPE exceptions, which decrease 
  4046.   performance. 
  4047. o If the precision or rounding bits are modified, you can reduce the precision 
  4048.   available for float and double variables. 
  4049. For information on bits in the control word and handling floating-point 
  4050. exceptions, see the Programming Guide. 
  4051.  
  4052. The bits in the returned value reflect the floating-point control word before 
  4053. the call. 
  4054.  
  4055. Example of _control187 
  4056.  
  4057.  
  4058. ΓòÉΓòÉΓòÉ <hidden> Example of _control187 ΓòÉΓòÉΓòÉ
  4059.  
  4060. /************************************************************************
  4061. *
  4062. This example prints the initial control word in hexadecimal, and then 
  4063. illustrates different representations of 0.1, depending on the precision. 
  4064.  
  4065.                                                                         *
  4066. ************************************************************************/
  4067.  
  4068. #include <stdio.h>
  4069. #include <float.h>
  4070.  
  4071. double a = .13;
  4072.  
  4073. int main(void)
  4074. {
  4075.     printf("control = 0x%.4x\n",
  4076.     _control87(CW_DEFAULT, 0));
  4077.                       /* Get control word */
  4078.  
  4079.     printf("a*a = .0169 = %.15e\n",a*a);
  4080.     _control87(PC_24, MCW_PC);
  4081.                      /* Set precision to 24 bits */
  4082.  
  4083.     printf("a*a = .0169 (rounded to 24 bits) = %.15e\n",a*a);
  4084.  
  4085.     _control87(CW_DEFAULT, 0xffff);
  4086.                      /* Restore to initial default */
  4087.     printf("a*a = .0169 = %.15e\n",a*a);
  4088.  
  4089.     return 0;
  4090.  
  4091.     /* Possible output could be:
  4092.  
  4093.        control = 0x0362
  4094.        a*a = .0169 = 1.690000000000000e-02
  4095.        a*a = .0169 (rounded to 24 bits) = 1.689999046325684e-03
  4096.        a*a = .0169 = 1.690000000000000e-02                      */
  4097.  
  4098. }
  4099.  
  4100.  
  4101. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4102.  
  4103. o _clear87 - Clear Floating-Point Status Word 
  4104. o _status87 - Get Floating-Point Status Word 
  4105. o _fpreset - Reset Floating-Point Unit 
  4106. o Floating Point Variables 
  4107. o signal Install Interrupt Handlers 
  4108. o float.h 
  4109.  
  4110.  
  4111. ΓòÉΓòÉΓòÉ 6.30. _close - Closes File Associated with Handle ΓòÉΓòÉΓòÉ
  4112.  
  4113.  
  4114. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4115.  
  4116. #include <io.h>
  4117.  
  4118. int _close(int handle);
  4119.  
  4120.  
  4121. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4122.  
  4123. Language Level: Extension 
  4124.  
  4125. The _close function closes the file associated with the handle. Use _close if 
  4126. you opened the handle with _open. If you opened the handle with fopen, use 
  4127. fclose to close it. 
  4128.  
  4129. The _close function returns 0 if it successfully closes the file. A return 
  4130. value of -1 shows an error, and _close sets errno to EBADF, showing an 
  4131. incorrect file handle argument. 
  4132.  
  4133. Example of _close 
  4134.  
  4135.  
  4136. ΓòÉΓòÉΓòÉ <hidden> Example of _close ΓòÉΓòÉΓòÉ
  4137.  
  4138. /************************************************************************
  4139. *
  4140.  
  4141. This example opens the file edclose.dat and then closes it using the _close 
  4142. function. 
  4143.  
  4144.                                                                         *
  4145. ************************************************************************/
  4146.  
  4147. #include <io.h>
  4148. #include <stdio.h>
  4149. #include <fcntl.h>
  4150. #include <sys\stat.h>
  4151.  
  4152. int main(void)
  4153. {
  4154.    int fh;
  4155.  
  4156.    printf("\nCreating edclose.dat.\n");
  4157.  
  4158.    if ( -1 ==
  4159.            (fh = _open("edclose.dat",
  4160.                       O_RDWR | O_CREAT | O_TRUNC,
  4161.                       S_IREAD | S_IWRITE)))
  4162.    {
  4163.       perror("Unable to open edclose.dat");
  4164.       return 1;
  4165.    }
  4166.  
  4167.    printf("File was successfully opened.\n");
  4168.  
  4169.    if ( -1 == _close(fh))
  4170.    {
  4171.       perror("Unable to close edclose.dat");
  4172.       return 1;
  4173.    }
  4174.  
  4175.    printf("File was successfully closed.\n");
  4176.    return 0;
  4177.  
  4178. /****************  The output should be similar to:  ********************
  4179.  
  4180.       Creating edclose.dat.
  4181.       File was successfully opened.
  4182.       File was successfully closed.
  4183. */
  4184. }
  4185.  
  4186.  
  4187. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4188.  
  4189. o fclose  - Close Stream 
  4190. o _creat - Create New File 
  4191. o _open - Open File 
  4192. o _sopen - Open Shared File 
  4193. o io.h 
  4194.  
  4195.  
  4196. ΓòÉΓòÉΓòÉ 6.31. cos  - Calculate Cosine ΓòÉΓòÉΓòÉ
  4197.  
  4198.  
  4199. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4200.  
  4201. #include <math.h>
  4202.  
  4203. double cos(double x);  /* Calculate the cosine of x */
  4204.  
  4205.  
  4206. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4207.  
  4208. Language Level: ANSI, SAA 
  4209.  
  4210. The cos function calculates the cosine of x. The value x is expressed in 
  4211. radians. If x is too large, a partial loss of significance in the result may 
  4212. occur. 
  4213.  
  4214. Example of cos 
  4215.  
  4216.  
  4217. ΓòÉΓòÉΓòÉ <hidden> Example of cos ΓòÉΓòÉΓòÉ
  4218.  
  4219. /************************************************************************
  4220. *
  4221.  
  4222. This example calculates y to be the cosine of x. 
  4223.  
  4224.                                                                         *
  4225. ************************************************************************/
  4226.  
  4227. #include <math.h>
  4228. #include <stdio.h>
  4229.  
  4230. int main(void)
  4231. {
  4232.    double x, y;
  4233.  
  4234.    x = 7.2;
  4235.    y = cos(x);
  4236.  
  4237.    printf("cos( %lf ) = %lf\n", x, y);
  4238. }
  4239.  
  4240. /*********************  Output should be similar to:  *******************
  4241.  
  4242. cos( 7.200000 ) = 0.608351
  4243. */
  4244.  
  4245.  
  4246. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4247.  
  4248. o acos  - Calculate Arccosine 
  4249. o cosh  - Calculate Hyperbolic Cosine 
  4250. o _facos - Calculate Arccosine 
  4251. o _fcos - Calculate Cosine 
  4252. o _fcossin - Calculate Cosine and Sine 
  4253. o _fsincos - Calculate Sine and Cosine 
  4254. o sin  - Calculate Sine 
  4255. o sinh  - Calculate Hyperbolic Sine 
  4256. o tan  - Calculate Tangent 
  4257. o tanh  - Calculate Hyperbolic Tangent 
  4258. o math.h 
  4259.  
  4260.  
  4261. ΓòÉΓòÉΓòÉ 6.32. cosh  - Calculate Hyperbolic Cosine ΓòÉΓòÉΓòÉ
  4262.  
  4263.  
  4264. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4265.  
  4266. #include <math.h>
  4267.  
  4268. double cosh(double x);
  4269.  
  4270.  
  4271. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4272.  
  4273. Language Level: ANSI, SAA 
  4274.  
  4275. The cosh function calculates the hyperbolic cosine of x. The value x is 
  4276. expressed in radians. If the result is too large, cosh returns the value 
  4277. HUGE_VAL and sets errno to ERANGE. 
  4278.  
  4279. Example of cosh 
  4280.  
  4281.  
  4282. ΓòÉΓòÉΓòÉ <hidden> Example of cosh ΓòÉΓòÉΓòÉ
  4283.  
  4284. /************************************************************************
  4285. *
  4286.  
  4287. This example calculates y to be the hyperbolic cosine of x. 
  4288.  
  4289.                                                                         *
  4290. ************************************************************************/
  4291.  
  4292. #include <math.h>
  4293. #include <stdio.h>
  4294.  
  4295. int main(void)
  4296. {
  4297.    double x,y;
  4298.  
  4299.    x = 7.2;
  4300.    y = cosh(x);
  4301.  
  4302.    printf("cosh( %lf ) = %lf\n", x, y);
  4303. }
  4304.  
  4305. /*********************  Output should be similar to:  *******************
  4306.  
  4307. cosh( 7.200000 ) = 669.715755
  4308. */
  4309.  
  4310.  
  4311. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4312.  
  4313. o acos  - Calculate Arccosine 
  4314. o cos  - Calculate Cosine 
  4315. o _facos - Calculate Arccosine 
  4316. o _fcos - Calculate Cosine 
  4317. o _fcossin - Calculate Cosine and Sine 
  4318. o _fsincos - Calculate Sine and Cosine 
  4319. o sin  - Calculate Sine 
  4320. o sinh  - Calculate Hyperbolic Sine 
  4321. o tan  - Calculate Tangent 
  4322. o tanh  - Calculate Hyperbolic Tangent 
  4323. o math.h 
  4324.  
  4325.  
  4326. ΓòÉΓòÉΓòÉ 6.33. _cprintf - Print Characters to Screen ΓòÉΓòÉΓòÉ
  4327.  
  4328.  
  4329. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4330.  
  4331. #include <conio.h>
  4332.  
  4333. int _cprintf(char *format-string, argument-list);
  4334.  
  4335.  
  4336. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4337.  
  4338. Language Level: Extension 
  4339.  
  4340. The _cprintf function formats and sends a series of characters and values 
  4341. directly to the screen, using the _putch function to send each character. 
  4342.  
  4343. The format-string has the same form and function as the format-string parameter 
  4344. for printf. Format specifications in the format-string determine the output 
  4345. format for any argument-list that follows. See printf for a description of the 
  4346. format-string. 
  4347.  
  4348. Note:  Unlike the fprintf, printf, and sprintf functions, _cprintf does not 
  4349. translate line feed characters into output of a carriage-return followed by a 
  4350. line-feed. 
  4351.  
  4352. The _cprintf function returns the number of characters printed. 
  4353.  
  4354. Example of _cprintf 
  4355.  
  4356.  
  4357. ΓòÉΓòÉΓòÉ <hidden> Example of _cprintf ΓòÉΓòÉΓòÉ
  4358.  
  4359. /************************************************************************
  4360. *
  4361. The following program uses _cprintf to write strings to the screen. 
  4362.  
  4363.                                                                         *
  4364. ************************************************************************/
  4365.  
  4366. #include <conio.h>
  4367.  
  4368. int main(void)
  4369. {
  4370.     char buffer[24];
  4371.  
  4372.     _cprintf("\nPlease enter a file name:\n");
  4373.     _cscanf("%23s", buffer);
  4374.  
  4375.     _cprintf("\nThe file name you entered was %23s.", buffer);
  4376.  
  4377.     return 0;
  4378.  
  4379. /******************  The output should be similar to:  ******************
  4380.  
  4381.     Please enter a file name:
  4382.                             file.dat
  4383.     The file name you entered was                file.dat.
  4384. */
  4385. }
  4386.  
  4387.  
  4388. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4389.  
  4390. o _cscanf - Read Data from Keyboard 
  4391. o fprintf  - Write Formatted Data 
  4392. o printf  - Formatted Print 
  4393. o _putch - Write Character to Screen 
  4394. o sprintf  - Formatted Print to Buffer 
  4395. o conio.h 
  4396.  
  4397.  
  4398. ΓòÉΓòÉΓòÉ 6.34. _cputs - Write String to Screen ΓòÉΓòÉΓòÉ
  4399.  
  4400.  
  4401. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4402.  
  4403. #include <conio.h>
  4404.  
  4405. int _cputs(char *str);
  4406.  
  4407.  
  4408. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4409.  
  4410. Language Level: Extension 
  4411.  
  4412. The _cputs function writes directly to the screen the string to which str 
  4413. points. The string str must end with a null character (\0). The _cputs function 
  4414. does not automatically add a carriage-return followed by a line-feed to the 
  4415. string after writing. 
  4416.  
  4417. If successful, _cputs returns 0. Otherwise, it returns a nonzero value. 
  4418.  
  4419. Example of _cputs 
  4420.  
  4421.  
  4422. ΓòÉΓòÉΓòÉ <hidden> Example of _cputs ΓòÉΓòÉΓòÉ
  4423.  
  4424. /************************************************************************
  4425. *
  4426.  
  4427. This example puts a prompt out to the screen. 
  4428.  
  4429.                                                                         *
  4430. ************************************************************************/
  4431.  
  4432. #include <conio.h>
  4433.  
  4434. int main(void)
  4435. {   char *buffer = "Insert data disk in drive a: \r\n";
  4436.  
  4437.     _cputs(buffer);
  4438.     return 0;
  4439.  
  4440. /***************  The output should be similar to:  *********************
  4441.  
  4442.     Insert data disk in drive a:
  4443. */
  4444.  
  4445. }
  4446.  
  4447.  
  4448. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4449.  
  4450. o _cgets - Read String of Characters from Keyboard 
  4451. o fputs  - Print Strings 
  4452. o _putch - Write Character to Screen 
  4453. o puts  - Write a String 
  4454. o conio.h 
  4455.  
  4456.  
  4457. ΓòÉΓòÉΓòÉ 6.35. _creat - Create New File ΓòÉΓòÉΓòÉ
  4458.  
  4459.  
  4460. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4461.  
  4462. #include <io.h>
  4463. #include <sys\stat.h>
  4464.  
  4465. int _creat(char *pathname, int pmode);
  4466.  
  4467.  
  4468. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4469.  
  4470. Language Level: Extension 
  4471.  
  4472. The _creat function either creates a new file or opens and truncates an 
  4473. existing file. If the file specified by pathname does not exist, _creat creates 
  4474. a new file with the given permission setting and opens for writing in text 
  4475. mode. If the file already exists, and the read-only attribute and sharing 
  4476. permissions allow writing, _creat truncates the file to length 0. This destroys 
  4477. the previous contents of the file and opens it for writing in text mode. The 
  4478. _creat function always opens a file in text mode for reading and writing. 
  4479.  
  4480. The permission setting pmode applies to newly created files only. The new file 
  4481. receives the specified permission setting after you close it for the first 
  4482. time. The pmode integer expression contains one or both of the constants 
  4483. S_IWRITE and S_IREAD, defined in <sys\stat.h>. The values of the pmode argument 
  4484. and their meanings are: 
  4485.  
  4486. Value                   Meaning 
  4487. S_IREAD                 Reading permitted 
  4488. S_IWRITE                Writing permitted 
  4489. S_IREAD | S_IWRITE      Reading and writing permitted. 
  4490.  
  4491. If you do not give permission to write to the file, the file is a read-only 
  4492. file. On the OS/2 operating system, you cannot give write-only permission. 
  4493. Thus, the modes S_IWRITE and S_IREAD | S_IWRITE have the same results. The 
  4494. _creat function applies the current file permission mask to pmode before 
  4495. setting the permissions. (See _umask - Sets File Mask of Current Process for 
  4496. more information about file permission masks.) 
  4497.  
  4498. When writing new code, you should use _open rather than _creat. 
  4499.  
  4500. Specifying a pmode of S_IREAD is similar to making a file read-only with the 
  4501. ATTRIB system command. 
  4502.  
  4503. The _creat function returns a handle for the created file if the call is 
  4504. successful. A return value of -1 shows an error, and _creat sets errno to one 
  4505. of the following values: 
  4506.  
  4507. Value          Meaning 
  4508. EACCESS        File sharing violated. 
  4509. EINVAL         The mode specified was not valid. 
  4510. EMFILE         No more file handles are available. 
  4511. ENOENT         The path name was not found, or the file name was incorrect. 
  4512. EOS2ERR        The call to the operating system was not successful. 
  4513.  
  4514. Example of _creat 
  4515.  
  4516.  
  4517. ΓòÉΓòÉΓòÉ <hidden> Example of _creat ΓòÉΓòÉΓòÉ
  4518.  
  4519. /************************************************************************
  4520. *
  4521.  
  4522. This example creates the file sample.dat so it can be read from and written to. 
  4523.  
  4524.                                                                         *
  4525. ************************************************************************/
  4526.  
  4527. #include <sys\stat.h>
  4528. #include <io.h>
  4529. #include <stdio.h>
  4530.  
  4531. int main(void)
  4532. {
  4533.    int fh;
  4534.    fh = _creat("sample.dat", S_IREAD | S_IWRITE);
  4535.    if ( -1 == fh)
  4536.    {
  4537.       perror("Error in creating sample.dat");
  4538.       return 1;
  4539.    }
  4540.    else
  4541.       printf("Successfully created sample.dat.\n");
  4542.  
  4543.    _close(fh);
  4544.    return 0;
  4545.  
  4546. /******************  Expected output is:  *******************************
  4547.  
  4548.       Successfully created sample.dat.
  4549. */
  4550. }
  4551.  
  4552.  
  4553. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4554.  
  4555. o _chmod - Change File Permission Setting 
  4556. o _close - Closes File Associated with Handle 
  4557. o _open - Open File 
  4558. o _fdopen - Associates Input Or Output With File 
  4559. o _sopen - Open Shared File 
  4560. o _umask - Sets File Mask of Current Process 
  4561. o sys\stat.h 
  4562. o io.h 
  4563.  
  4564.  
  4565. ΓòÉΓòÉΓòÉ 6.36. _CRT_init - Initialize DLL Runtime Environment ΓòÉΓòÉΓòÉ
  4566.  
  4567.  
  4568. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4569.  
  4570.    int _CRT_init(void);
  4571.  
  4572.  
  4573. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4574.  
  4575. Language Level: Extended 
  4576.  
  4577. Before you can call any C/C++ Tools library functions, you must first 
  4578. initialize the runtime environment. Use the function _CRT_init, which is 
  4579. provided in the runtime libraries. 
  4580.  
  4581. If the runtime environment is successfully initialized, _CRT_init returns 0.  A 
  4582. return code of -1 indicates an error. If an error occurs, an error message is 
  4583. written to file handle 2, which is the usual destination of stderr. 
  4584.  
  4585. If your DLL contains C++ code, you must also call __ctordtorInit after 
  4586. _CRT_init to ensure that static constructors and destructors are initialized 
  4587. properly.  The prototype for __ctordtorInit is: 
  4588.  
  4589.    void __ctordtorInit(void);
  4590.  
  4591. Note:  If you are providing your own version of the _matherr function to be 
  4592. used in your DLL, you must call the _exception_dllinit function after the 
  4593. runtime environment is initialized. Calling this function ensures that the 
  4594. proper _matherr function will be called during exception handling. The 
  4595. prototype for this function is: 
  4596.  
  4597.    void _Optlink _exception_dllinit( int (*)(struct exception *) );
  4598.  
  4599. The parameter required is the address of your _matherr function. 
  4600.  
  4601.  
  4602. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4603.  
  4604. o _DLL_InitTerm - Initialize and Terminate DLL Environment 
  4605. o _CRT_term - Terminate DLL Runtime Environment 
  4606.  
  4607.  
  4608. ΓòÉΓòÉΓòÉ 6.37. _CRT_term - Terminate DLL Runtime Environment ΓòÉΓòÉΓòÉ
  4609.  
  4610.  
  4611. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4612.  
  4613.    void _CRT_term(void);
  4614.  
  4615.  
  4616. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4617.  
  4618. Language Level: Extended 
  4619.  
  4620. If your DLL is statically linked, you must use the _CRT_term function to 
  4621. correctly terminate the C runtime environment.  The _CRT_term function is 
  4622. provided in the C/C++ Tools runtime libraries. 
  4623.  
  4624. If your DLL contains C++ code, you must also call __ctordtorTerm before you 
  4625. call _CRT_term to ensure that static constructors and destructors are 
  4626. terminated correctly. The prototype for __ctordtorTerm is: 
  4627.  
  4628.    void __ctordtorTerm(void);
  4629.  
  4630. Once you have called _CRT_term, you cannot call any other library functions. 
  4631.  
  4632. If your DLL is dynamically linked, you cannot call library functions in the 
  4633. termination section of your _DLL_InitTerm function. If your termination routine 
  4634. requires calling library functions, you must register the termination routine 
  4635. with DosExitList. Note that all DosExitList routines are called before DLL 
  4636. termination routines. 
  4637.  
  4638.  
  4639. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4640.  
  4641. o _CRT_init - Initialize DLL Runtime Environment 
  4642. o _DLL_InitTerm - Initialize and Terminate DLL Environment 
  4643.  
  4644.  
  4645. ΓòÉΓòÉΓòÉ 6.38. _cscanf - Read Data from Keyboard ΓòÉΓòÉΓòÉ
  4646.  
  4647.  
  4648. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4649.  
  4650. #include <conio.h>
  4651.  
  4652. int _cscanf(char *format-string, argument-list);
  4653.  
  4654.  
  4655. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4656.  
  4657. Language Level: Extension 
  4658.  
  4659. The _cscanf function reads data directly from the keyboard to the locations 
  4660. given by argument-list, if any are specified. The _cscanf function uses the 
  4661. _getche function to read characters. Each argument must be a pointer to a 
  4662. variable with a type that corresponds to a type specifier in the format-string. 
  4663.  
  4664. The format-string controls the interpretation of the input fields and has the 
  4665. same form and function as the format-string argument for the scanf function. 
  4666. See scanf for a description of the format-string. 
  4667.  
  4668. Note:  Although _cscanf normally echoes the input character, it does not do so 
  4669. if the last action was a call to _ungetch. 
  4670.  
  4671. The _cscanf function returns the number of fields that were successfully 
  4672. converted and assigned. The return value does not include fields that were read 
  4673. but not assigned. 
  4674.  
  4675. The return value is EOF for an attempt to read at the end of the file. A return 
  4676. value of 0 means that no fields were assigned. 
  4677.  
  4678. Example of _cscanf 
  4679.  
  4680.  
  4681. ΓòÉΓòÉΓòÉ <hidden> Example of _cscanf ΓòÉΓòÉΓòÉ
  4682.  
  4683. /************************************************************************
  4684. *
  4685.  
  4686. This example uses _cscanf to read strings from the screen. 
  4687.  
  4688.                                                                         *
  4689. ************************************************************************/
  4690.  
  4691. #include <conio.h>
  4692.  
  4693. int main(void)
  4694. {
  4695.     char buffer[24];
  4696.  
  4697.     _cprintf("\nPlease enter a file name:\n");
  4698.     _cscanf("%23s", buffer);
  4699.  
  4700.     _cprintf("\nThe file name you entered was %23s.", buffer);
  4701.  
  4702.     return 0;
  4703.  
  4704. /******************  The output should be similar to:  ******************
  4705.  
  4706.     Please enter a file name:
  4707.                             file.dat
  4708.     The file name you entered was                file.dat.
  4709. */
  4710. }
  4711.  
  4712.  
  4713. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4714.  
  4715. o fscanf  - Read Formatted Data 
  4716. o _getch - _getche - Read Character from Keyboard 
  4717. o scanf  - Read Data 
  4718. o sscanf  - Read Data 
  4719. o _ungetch - Push Character Back to Keyboard 
  4720. o conio.h 
  4721.  
  4722.  
  4723. ΓòÉΓòÉΓòÉ 6.39. ctime  - Convert Time ΓòÉΓòÉΓòÉ
  4724.  
  4725.  
  4726. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4727.  
  4728. #include <time.h>
  4729.  
  4730. char *ctime(const time_t *time);
  4731.  
  4732.  
  4733. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4734.  
  4735. Language Level: ANSI, SAA 
  4736.  
  4737. The ctime function converts the time value pointed to by time to local time in 
  4738. the form of a character string.  A time value is usually obtained by a call to 
  4739. the time function. 
  4740.  
  4741. The string result produced by ctime contains exactly 26 characters and has the 
  4742. format 
  4743.  
  4744.    "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n"
  4745. for example: 
  4746.  
  4747.    Mon Jul 16 02:03:55 1987\n\0
  4748.  
  4749. The ctime function uses a 24-hour clock format.  The days are abbreviated to: 
  4750. Sun, Mon, Tue, Wed, Thu, Fri, and Sat.  The months are abbreviated to:  Jan, 
  4751. Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, and Dec.  All fields have a 
  4752. constant width. Dates with only one digit are preceded either with a zero or a 
  4753. blank space, depending on the compiler. The new-line character (\n) and the 
  4754. null character (\0) occupy the last two positions of the string. 
  4755.  
  4756. Note:  The asctime, ctime, and other time functions may use a common, 
  4757.        statically allocated buffer for holding the return string.  Each call to 
  4758.        one of these functions may destroy the result of the previous call. 
  4759.  
  4760. The time and date functions begin at 00:00:00 Universal Time, January 1, 1970. 
  4761.  
  4762. The ctime function returns a pointer to the character string result.  There is 
  4763. no error return value.  The ctime function is equivalent to: 
  4764.  
  4765.    asctime(localtime(&anytime))
  4766.  
  4767. Example of ctime 
  4768.  
  4769.  
  4770. ΓòÉΓòÉΓòÉ <hidden> Example of ctime ΓòÉΓòÉΓòÉ
  4771.  
  4772. /************************************************************************
  4773. *
  4774.  
  4775. This example polls the system clock by using the library function time.  It 
  4776. then prints a message giving the current date and time. 
  4777.  
  4778.                                                                         *
  4779. ************************************************************************/
  4780.  
  4781. #include <time.h>
  4782. #include <stdio.h>
  4783.  
  4784. int main(void)
  4785. {
  4786.    time_t ltime;
  4787.  
  4788.    time(<ime);
  4789.    printf("the time is %s", ctime(<ime));
  4790. }
  4791.  
  4792.  
  4793. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4794.  
  4795. o asctime  - Convert Time 
  4796. o gmtime  - Convert Time 
  4797. o localtime  - Convert Time 
  4798. o mktime  - Convert Local Time 
  4799. o strftime  - Convert to Formatted Time 
  4800. o time  - Determine Current Time 
  4801. o time.h 
  4802.  
  4803.  
  4804. ΓòÉΓòÉΓòÉ 6.40. _cwait - Wait for Child Process ΓòÉΓòÉΓòÉ
  4805.  
  4806.  
  4807. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4808.  
  4809. #include <process.h>
  4810.  
  4811. int _cwait(int *stat_loc, int process_id, int action_code);
  4812.  
  4813.  
  4814. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4815.  
  4816. Language Level: Extension 
  4817.  
  4818. The _cwait function delays the completion of a parent process until the child 
  4819. process specified by process_id ends. 
  4820.  
  4821. The process_id is the value returned by the _spawn function that started the 
  4822. child process. If the specified child process ends before _cwait is called, 
  4823. _cwait returns to the calling process immediately with a value of -1. If the 
  4824. value of process_id is 0, the parent process waits until all of its child 
  4825. processes end. 
  4826.  
  4827. If the variable pointed to by stat_loc is NULL, the _cwait function does not 
  4828. use it.  If it is not NULL, _cwait places information about the return status 
  4829. and the return code of the child process in the location to which stat_loc 
  4830. points. 
  4831.  
  4832. If the child process ended normally with a call to the OS/2 DosExit API, the 
  4833. lowest-order byte of the variable pointed to by stat_loc is 0.  The next 
  4834. highest-order byte contains the lowest-order byte of the argument passed to 
  4835. DosExit by the child process. The value of this byte depends on how the child 
  4836. process caused the system to call DosExit.  If the child called exit, _exit, or 
  4837. return from main, or used a DosExit coded into the program, the byte contains 
  4838. the lowest-order byte of the argument the child passed to exit, _exit, or 
  4839. return. The value of the byte is undefined if the child caused a DosExit call 
  4840. simply by reaching the end of main. 
  4841.  
  4842. If the child process ended abnormally (without a call to DosExit), the 
  4843. lowest-order byte of the variable pointed to by stat_loc contains the return 
  4844. code from the OS/2 DosWaitChild API, and the next higher-order byte is 0. See 
  4845. the OS/2 online reference for details about the DosWaitChild return codes. 
  4846.  
  4847. The action_code specifies when the parent process is to start running again. 
  4848. Values for action_code include: 
  4849.  
  4850. Action Code Meaning 
  4851. WAIT_CHILD 
  4852.           The parent process waits until the specified child process ends. 
  4853. WAIT_GRANDCHILD 
  4854.           The parent process waits until the child process and all of the child 
  4855.           processes of that process end. 
  4856.  
  4857. The action code values are defined in <process.h>. 
  4858.  
  4859. Note:  Because the size of an int is only 2 bytes in 16-bit compilers, if you 
  4860. are migrating a 16-bit program, some parts of your programs may have to be 
  4861. rewritten if they use this function. 
  4862.  
  4863. An alternative to this function is the DosWaitChild API call. 
  4864.  
  4865. At the normal end of the child process, _cwait returns the process identifier 
  4866. of the child to the parent process. If a child process ends abnormally, _cwait 
  4867. returns -1 to the parent process and sets errno to EINTR. In the case of an 
  4868. error, _cwait returns immediately with a value of -1 and sets errno to one of 
  4869. the following values: 
  4870.  
  4871. Value     Meaning 
  4872. EINVAL    Incorrect action code 
  4873. ECHILD    No child process exists, or the process identifier is incorrect. 
  4874.  
  4875. Example of _cwait 
  4876.  
  4877.  
  4878. ΓòÉΓòÉΓòÉ <hidden> Example of _cwait ΓòÉΓòÉΓòÉ
  4879.  
  4880. /************************************************************************
  4881. *
  4882. This example creates a new process called child.exe.  The parent calls _cwait 
  4883. and waits for the child to end.  The parent then displays the child's return 
  4884. information in hexadecimal. 
  4885.  
  4886.                                                                        *
  4887. ***********************************************************************/
  4888.  
  4889. #include <stdio.h>
  4890. #include <process.h>
  4891. #include <errno.h>
  4892.  
  4893. int stat_child;
  4894.  
  4895. int main(void)
  4896. {
  4897.     int i, result;
  4898.  
  4899.     /* spawn a child and 'cwait' for it to finish*/
  4900.     if ((result = _spawnl(P_NOWAIT,"child","child","1",
  4901.           NULL)) != -1)
  4902.        {
  4903.        if ((i= _cwait(&stat_child,result,WAIT_CHILD)) != result)
  4904.           printf("Error ...expected pid from child");
  4905.        else {
  4906.           if (errno == 0) {
  4907.               printf("Child process ended successfully and ...\n");
  4908.               printf("program returned to the Parent process.\n");
  4909.           }
  4910.           else
  4911.               printf("Child process had an error\n");
  4912.        }
  4913.    }
  4914.    else
  4915.       printf("Error ...could not spawn a child process\n");
  4916.  
  4917.    return 0;
  4918. }
  4919. /**************  If the source code for child.exe is:  ****************
  4920.  
  4921. #include <stdio.h>
  4922.  
  4923. int main(void)
  4924. {
  4925.     puts("This line was written by child.exe");
  4926. }
  4927. */
  4928.  
  4929. ***************  then the output should be similar to:  **************
  4930.  
  4931.    This line was written by child.exe
  4932.    Child process ended successfully and ...
  4933.    program returned to the Parent process.
  4934. */
  4935.  
  4936.  
  4937. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  4938.  
  4939. o exit  - End Program 
  4940. o _exit - End Process 
  4941. o _spawnl -_spawnvpe -Start and Run Child Processes 
  4942. o _wait - Wait for Child Process 
  4943. o return 
  4944. o process.h 
  4945.  
  4946.  
  4947. ΓòÉΓòÉΓòÉ 6.41. _debug_calloc - Reserve and Initialize Storage ΓòÉΓòÉΓòÉ
  4948.  
  4949.  
  4950. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  4951.  
  4952. #define __DEBUG_ALLOC__
  4953. #include <stdlib.h>  /* also defined in <malloc.h> */
  4954.  
  4955. void *_debug_calloc(size_t num, size_t size,
  4956.                            const char *pFilename,
  4957.                            size_t linenum);
  4958.  
  4959.  
  4960. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  4961.  
  4962. Language Level: Extension 
  4963.  
  4964. The _debug_calloc function is the debug version of calloc, and performs the 
  4965. same function as calloc. It reserves storage space for an array of num 
  4966. elements, each of length size bytes, and initializes all bits of each element 
  4967. to 0. 
  4968.  
  4969. In addition, _debug_calloc makes an implicit call to the _heap_check function. 
  4970. It also stores the name of the file pFilename and the line number linenum where 
  4971. the storage is allocated.  This information can be used later by _heap_check 
  4972. and the _dump_allocated function. 
  4973.  
  4974. The _debug_calloc function returns a pointer to the reserved space. If not 
  4975. enough storage is available, or if num or size is 0, _debug_calloc returns 
  4976. NULL. 
  4977.  
  4978. Example of _debug_calloc 
  4979.  
  4980.  
  4981. ΓòÉΓòÉΓòÉ <hidden> Example of _debug_calloc ΓòÉΓòÉΓòÉ
  4982.  
  4983. /************************************************************************
  4984. *
  4985. This example reserves storage of 124 bytes. It then attempts to write to 
  4986. storage that was not allocated.  When _debug_calloc is called again, 
  4987. _heap_check detects the error, generates several messages, and stops the 
  4988. program. 
  4989.  
  4990. Note:  Although the function calloc is coded in the example, the 
  4991. __DEBUG_ALLOC__ macro redefines calloc to _debug_calloc. 
  4992.  
  4993.                                                                         *
  4994. ************************************************************************/
  4995.  
  4996. #ifndef __DEBUG_ALLOC__      /* this macro could also be defined */
  4997.    #define __DEBUG_ALLOC__   /*      from the command line       */
  4998. #endif
  4999. #include <stdlib.h>
  5000. #include <stdio.h>
  5001.  
  5002. int main(void)
  5003. {
  5004.    char *ptr;
  5005.  
  5006.    if (( ptr = calloc(2, 62) ) == NULL)
  5007.    {
  5008.       printf( "Could not allocate memory block.\n" );
  5009.       return EXIT_FAILURE;
  5010.    }
  5011.  
  5012.    *(ptr + 124) = 'a';     /* overwrites storage that was not allocated */
  5013.  
  5014.    ptr = calloc(23, 45); /* this call to calloc invokes _heap_check */
  5015.  
  5016.    printf("_debug_calloc did not detect
  5017.    that a memory block was overwritten.\n");
  5018.  
  5019.    return EXIT_FAILURE;
  5020.  
  5021.    /* Possible output is:
  5022.  
  5023.       Memory was overwritten after the allocated memory block
  5024.       that starts at address 0x000B0F10.
  5025.       The first eight bytes of the memory block (in hex) are: 0000000000000000.
  5026.       This memory block was (re)allocated at line number 11 in TDCALLC.C.       */
  5027.  
  5028. }
  5029.  
  5030.  
  5031. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5032.  
  5033. o calloc  - Reserve and Initialize Storage 
  5034. o _debug_free - Release Storage Blocks 
  5035. o _debug_malloc - Reserve Storage Blocks 
  5036. o _debug_realloc - Change Reserved Storage Block Size 
  5037. o _dump_allocated - Get Information about Allocated Storage 
  5038. o _heap_check - Validate Run-Time Storage Heap 
  5039. o Using the Debug Memory Management Functions 
  5040. o malloc.h 
  5041. o stdlib.h 
  5042.  
  5043.  
  5044. ΓòÉΓòÉΓòÉ 6.42. _debug_free - Release Storage Blocks ΓòÉΓòÉΓòÉ
  5045.  
  5046.  
  5047. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5048.  
  5049. #define __DEBUG_ALLOC__
  5050. #include <stdlib.h>  /* also defined in <malloc.h> */
  5051.  
  5052. void _debug_free(void *ptr, const char *pFilename,
  5053.                         size_t linenum);
  5054.  
  5055.  
  5056. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5057.  
  5058. Language Level: Extension 
  5059.  
  5060. The _debug_free function is the debug version of free, and performs the same 
  5061. function as free. It frees the block of storage pointed to by ptr that has been 
  5062. allocated by either a normal or a debug version of the memory management 
  5063. functions. 
  5064.  
  5065. In addition, _debug_free makes an implicit call to the _heap_check function. It 
  5066. also stores the file name pFilename and  the line number linenum where the 
  5067. storage is freed.  This information can be used later by _heap_check and the 
  5068. _dump_allocated function. 
  5069.  
  5070. Note:  If the block of storage pointed to by ptr was not allocated using the 
  5071.        memory management functions or was previously freed, a message appears 
  5072.        and the program ends. 
  5073.  
  5074. There is no return value. 
  5075.  
  5076. Example of _debug_free 
  5077.  
  5078.  
  5079. ΓòÉΓòÉΓòÉ <hidden> Example of _debug_free ΓòÉΓòÉΓòÉ
  5080.  
  5081. /************************************************************************
  5082. *
  5083. This example reserves two blocks of 62 bytes each.  It then frees the first 
  5084. block and attempts to overwrite the freed storage.  When _debug_free is called 
  5085. a second time, _heap_check detects the error, prints out several messages, and 
  5086. stops the program. 
  5087.  
  5088. Note:  Although the function free is coded in the example, the __DEBUG_ALLOC__ 
  5089. macro redefines free to _debug_free. 
  5090.  
  5091.                                                                         *
  5092. ************************************************************************/
  5093.  
  5094. #ifndef __DEBUG_ALLOC__      /* this macro could also be defined */
  5095.    #define __DEBUG_ALLOC__   /*      from the command line       */
  5096. #endif
  5097. #include <stdlib.h>
  5098. #include <stdio.h>
  5099.  
  5100. int main(void)
  5101. {
  5102.    char *ptr1;
  5103.    char *ptr2;
  5104.  
  5105.    if ( (( ptr1 = malloc(62) ) == NULL)
  5106.                 || (( ptr2 = malloc(62) ) == NULL) )
  5107.    {
  5108.       printf("Could not allocate memory block.\n");
  5109.       return EXIT_FAILURE;
  5110.    }
  5111.  
  5112.    free(ptr1);
  5113.  
  5114.    *(ptr1 - 1) = 'a';   /* overwrites storage that has been freed */
  5115.  
  5116.    free(ptr2);         /* this call to free invokes _heap_check */
  5117.  
  5118.    printf("_debug_free did not detect that a free memory block
  5119.            was overwritten.\n");
  5120.  
  5121.    return EXIT_FAILURE;
  5122.  
  5123.    /* Possible output is:
  5124.  
  5125.       Memory was overwritten before the free memory block that starts
  5126.             at address 0x00150010.
  5127.       The first eight bytes of the memory block (in hex) are: B5B5A5A500000000.
  5128.       This memory block was freed at line number 17 in TDFREE.C.                */
  5129.  
  5130. }
  5131.  
  5132.  
  5133. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5134.  
  5135. o _debug_calloc - Reserve and Initialize Storage 
  5136. o _debug_malloc - Reserve Storage Blocks 
  5137. o _debug_realloc - Change Reserved Storage Block Size 
  5138. o _dump_allocated - Get Information about Allocated Storage 
  5139. o free  - Release Storage Blocks 
  5140. o _heap_check - Validate Run-Time Storage Heap 
  5141. o Using the Debug Memory Management Functions 
  5142. o malloc.h 
  5143. o stdlib.h 
  5144.  
  5145.  
  5146. ΓòÉΓòÉΓòÉ 6.43. _debug_heapmin - Release Unused Memory in the Heap ΓòÉΓòÉΓòÉ
  5147.  
  5148.  
  5149. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5150.  
  5151. #define __DEBUG_ALLOC__
  5152. #include <stdlib.h>  /* also defined in <malloc.h> */
  5153.  
  5154. int _debug_heapmin(const char *pFilename, size_t linenum);
  5155.  
  5156.  
  5157. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5158.  
  5159. Language Level: Extension 
  5160.  
  5161. The _debug_heapmin function is the debug version of _heapmin, and performs the 
  5162. same function as _heapmin. It returns all unused memory from the run-time heap 
  5163. to the operating system. 
  5164.  
  5165. In addition, _debug_heapmin makes an implicit call to the _heap_check function. 
  5166. It also stores the file name pFilename and the line number linenum where the 
  5167. memory is returned.  This information can be used later by _heap_check and the 
  5168. _dump_allocated function. 
  5169.  
  5170. If successful, _debug_heapmin returns 0; otherwise, it returns -1. 
  5171.  
  5172. Example of _debug_heapmin 
  5173.  
  5174.  
  5175. ΓòÉΓòÉΓòÉ <hidden> Example of _debug_heapmin ΓòÉΓòÉΓòÉ
  5176.  
  5177. /************************************************************************
  5178. *
  5179. This example allocates 5000 bytes of storage, then changes the storage size to 
  5180. 35 bytes, and uses _debug_heapmin to return the unused memory to the operating 
  5181. system. The storage is then freed, and the program attempts to overwrite the 
  5182. freed storage. When _debug_heapmin is called again, _heap_check detects the 
  5183. error, generates several messages, and stops the program. 
  5184.  
  5185. Note:  Although the function _heapmin is coded in the example, the 
  5186. __DEBUG_ALLOC__ macro redefines _heapmin to _debug_heapmin. 
  5187.  
  5188.                                                                         *
  5189. ************************************************************************/
  5190.  
  5191. #ifndef __DEBUG_ALLOC__       /* this macro could also be defined */
  5192.    #define __DEBUG_ALLOC__    /*      from the command line       */
  5193. #endif
  5194. #include <stdlib.h>
  5195. #include <stdio.h>
  5196.  
  5197. int main(void)
  5198. {
  5199.    char *ptr;
  5200.  
  5201.    ptr = malloc(5000);
  5202.  
  5203.    ptr = realloc(ptr, 35);
  5204.  
  5205.    _heapmin();    /* no allocation problems to detect */
  5206.  
  5207.    free(ptr);
  5208.    *ptr = 'a';     /* overwrites storage that has been freed */
  5209.  
  5210.    _heapmin();    /* this call to _heapmin invokes _heap_check */
  5211.  
  5212.    printf("_debug_heapmin did not detect
  5213.                that a free memory block was accessed\n");
  5214.    return 0;
  5215.  
  5216.    /* Possible output is:
  5217.  
  5218.       The free memory block that starts at address 0x00150010
  5219.       has been accessed.
  5220.       The first eight bytes of the memory block (in hex) are: 61B5A5A500000000.
  5221.       This memory block was freed at line number 17 in THPMIN.C.                  */
  5222.  
  5223.    }
  5224.  
  5225.  
  5226. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5227.  
  5228. o _dump_allocated - Get Information about Allocated Storage 
  5229. o _heapmin - Release Unused Memory in the Heap 
  5230. o _heap_check - Validate Run-Time Storage Heap 
  5231. o Using the Debug Memory Management Functions 
  5232. o malloc.h 
  5233. o stdlib.h 
  5234.  
  5235.  
  5236. ΓòÉΓòÉΓòÉ 6.44. _debug_malloc - Reserve Storage Blocks ΓòÉΓòÉΓòÉ
  5237.  
  5238.  
  5239. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5240.  
  5241. #define __DEBUG_ALLOC__
  5242. #include <stdlib.h>  /* also defined in <malloc.h> */
  5243.  
  5244. void *_debug_malloc(size_t size, const char *pFilename,
  5245.                            size_t linenum);
  5246.  
  5247.  
  5248. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5249.  
  5250. Language Level: Extension 
  5251.  
  5252. The _debug_malloc function is the debug version of malloc, and performs the 
  5253. same function as malloc. It reserves a block of storage of size bytes. 
  5254.  
  5255. In addition, _debug_malloc makes an implicit call to the _heap_check function. 
  5256. It also stores the file name pFilename and the line number linenum where the 
  5257. storage is allocated.  This information can later be used by _heap_check and 
  5258. the _dump_allocated function. 
  5259.  
  5260. The _debug_malloc function returns a pointer to the reserved space.  If not 
  5261. enough storage is available or if size is 0, _debug_malloc returns NULL. 
  5262.  
  5263. Example of _debug_malloc 
  5264.  
  5265.  
  5266. ΓòÉΓòÉΓòÉ <hidden> Example of _debug_malloc ΓòÉΓòÉΓòÉ
  5267.  
  5268. /************************************************************************
  5269. *
  5270. This example allocates 62 bytes of storage. It then attempts to write to 
  5271. storage that was not allocated.  When _debug_malloc is called again, 
  5272. _heap_check detects the error, generates several messages, and stops the 
  5273. program. 
  5274.  
  5275. Note:  Although the function malloc is coded in the example, the 
  5276. __DEBUG_ALLOC__ macro redefines malloc to _debug_malloc. 
  5277.  
  5278.                                                                         *
  5279. ************************************************************************/
  5280.  
  5281. #ifndef __DEBUG_ALLOC__     /* this macro could also be defined */
  5282.    #define __DEBUG_ALLOC__  /*      from the command line       */
  5283. #endif
  5284. #include <stdlib.h>
  5285. #include <stdio.h>
  5286.  
  5287. int main(void)
  5288. {
  5289.    char *ptr;
  5290.  
  5291.    if ( (ptr = malloc(62) ) == NULL)
  5292.    {
  5293.       printf( "Could not allocate memory block.\n" );
  5294.       return EXIT_FAILURE;
  5295.    }
  5296.  
  5297.    *(ptr - 1) = 'a';     /* overwrites storage that was not allocated */
  5298.  
  5299.    ptr = malloc(2345);   /* this call to malloc invokes _heap_check */
  5300.  
  5301.    printf("_debug_malloc did not detect that a memory block
  5302.                was overwritten.\n");
  5303.  
  5304.    return EXIT_FAILURE;
  5305.  
  5306.    /* Possible output is:
  5307.  
  5308.       Memory was overwritten before the allocated memory block
  5309.       that starts at address 0x00150010.
  5310.       The first eight bytes of the memory block (in hex) are: 0000000000000000.
  5311.       This memory block was (re)allocated at line number 11 in TDMALLC.C.        */
  5312.  
  5313. }
  5314.  
  5315.  
  5316. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5317.  
  5318. o _debug_calloc - Reserve and Initialize Storage 
  5319. o _debug_free - Release Storage Blocks 
  5320. o _debug_realloc - Change Reserved Storage Block Size 
  5321. o _dump_allocated - Get Information about Allocated Storage 
  5322. o _heap_check - Validate Run-Time Storage Heap 
  5323. o malloc  - Reserve Storage Block 
  5324. o Using the Debug Memory Management Functions 
  5325. o malloc.h 
  5326. o stdlib.h 
  5327.  
  5328.  
  5329. ΓòÉΓòÉΓòÉ 6.45. _debug_realloc - Change Reserved Storage Block Size ΓòÉΓòÉΓòÉ
  5330.  
  5331.  
  5332. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5333.  
  5334. #define __DEBUG_ALLOC__
  5335. #include <stdlib.h>  /* also defined in <malloc.h> */
  5336.  
  5337. void *_debug_realloc(void *ptr, size_t size,
  5338.                             const char *pFilename,
  5339.                             size_t linenum);
  5340.  
  5341.  
  5342. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5343.  
  5344. Language Level: Extension 
  5345.  
  5346. The _debug_realloc function is the debug version of realloc, and performs the 
  5347. same function as realloc. It reallocates the block of storage pointed to by ptr 
  5348. to a new size, specified in bytes. In addition, _debug_realloc makes an 
  5349. implicit call to the _heap_check function. 
  5350.  
  5351. It also stores the file name pFilename and the line number linenum where the 
  5352. storage is reallocated.  This information can be used later by _heap_check and 
  5353. the _dump_allocated function. 
  5354.  
  5355. If ptr is NULL, _debug_realloc behaves like _debug_malloc. 
  5356.  
  5357. Note:  The _debug_realloc function reallocates storage that has been allocated 
  5358.        by either a normal or a debug version of the memory management 
  5359.        functions. If the block of storage pointed to by ptr was not allocated 
  5360.        using the memory management functions or was previously freed, a message 
  5361.        will appear and the program will end. 
  5362.  
  5363. The _debug_realloc function returns a pointer to the reallocated storage block. 
  5364. The ptr argument to _debug_realloc is not necessarily the same as the return 
  5365. value, because the storage location might be moved by _debug_realloc. 
  5366.  
  5367. If size is 0, _debug_realloc returns NULL.  If not enough storage space is 
  5368. available to expand the block to the given size, the original block is 
  5369. unchanged and NULL is returned. 
  5370.  
  5371. Example of _debug_realloc 
  5372.  
  5373.  
  5374. ΓòÉΓòÉΓòÉ <hidden> Example of _debug_realloc ΓòÉΓòÉΓòÉ
  5375.  
  5376. /************************************************************************
  5377. *
  5378. This example uses _debug_realloc to allocate 62 bytes of storage. It then 
  5379. attempts to write to storage that was not allocated. When _debug_realloc is 
  5380. called again, _heap_check detects the error, generates several messages, and 
  5381. stops the program. 
  5382.  
  5383. Note:  Although the function realloc is coded in the example, the 
  5384. __DEBUG_ALLOC__ macro redefines realloc to _debug_realloc. 
  5385.  
  5386.                                                                         *
  5387. ************************************************************************/
  5388.  
  5389. #ifndef __DEBUG_ALLOC__      /* this macro could also be defined */
  5390.    #define __DEBUG_ALLOC__   /*      from the command line       */
  5391. #endif
  5392. #include <stdlib.h>
  5393. #include <stdio.h>
  5394.  
  5395. int main(void)
  5396. {
  5397.    char *ptr;
  5398.  
  5399.    if (( ptr = realloc(NULL, 62) ) == NULL)
  5400.    {
  5401.       printf("Could not allocate memory block.\n");
  5402.       return EXIT_FAILURE;
  5403.    }
  5404.  
  5405.    *(ptr - 2) = 'a';           /* overwrites storage that was not allocated */
  5406.  
  5407.    ptr = realloc(ptr, 2345); /* this call to realloc invokes _heap_check */
  5408.  
  5409.    printf("_debug_realloc did not detect that a memory block
  5410.                was overwritten.\n");
  5411.  
  5412.    return EXIT_FAILURE;
  5413.  
  5414.    /* Possible output is:
  5415.  
  5416.       Memory was overwritten before the allocated memory block
  5417.       that starts at address 0x00150010.
  5418.       The first eight bytes of the memory block (in hex) are: 0000000000000000.
  5419.       This memory block was (re)allocated at line number 11 in TDRALLC.C.       */
  5420.  
  5421. }
  5422.  
  5423.  
  5424. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5425.  
  5426. o _debug_calloc - Reserve and Initialize Storage 
  5427. o _debug_free - Release Storage Blocks 
  5428. o _debug_malloc - Reserve Storage Blocks 
  5429. o _dump_allocated - Get Information about Allocated Storage 
  5430. o _heap_check - Validate Run-Time Storage Heap 
  5431. o realloc  - Change Reserved Storage Block Size 
  5432. o Using the Debug Memory Management Functions 
  5433. o malloc.h 
  5434. o stdlib.h 
  5435.  
  5436.  
  5437. ΓòÉΓòÉΓòÉ 6.46. difftime  - Compute Time Difference ΓòÉΓòÉΓòÉ
  5438.  
  5439.  
  5440. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5441.  
  5442. #include <time.h>
  5443.  
  5444. double difftime(time_t time2, time_t time1);
  5445.  
  5446.  
  5447. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5448.  
  5449. Language Level: ANSI, SAA 
  5450.  
  5451. The difftime function computes the difference in seconds between time2 and 
  5452. time1. The difftime function returns the elapsed time in seconds from time1 to 
  5453. time2 as a double precision number.  Type time_t is defined in <time.h>. 
  5454.  
  5455. Example of difftime 
  5456.  
  5457.  
  5458. ΓòÉΓòÉΓòÉ <hidden> Example of difftime ΓòÉΓòÉΓòÉ
  5459.  
  5460. /************************************************************************
  5461. *
  5462.  
  5463. This example shows a timing application using difftime.  The example calculates 
  5464. how long, on average, it takes to find the prime numbers from 2 to 10000. 
  5465.  
  5466.                                                                         *
  5467. ************************************************************************/
  5468.  
  5469. #include <time.h>
  5470. #include <stdio.h>
  5471.  
  5472. #define RUNS 1000
  5473. #define SIZE 10000
  5474.  
  5475. int mark[SIZE];
  5476.  
  5477. int main(void)
  5478. {
  5479.    time_t start, finish;
  5480.    int i, loop, n, num;
  5481.  
  5482.    time(&start);
  5483.  
  5484.    /*  This loop finds the prime numbers between 2 and SIZE   */
  5485.    for (loop = 0; loop < RUNS; ++loop)
  5486.       {
  5487.       for (n = 0; n < SIZE; ++n)
  5488.          mark [n] = 0;
  5489.       /*  This loops marks all the composite numbers with -1  */
  5490.       for (num = 0, n = 2; n < SIZE; ++n)
  5491.          if ( ! mark[n])
  5492.          {
  5493.             for (i = 2 * n; i < SIZE; i += n)
  5494.                 mark[i] = -1;
  5495.             ++num;
  5496.             }
  5497.       }
  5498.    time(&finish);
  5499.    printf("Program takes an average of %f seconds "
  5500.                   "to find %d primes.\n",
  5501.                    difftime(finish,start)/RUNS, num);
  5502. }
  5503.  
  5504. /********************  Output should be similar:  *****************
  5505.  
  5506. The program takes an average of 0.106000 seconds to find 1229 primes.
  5507. */
  5508.  
  5509.  
  5510. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5511.  
  5512. o asctime  - Convert Time 
  5513. o ctime  - Convert Time 
  5514. o gmtime  - Convert Time 
  5515. o localtime  - Convert Time 
  5516. o mktime  - Convert Local Time 
  5517. o strftime  - Convert to Formatted Time 
  5518. o time  - Determine Current Time 
  5519. o time.h 
  5520.  
  5521.  
  5522. ΓòÉΓòÉΓòÉ 6.47. _disable - Disable Interrupts ΓòÉΓòÉΓòÉ
  5523.  
  5524.  
  5525. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5526.  
  5527. #include <builtin.h>
  5528.  
  5529. void _disable( void );
  5530.  
  5531.  
  5532. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5533.  
  5534. Language Level: Extension 
  5535.  
  5536. The _disable function disables interrupts by executing the CLI machine 
  5537. instruction. It disables interrupts until the instruction after a call to 
  5538. _enable has been executed. 
  5539.  
  5540. Because it is a built-in function and has no backing code in the library: 
  5541.  
  5542. o You cannot take the address of _disable. 
  5543. o You cannot parenthesize a _disable function call, because parentheses specify 
  5544.   a call to the backing code for the function in the library. 
  5545.  
  5546. You can run code containing this function only at ring zero. Otherwise, an 
  5547. invalid instruction exception is generated. 
  5548.  
  5549. This function has no return value. 
  5550.  
  5551. Example of _disable 
  5552.  
  5553.  
  5554. ΓòÉΓòÉΓòÉ <hidden> Example of _disable ΓòÉΓòÉΓòÉ
  5555.  
  5556. /************************************************************************
  5557. *
  5558.  
  5559. In this example, the _disable function disables interrupts by executing a CLI 
  5560. instruction. 
  5561.  
  5562.                                                                         *
  5563. ************************************************************************/
  5564.  
  5565. #include <builtin.h>
  5566.  
  5567. int main(void)
  5568.    {
  5569.    /* ------------------------------------------------------ */
  5570.    /* The expected assembler instruction looks like this :   */
  5571.    /*       CLI                                              */
  5572.    /* -------------------------------------------------------*/
  5573.    _disable();
  5574.    return 0;
  5575. }
  5576.  
  5577.  
  5578. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5579.  
  5580. o _enable - Enable Interrupts 
  5581. o _interrupt - Call Interrupt  Procedure 
  5582.  
  5583.  
  5584. ΓòÉΓòÉΓòÉ 6.48. div  - Calculate Quotient and Remainder ΓòÉΓòÉΓòÉ
  5585.  
  5586.  
  5587. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5588.  
  5589. #include <stdlib.h>
  5590.  
  5591. div_t div(int numerator, int denominator);
  5592.  
  5593.  
  5594. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5595.  
  5596. Language Level: ANSI, SAA 
  5597.  
  5598. The div function calculates the quotient and remainder of the division of 
  5599. numerator by denominator. 
  5600.  
  5601. The div function returns a structure of type div_t, containing both the 
  5602. quotient int quot and the remainder int rem.  If the return value cannot be 
  5603. represented, its value is undefined. If denominator is 0, an exception will be 
  5604. raised. 
  5605.  
  5606. Example of div 
  5607.  
  5608.  
  5609. ΓòÉΓòÉΓòÉ <hidden> Example of div ΓòÉΓòÉΓòÉ
  5610.  
  5611. /************************************************************************
  5612. *
  5613.  
  5614. This example uses the div function to calculate the quotients and remainders 
  5615. for a set of two dividends and two divisors. 
  5616.  
  5617.                                                                         *
  5618. ************************************************************************/
  5619.  
  5620. #include <stdlib.h>
  5621. #include <stdio.h>
  5622.  
  5623. int main(void)
  5624. {
  5625.    int num[2] = {45,-45};
  5626.    int den[2] = {7,-7};
  5627.    div_t ans;   /* div_t is a struct type containing two ints:
  5628.                    'quot' stores quotient; 'rem' stores remainder */
  5629.    short i,j;
  5630.  
  5631.    printf("Results of division:\n");
  5632.    for (i = 0; i < 2; i++)
  5633.       for (j = 0; j < 2; j++)
  5634.       {
  5635.          ans = div(num[i],den[j]);
  5636.          printf("Dividend: %6ld  Divisor: %6ld", num[i], den[j]);
  5637.          printf("  Quotient: %6ld  Remainder: %6ld\n", ans.quot, ans.rem);
  5638.       }
  5639. }
  5640.  
  5641. /*****************  Output should be similar to:  *****************
  5642.  
  5643. Results of division:
  5644. Dividend:  45  Divisor:   7  Quotient:   6  Remainder:   3
  5645. Dividend:  45  Divisor:  -7  Quotient:  -6  Remainder:   3
  5646. Dividend: -45  Divisor:   7  Quotient:  -6  Remainder:  -3
  5647. Dividend: -45  Divisor:  -7  Quotient:   6  Remainder:  -3
  5648. */ 
  5649.  
  5650.  
  5651. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5652.  
  5653. o ldiv  - Long Division 
  5654. o stdlib.h 
  5655.  
  5656.  
  5657. ΓòÉΓòÉΓòÉ 6.49. _DLL_InitTerm - Initialize and Terminate DLL Environment ΓòÉΓòÉΓòÉ
  5658.  
  5659.  
  5660. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5661.  
  5662. unsigned long _System _DLL_InitTerm(unsigned long modhandle,
  5663.                                             unsigned long flag);
  5664.  
  5665.  
  5666. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5667.  
  5668. Language Level: Extension 
  5669.  
  5670. The initialization and termination entry point for a DLL is the _DLL_InitTerm 
  5671. function. When each new process gains access to the DLL, this function 
  5672. initializes the necessary environment for the DLL, including storage, 
  5673. semaphores, and variables. When each process frees its access to the DLL, the 
  5674. _DLL_InitTerm function terminates the DLL environment created for that process. 
  5675.  
  5676. The default _DLL_InitTerm function supplied by the C/C++ Tools compiler 
  5677. performs the actions required to initialize and terminate the runtime 
  5678. environment. It is called automatically when you link to the DLL. If your DLL 
  5679. requires initialization or termination actions in addition to the actions 
  5680. performed for the runtime environment, you will need to create your own 
  5681. _DLL_InitTerm function. 
  5682.  
  5683. If the value of the flag parameter is 0, the DLL environment is initialized. If 
  5684. the value of the flag parameter is 1, the DLL environment is ended. 
  5685.  
  5686. The modhandle parameter is the module handle assigned by the operating system 
  5687. for this DLL. The module handle can be used as a parameter to various OS/2 API 
  5688. calls.  For example, DosQueryModuleName can be used to return the fully 
  5689. qualified path name of the DLL, which tells you where the DLL was loaded from. 
  5690.  
  5691. The return code from _DLL_InitTerm tells the loader if the initialization or 
  5692. termination was performed successfully. If the call was successful, 
  5693. _DLL_InitTerm returns a nonzero value. A return code of 0 indicates that the 
  5694. function failed. If a failure is indicated, the loader will not load the 
  5695. program that is accessing the DLL. 
  5696.  
  5697. Because it is called by the operating system loader, the _DLL_InitTerm function 
  5698. must be compiled using _System linkage. 
  5699.  
  5700. Note:  A _DLL_InitTerm function for a subsystem DLL has the same prototype, but 
  5701. the content of the function is different because there is no runtime 
  5702. environment to initialize or terminate. 
  5703.  
  5704. Example of _DLL_InitTerm 
  5705.  
  5706. Example of _DLL_InitTerm for a Subsystem 
  5707.  
  5708.  
  5709. ΓòÉΓòÉΓòÉ <hidden> Example of _DLL_InitTerm ΓòÉΓòÉΓòÉ
  5710.  
  5711. /************************************************************************
  5712. *
  5713.  
  5714. The following example shows the _DLL_InitTerm function from the SAMPLE03 
  5715. program that is shipped with the C/C++ Tools product. 
  5716.  
  5717.                                                                         *
  5718. ************************************************************************/
  5719.  
  5720. #define  INCL_DOSMODULEMGR
  5721. #define  INCL_DOSPROCESS
  5722. #include <os2.h>
  5723. #include <stdlib.h>
  5724. #include <stdio.h>
  5725. #include <string.h>
  5726.  
  5727. /* _CRT_init is the C run-time environment initialization function.         */
  5728. /* It will return 0 to indicate success and -1 to indicate failure.         */
  5729.  
  5730. int _CRT_init(void);
  5731. #ifdef   STATIC_LINK
  5732.  
  5733. /* _CRT_term is the C run-time environment termination function.            */
  5734. /* It only needs to be called when the C run-time functions are statically  */
  5735. /* linked.                                                                  */
  5736.  
  5737. void _CRT_term(void);
  5738. #else
  5739.  
  5740. /* A clean up routine registered with DosExitList must be used if runtime   */
  5741. /* calls are required and the runtime is dynamically linked.  This will     */
  5742. /* guarantee that this clean up routine is run before the library DLL is    */
  5743. /* terminated.                                                              */
  5744.  
  5745. static void _System cleanup(ULONG ulReason);
  5746. #endif
  5747. size_t nSize;
  5748. int *pArray;
  5749.  
  5750. /* _DLL_InitTerm is the function that gets called by the operating system   */
  5751. /* loader when it loads and frees this DLL for each process that accesses   */
  5752. /* this DLL.  However, it only gets called the first time the DLL is loaded */
  5753. /* and the last time it is freed for a particular process.  The system      */
  5754. /* linkage convention MUST be used because the operating system loader is   */
  5755. /* calling this function.                                                   */
  5756.  
  5757. unsigned long _System _DLL_InitTerm(unsigned long hModule, unsigned long
  5758.                                     ulFlag)
  5759. {
  5760.    size_t i;
  5761.    APIRET rc;
  5762.    char namebuf[CCHMAXPATH];
  5763.  
  5764.    /* If ulFlag is zero then the DLL is being loaded so initialization should*/
  5765.    /* be performed.  If ulFlag is 1 then the DLL is being freed so          */
  5766.    /* termination should be performed.                                      */
  5767.  
  5768.    switch (ulFlag) {
  5769.       case 0 :
  5770.  
  5771.          /*******************************************************************/
  5772.          /* The C run-time environment initialization function must be      */
  5773.          /* called before any calls to C run-time functions that are not    */
  5774.          /* inlined.                                                        */
  5775.          /*******************************************************************/
  5776.  
  5777.          if (_CRT_init() == -1)
  5778.             return 0UL;
  5779. #ifndef  STATIC_LINK
  5780.  
  5781.          /*******************************************************************/
  5782.          /* A DosExitList routine must be used to clean up if runtime calls */
  5783.          /* are required and the runtime is dynamically linked.             */
  5784.          /*******************************************************************/
  5785.  
  5786.             if (rc = DosExitList(0x0000FF00|EXLST_ADD, cleanup))
  5787.             printf("DosExitList returned %lu\n", rc);
  5788. #endif
  5789.          if (rc = DosQueryModuleName(hModule, CCHMAXPATH, namebuf))
  5790.             printf("DosQueryModuleName returned %lu\n", rc);
  5791.          else
  5792.             printf("The name of this DLL is %s\n", namebuf);
  5793.          srand(17);
  5794.          nSize = (rand()%128)+32;
  5795.          printf("The array size for this process is %u\n", nSize);
  5796.          if ((pArray = malloc(nSize *sizeof(int))) == NULL) {
  5797.             printf("Could not allocate space for unsorted array.\n");
  5798.             return 0UL;
  5799.          }
  5800.          for (i = 0; i < nSize; ++i)
  5801.             pArray[i] = rand();
  5802.          break;
  5803.       case 1 :
  5804. #ifdef   STATIC_LINK
  5805.          printf("The array will now be freed.\n");
  5806.          free(pArray);
  5807.          _CRT_term();
  5808. #endif
  5809.          break;
  5810.       default  :
  5811.          printf("ulFlag = %lu\n", ulFlag);
  5812.          return 0UL;
  5813.    }
  5814.  
  5815.    /* A non-zero value must be returned to indicate success.                */
  5816.  
  5817.    return 1UL;
  5818. }
  5819. #ifndef  STATIC_LINK
  5820. static void cleanup(ULONG ulReason)
  5821. {
  5822.    if (!ulReason) {
  5823.       printf("The array will now be freed.\n");
  5824.       free(pArray);
  5825.    }
  5826.    DosExitList(EXLST_EXIT, cleanup);
  5827.    return ;
  5828. }
  5829. #endif
  5830.  
  5831.  
  5832. ΓòÉΓòÉΓòÉ <hidden> Example of _DLL_InitTerm for a Subsystem ΓòÉΓòÉΓòÉ
  5833.  
  5834. /************************************************************************
  5835. *
  5836.  
  5837. The following example shows the _DLL_InitTerm function from the SAMPLE05 
  5838. program that is shipped with the C/C++ Tools product. 
  5839.  
  5840.                                                                         *
  5841. ************************************************************************/
  5842.  
  5843. /* _DLL_InitTerm() - called by the loader for DLL
  5844. initialization/termination  */
  5845. /* This function must return a non-zero value if successful and a zero value  */
  5846. /* if unsuccessful.                                                           */
  5847.  
  5848. unsigned long _DLL_InitTerm( unsigned long hModule, unsigned long ulFlag )
  5849.    {
  5850.    APIRET rc;
  5851.  
  5852.    /* If ulFlag is zero then initialization is required:                      */
  5853.    /*    If the shared memory pointer is NULL then the DLL is being loaded    */
  5854.    /*    for the first time so acquire the named shared storage for the       */
  5855.    /*    process control structures.  A linked list of process control        */
  5856.    /*    structures will be maintained.  Each time a new process loads this   */
  5857.    /*    DLL, a new process control structure is created and it is inserted   */
  5858.    /*    at the end of the list by calling DLLREGISTER.                       */
  5859.    /*                                                                         */
  5860.    /* If ulFlag is 1 then termination is required:                            */
  5861.    /*    Call DLLDEREGISTER which will remove the process control structure   */
  5862.    /*    and free the shared memory block from its virtual address space.     */
  5863.  
  5864.    switch( ulFlag )
  5865.       {
  5866.       case 0:
  5867.          if ( !ulProcessCount )
  5868.             {
  5869.             /* Create the shared mutex semaphore.                             */
  5870.  
  5871.             if ( ( rc = DosCreateMutexSem( SHARED_SEMAPHORE_NAME,
  5872.                                            &hmtxSharedSem,
  5873.                                            0,
  5874.                                            FALSE ) ) != NO_ERROR )
  5875.                {
  5876.                printf( "DosCreateMutexSem rc = %lu\n", rc );
  5877.                return 0;
  5878.                }
  5879.             }
  5880.  
  5881.          /* Register the current process.                                     */
  5882.  
  5883.          if ( DLLREGISTER( ) )
  5884.             return 0;
  5885.          break;
  5886.  
  5887.       case 1:
  5888.          /* De-register the current process.                                  */
  5889.  
  5890.          if ( DLLDEREGISTER( ) )
  5891.             return 0;
  5892.          break;
  5893.  
  5894.       default:
  5895.          return 0;
  5896.       }
  5897.  
  5898.    /* Indicate success.  Non-zero means success!!!             */
  5899.  
  5900.    return 1;
  5901.    }
  5902.  
  5903.  
  5904. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  5905.  
  5906. o _CRT_init - Initialize DLL Runtime Environment 
  5907. o _CRT_term - Terminate DLL Runtime Environment 
  5908.  
  5909.  
  5910. ΓòÉΓòÉΓòÉ 6.50. _dump_allocated - Get Information about Allocated Storage ΓòÉΓòÉΓòÉ
  5911.  
  5912.  
  5913. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  5914.  
  5915. #define __DEBUG_ALLOC__
  5916. #include <stdlib.h>  /* also defined in <malloc.h> */
  5917.  
  5918. void _dump_allocated(int nbytes);
  5919.  
  5920.  
  5921. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  5922.  
  5923. Language Level: Extension 
  5924.  
  5925. The _dump_allocated function prints out information about each memory block 
  5926. that is currently allocated, if it was allocated by the debug versions of the 
  5927. memory management functions. The nbytes argument specifies how many bytes of 
  5928. each memory block are to be printed. 
  5929.  
  5930. If nbytes is a negative value, all the bytes of each memory block are printed. 
  5931. If nbytes is 0, no bytes are printed.  If nbytes is a positive value, the 
  5932. number of bytes printed for each block will be the minimum of the requested 
  5933. size and the block size. 
  5934.  
  5935. Note:  You should call the _dump_allocated function at a point in your code 
  5936. where you would like a report of the currently allocated memory. For example, a 
  5937. good place to call _dump_allocated is a point where most of the memory is 
  5938. already freed and you want to find a memory leak, such as the end of a program. 
  5939.  
  5940. Example of _dump_allocated 
  5941.  
  5942.  
  5943. ΓòÉΓòÉΓòÉ <hidden> Example of _dump_allocated ΓòÉΓòÉΓòÉ
  5944.  
  5945. /************************************************************************
  5946. *
  5947. This example allocates three memory blocks, and then calls _dump_allocated to 
  5948. dump information and the first 8 bytes for each memory block. 
  5949.  
  5950.                                                                         *
  5951. ************************************************************************/
  5952.  
  5953. rules=none.
  5954.  
  5955. #ifndef __DEBUG_ALLOC__     /* this macro could also be defined */
  5956.    #define __DEBUG_ALLOC__  /*      from the command line       */
  5957. #endif
  5958. #include <stdlib.h>
  5959. #include <string.h>
  5960. #include <stdio.h>
  5961.  
  5962. #define INIT_STR     "It\0works"
  5963. #define INIT_STR_LEN (sizeof(INIT_STR) - 1)
  5964.  
  5965. int main(void)
  5966. {
  5967.    char *pBlock1;
  5968.    char *pBlock2;
  5969.    char *pBlock3;
  5970.  
  5971.    if (( pBlock1 = malloc(35) ) == NULL)    /* allocate first memory block */
  5972.    {
  5973.       printf( "Could not allocate first memory block.\n" );
  5974.       return EXIT_FAILURE;
  5975.    }
  5976.  
  5977.    memcpy(pBlock1, INIT_STR, INIT_STR_LEN);    /* initialize first memory block */
  5978.  
  5979.    if (( pBlock2 = calloc(2, 120) ) == NULL)   /* allocate second memory block */
  5980.    {
  5981.       printf( "Could not allocate second memory block.\n" );
  5982.       return EXIT_FAILURE;
  5983.    }
  5984.  
  5985.    memcpy(pBlock2, INIT_STR, INIT_STR_LEN);    /* initialize second memory block */
  5986.  
  5987.    if (( pBlock3 = realloc(NULL, 2235) ) == NULL) /* allocate third memory block */
  5988.    {
  5989.       printf( "Could not allocate third memory block.\n" );
  5990.       return EXIT_FAILURE;
  5991.    }
  5992.  
  5993.    memcpy(pBlock3, INIT_STR, INIT_STR_LEN);    /* initialize third memory block */
  5994.  
  5995.    if (( pBlock3 = realloc(pBlock3, 300) ) == NULL) /* reallocate third memory */
  5996.                                                     /* block to different size */
  5997.    {
  5998.       printf("Could not reallocate third memory block.\n");
  5999.       return EXIT_FAILURE;
  6000.    }
  6001.  
  6002.    _dump_allocated(8);   /* show first eight bytes of each memory block */
  6003.  
  6004.    return 0;
  6005.  
  6006.    /* Possible output is:
  6007.  
  6008.  ============================================================================
  6009.                   START OF DUMP OF ALLOCATED MEMORY BLOCKS
  6010.  ============================================================================
  6011.  Address: 0x00180010      Size: 0x0000012C (300)
  6012.  This memory block was (re)allocated at line number 41 in TDMPAL.C.
  6013.  Memory contents:  49740077 6F726B73                      {It.works        }
  6014.  ============================================================================
  6015.  Address: 0x00170010      Size: 0x000000F0 (240)
  6016.  This memory block was (re)allocated at line number 25 in TDMPAL.C.
  6017.  Memory contents:  49740077 6F726B73                      {It.works        }
  6018.  ============================================================================
  6019.  Address: 0x00150010      Size: 0x00000023 (35)
  6020.  This memory block was (re)allocated at line number 17 in TDMPAL.C.
  6021.  Memory contents:  49740077 6F726B73                      {It.works        }
  6022.  ============================================================================
  6023.                   END OF DUMP OF ALLOCATED MEMORY BLOCKS
  6024.  ============================================================================
  6025.                                                                        */
  6026.  
  6027. }
  6028.  
  6029.  
  6030. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6031.  
  6032. o _debug_calloc - Reserve and Initialize Storage 
  6033. o _debug_free - Release Storage Blocks 
  6034. o _debug_malloc - Reserve Storage Blocks 
  6035. o _debug_realloc - Change Reserved Storage Block Size 
  6036. o _heap_check - Validate Run-Time Storage Heap 
  6037. o Using the Debug Memory Management Functions 
  6038. o malloc.h 
  6039. o stdlib.h 
  6040.  
  6041.  
  6042. ΓòÉΓòÉΓòÉ 6.51. _dup -Associate Second Handle with Open File ΓòÉΓòÉΓòÉ
  6043.  
  6044.  
  6045. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6046.  
  6047. #include <io.h>
  6048.  
  6049. int _dup(int handle);
  6050.  
  6051.  
  6052. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6053.  
  6054. Language Level: Extension 
  6055.  
  6056. The _dup function associates a second file handle with a currently open file. 
  6057. You can carry out operations on the file using either file handle because all 
  6058. handles associated with a given file use the same file pointer. Creation of a 
  6059. new handle does not affect the type of access allowed for the file. 
  6060.  
  6061. For example, given: 
  6062.  
  6063.    handle2 = _dup(handle1)
  6064. handle2 will have the same file access mode (text or binary) as handle1. In 
  6065. addition, if handle1 was originally opened with the O_APPEND flag (described in 
  6066. _open - Open File), handle2 will also have that attribute. 
  6067.  
  6068. Warning: Both handles share a single file pointer. Therefore, if you reposition 
  6069. a file using handle1, the position in the file returned by handle2 will also 
  6070. change. 
  6071.  
  6072. If you duplicate a file handle for an open stream, the resulting file handle 
  6073. has the same restrictions as the original file handle. 
  6074.  
  6075. The _dup function returns the next available file handle for the given file. 
  6076. The _dup function returns a new file handle. It returns -1 if an error occurs 
  6077. and sets errno to one of the following values: 
  6078.  
  6079. Value          Meaning 
  6080. EBADF          The file handle is not valid. 
  6081. EMFILE         No more file handles are available. 
  6082. EOS2ERR        The call to the operating system was not successful. 
  6083.  
  6084. Example of _dup 
  6085.  
  6086.  
  6087. ΓòÉΓòÉΓòÉ <hidden> Example of _dup ΓòÉΓòÉΓòÉ
  6088.  
  6089. /************************************************************************
  6090. *
  6091.  
  6092. This example makes a second file handle, fh3, refer to the same file as the 
  6093. file handle fh1 using _dup. The file handle fh2 is then associated with the 
  6094. file edopen.da2, and finally fh2 is forced to associate with edopen.da1 by the 
  6095. _dup2 function. 
  6096.  
  6097.                                                                         *
  6098. ************************************************************************/
  6099.  
  6100. #include <io.h>
  6101. #include <stdio.h>
  6102. #include <fcntl.h>
  6103. #include <sys\stat.h>
  6104.  
  6105. int main(void)
  6106. {
  6107.    int fh1, fh2, fh3;
  6108.  
  6109.    if ( -1 == (fh1 = _open("edopen.da1", O_CREAT | O_TRUNC | O_RDWR ,
  6110.    S_IREAD | S_IWRITE)))
  6111.    {
  6112.       perror("Unable to open edopen.da1");
  6113.       return 1;
  6114.    }
  6115.  
  6116.    /* fh3 refers to the sample file as fh1 */
  6117.    if (-1 == (fh3 = _dup(fh1))) {
  6118.       perror("Unable to dup");
  6119.       _close(fh1);
  6120.       return 1;
  6121.    }
  6122.    else
  6123.       printf("Successfully performed dup handle.\n");
  6124.  
  6125.    if ( -1 == (fh2 = _open("edopen.da2", O_CREAT | O_TRUNC | O_RDWR ,
  6126.    S_IREAD | S_IWRITE)))
  6127.    {
  6128.       perror("Unable to open edopen.da2");
  6129.       _close(fh1);
  6130.       _close(fh3);
  6131.       return 1;
  6132.    }
  6133.  
  6134.    if (-1 == _dup2(fh1,fh2))  /* Force fh2 to the refer to the same file */
  6135.    {                         /* as fh1.                                 */
  6136.       perror("Unable to dup2");
  6137.    }
  6138.    else
  6139.       printf("Successfully performed dup2 handle.\n");
  6140.  
  6141.    _close(fh1);
  6142.    _close(fh2);
  6143.    _close(fh3);
  6144.  
  6145.    return 0;
  6146.  
  6147. /******************  The expected output is:  ***************************
  6148.  
  6149.       Successfully performed dup handle.
  6150.       Successfully performed dup2 handle.
  6151. */
  6152. }
  6153.  
  6154.  
  6155. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6156.  
  6157. o _close - Closes File Associated with Handle 
  6158. o _creat - Create New File 
  6159. o _dup2 -Associate Second Handle with Open File 
  6160. o _open - Open File 
  6161. o _sopen - Open Shared File 
  6162. o io.h 
  6163.  
  6164.  
  6165. ΓòÉΓòÉΓòÉ 6.52. _dup2 -Associate Second Handle with Open File ΓòÉΓòÉΓòÉ
  6166.  
  6167.  
  6168. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6169.  
  6170. #include <io.h>
  6171.  
  6172. int _dup2(int handle1, int handle2);
  6173.  
  6174.  
  6175. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6176.  
  6177. Language Level: Extension 
  6178.  
  6179. The _dup2 function associates a second file handle with a currently open file. 
  6180. You can carry out operations on the file using either file handle because all 
  6181. handles associated with a given file use the same file pointer. 
  6182.  
  6183. The handle handle2 will point to the same file as handle1, but will retain the 
  6184. file access mode (text or binary) that it had before duplication.  In addition, 
  6185. if handle2 was originally opened with the O_APPEND flag, it will also retain 
  6186. that attribute. 
  6187.  
  6188. Warning: Both handles share a single file position. Therefore, if you 
  6189. reposition a file using handle1, the position in the file returned by handle2 
  6190. will also change. 
  6191.  
  6192. If you duplicate a file handle for an open stream (using fileno), the resulting 
  6193. file handle has the same restrictions as the original file handle. 
  6194.  
  6195. The _dup2 function forces the given handle, handle2, to refer to the same file 
  6196. as handle1. If handle2 is associated with an open file at the time of the call, 
  6197. that file is closed. The _dup2 function returns 0 to indicate success. It 
  6198. returns -1 if an error occurs and sets errno to one of the following values: 
  6199.  
  6200. Value          Meaning 
  6201. EBADF          The file handle is not valid. 
  6202. EMFILE         No more file handles are available. 
  6203. EOS2ERR        The call to the operating system was not successful. 
  6204.  
  6205. Example of _dup2 
  6206.  
  6207.  
  6208. ΓòÉΓòÉΓòÉ <hidden> Example of _dup2 ΓòÉΓòÉΓòÉ
  6209.  
  6210. /************************************************************************
  6211. *
  6212.  
  6213. This example makes a second file handle, fh3, refer to the same file as the 
  6214. file handle fh1 using _dup. The file handle fh2 is then associated with the 
  6215. file edopen.da2, and finally fh2 is forced to associate with edopen.da1 by the 
  6216. _dup2 function. 
  6217.  
  6218.                                                                         *
  6219. ************************************************************************/
  6220.  
  6221. #include <io.h>
  6222. #include <stdio.h>
  6223. #include <fcntl.h>
  6224. #include <sys\stat.h>
  6225.  
  6226. int main(void)
  6227. {
  6228.    int fh1, fh2, fh3;
  6229.  
  6230.    if ( -1 == (fh1 = _open("edopen.da1", O_CREAT | O_TRUNC | O_RDWR ,
  6231.    S_IREAD | S_IWRITE)))
  6232.    {
  6233.       perror("Unable to open edopen.da1");
  6234.       return 1;
  6235.    }
  6236.  
  6237.    /* fh3 refers to the sample file as fh1 */
  6238.    if (-1 == (fh3 = _dup(fh1))) {
  6239.       perror("Unable to dup");
  6240.       _close(fh1);
  6241.       return 1;
  6242.    }
  6243.    else
  6244.       printf("Successfully performed dup handle.\n");
  6245.  
  6246.    if ( -1 == (fh2 = _open("edopen.da2", O_CREAT | O_TRUNC | O_RDWR ,
  6247.    S_IREAD | S_IWRITE)))
  6248.    {
  6249.       perror("Unable to open edopen.da2");
  6250.       _close(fh1);
  6251.       _close(fh3);
  6252.       return 1;
  6253.    }
  6254.  
  6255.    if (-1 == _dup2(fh1,fh2))  /* Force fh2 to the refer to the same file */
  6256.    {                         /* as fh1.                                 */
  6257.       perror("Unable to dup2");
  6258.    }
  6259.    else
  6260.       printf("Successfully performed dup2 handle.\n");
  6261.  
  6262.    _close(fh1);
  6263.    _close(fh2);
  6264.    _close(fh3);
  6265.  
  6266.    return 0;
  6267.  
  6268. /******************  The expected output is:  ***************************
  6269.  
  6270.       Successfully performed dup handle.
  6271.       Successfully performed dup2 handle.
  6272. */
  6273. }
  6274.  
  6275.  
  6276. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6277.  
  6278. o _close - Closes File Associated with Handle 
  6279. o _creat - Create New File 
  6280. o _dup -Associate Second Handle with Open File 
  6281. o _open - Open File 
  6282. o _sopen - Open Shared File 
  6283. o io.h 
  6284.  
  6285.  
  6286. ΓòÉΓòÉΓòÉ 6.53. _ecvt - Convert Floating-Point to Character ΓòÉΓòÉΓòÉ
  6287.  
  6288.  
  6289. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6290.  
  6291. #include <stdlib.h>
  6292.  
  6293. char *_ecvt(double value, int ndigits, int *decptr, int *signptr);
  6294.  
  6295.  
  6296. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6297.  
  6298. Language Level: Extension 
  6299.  
  6300. The _ecvt function converts a floating-point number to a character string. The 
  6301. variable value is the floating-point number to be converted. The _ecvt function 
  6302. stores ndigits digits of value as a string and adds a null character (\0). If 
  6303. the number of digits in value exceeds ndigits, the low-order digit is rounded. 
  6304. If there are fewer than ndigits digits, the string is padded with zeros. 
  6305.  
  6306. Only digits are stored in the string. You can obtain the position of the 
  6307. decimal point and the sign of value after the call from decptr and signptr. The 
  6308. variable decptr points to an integer value that gives the position of the 
  6309. decimal point with respect to the beginning of the string. A 0 or a negative 
  6310. integer value indicates that the decimal point lies to the left of the first 
  6311. digit. The variable signptr points to an integer that indicates the sign of the 
  6312. converted number. If the integer value is 0, the number is positive. If it is 
  6313. not 0, the number is negative. 
  6314.  
  6315. The _ecvt function also converts NaN and infinity values to the strings NAN and 
  6316. INFINITY, respectively. For more information on NaN and infinity values, see 
  6317. Infinity and NaN Support. 
  6318.  
  6319. Warning: For each thread, the _ecvt, _fcvt and _gcvt functions use a single, 
  6320. dynamically allocated buffer for the conversion. Any subsequent call that the 
  6321. same thread makes to these functions destroys the result of the previous call. 
  6322.  
  6323. The _ecvt function returns a pointer to the string of digits. A failure to 
  6324. allocate memory results in a NULL return value, and errno is set to ENOMEM. 
  6325. Because of the limited precision of the double type, no more than 16 decimal 
  6326. digits are significant in any conversion. 
  6327.  
  6328. Example of _ecvt 
  6329.  
  6330.  
  6331. ΓòÉΓòÉΓòÉ <hidden> Example of _ecvt ΓòÉΓòÉΓòÉ
  6332.  
  6333. /************************************************************************
  6334. *
  6335. This example reads in two floating-point numbers, calculates their product, and 
  6336. prints out only the billions digit of its character representation. At most, 16 
  6337. decimal digits of significance can be expected. The output assumes the user 
  6338. enters the numbers 1000000 and 3000. 
  6339.  
  6340.                                                                         *
  6341. ************************************************************************/
  6342.  
  6343. #include <stdio.h>
  6344. #include <stdlib.h>
  6345. #include <math.h>
  6346.  
  6347. int main(void)
  6348. {
  6349.     float x, y;
  6350.     double z;
  6351.     int w, b, decimal, sign;
  6352.     char *buffer;
  6353.  
  6354.     printf("Enter two floating-point numbers:\n");
  6355.     if ( scanf("%e %e", &x, 0x) != 2 )
  6356.     {
  6357.         printf("input error...\n");
  6358.         exit(-1);
  6359.     }
  6360.  
  6361.     z = x*y;
  6362.     printf("Their product is %g\n", z);
  6363.  
  6364.     w = log10( fabs(z) ) + 1.;
  6365.     buffer = _ecvt(z, w, &decimal, signed);
  6366.  
  6367.     b = decimal - 10;
  6368.     if (b < 0)
  6369.         printf("Their product does not exceed one billion.\n");
  6370.     else if (b > 15)
  6371.         printf("The billions digit of their product is insignificant.\n");
  6372.     else
  6373.         printf("The billions digit of their product is %c.\n", buffer[b]);
  6374.  
  6375.     return 0;
  6376.  
  6377. /*****  The expected output on input of 1000000 3000 is  **************
  6378.  
  6379.          Enter two floating point numbers:
  6380.          1000000 3000
  6381.          Their product is 3e+09
  6382.          the billions digit of their product is 3.
  6383.  
  6384. */
  6385. }
  6386.  
  6387.  
  6388. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6389.  
  6390. o _fcvt - Convert Floating-Point to String 
  6391. o _gcvt - Convert Floating-Point to String 
  6392. o Infinity and NaN Support 
  6393. o stdlib.h 
  6394.  
  6395.  
  6396. ΓòÉΓòÉΓòÉ 6.54. _enable - Enable Interrupts ΓòÉΓòÉΓòÉ
  6397.  
  6398.  
  6399. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6400.  
  6401. #include <builtin.h>  /* also defined in <stdlib.h> */
  6402.  
  6403. void _enable( void );
  6404.  
  6405.  
  6406. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6407.  
  6408. Language Level: Extension 
  6409.  
  6410. The _enable function enables interrupts by generating the STI machine 
  6411. instruction.  Interrupts are enabled after the instruction following STI has 
  6412. been executed. If interrupts are disabled and you call _enable followed 
  6413. immediately by a call to _disable, interrupts remain disabled. 
  6414.  
  6415. Because it is a built-in function and has no backing code in the library: 
  6416.  
  6417. o You cannot take the address of _enable. 
  6418. o You cannot parenthesize an _enable function call because parentheses specify 
  6419.   a call to the backing code for the function in the library. 
  6420.  
  6421. You can run code containing this function only at ring zero. Otherwise, an 
  6422. invalid instruction exception will be generated. 
  6423.  
  6424. There is no return value. 
  6425.  
  6426. Example of _enable 
  6427.  
  6428.  
  6429. ΓòÉΓòÉΓòÉ <hidden> Example of _enable ΓòÉΓòÉΓòÉ
  6430.  
  6431. /************************************************************************
  6432. *
  6433.  
  6434. In this example, the _enable function enables interrupts by executing an STI 
  6435. instruction. 
  6436.  
  6437.                                                                         *
  6438. ************************************************************************/
  6439.  
  6440. #include <builtin.h>
  6441.  
  6442. int main(void)
  6443.    {
  6444.    /* ------------------------------------------------------ */
  6445.    /* The expected assembler instruction looks like this :   */
  6446.    /*       STI                                              */
  6447.    /* ------------------------------------------------------ */
  6448.    _enable();
  6449.    return 0;
  6450. }
  6451.  
  6452.  
  6453. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6454.  
  6455. o _disable - Disable Interrupts 
  6456. o _interrupt - Call Interrupt  Procedure 
  6457.  
  6458.  
  6459. ΓòÉΓòÉΓòÉ 6.55. _endthread - Terminate Current Thread ΓòÉΓòÉΓòÉ
  6460.  
  6461.  
  6462. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6463.  
  6464. #include <stdlib.h>    /* also defined in <process.h> */
  6465.  
  6466. void _endthread(void);
  6467.  
  6468.  
  6469. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6470.  
  6471. Language Level: Extension 
  6472.  
  6473. The _endthread function explicitly ends a thread that you previously created 
  6474. with _beginthread before the thread has completed its function. For example, if 
  6475. some condition is not met, _endthread terminates the thread. When the thread 
  6476. has finished, it automatically ends itself with an implicit call to _endthread. 
  6477.  
  6478. Note: 
  6479.  
  6480.  1. When using the _beginthread and _endthread functions, you must specify the 
  6481.     /Gm+ compiler option to use the multithread libraries. 
  6482.  
  6483.  2. If you use DosCreateThread, you must explicitly call _endthread to 
  6484.     terminate the thread. 
  6485.  
  6486. There is no return value. 
  6487.  
  6488. Example of _endthread 
  6489.  
  6490.  
  6491. ΓòÉΓòÉΓòÉ <hidden> Example of _endthread ΓòÉΓòÉΓòÉ
  6492.  
  6493. /************************************************************************
  6494. *
  6495. In this example, the main program creates two threads, bonjour and au_revoir. 
  6496. The thread bonjour is forcibly terminated by a call to _endthread, while the 
  6497. au_revoir thread ends itself with an implicit call to _endthread. 
  6498.  
  6499. Note:  To run this example, you must compile it using the /Gm+ compile-time 
  6500. option. 
  6501.  
  6502.                                                                         *
  6503. ************************************************************************/
  6504.  
  6505. #define INCL_DOS
  6506. #include <os2.h>
  6507. #include <stdio.h>
  6508. #include <stdlib.h>
  6509. #include <process.h>
  6510.  
  6511. void bonjour(void *arg)
  6512. {
  6513.    int i = 0;
  6514.    while ( i++ < 5 )
  6515.       printf("Bonjour!\n");
  6516.  
  6517.    _endthread();              /* This thread ends itself explicitly */
  6518.    puts("thread should terminate before printing this");
  6519. }
  6520.  
  6521. void au_revoir(void *arg)
  6522. {
  6523.    int i = 0;
  6524.    while ( i++ < 5 )           /* This thread makes an implicit */
  6525.       printf("Au revoir!\n");  /* call to _endthread            */
  6526. }
  6527.  
  6528. int main(void)
  6529. {
  6530.    unsigned long tid1;
  6531.    unsigned long tid2;
  6532.  
  6533.    tid1 = _beginthread(bonjour, NULL, 8192, NULL);
  6534.    tid2 = _beginthread(au_revoir, NULL, 8192, NULL);
  6535.  
  6536.    if ( (tid1 == -1) || (tid2 == -1) )
  6537.    {
  6538.       printf("Unable to start threads.\n");
  6539.       exit(-1);
  6540.    }
  6541.  
  6542.    DosWaitThread( &tid2, DCWW_WAIT );   /*  wait until threads 1 and 2  */
  6543.    DosWaitThread( &tid1, DCWW_WAIT );   /*  have been completed         */
  6544.  
  6545.    return 0;
  6546.  
  6547.    /* Possible output could be:
  6548.  
  6549.       Bonjour!
  6550.       Au revoir!
  6551.       Bonjour!
  6552.       Au revoir!
  6553.       Bonjour!
  6554.       Au revoir!
  6555.       Bonjour!
  6556.       Au revoir!
  6557.       Bonjour!
  6558.       Au revoir!           */
  6559.  
  6560. }
  6561.  
  6562.  
  6563. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6564.  
  6565. o _beginthread - Create New Thread 
  6566. o /Gm+ option. 
  6567. o stdlib.h 
  6568. o process.h 
  6569.  
  6570.  
  6571. ΓòÉΓòÉΓòÉ 6.56. __eof - Determine End of File ΓòÉΓòÉΓòÉ
  6572.  
  6573.  
  6574. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6575.  
  6576. #include <io.h>
  6577.  
  6578. int __eof (int handle);
  6579.  
  6580.  
  6581. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6582.  
  6583. Language Level: Extension 
  6584.  
  6585. The __eof function determines whether the file pointer has reached the 
  6586. end-of-file for the file associated with handle. You cannot use __eof on a 
  6587. nonseekable file; it will fail. 
  6588.  
  6589. The __eof function returns the value 1 if the current position is the end of 
  6590. the file or 0 if it is not. A return value of -1 shows an error, and the system 
  6591. sets errno to the following values: 
  6592.  
  6593. Value          Meaning 
  6594. EBADF          File handle is not valid. 
  6595. EOS2ERR        The call to the operating system was not successful. 
  6596.  
  6597. Example of __eof 
  6598.  
  6599.  
  6600. ΓòÉΓòÉΓòÉ <hidden> Example of __eof ΓòÉΓòÉΓòÉ
  6601.  
  6602. /************************************************************************
  6603. *
  6604.  
  6605. This example creates the file sample.dat and then checks if the file pointer is 
  6606. at the end of that file using the __eof function: 
  6607.  
  6608.                                                                         *
  6609. ************************************************************************/
  6610.  
  6611. #include <sys\stat.h>
  6612. #include <io.h>
  6613. #include <stdio.h>
  6614.  
  6615. int main(void)
  6616. {
  6617.    int fh, returnValue;
  6618.  
  6619.    fh = _creat("sample.dat", S_IREAD | S_IWRITE);
  6620.  
  6621.    if ( -1 == fh)
  6622.    {
  6623.       perror("Error creating sample.dat");
  6624.       return 1;
  6625.    }
  6626.  
  6627.    if ( -1 == (returnValue = __eof(fh)))
  6628.    {
  6629.       perror("eof function error");
  6630.       return 1;
  6631.    }
  6632.    if (returnValue == 1)
  6633.       printf("File pointer is at end-of-file position.\n");
  6634.    else
  6635.       printf("File pointer is not at end-of-file position.\n");
  6636.    _close(fh);
  6637.    return 0;
  6638.  
  6639. /****************  The expected output is:  *****************************
  6640.  
  6641.       File pointer is at end-of-file position.
  6642. */
  6643.  
  6644. }
  6645.  
  6646.  
  6647. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6648.  
  6649. o _chsize - Alter Length of File 
  6650. o _creat - Create New File 
  6651. o _filelength - Determine File Length 
  6652. o _sopen - Open Shared File 
  6653. o _open - Open File 
  6654. o io.h 
  6655.  
  6656.  
  6657. ΓòÉΓòÉΓòÉ 6.57. erf  - Calculate Error Functions ΓòÉΓòÉΓòÉ
  6658.  
  6659.  
  6660. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6661.  
  6662. #include <math.h> /* SAA extensions to ANSI */
  6663.  
  6664. double erf(double x);
  6665.  
  6666. double erfc(double x);
  6667.  
  6668.  
  6669. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6670.  
  6671. Language Level: SAA 
  6672.  
  6673. The erf function calculates the error function. The erfc function returns the 
  6674. value of 1.0 - erf(x);.  The erfc function is used in place of erf for large 
  6675. values of x. 
  6676.  
  6677. Example of erf - erfc 
  6678.  
  6679.  
  6680. ΓòÉΓòÉΓòÉ <hidden> Example of erf - erfc ΓòÉΓòÉΓòÉ
  6681.  
  6682. /************************************************************************
  6683. *
  6684.  
  6685. This example uses erf to compute the error function of two numbers. 
  6686.  
  6687.                                                                         *
  6688. ************************************************************************/
  6689.  
  6690. #include <stdio.h>
  6691. #include <math.h>
  6692.  
  6693. double smallx, largex, value;
  6694.  
  6695. int main(void)
  6696. {
  6697.    smallx = 0.1;
  6698.    largex = 10.0;
  6699.  
  6700.    value = erf(smallx);         /* value = 0.112463 */
  6701.    printf("Error value for 0.1: %lf\n", value);
  6702.  
  6703.    value = erfc(largex);        /* value = 2.088488e-45 */
  6704.    printf("Error value for 10.0: %le\n", value);
  6705. }
  6706.  
  6707. /*****************  Output should be similar to:  *****************
  6708.  
  6709. Error value for 0.1: 0.112463
  6710. Error value for 10.0: 2.088488e-45
  6711. */
  6712.  
  6713.  
  6714. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6715.  
  6716. o Bessel Functions 
  6717. o math.h 
  6718. o gamma  - Gamma Function 
  6719.  
  6720.  
  6721. ΓòÉΓòÉΓòÉ 6.58. _execl - _execvp - Load and Run Child Process ΓòÉΓòÉΓòÉ
  6722.  
  6723.  
  6724. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6725.  
  6726. #include <process.h>
  6727.  
  6728. int _execl(char *pathname, char *arg0, char *arg1,..., char *argn, NULL);
  6729.  
  6730. int _execle(char *pathname, char *arg0, char *arg1,..., char *argn,
  6731.                                                   NULL, char *envp[ ]);
  6732.  
  6733. int _execlp(char *pathname, char *arg0, char *arg1,..., char *argn, NULL);
  6734.  
  6735. int _execlpe(char *pathname, char *arg0, char *arg1,..., char *argn,
  6736.                                                   NULL, char *envp[ ]);
  6737.  
  6738. int _execv(char *pathname, char *argv[ ]);
  6739.  
  6740. int _execve(char *pathname, char *argv[ ],char *envp[ ]);
  6741.  
  6742. int _execvp(char *pathname, char *argv[ ]);
  6743.  
  6744. int _execvpe(char *pathname, char *argv[ ], char *envp[ ]);
  6745.  
  6746.  
  6747. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6748.  
  6749. Language Level: Extension 
  6750.  
  6751. The _exec functions load and run new child processes. The parent process is 
  6752. ended after the child process has started.  Sufficient storage must be 
  6753. available for loading and running the child process. 
  6754.  
  6755. All of the _exec functions are versions of the same routine;  the letters at 
  6756. the end determine the specific variation: 
  6757.  
  6758. Letter    Variation 
  6759.  p        Uses PATH environment variable to find the file to be run 
  6760.  l        Passes a list of command line arguments separately 
  6761.  v        Passes to the child process an array of pointers to command-line 
  6762.           arguments 
  6763.  e        Passes to the child process an array of pointers to environment 
  6764.           strings. 
  6765.  
  6766. The pathname argument specifies the file to run as the child process.  The 
  6767. pathname can specify a full path from the root, a partial path from the current 
  6768. working directory, or a file name.  If pathname does not have a file name 
  6769. extension or does not end with a period, the _exec functions will add the .EXE 
  6770. extension and search for the file.  If pathname has an extension, the _exec 
  6771. function uses only that extension. If pathname ends with a period, the _exec 
  6772. functions search for pathname with no extension.  The _execlp, _execlpe, 
  6773. _execvp, and _execvpe functions search for the pathname in the directories that 
  6774. the PATH environment variable specifies. 
  6775.  
  6776. You pass arguments to the new process by giving one or more pointers to 
  6777. character strings as arguments in the _exec call.  These character strings form 
  6778. the argument list for the child process. 
  6779.  
  6780. The compiler can pass the argument pointers as separate arguments (_execl, 
  6781. _execle, _execlp, and _execlpe) or as an array of pointers (_execv, _execve, 
  6782. _execvp, and _execvpe).  You should pass at least one argument, either arg0 or 
  6783. argv[0], to the child process. If you do not, an argument will be returned that 
  6784. points to the same file as the path name argument you specified. This argument 
  6785. may not be exactly identical to the path name argument you specified.  A 
  6786. different value does not produce an error. 
  6787.  
  6788. Use the _execl, _execle, _execlp, and _execlpe functions for the cases where 
  6789. you know the number of arguments in advance. The arg0 argument is usually a 
  6790. pointer to pathname. The arg1 through argn arguments are pointers to the 
  6791. character strings forming the new argument list. There must be a NULL pointer 
  6792. following argn to mark the end of the argument list. 
  6793.  
  6794. Use the _execv, _execve, _execvp, and _execvpe functions when the number of 
  6795. arguments to the new process is variable.  Pass pointers to the arguments of 
  6796. these functions as an array, argv[ ]. The argv[0] argument is usually a pointer 
  6797. to pathname. The argv[1] through argv[n] arguments are pointers to the 
  6798. character strings forming the new argument list.  If argv[n] is the last 
  6799. parameter, then argv[n+1] must be NULL. 
  6800.  
  6801. Files that are open when you make an _exec call remain open in the new process. 
  6802. In the _execl, _execlp, _execv, and _execvp calls, the child process receives 
  6803. the environment of the parent.  The _execle, _execlpe, _execve, and _execvpe 
  6804. functions let you change the environment for the child process by passing a 
  6805. list of environment settings through the envp argument.  The envp argument is 
  6806. an array of character pointers, each element of which points to a string ending 
  6807. with a null character that defines an environment variable.  Such a string 
  6808. usually has the following form: 
  6809.  
  6810.    NAME=value
  6811.  
  6812. where NAME is the name of an environment variable, and value is the string 
  6813. value to which the _exec function sets that variable. 
  6814.  
  6815. Note:  Do not enclose the value in double quotation marks. 
  6816.  
  6817. The final element of the envp array should be NULL. When envp itself is NULL, 
  6818. the child process receives the environment settings of the parent process. 
  6819.  
  6820. The _exec functions do not preserve signal settings in child processes created 
  6821. by calls to _exec functions.  Calls to _exec functions reset the signal 
  6822. settings to the default in the child process. 
  6823.  
  6824. The _exec functions do not normally return control to the calling process. 
  6825. They are equivalent to the corresponding _spawn functions with P_OVERLAY as the 
  6826. value of modeflag.  If an error occurs, the _exec functions return -1 and set 
  6827. errno to one of the following values: 
  6828.  
  6829. Value          Meaning 
  6830. EACCESS        The specified file has a locking or sharing violation. 
  6831. EMFILE         There are too many open files.  The system must open the 
  6832.                specified file to tell whether it is an executable file. 
  6833. ENOENT         The file or pathname was not found or was specified incorrectly. 
  6834. ENOEXEC        The specified file cannot run or has an incorrect executable 
  6835.                file format. 
  6836. ENOMEM         One of the following conditions exists: 
  6837.  
  6838.    o Not enough storage is available to run the child process. 
  6839.    o Not enough storage is available for the argument or environment strings. 
  6840.  
  6841. Example of _execl - execvp 
  6842.  
  6843.  
  6844. ΓòÉΓòÉΓòÉ <hidden> Example of _execl - execvp ΓòÉΓòÉΓòÉ
  6845.  
  6846. /************************************************************************
  6847. *
  6848. This example calls four of the eight _exec routines.  When invoked without 
  6849. arguments, the program first runs the code for case PARENT.  It then calls 
  6850. _execle() to load and run a copy of itself.  The instructions for the child are 
  6851. blocked to run only if argv[0] and one parameter were passed (case CHILD).  In 
  6852. its turn, the child runs its own child as a copy of the same program.  This 
  6853. sequence is continued until four generations of child processes have run.  Each 
  6854. of the processes prints a message identifying itself. 
  6855.  
  6856.                                                                         *
  6857. ************************************************************************/
  6858.  
  6859. #include <stdio.h>
  6860. #include <stdlib.h>
  6861. #include <process.h>
  6862. #define  PARENT       1
  6863. #define  CHILD        2
  6864.  
  6865. char *args[3];
  6866.  
  6867. int main(int argc, char **argv, char **envp)
  6868. {
  6869.     switch(argc)
  6870.     {
  6871.         case PARENT:      /* No argument: run a child */
  6872.         {
  6873.             printf("Parent process began.\n");
  6874.             _execle(argv[0],argv[0],"1",NULL,envp);
  6875.             abort();  /* Not executed because parent was overlaid. */
  6876.         }
  6877.         case CHILD:       /* One argument: run a child's child */
  6878.         {
  6879.             printf("Child process %s began.\n", argv[1]);
  6880.             if('1'==*argv[1])     /* generation one */
  6881.             {
  6882.                 _execl(argv[0],argv[0],"2",NULL);
  6883.                 abort();  /* Not executed because child was overlaid */
  6884.             }
  6885.             if('2'==*argv[1])     /* generation two */
  6886.             {
  6887.                 args[0]=argv[0];
  6888.                 args[1]="3";
  6889.                 args[2]=NULL;
  6890.                 _execv(argv[0],args);
  6891.                 abort();  /* Not executed because child was overlaid */
  6892.             }
  6893.             if('3'==*argv[1])     /* generation three */
  6894.             {
  6895.                 args[0]=argv[0];
  6896.                 args[1]="4";
  6897.                 args[2]=NULL;
  6898.                 _execve(argv[0],args,_environ);
  6899.                 abort();    /* Not executed because child was overlaid */
  6900.             }
  6901.  
  6902.             if('4'==*argv[1]) /* generation four */
  6903.                 printf("Child process %s", argv[1]);
  6904.         }
  6905.     }
  6906.     printf(" ended.\n");
  6907.     _exit(0);
  6908.  
  6909.  
  6910.     return 0;
  6911.  
  6912.  
  6913. /***************** The output should be similar to:  ********************
  6914.  
  6915.    Parent process began.
  6916.    Child process 1 began.
  6917.    Child process 2 began.
  6918.    Child process 3 began.
  6919.    Child process 4 began.
  6920.    Child process 4 ended.
  6921. */
  6922.  
  6923. }
  6924.  
  6925.  
  6926. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6927.  
  6928. o abort  - Stop a Program 
  6929. o _cwait - Wait for Child Process 
  6930. o exit  - End Program 
  6931. o _exit - End Process 
  6932. o _spawnl -_spawnvpe -Start and Run Child Processes 
  6933. o system - Invoke the Command Processor 
  6934. o _wait - Wait for Child Process 
  6935. o envp Parameter to main 
  6936. o process.h 
  6937.  
  6938.  
  6939. ΓòÉΓòÉΓòÉ 6.59. exit  - End Program ΓòÉΓòÉΓòÉ
  6940.  
  6941.  
  6942. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  6943.  
  6944. #include <stdlib.h>  /* also defined in <process.h> */
  6945.  
  6946. void exit(int status);
  6947.  
  6948.  
  6949. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  6950.  
  6951. Language Level: ANSI, SAA, Extension 
  6952.  
  6953. The exit function returns control to the host environment from the program. It 
  6954. first calls all functions registered with the atexit function, in reverse 
  6955. order;  that is, the last one registered is the first one called. It flushes 
  6956. all buffers and closes all open files before ending the program. 
  6957.  
  6958. The argument status can have a value from 0 to 255 inclusive or be one of the 
  6959. macros EXIT_SUCCESS or EXIT_FAILURE. A status value of EXIT_SUCCESS or 0 
  6960. indicates a normal exit; otherwise, another status value is returned. 
  6961.  
  6962. All files opened with tmpfile are deleted. The exit function returns both 
  6963. control and the value of status to the operating system. 
  6964.  
  6965. Example of exit 
  6966.  
  6967.  
  6968. ΓòÉΓòÉΓòÉ <hidden> Example of exit ΓòÉΓòÉΓòÉ
  6969.  
  6970. /***********************************************************************
  6971. *
  6972.  
  6973. This example ends the program after flushing buffers and closing any open files 
  6974. if it cannot open the file myfile. 
  6975.  
  6976.                                                                        *
  6977. ***********************************************************************/
  6978.  
  6979. #include <stdio.h>
  6980. #include <stdlib.h>
  6981.  
  6982. FILE *stream;
  6983.  
  6984. int main(void)
  6985. {
  6986.    .
  6987.    .
  6988.    .
  6989.    if ((stream = fopen("myfile.dat", "r")) == NULL)
  6990.    {
  6991.       perror("Could not open data file");
  6992.       exit(EXIT_FAILURE);
  6993.    }
  6994. }
  6995.  
  6996.  
  6997. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  6998.  
  6999. o abort  - Stop a Program 
  7000. o atexit  - Record Program Termination Function 
  7001. o _onexit - Record Termination Function 
  7002. o _exit - End Process 
  7003. o signal Install Interrupt Handlers 
  7004. o stdlib.h 
  7005. o tmpfile  - Create Temporary File 
  7006.  
  7007.  
  7008. ΓòÉΓòÉΓòÉ 6.60. _exit - End Process ΓòÉΓòÉΓòÉ
  7009.  
  7010.  
  7011. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7012.  
  7013. #include <stdlib.h>      /* Declared in both   */
  7014. #include <process.h>
  7015.  
  7016. void _exit(int status);
  7017.  
  7018.  
  7019. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7020.  
  7021. Language Level: Extension 
  7022.  
  7023. The _exit function ends the calling process without calling functions 
  7024. registered by _onexit or atexit. It also does not flush stream buffers or 
  7025. delete temporary files. You supply the status value as a parameter; the value 0 
  7026. typically means a normal exit. 
  7027.  
  7028. Although _exit does not return a value, the value is available to the waiting 
  7029. parent process, if there is one, after the child process ends.  If no parent 
  7030. process waits for the exiting process, the status value is lost.  The status 
  7031. value is available through the operating system batch command IF ERRORLEVEL. 
  7032.  
  7033. Example of _exit 
  7034.  
  7035.  
  7036. ΓòÉΓòÉΓòÉ <hidden> Example of _exit ΓòÉΓòÉΓòÉ
  7037.  
  7038. /************************************************************************
  7039. *
  7040. This example calls _exit to end the process. Because _exit does not flush the 
  7041. buffer first, the output from the second printf statement will not appear. 
  7042.  
  7043.                                                                         *
  7044. ************************************************************************/
  7045.  
  7046. #include <stdio.h>
  7047. #include <stdlib.h>   /* You can also use <process.h> */
  7048.  
  7049. char buf[51];
  7050.  
  7051. int main(void)
  7052. {
  7053.    /* Make sure the standard output stream is line-buffered */
  7054.    /* even if the output is redirected to a file.           */
  7055.  
  7056.    if (setvbuf( stdout, buf, _IOLBF, 50 ) != 0)
  7057.       printf("The buffering was not set correctly.\n");
  7058.  
  7059.    printf( "This will print out but ...\n" );
  7060.  
  7061.    printf( "this will not!" );
  7062.  
  7063.    _exit( 1 );
  7064.  
  7065.     return 0;
  7066.  
  7067.  
  7068. /******************  The output should be similar to:  ******************
  7069.  
  7070.    This will print out but ...
  7071. */
  7072. }
  7073.  
  7074.  
  7075. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7076.  
  7077. o abort  - Stop a Program 
  7078. o atexit  - Record Program Termination Function 
  7079. o _execl - _execvp - Load and Run Child Process 
  7080. o exit  - End Program 
  7081. o _onexit - Record Termination Function 
  7082. o process.h 
  7083. o stdlib.h 
  7084.  
  7085.  
  7086. ΓòÉΓòÉΓòÉ 6.61. exp  - Exponential Function ΓòÉΓòÉΓòÉ
  7087.  
  7088.  
  7089. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7090.  
  7091. #include <math.h>
  7092.  
  7093. double exp(double x);
  7094.  
  7095.  
  7096. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7097.  
  7098. Language Level: ANSI, SAA 
  7099.  
  7100. The exp function calculates the exponential function of a floating-point 
  7101. argument x (e**x, where e equals 2.17128128...). 
  7102.  
  7103. If an overflow occurs, the function returns HUGE_VAL. If an underflow occurs, 
  7104. it returns 0. Both overflow and underflow set errno to ERANGE. 
  7105.  
  7106. Example of exp 
  7107.  
  7108.  
  7109. ΓòÉΓòÉΓòÉ <hidden> Example of exp ΓòÉΓòÉΓòÉ
  7110.  
  7111. /***********************************************************************
  7112. *
  7113.  
  7114. This example calculates y as the exponential function of x: 
  7115.  
  7116.                                                                        *
  7117. ***********************************************************************/
  7118.  
  7119. #include <math.h>
  7120. #include <stdio.h>
  7121.  
  7122. int main(void)
  7123. {
  7124.    double x, y;
  7125.  
  7126.    x = 5.0;
  7127.    y = exp(x);
  7128.  
  7129.    printf("exp( %lf ) = %lf\n", x, y);
  7130. }
  7131.  
  7132. /*****************  Output should be similar to:  *****************
  7133.  
  7134. exp( 5.000000 ) = 148.413159
  7135. */
  7136.  
  7137.  
  7138. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7139.  
  7140. o log  - Calculate Natural Logarithm 
  7141. o log10  - Calculate Base 10 Logarithm 
  7142. o math.h 
  7143.  
  7144.  
  7145. ΓòÉΓòÉΓòÉ 6.62. fabs  - Calculate Floating-Point Absolute Value ΓòÉΓòÉΓòÉ
  7146.  
  7147.  
  7148. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7149.  
  7150. #include <math.h>
  7151.  
  7152. double fabs(double x);
  7153.  
  7154.  
  7155. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7156.  
  7157. Language Level: ANSI, SAA 
  7158.  
  7159. The fabs function returns the absolute value of a floating-point argument. 
  7160.  
  7161. There is no error return value. 
  7162.  
  7163. Example of fabs 
  7164.  
  7165.  
  7166. ΓòÉΓòÉΓòÉ <hidden> Example of fabs ΓòÉΓòÉΓòÉ
  7167.  
  7168. /************************************************************************
  7169. *
  7170.  
  7171. This example calculates y as the absolute value of x: 
  7172.  
  7173.                                                                         *
  7174. ************************************************************************/
  7175.  
  7176. #include <math.h>
  7177. #include <stdio.h>
  7178.  
  7179. int main(void)
  7180. {
  7181.    double x, y;
  7182.  
  7183.    x = -5.6798;
  7184.    y = fabs(x);
  7185.  
  7186.    printf("fabs( %lf ) = %lf\n", x, y);
  7187. }
  7188.  
  7189. /*******************  Output should be similar to:  ***************
  7190.  
  7191. fabs( -5.679800 ) = 5.679800
  7192. */
  7193.  
  7194.  
  7195. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7196.  
  7197. o abs  - Calculate Integer Absolute Value 
  7198. o _cabs - Calculate Absolute Value of Complex Number 
  7199. o labs  - Calculate long Absolute Value 
  7200. o math.h 
  7201.  
  7202.  
  7203. ΓòÉΓòÉΓòÉ 6.63. _facos - Calculate Arccosine ΓòÉΓòÉΓòÉ
  7204.  
  7205.  
  7206. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7207.  
  7208. #include <builtin.h>
  7209.  
  7210. double _facos(double x);
  7211.  
  7212.  
  7213. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7214.  
  7215. Language Level: Extension 
  7216.  
  7217. The _facos function calculates the arccosine of x. This function causes the 
  7218. compiler to emit the appropriate 80387 instructions for the calculation of the 
  7219. arccosine. 
  7220.  
  7221. Because it is a built-in function and has no backing code in the library: 
  7222.  
  7223. o You cannot take the address of _facos. 
  7224. o You cannot parenthesize a _facos function call, because parentheses specify a 
  7225.   call to the backing code for the function. 
  7226.  
  7227. This function returns the arccosine of a variable x. 
  7228.  
  7229. Example of _facos 
  7230.  
  7231.  
  7232. ΓòÉΓòÉΓòÉ <hidden> Example of _facos ΓòÉΓòÉΓòÉ
  7233.  
  7234. /************************************************************************
  7235. *
  7236.  
  7237. This example prompts for a value for x. It prints an error message if x is 
  7238. greater than 1 or less than -1. Otherwise, it assigns the arccosine of x to y. 
  7239.  
  7240.                                                                         *
  7241. ************************************************************************/
  7242.  
  7243. #include <builtin.h>
  7244. #include <stdio.h>
  7245. #include <stdlib.h>
  7246. #include <math.h>
  7247. #define MAX  1.0
  7248. #define MIN -1.0
  7249.  
  7250. int main(void)
  7251.   {
  7252.   double x, y;
  7253.  
  7254.   printf( "Enter x\n" );
  7255.   scanf( "%lf", &x );
  7256.  
  7257.   /* Output error if not in range */
  7258.   if ( x > MAX )
  7259.     printf( "Error: %lf too large for acos\n", x );
  7260.   else if ( x < MIN )
  7261.     printf( "Error: %lf too small for acos\n", x );
  7262.   else
  7263.     {
  7264.     y = _facos( x );
  7265.     printf( "The cossine of %lf is %lf.\n", x, y );
  7266.     }
  7267. }
  7268.  
  7269.  
  7270. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7271.  
  7272. o acos  - Calculate Arccosine 
  7273. o cos  - Calculate Cosine 
  7274. o cosh  - Calculate Hyperbolic Cosine 
  7275. o _fcos - Calculate Cosine 
  7276. o _fcossin - Calculate Cosine and Sine 
  7277. o _fsincos - Calculate Sine and Cosine 
  7278.  
  7279.  
  7280. ΓòÉΓòÉΓòÉ 6.64. _fasin - Calculate Arcsine ΓòÉΓòÉΓòÉ
  7281.  
  7282.  
  7283. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7284.  
  7285. #include <builtin.h>
  7286.  
  7287. double _fasin(double x);
  7288.  
  7289.  
  7290. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7291.  
  7292. Language Level: Extension 
  7293.  
  7294. The _fasin function calculates the arcsine of x. This function causes the 
  7295. compiler to emit the appropriate 80387 instructions for the calculation of 
  7296. arcsine. 
  7297.  
  7298. Because it is a built-in function and has no backing code in the library: 
  7299.  
  7300. o You cannot take the address of _fasin. 
  7301. o You cannot parenthesize a _fasin function call, because parentheses specify a 
  7302.   call to the backing code for the function. 
  7303.  
  7304. This function returns the arcsine of a variable x. 
  7305.  
  7306. Example of _fasin 
  7307.  
  7308.  
  7309. ΓòÉΓòÉΓòÉ <hidden> Example of _fasin ΓòÉΓòÉΓòÉ
  7310.  
  7311. /************************************************************************
  7312. *
  7313.  
  7314. This example prompts for a value of x. It prints an error message if x is 
  7315. greater than 1 or less than -1. Otherwise, it assigns the arcsine of x to y. 
  7316.  
  7317.                                                                         *
  7318. ************************************************************************/
  7319.  
  7320. #include <builtin.h>
  7321. #include <stdio.h>
  7322. #include <stdlib.h>
  7323. #include <math.h>
  7324. #define MAX  1.0
  7325. #define MIN -1.0
  7326.  
  7327. int main(void)
  7328.   {
  7329.   double x, y;
  7330.  
  7331.   printf( "Enter x\n" );
  7332.   scanf( "%lf", &x );
  7333.  
  7334.   /* Output error if not in range */
  7335.   if ( x > MAX )
  7336.     printf( "Error: %lf too large for _fasin\n", x );
  7337.   else if ( x < MIN )
  7338.     printf( "Error: %lf too small for _fasin\n", x );
  7339.   else
  7340.     {
  7341.     y = _fasin( x );
  7342.     printf( "The arcsine of %lf is %lf.\n", x, y );
  7343.     }
  7344. }
  7345.  
  7346.  
  7347. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7348.  
  7349. o asin  - Calculate Arcsine 
  7350. o _fcossin - Calculate Cosine and Sine 
  7351. o _fsin - Calculate Sine 
  7352. o _fsincos - Calculate Sine and Cosine 
  7353. o sin  - Calculate Sine 
  7354. o sinh  - Calculate Hyperbolic Sine 
  7355.  
  7356.  
  7357. ΓòÉΓòÉΓòÉ 6.65. fclose  - Close Stream ΓòÉΓòÉΓòÉ
  7358.  
  7359.  
  7360. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7361.  
  7362. #include <stdio.h>
  7363.  
  7364. int fclose(FILE *stream);
  7365.  
  7366.  
  7367. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7368.  
  7369. Language Level: ANSI, SAA 
  7370.  
  7371. The fclose function closes a stream pointed to by stream.  This function 
  7372. flushes all buffers associated with the stream before closing it.  When it 
  7373. closes the stream, the function releases any buffers that the system reserved. 
  7374.  
  7375. The fclose function returns 0 if it successfully closes the stream, or EOF if 
  7376. any errors were detected. 
  7377.  
  7378. Note:  Once a stream has been closed with fclose, it must be opened again 
  7379. before it can be used. 
  7380.  
  7381. Example of fclose 
  7382.  
  7383.  
  7384. ΓòÉΓòÉΓòÉ <hidden> Example of fclose ΓòÉΓòÉΓòÉ
  7385.  
  7386. /************************************************************************
  7387. *
  7388.  
  7389. This example opens a file myfile for reading as a stream; then it closes this 
  7390. file. 
  7391.  
  7392.                                                                         *
  7393. ************************************************************************/
  7394.  
  7395. #include <stdio.h>
  7396.  
  7397. int main(void)
  7398. {
  7399.   FILE *stream;
  7400.  
  7401.   stream = fopen("myfile.dat", "r");
  7402.  
  7403.   if (fclose(stream))   /* Close the stream. */
  7404.       perror("fclose error");
  7405. }
  7406.  
  7407.  
  7408. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7409.  
  7410. o _close - Closes File Associated with Handle 
  7411. o _fcloseall - Close All Open Streams 
  7412. o fflush  - Write Buffer to File 
  7413. o fopen  - Open Files 
  7414. o freopen  - Redirect Open Files 
  7415. o stdio.h 
  7416.  
  7417.  
  7418. ΓòÉΓòÉΓòÉ 6.66. _fcloseall - Close All Open Streams ΓòÉΓòÉΓòÉ
  7419.  
  7420.  
  7421. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7422.  
  7423. #include <stdio.h>
  7424.  
  7425. int _fcloseall(void);
  7426.  
  7427.  
  7428. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7429.  
  7430. Language Level: Extension 
  7431.  
  7432. The _fcloseall function closes all open streams, except stdin, stdout, and 
  7433. stderr. It also closes and deletes any temporary files created by tmpfile. 
  7434.  
  7435. The function flushes all buffers associated with the streams before closing 
  7436. them. When it closes streams, it releases the buffers that the system reserved, 
  7437. but does not release user-allocated buffers. 
  7438.  
  7439. The _fcloseall function returns the total number of streams closed, or EOF if 
  7440. an error occurs. 
  7441.  
  7442. Example of _fcloseall 
  7443.  
  7444.  
  7445. ΓòÉΓòÉΓòÉ <hidden> Example of _fcloseall ΓòÉΓòÉΓòÉ
  7446.  
  7447. /************************************************************************
  7448. *
  7449. This example opens a file john for reading as a data stream, and then closes 
  7450. the file. It closes all other streams except stdin, stdout, and stderr. 
  7451.  
  7452.                                                                         *
  7453. ************************************************************************/
  7454.  
  7455. #include <stdio.h>
  7456.  
  7457. int main(void)
  7458. {
  7459.     FILE *stream;
  7460.     int numclosed;
  7461.  
  7462.     stream = fopen("john", "w");
  7463.  
  7464.     numclosed = _fcloseall();
  7465.     printf("Number of files closed = %d\n", numclosed);
  7466.  
  7467.     return 0;
  7468.  
  7469.     /* The expected output is:
  7470.  
  7471.        Number of files closed = 1    */
  7472. }
  7473.  
  7474.  
  7475. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7476.  
  7477. o _close - Closes File Associated with Handle 
  7478. o fclose  - Close Stream 
  7479. o fflush  - Write Buffer to File 
  7480. o fopen  - Open Files 
  7481. o freopen  - Redirect Open Files 
  7482. o tmpfile  - Create Temporary File 
  7483. o stdio.h 
  7484.  
  7485.  
  7486. ΓòÉΓòÉΓòÉ 6.67. _fcos - Calculate Cosine ΓòÉΓòÉΓòÉ
  7487.  
  7488.  
  7489. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7490.  
  7491. #include <builtin.h>
  7492.  
  7493. double _fcos( double x);
  7494.  
  7495.  
  7496. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7497.  
  7498. Language Level: Extension 
  7499.  
  7500. The _fcos function calculates the cosine of x, where x is expressed in radians. 
  7501. The value of x must be less than 2**63. This function causes the compiler to 
  7502. emit the FSINCOS 80387 instruction and return only the cosine. 
  7503.  
  7504. Because it is a built-in function and has no backing code in the library: 
  7505.  
  7506. o You cannot take the address of _fcos. 
  7507. o You cannot parenthesize a _fcos function call, because parentheses specify a 
  7508.   call to the backing code for the function in the library. 
  7509.  
  7510. This function returns the cosine of a variable x expressed in radians. 
  7511.  
  7512. Example of _fcos 
  7513.  
  7514.  
  7515. ΓòÉΓòÉΓòÉ <hidden> Example of _fcos ΓòÉΓòÉΓòÉ
  7516.  
  7517. /************************************************************************
  7518. *
  7519.  
  7520. This example calculates y to be the cosine of x. 
  7521.  
  7522.                                                                         *
  7523. ************************************************************************/
  7524.  
  7525. #include <stdio.h>
  7526. #include <builtin.h>
  7527. #include <math.h>
  7528.  
  7529. int main(void)
  7530.    {
  7531.    double x, y;
  7532.  
  7533.    x = 7.2;
  7534.    y = _fcos(x);
  7535.  
  7536.    printf("The cosine of %lf is %lf.\n", x, y);
  7537. }
  7538.  
  7539.  
  7540. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7541.  
  7542. o cos  - Calculate Cosine 
  7543. o cosh  - Calculate Hyperbolic Cosine 
  7544. o _facos - Calculate Arccosine 
  7545. o _fcossin - Calculate Cosine and Sine 
  7546. o _fsincos - Calculate Sine and Cosine 
  7547.  
  7548.  
  7549. ΓòÉΓòÉΓòÉ 6.68. _fcossin - Calculate Cosine and Sine ΓòÉΓòÉΓòÉ
  7550.  
  7551.  
  7552. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7553.  
  7554. #include <builtin.h>
  7555.  
  7556. double _fcossin(double x, double *y);
  7557.  
  7558.  
  7559. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7560.  
  7561. Language Level: Extension 
  7562.  
  7563. The _fcossin function calculates the cosine of x, and stores the sine of x in 
  7564. *y. This is faster than separately calculating the sine and cosine. Use this 
  7565. function instead of _fsincos when you will be using the cosine first, and then 
  7566. the sine. This function causes the compiler to emit the FSINCOS 80387 
  7567. instruction. 
  7568.  
  7569. Because it is a built-in function and has no backing code in the library: 
  7570.  
  7571. o You cannot take the address of _fcossin. 
  7572. o You cannot parenthesize a _fcossin function call, because parentheses specify 
  7573.   a call to the backing code for the function in the library. 
  7574.  
  7575. This function returns the cosine of a variable x. 
  7576.  
  7577. Example of _fcossin 
  7578.  
  7579.  
  7580. ΓòÉΓòÉΓòÉ <hidden> Example of _fcossin ΓòÉΓòÉΓòÉ
  7581.  
  7582. /************************************************************************
  7583. *
  7584.  
  7585. This example calculates the cosine of x and stores the sine of x in y. 
  7586.  
  7587.                                                                         *
  7588. ************************************************************************/
  7589.  
  7590. #include <stdio.h>
  7591. #include <stdlib.h>
  7592. #include <builtin.h>
  7593. #define MAX  1.0
  7594. #define MIN -1.0
  7595.  
  7596. int main(void)
  7597.   {
  7598.   double x,y;
  7599.  
  7600.   printf( "Enter x\n" );
  7601.   scanf( "%lf", &x );
  7602.  
  7603.   /* Output error if not in range */
  7604.   if ( x > MAX )
  7605.     printf( "Error: %lf too large for _facos\n", x );
  7606.   else if ( x < MIN )
  7607.     printf( "Error: %lf too small for _facos\n", x );
  7608.   else
  7609.     {
  7610.     z = _fcossin( x, *y);
  7611.     printf("The cosine of %d is %lf\n", x, z);
  7612.     printf("The sine of %d is %lf\n", x, *y);
  7613.     }
  7614. }
  7615.  
  7616.  
  7617. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7618.  
  7619. o acos  - Calculate Arccosine 
  7620. o asin  - Calculate Arcsine 
  7621. o cos  - Calculate Cosine 
  7622. o cosh  - Calculate Hyperbolic Cosine 
  7623. o _facos - Calculate Arccosine 
  7624. o _fasin - Calculate Arcsine 
  7625. o _fcos - Calculate Cosine 
  7626. o sin  - Calculate Sine 
  7627. o sinh  - Calculate Hyperbolic Sine 
  7628. o _fsin - Calculate Sine 
  7629. o _fsincos - Calculate Sine and Cosine 
  7630.  
  7631.  
  7632. ΓòÉΓòÉΓòÉ 6.69. _fcvt - Convert Floating-Point to String ΓòÉΓòÉΓòÉ
  7633.  
  7634.  
  7635. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7636.  
  7637. #include <stdlib.h>
  7638.  
  7639. char *_fcvt(double value, int ndec, int *decptr, int *signptr);
  7640.  
  7641.  
  7642. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7643.  
  7644. Language Level: Extension 
  7645.  
  7646. The _fcvt function converts a floating-point number to a character string. The 
  7647. variable value is the floating-point number to be converted. The _fcvt function 
  7648. stores the digits of value as a string and adds a null character (\0). The ndec 
  7649. variable specifies the number of digits to be stored after the decimal point. 
  7650.  
  7651. If the number of digits after the decimal point in value exceeds ndec, _fcvt 
  7652. rounds the correct digit according to the FORTRAN F format.  If there are fewer 
  7653. than ndec digits of precision, _fcvt pads the string with zeros. 
  7654.  
  7655. A FORTRAN F number has the following format: 
  7656.  
  7657.        ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ    ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  7658.  ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdigitΓöÇΓö┤ΓöÇΓöÇΓöÇ.ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  7659.    Γö£ΓöÇΓöÇ+ΓöÇΓöÇΓöñ          ΓööΓöÇdigitΓöÇΓöÿ
  7660.    ΓööΓöÇΓöÇ-ΓöÇΓöÇΓöÿ
  7661.  
  7662. The _fcvt function stores only digits in the string. You can obtain the 
  7663. position of the decimal point and the sign of value after the call from decptr 
  7664. and signptr. The decptr variable points to an integer value giving the position 
  7665. of the decimal point with respect to the beginning of the string.  A 0 or 
  7666. negative integer value shows that the decimal point lies to the left of the 
  7667. first digit. The signptr variable points to an integer showing the sign of 
  7668. value. The _fcvt function sets the integer to 0 if value is positive and to a 
  7669. nonzero number if value is negative. 
  7670.  
  7671. The _fcvt function also converts NaN and infinity values to the strings NAN and 
  7672. INFINITY, respectively. For more information on NaN and infinity values, see 
  7673. Infinity and NaN Support. 
  7674.  
  7675. Warning: For each thread, the _ecvt, _fcvt, and _gcvt functions use a single, 
  7676. dynamically allocated buffer for the conversion. Any subsequent call that the 
  7677. same thread makes to these functions destroys the result of the previous call. 
  7678.  
  7679. The _fcvt function returns a pointer to the string of digits. A failure to 
  7680. allocate memory results in a NULL return value and sets errno to ENOMEM. 
  7681. Because of the limited precision of the double type, no more than 16 decimal 
  7682. digits are significant in any conversion. 
  7683.  
  7684. Example of _fcvt 
  7685.  
  7686.  
  7687. ΓòÉΓòÉΓòÉ <hidden> Example of _fcvt ΓòÉΓòÉΓòÉ
  7688.  
  7689. /************************************************************************
  7690. *
  7691. This example reads in two floating-point numbers, computes their product, and 
  7692. prints out only the billions digit of its character representation.  At most, 
  7693. 16 decimal digits of significance can be expected. The output given assumes the 
  7694. user enters the values 2000000 and 3000. 
  7695.  
  7696.                                                                         *
  7697. ************************************************************************/
  7698.  
  7699. #include <stdio.h>
  7700. #include <stdlib.h>
  7701. #include <math.h>
  7702.  
  7703. int main(void)
  7704. {
  7705.     float x, y;
  7706.     double z
  7707.     int w, b, decimal, sign;
  7708.     char *buffer;
  7709.  
  7710.     printf("Enter two floating-point numbers:\n");
  7711.     if ( scanf("%e %e", &x, 0x) != 2 )
  7712.     {
  7713.         printf("input error...\n");
  7714.         exit(-1);
  7715.     }
  7716.  
  7717.     z = x*y;
  7718.     printf("Their product is %g\n", z);
  7719.  
  7720.     w = log10( fabs(z) ) + 1.;
  7721.     buffer = _fcvt(z, w, &decimal, signed);
  7722.  
  7723.     b = decimal - 10;
  7724.     if (b < 0)
  7725.         printf("Their product does not exceed one billion.\n");
  7726.     else if (b > 15)
  7727.         printf("The billions digit of their product is insignificant.\");
  7728.     else
  7729.         printf("The billions digit of their product is %c.\n", buffer[b]);
  7730.  
  7731.     return 0;
  7732.  
  7733. /*****  The expected output on input of 2000000 3000 is  **************
  7734.  
  7735.          Enter two floating point numbers:
  7736.          2000000 3000
  7737.          Their product is 6e+09
  7738.          the billions digit of their product is 6.
  7739.  
  7740. */
  7741. }
  7742.  
  7743.  
  7744. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7745.  
  7746. o _ecvt - Convert Floating-Point to Character 
  7747. o _gcvt - Convert Floating-Point to String 
  7748. o Infinity and NaN Support 
  7749. o stdlib.h 
  7750.  
  7751.  
  7752. ΓòÉΓòÉΓòÉ 6.70. _fdopen - Associates Input Or Output With File ΓòÉΓòÉΓòÉ
  7753.  
  7754.  
  7755. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7756.  
  7757. #include <stdio.h>
  7758.  
  7759. FILE *_fdopen(int handle, char *type);
  7760.  
  7761.  
  7762. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7763.  
  7764. Language Level: Extension 
  7765.  
  7766. The _fdopen function associates an input or output stream with the file 
  7767. identified by handle. The type variable is a character string specifying the 
  7768. type of access requested for the stream. 
  7769.  
  7770. Mode Description 
  7771.      Create a stream to read a text file. The file pointer is set to the 
  7772.      beginning of the file. 
  7773.      Create a stream to write to a text file. The file pointer is set to the 
  7774.      beginning of the file. 
  7775.      Create a stream to write, in append mode, at the end of the text file. The 
  7776.      file pointer is set to the end of the file. 
  7777. r+ 
  7778.      Create a stream for reading and writing a text file. The file pointer is 
  7779.      set to the beginning of the file. 
  7780. w+ 
  7781.      Create a stream for reading and writing a text file. The file pointer is 
  7782.      set to the beginning of the file. 
  7783. a+ 
  7784.      Create a stream for reading or writing, in append mode, at the end of the 
  7785.      text file. The file pointer is set to the end of the file. 
  7786. rb 
  7787.      Create a stream to read a binary file. The file pointer is set to the 
  7788.      beginning of the file. 
  7789. wb 
  7790.      Create a stream to write to a binary file. The file pointer is set to the 
  7791.      beginning of the file. 
  7792. ab 
  7793.      Create a stream to write to a binary file in append mode. The file pointer 
  7794.      is set to the end of the file. 
  7795. r+b or rb+ 
  7796.      Create a stream for reading and writing a binary file. The file pointer is 
  7797.      set to the beginning of the file. 
  7798. w+b or wb+ 
  7799.      As in previous mode. 
  7800. a+b or ab+ 
  7801.      Create a stream for reading and writing to a binary file in append mode. 
  7802.      The file pointer is set to the end of the file. 
  7803.  
  7804. Warning: Use the w, w+, wb, wb+, and w+b modes with care; they can destroy 
  7805. existing files. 
  7806.  
  7807. The specified type must be compatible with the access mode you used to open the 
  7808. file. 
  7809.  
  7810. If the file was opened with the O_APPEND FLAG, the stream mode must be r, a, 
  7811. a+, rb, ab, a+b, or ab+. 
  7812.  
  7813. When you open a file with a, a+, ab, a+b, or ab+ as the value of type, all 
  7814. write operations take place at the end of the file. Although you can reposition 
  7815. the file pointer using fseek or rewind, the file pointer always moves back to 
  7816. the end of the file before the system carries out any write operation. This 
  7817. action prevents you from writing over existing data. 
  7818.  
  7819. When you specify any of the types containing +, you can read from and write to 
  7820. the file, and the file is said to be open for update. However, when switching 
  7821. from reading to writing or from writing to reading, you must include an 
  7822. intervening fseek, fsetpos, or rewind operation. You can specify the current 
  7823. file position with fseek. 
  7824.  
  7825. In accessing text files, carriage-return line-feed (CR-LF) combinations are 
  7826. translated into a single line feed (LF) on input; LF characters are translated 
  7827. to CR-LF combinations on output. Accesses to binary files suppress all of these 
  7828. translations. (See the Programming Guide for differences between text and 
  7829. binary streams.) 
  7830.  
  7831. If _fdopen returns NULL, use the _close function to close the file. If _fdopen 
  7832. is successful, you must use fclose to close the stream and file. The _fdopen 
  7833. function returns a pointer to a file structure that can be used to access the 
  7834. open file. A NULL pointer return value indicates an error. 
  7835.  
  7836. Example of _fdopen 
  7837.  
  7838.  
  7839. ΓòÉΓòÉΓòÉ <hidden> Example of _fdopen ΓòÉΓòÉΓòÉ
  7840.  
  7841. /************************************************************************
  7842. *
  7843.  
  7844. This example opens the file sample.dat and associates a stream with the file 
  7845. using _fdopen. It then reads from the stream into the buffer. 
  7846.  
  7847.                                                                         *
  7848. ************************************************************************/
  7849.  
  7850. #include <io.h>
  7851. #include <stdio.h>
  7852. #include <stdlib.h>
  7853. #include <fcntl.h>
  7854. #include <string.h>
  7855.  
  7856. int main(void)
  7857. {
  7858.    long length;
  7859.    int  fh;
  7860.    char buffer[20];
  7861.    FILE *fp;
  7862.  
  7863.    memset(buffer,'\0',20); /* Initialize buffer */
  7864.  
  7865.    printf("\nCreating sample.dat.\n");
  7866.    system("echo Sample Program > sample.dat");
  7867.  
  7868.    if (-1 == (fh = _open("sample.dat",O_RDWR | O_APPEND)))
  7869.    {
  7870.       perror("Unable to open sample.dat");
  7871.       return 1;
  7872.       }
  7873.    if (NULL == (fp = _fdopen(fh,"r")))
  7874.    {
  7875.       perror("fdopen failed");
  7876.       _close(fh);
  7877.       return 1;
  7878.       }
  7879.  
  7880.    if ( 7 != fread(buffer,1,7,fp))
  7881.    {
  7882.       perror("fread failed");
  7883.       fclose(fp);
  7884.       return 1;
  7885.    }
  7886.  
  7887.    printf("Successfully read from the stream
  7888.             the following:\n%s\n ",buffer);
  7889.  
  7890.    fclose(fp);
  7891.  
  7892.    return 0;
  7893.  
  7894.  
  7895. /*******************  The expected output is:  **************************
  7896.  
  7897.       Creating sample.dat.
  7898.       Successfully read from the stream the following:
  7899.       Sample
  7900. */
  7901.  
  7902. }
  7903.  
  7904.  
  7905. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7906.  
  7907. o _close - Closes File Associated with Handle 
  7908. o _creat - Create New File 
  7909. o fclose  - Close Stream 
  7910. o fopen  - Open Files 
  7911. o fseek  - Reposition File Position 
  7912. o fsetpos  - Set File Position 
  7913. o _open - Open File 
  7914. o rewind  - Adjust Current File Position 
  7915. o _sopen - Open Shared File 
  7916. o stdio.h 
  7917.  
  7918.  
  7919. ΓòÉΓòÉΓòÉ 6.71. feof  - Test End-of-File Indicator ΓòÉΓòÉΓòÉ
  7920.  
  7921.  
  7922. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7923.  
  7924. #include <stdio.h>
  7925.  
  7926. int feof(FILE *stream);
  7927.  
  7928.  
  7929. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7930.  
  7931. Language Level: ANSI, SAA 
  7932.  
  7933. The feof function indicates whether the end-of-file flag is set for the given 
  7934. stream.  The end-of-file flag is set by several functions to indicate the end 
  7935. of the file.  The end-of-file flag is cleared by calling rewind, fsetpos, 
  7936. fseek, or clearerr for this stream. 
  7937.  
  7938. The feof function returns a nonzero value if and only if the EOF flag is set; 
  7939. otherwise, 0 is returned. 
  7940.  
  7941. Example of feof 
  7942.  
  7943.  
  7944. ΓòÉΓòÉΓòÉ <hidden> Example of feof ΓòÉΓòÉΓòÉ
  7945.  
  7946. /************************************************************************
  7947. *
  7948.  
  7949. This example scans the input stream until it reads an end-of-file character. 
  7950.  
  7951.                                                                         *
  7952. ************************************************************************/
  7953.  
  7954. #include <stdio.h>
  7955.  
  7956. int main(void)
  7957. {
  7958.    char string[100];
  7959.    FILE *stream;
  7960.    stream = fopen("myfile.dat", "r");
  7961.    .
  7962.    .
  7963.    .
  7964.    /* scan an input stream until an end-of-file character is read */
  7965.    while (!feof(stream))
  7966.       if (fscanf(stream, "%s", string))
  7967.          /* process the string */;
  7968. }
  7969.  
  7970.  
  7971. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  7972.  
  7973. o clearerr  - Reset Error Indicators 
  7974. o ferror  - Test for Read/Write Errors 
  7975. o fseek  - Reposition File Position 
  7976. o fsetpos  - Set File Position 
  7977. o perror  - Print Error Message 
  7978. o rewind  - Adjust Current File Position 
  7979. o stdio.h 
  7980.  
  7981.  
  7982. ΓòÉΓòÉΓòÉ 6.72. ferror  - Test for Read/Write Errors ΓòÉΓòÉΓòÉ
  7983.  
  7984.  
  7985. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  7986.  
  7987. #include <stdio.h>
  7988.  
  7989. int ferror(FILE *stream);
  7990.  
  7991.  
  7992. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  7993.  
  7994. Language Level: ANSI, SAA 
  7995.  
  7996. The ferror function tests for an error in reading from or writing to the given 
  7997. stream.  If an error occurs, the error indicator for the stream remains set 
  7998. until you close stream, call rewind, or call clearerr. 
  7999.  
  8000. The ferror function returns a nonzero value to indicate an error on the given 
  8001. stream.  A return value of 0 means no error has occurred. 
  8002.  
  8003. Note:  Some compilers are able to continue reading past EOF. Others require a 
  8004. call to another function such as clearerr to read beyond EOF. See the 
  8005. Programming Guide for more information. 
  8006.  
  8007. Example of ferror 
  8008.  
  8009.  
  8010. ΓòÉΓòÉΓòÉ <hidden> Example of ferror ΓòÉΓòÉΓòÉ
  8011.  
  8012. /************************************************************************
  8013. *
  8014.  
  8015. This example puts data out to a stream and then checks that a write error has 
  8016. not occurred. 
  8017.  
  8018.                                                                         *
  8019. ************************************************************************/
  8020.  
  8021. #include <stdio.h>
  8022.  
  8023. int main(void)
  8024. {
  8025.    FILE *stream;
  8026.    char *string = "Important information";
  8027.  
  8028.    stream = fopen("myfile.dat","w");
  8029.  
  8030.    fprintf(stream, "%s\n", string);
  8031.    if (ferror(stream))
  8032.    {
  8033.       printf("write error\n");
  8034.       clearerr(stream);
  8035.    }
  8036.    if (fclose(stream))
  8037.       perror("fclose error");
  8038. }
  8039.  
  8040.  
  8041. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8042.  
  8043. o clearerr  - Reset Error Indicators 
  8044. o feof  - Test End-of-File Indicator 
  8045. o fopen  - Open Files 
  8046. o perror  - Print Error Message 
  8047. o stdio.h 
  8048. o strerror  - Set Pointer to Runtime Error Message 
  8049. o _strerror - Set Pointer to System Error String 
  8050.  
  8051.  
  8052. ΓòÉΓòÉΓòÉ 6.73. fflush  - Write Buffer to File ΓòÉΓòÉΓòÉ
  8053.  
  8054.  
  8055. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8056.  
  8057. #include <stdio.h>
  8058.  
  8059. int fflush(FILE *stream);
  8060.  
  8061.  
  8062. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8063.  
  8064. Language Level: ANSI, SAA 
  8065.  
  8066. The fflush function causes the system to empty the buffer associated with the 
  8067. specified output stream, if possible. If the stream is open for input, fflush 
  8068. undoes the effect of any ungetc function. The stream remains open after the 
  8069. call. 
  8070.  
  8071. If stream is NULL, the system flushes all open streams. 
  8072.  
  8073. The fflush function returns the value 0 if it successfully flushes the buffer. 
  8074. The fflush function returns EOF if an error occurs. 
  8075.  
  8076. Note:  The system automatically flushes buffers when you close the stream, or 
  8077.        when a program ends normally without closing the stream. 
  8078.  
  8079. Example of fflush 
  8080.  
  8081.  
  8082. ΓòÉΓòÉΓòÉ <hidden> Example of fflush ΓòÉΓòÉΓòÉ
  8083.  
  8084. /************************************************************************
  8085. *
  8086.  
  8087. This example flushes a stream buffer. 
  8088.  
  8089.                                                                         *
  8090. ************************************************************************/
  8091.  
  8092. #include <stdio.h>
  8093.  
  8094. int main(void)
  8095. {
  8096.    FILE *stream;
  8097.    stream = fopen("myfile.dat", "w");
  8098.    .
  8099.    .
  8100.    .
  8101.    fflush(stream);
  8102. }
  8103.  
  8104.  
  8105. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8106.  
  8107. o fclose  - Close Stream 
  8108. o _flushall - Write Buffers to Files 
  8109. o setbuf  - Control Buffering 
  8110. o ungetc  - Push Character onto Input Stream 
  8111. o stdio.h 
  8112.  
  8113.  
  8114. ΓòÉΓòÉΓòÉ 6.74. fgetc  - Read a Character ΓòÉΓòÉΓòÉ
  8115.  
  8116.  
  8117. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8118.  
  8119. #include <stdio.h>
  8120.  
  8121. int fgetc(FILE *stream);
  8122.  
  8123.  
  8124. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8125.  
  8126. Language Level: ANSI, SAA 
  8127.  
  8128. The fgetc function reads a single unsigned character from the input stream at 
  8129. the current position and increases the associated file pointer, if any, so that 
  8130. it points to the next character. 
  8131.  
  8132. The fgetc function returns the character read as an integer. An EOF return 
  8133. value indicates an error or an end-of-file condition.  Use feof or ferror to 
  8134. determine whether the EOF value indicates an error or the end of the file. 
  8135.  
  8136. The fgetc function is identical to getc but is guaranteed to be a function. 
  8137.  
  8138. Example of fgetc 
  8139.  
  8140.  
  8141. ΓòÉΓòÉΓòÉ <hidden> Example of fgetc ΓòÉΓòÉΓòÉ
  8142.  
  8143. /************************************************************************
  8144. *
  8145.  
  8146. This example gathers a line of input from a stream. 
  8147.  
  8148.                                                                         *
  8149. ************************************************************************/
  8150.  
  8151. #include <stdio.h>
  8152.  
  8153. #define  MAX_LEN  80
  8154.  
  8155. int main(void)
  8156. {
  8157.    FILE *stream;
  8158.    char buffer[MAX_LEN + 1];
  8159.    int i, ch;
  8160.  
  8161.    stream = fopen("myfile.dat","r");
  8162.  
  8163.    for (i = 0; (i < (sizeof(buffer)-1) &&
  8164.          ((ch = fgetc(stream)) != EOF) && (ch != '\n')); i++)
  8165.       buffer[i] = ch;
  8166.  
  8167.    buffer[i] = '\0';
  8168.  
  8169.    if (fclose(stream))
  8170.       perror("fclose error");
  8171. }
  8172.  
  8173.  
  8174. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8175.  
  8176. o _fgetchar - Read Single Character from stdin 
  8177. o feof  - Test End-of-File Indicator 
  8178. o ferror  - Test for Read/Write Errors 
  8179. o fputc  - Write a Character 
  8180. o getc  - Read a Character 
  8181. o _getch - _getche - Read Character from Keyboard 
  8182. o stdio.h 
  8183.  
  8184.  
  8185. ΓòÉΓòÉΓòÉ 6.75. _fgetchar - Read Single Character from stdin ΓòÉΓòÉΓòÉ
  8186.  
  8187.  
  8188. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8189.  
  8190. #include <stdio.h>
  8191.  
  8192. int _fgetchar(void);
  8193.  
  8194.  
  8195. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8196.  
  8197. Language Level: Extension 
  8198.  
  8199. The _fgetchar function reads a single character from the stdin stream. It is 
  8200. equivalent to a call to the SAA function fgetc: 
  8201.  
  8202.    fgetc(c, stdin);
  8203.  
  8204. For portability, replace _fgetchar with its SAA equivalent. 
  8205.  
  8206. The _fgetchar function returns the character read.  A return value of EOF 
  8207. indicates an error or end-of-file position. Use feof or ferror to tell whether 
  8208. the return value indicates an error or an end-of-file position. 
  8209.  
  8210. Example of _fgetchar 
  8211.  
  8212.  
  8213. ΓòÉΓòÉΓòÉ <hidden> Example of _fgetchar ΓòÉΓòÉΓòÉ
  8214.  
  8215. /************************************************************************
  8216. *
  8217. This example gathers a line of input from stdin using _fgetchar: 
  8218.  
  8219.                                                                         *
  8220. ************************************************************************/
  8221.  
  8222. #include <stdio.h>
  8223.  
  8224. int main(void)
  8225. {
  8226.     char buffer[81];
  8227.     int i, ch;
  8228.  
  8229.     printf("Please input a line of characters...\n");
  8230.  
  8231.     for (i=0; (i<80) && ((ch = _fgetchar()) != EOF) && (ch!='\n'); i++)
  8232.         buffer[i] = ch;
  8233.     buffer[i] = '\0';
  8234.  
  8235.     printf("The input line was : %s\n", buffer);
  8236.  
  8237.     return 0;
  8238.  
  8239. /***********  If the input was "A line of characters.", then  *********
  8240. **************    the output should be similar to:  *******************
  8241.  
  8242.    Please input a line of characters...
  8243.    A line of characters.
  8244.    The input line was : A line of characters.
  8245. */
  8246. }
  8247.  
  8248.  
  8249. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8250.  
  8251. o feof  - Test End-of-File Indicator 
  8252. o ferror  - Test for Read/Write Errors 
  8253. o fgetc  - Read a Character 
  8254. o _fputchar - Write Character 
  8255. o getc  - Read a Character 
  8256. o _getch - _getche - Read Character from Keyboard 
  8257. o stdio.h 
  8258.  
  8259.  
  8260. ΓòÉΓòÉΓòÉ 6.76. fgetpos  - Get File Position ΓòÉΓòÉΓòÉ
  8261.  
  8262.  
  8263. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8264.  
  8265. #include <stdio.h>
  8266.  
  8267. int fgetpos(FILE *stream, fpos_t *pos);
  8268.  
  8269.  
  8270. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8271.  
  8272. Language Level: ANSI, SAA 
  8273.  
  8274. The fgetpos function stores the current position of the file pointer associated 
  8275. with stream into the object pointed to by pos.  The value pointed to by pos can 
  8276. be used later in a call to fsetpos to reposition the stream. 
  8277.  
  8278. If successful, the fgetpos function returns 0.  On error, fgetpos returns 
  8279. nonzero and sets errno to a nonzero value. 
  8280.  
  8281. Example of fgetpos 
  8282.  
  8283.  
  8284. ΓòÉΓòÉΓòÉ <hidden> Example of fgetpos ΓòÉΓòÉΓòÉ
  8285.  
  8286. /************************************************************************
  8287. *
  8288.  
  8289. This example opens the file myfile for reading.  The current file pointer 
  8290. position is stored into the variable pos. 
  8291.  
  8292.                                                                         *
  8293. ************************************************************************/
  8294.  
  8295. #include <stdio.h>
  8296.  
  8297. FILE *stream;
  8298.  
  8299. int main(void)
  8300. {
  8301.    int retcode;
  8302.    fpos_t pos;
  8303.  
  8304.    stream = fopen("myfile.dat", "rb");
  8305.  
  8306.    /* The value returned by fgetpos can be used by fsetpos */
  8307.    /* to set the file pointer if 'retcode' is 0            */
  8308.  
  8309.    if ((retcode = fgetpos(stream, &pos)) == 0)
  8310.       printf("Current position of file pointer found\n");
  8311.    fclose(stream);
  8312. }
  8313.  
  8314.  
  8315. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8316.  
  8317. o fseek  - Reposition File Position 
  8318. o fsetpos  - Set File Position 
  8319. o ftell  - Get Current Position 
  8320. o stdio.h 
  8321.  
  8322.  
  8323. ΓòÉΓòÉΓòÉ 6.77. fgets  - Read a String ΓòÉΓòÉΓòÉ
  8324.  
  8325.  
  8326. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8327.  
  8328. #include <stdio.h>
  8329.  
  8330. char *fgets (char *string, int n, FILE *stream);
  8331.  
  8332.  
  8333. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8334.  
  8335. Language Level: ANSI, SAA 
  8336.  
  8337. The fgets function reads characters from the current stream position up to and 
  8338. including the first new-line character (\n), up to the end of the stream, or 
  8339. until the number of characters read is equal to n-1, whichever comes first. 
  8340. The fgets function stores the result in string and adds a null character (\0) 
  8341. to the end of the string.  The string includes the new-line character, if read. 
  8342. If n is equal to 1, the string is empty. 
  8343.  
  8344. The fgets function returns a pointer to the string buffer if successful.  A 
  8345. NULL return value indicates an error or an end-of-file condition.  Use feof or 
  8346. ferror to determine whether the NULL value indicates an error or the end of the 
  8347. file. In either case, the value of the string is unchanged. 
  8348.  
  8349. Example of fgets 
  8350.  
  8351.  
  8352. ΓòÉΓòÉΓòÉ <hidden> Example of fgets ΓòÉΓòÉΓòÉ
  8353.  
  8354. /************************************************************************
  8355. *
  8356.  
  8357. This example gets a line of input from a data stream.  The example reads no 
  8358. more than MAX_LEN - 1 characters, or up to a new-line character, from the 
  8359. stream. 
  8360.  
  8361.                                                                         *
  8362. ************************************************************************/
  8363.  
  8364. #include <stdio.h>
  8365.  
  8366. #define  MAX_LEN  100
  8367.  
  8368. int main(void)
  8369. {
  8370.    FILE *stream;
  8371.    char line[MAX_LEN], *result;
  8372.  
  8373.    stream = fopen("myfile.dat","rb");
  8374.  
  8375.    if ((result = fgets(line,MAX_LEN,stream)) != NULL)
  8376.        printf("The string is %s\n", result);
  8377.  
  8378.    if (fclose(stream))
  8379.        perror("fclose error");
  8380. }
  8381.  
  8382.  
  8383. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8384.  
  8385. o feof  - Test End-of-File Indicator 
  8386. o ferror  - Test for Read/Write Errors 
  8387. o fputs  - Print Strings 
  8388. o gets  - Read a Line 
  8389. o puts  - Write a String 
  8390. o stdio.h 
  8391.  
  8392.  
  8393. ΓòÉΓòÉΓòÉ 6.78. _filelength - Determine File Length ΓòÉΓòÉΓòÉ
  8394.  
  8395.  
  8396. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8397.  
  8398. #include <io.h>
  8399.  
  8400. long _filelength(int handle);
  8401.  
  8402.  
  8403. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8404.  
  8405. Language Level: Extension 
  8406.  
  8407. The _filelength function returns the length, in bytes, of the file associated 
  8408. with handle. The length of the file will be correct even if you have the handle 
  8409. opened and have appended data to the file. 
  8410.  
  8411. A return value of -1L indicates an error, and errno is set to one of the 
  8412. following values: 
  8413.  
  8414. Value          Meaning 
  8415. EBADF          The file handle is incorrect or the mode specified does not 
  8416.                match the mode you opened the file with. 
  8417. EOS2ERR        The call to the operating system was not successful. 
  8418.  
  8419. Example of _filelength 
  8420.  
  8421.  
  8422. ΓòÉΓòÉΓòÉ <hidden> Example of _filelength ΓòÉΓòÉΓòÉ
  8423.  
  8424. /************************************************************************
  8425. *
  8426.  
  8427. This example opens a file and tries to determine the current length of the file 
  8428. using _filelength. 
  8429.  
  8430.                                                                         *
  8431. ************************************************************************/
  8432.  
  8433. #include <io.h>
  8434. #include <stdio.h>
  8435. #include <stdlib.h>
  8436. #include <fcntl.h>
  8437.  
  8438. int main(void)
  8439. {
  8440.    long length;
  8441.    int  fh;
  8442.  
  8443.    printf("\nCreating sample.dat.\n");
  8444.    system("echo Sample Program > sample.dat");
  8445.  
  8446.    if (-1 == (fh = _open("sample.dat",O_RDWR | O_APPEND)))
  8447.    {
  8448.       printf("Unable to open sample.dat.\n");
  8449.       return 1;
  8450.    }
  8451.  
  8452.    if (-1 == (length = _filelength(fh)))
  8453.    {
  8454.       printf("Unable to determine length of sample.dat.\n");
  8455.       return 1;
  8456.    }
  8457.  
  8458.    printf("Current length of sample.dat is %d.\n",length);
  8459.  
  8460.    _close(fh);
  8461.    return 0;
  8462.  
  8463. /****************  The expected output is:  *****************************
  8464.  
  8465.       Creating sample.dat.
  8466.       Current length of sample.dat is 17.
  8467. */
  8468. }
  8469.  
  8470.  
  8471. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8472.  
  8473. o _chsize - Alter Length of File 
  8474. o __eof - Determine End of File 
  8475. o io.h 
  8476.  
  8477.  
  8478. ΓòÉΓòÉΓòÉ 6.79. _fileno - Determine File Handle ΓòÉΓòÉΓòÉ
  8479.  
  8480.  
  8481. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8482.  
  8483. #include <stdio.h>
  8484.  
  8485. int _fileno(FILE *stream);
  8486.  
  8487.  
  8488. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8489.  
  8490. Language Level: Extension 
  8491.  
  8492. The _fileno function determines the file handle currently associated with 
  8493. stream. 
  8494.  
  8495. The _fileno function returns the file handle. If the function fails, the return 
  8496. value is -1 and the errno variable may be set to one of the following values: 
  8497.  
  8498. Value          Meaning 
  8499. ENULLFCB       The input stream is NULL. 
  8500. EBADTYPE       The input stream file is not a stream file. 
  8501.  
  8502. The result is undefined if stream does not specify an open file. 
  8503.  
  8504. Example of _fileno 
  8505.  
  8506.  
  8507. ΓòÉΓòÉΓòÉ <hidden> Example of _fileno ΓòÉΓòÉΓòÉ
  8508.  
  8509. /************************************************************************
  8510. *
  8511. This example determines the file handle of the stderr data stream: 
  8512.  
  8513.                                                                         *
  8514. ************************************************************************/
  8515.  
  8516. #include <stdio.h>
  8517.  
  8518. int main(void)
  8519. {
  8520.     int result;
  8521.  
  8522.     result = 0xFFFF & _fileno(stderr);
  8523.  
  8524.     printf("The file handle associated with stderr is %d.\n", result);
  8525.  
  8526.     return 0;
  8527.  
  8528.  
  8529. /*******************  The output should be similar to:  *****************
  8530.  
  8531.    The file handle associated with stderr is 2.
  8532. */
  8533. }
  8534.  
  8535.  
  8536. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8537.  
  8538. o _dup -Associate Second Handle with Open File 
  8539. o _dup2 -Associate Second Handle with Open File 
  8540. o fopen  - Open Files 
  8541. o freopen  - Redirect Open Files 
  8542. o _isatty - Test Handle for Character Device 
  8543. o _open - Open File 
  8544. o stdio.h 
  8545.  
  8546.  
  8547. ΓòÉΓòÉΓòÉ 6.80. floor - Integer <= Argument ΓòÉΓòÉΓòÉ
  8548.  
  8549.  
  8550. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8551.  
  8552. #include <math.h>
  8553.  
  8554. double floor(double x);
  8555.  
  8556.  
  8557. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8558.  
  8559. Language Level: ANSI, SAA 
  8560.  
  8561. The floor function calculates the largest integer that is less than or equal to 
  8562. x. The floor function returns the floating-point result as a double value. 
  8563.  
  8564. The result of the floor function cannot have a range error. 
  8565.  
  8566. Example of floor 
  8567.  
  8568.  
  8569. ΓòÉΓòÉΓòÉ <hidden> Example of floor ΓòÉΓòÉΓòÉ
  8570.  
  8571. /************************************************************************
  8572. *
  8573. This example assigns y value of the largest integer less than or equal to 2.8 
  8574. and z the value of the largest integer less than or equal to -2.8. 
  8575.  
  8576.                                                                         *
  8577. ************************************************************************/
  8578.  
  8579. #include <math.h>
  8580. #include <stdio.h>
  8581.  
  8582. int main(void)
  8583. {
  8584.    double y, z;
  8585.  
  8586.    y = floor(2.8);
  8587.    z = floor(-2.8);
  8588.  
  8589.    printf("floor(  2.8 ) = %lf\n", y);
  8590.    printf("floor( -2.8 ) = %lf\n", z);
  8591. }
  8592.  
  8593. /*******************  Output should be similar to:  ***************
  8594.  
  8595. floor(  2.8 ) = 2.000000
  8596. floor( -2.8 ) = -3.000000
  8597. */
  8598.  
  8599.  
  8600. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8601.  
  8602. o ceil - Integer >= Argument 
  8603. o fmod  - Floating-Point Remainder 
  8604. o math.h 
  8605.  
  8606.  
  8607. ΓòÉΓòÉΓòÉ 6.81. _flushall - Write Buffers to Files ΓòÉΓòÉΓòÉ
  8608.  
  8609.  
  8610. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8611.  
  8612. #include <stdio.h>
  8613.  
  8614. int _flushall(void);
  8615.  
  8616.  
  8617. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8618.  
  8619. Language Level: Extension 
  8620.  
  8621. The _flushall function causes the system to write to file the contents of all 
  8622. buffers associated with open output streams (including stdin, stdout, and 
  8623. stderr). It clears all buffers associated with open input streams of their 
  8624. current contents. The next read operation, if there is one, reads new data from 
  8625. the input files into the buffers.  All streams remain open after the call. 
  8626.  
  8627. For portability, use the SAA function fflush instead of _flushall. 
  8628.  
  8629. The _flushall function returns the number of open streams of input and output. 
  8630. If an error occurs, _flushall returns EOF. 
  8631.  
  8632. Example of _flushall 
  8633.  
  8634.  
  8635. ΓòÉΓòÉΓòÉ <hidden> Example of _flushall ΓòÉΓòÉΓòÉ
  8636.  
  8637. /************************************************************************
  8638. *
  8639. In this example, _flushall completes any pending input or output on all streams 
  8640. by flushing all buffers: 
  8641.  
  8642.                                                                         *
  8643. ************************************************************************/
  8644.  
  8645. #include <stdio.h>
  8646.  
  8647. int main(void)
  8648. {
  8649.     int i,numflushed;
  8650.  
  8651.     char buffer1[5] = {1,2,3,4};
  8652.     char buffer2[5] = {5,6,7,8};
  8653.  
  8654.     char *file1 = "file1.dat";
  8655.     char *file2 = "file2.dat";
  8656.     FILE *stream1, *stream2;
  8657.  
  8658.     stream1 = fopen(file1,"a+");
  8659.     stream2 = fopen(file2,"a+");
  8660.  
  8661.     for(i = 0; i <= sizeof(buffer1); i++)
  8662.     {
  8663.          fputc(buffer1[i], stream1);
  8664.          fputc(buffer2[i], stream2);
  8665.     };
  8666.  
  8667.     numflushed = _flushall();       /*  all streams flushed  */
  8668.     printf("Number of files flushed = %d\n", numflushed);
  8669.  
  8670.     fclose(stream1);
  8671.     fclose(stream2);
  8672.  
  8673.     return 0;
  8674.  
  8675. /*******************  The output should be similar to:  *****************
  8676.  
  8677.    Number of files flushed = 5
  8678. */
  8679. }
  8680.  
  8681.  
  8682. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8683.  
  8684. o _close - Closes File Associated with Handle 
  8685. o fclose  - Close Stream 
  8686. o fflush  - Write Buffer to File 
  8687. o stdio.h 
  8688.  
  8689.  
  8690. ΓòÉΓòÉΓòÉ 6.82. fmod  - Floating-Point Remainder ΓòÉΓòÉΓòÉ
  8691.  
  8692.  
  8693. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8694.  
  8695. #include <math.h>
  8696.  
  8697. double fmod(double x, double y);
  8698.  
  8699.  
  8700. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8701.  
  8702. Language Level: ANSI, SAA 
  8703.  
  8704. The fmod function calculates the floating-point remainder of x/y. The absolute 
  8705. value of the result is always less than the absolute value of y. The result 
  8706. will have the same sign as x. If y is zero or if x/y causes an overflow, the 
  8707. function returns 0. 
  8708.  
  8709. Example of fmod 
  8710.  
  8711.  
  8712. ΓòÉΓòÉΓòÉ <hidden> Example of fmod ΓòÉΓòÉΓòÉ
  8713.  
  8714. /************************************************************************
  8715. *
  8716.  
  8717. This example computes z as the remainder of x/y; here x/y is -3 with a 
  8718. remainder of -1: 
  8719.  
  8720.                                                                         *
  8721. ************************************************************************/
  8722.  
  8723. #include <math.h>
  8724.  
  8725. int main(void)
  8726. {
  8727.    double x, y, z;
  8728.  
  8729.    x = -10.0;
  8730.    y = 3.0;
  8731.    z = fmod(x,y);      /* z = -1.0 */
  8732.  
  8733.    printf("fmod( %lf, %lf) = %lf\n", x, y, z);
  8734. }
  8735.  
  8736. /*******************  Output should be similar to:  ***************
  8737.  
  8738. fmod( -10.000000, 3.000000) = -1.000000
  8739. */
  8740.  
  8741.  
  8742. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8743.  
  8744. o ceil - Integer >= Argument 
  8745. o fabs  - Calculate Floating-Point Absolute Value 
  8746. o floor - Integer <= Argument 
  8747. o math.h 
  8748.  
  8749.  
  8750. ΓòÉΓòÉΓòÉ 6.83. fopen  - Open Files ΓòÉΓòÉΓòÉ
  8751.  
  8752.  
  8753. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8754.  
  8755. #include <stdio.h>
  8756.  
  8757. FILE *fopen(const char *filename, const char *mode);
  8758.  
  8759.  
  8760. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8761.  
  8762. Language Level: ANSI, SAA 
  8763.  
  8764. The fopen function opens the file specified by filename.  The mode variable is 
  8765. a character string specifying the type of access requested for the file.  The 
  8766. mode variable contains one positional parameter followed by optional keyword 
  8767. parameters. 
  8768.  
  8769. The possible values for the positional parameters are: 
  8770.  
  8771. Mode Description 
  8772.   Open a text file for reading.  The file must exist. 
  8773.   Create a text file for writing.  If the given file exists, its contents are 
  8774.   destroyed. 
  8775.   Open a text file in append mode for writing at the end of the file.  fopen 
  8776.   creates the file if it does not exist. 
  8777. r+ 
  8778.   Open a text file for both reading and writing.  The file must exist. 
  8779. w+ 
  8780.   Create a text file for both reading and writing.  If the given file exists, 
  8781.   its contents are destroyed. 
  8782. a+ 
  8783.   Open a text file in append mode for reading or updating at the end of the 
  8784.   file.  fopen creates the file if it does not exist. 
  8785. rb 
  8786.   Open a binary file for reading.  The file must exist. 
  8787. wb 
  8788.   Create an empty binary file for writing.  If the file exists, its contents 
  8789.   are destroyed. 
  8790. ab 
  8791.   Open a binary file in append mode for writing at the end of the file. fopen 
  8792.   creates the file if it does not exist. 
  8793. r+b or rb+ 
  8794.   Open a binary file for both reading and writing.  The file must exist. 
  8795. w+b or wb+ 
  8796.   Create an empty binary file for both reading and writing.  If the file 
  8797.   exists, its contents will be destroyed. 
  8798. a+b or ab+ 
  8799.   Open a binary file in append mode for writing at the end of the file.  fopen 
  8800.   creates the file if it does not exist. 
  8801.  
  8802. Warning: Use the w, w+, wb, w+b, and wb+ parameters with care;  data in 
  8803. existing files of the same name will be lost. 
  8804.  
  8805. Text files contain printable characters and control characters organized into 
  8806. lines.  Each line ends with a new-line character, except for the last line, 
  8807. which does not require one. The system may insert or convert control characters 
  8808. in an output text stream. 
  8809.  
  8810. Note:  Data output to a text stream may not compare as equal to the same data 
  8811. on input. 
  8812.  
  8813. Binary files contain a series of characters.  For binary files, the system does 
  8814. not translate control characters on input or output. 
  8815.  
  8816. When you open a file with a, a+, ab, a+b or ab+ mode, all write operations take 
  8817. place at the end of the file.  Although you can reposition the file pointer 
  8818. using fseek or rewind, the write functions move the file pointer back to the 
  8819. end of the file before they carry out any operation. This action prevents you 
  8820. from overwriting existing data. 
  8821.  
  8822. When you specify the update mode (using + in the second or third position), you 
  8823. can both read from and write to the file.  However, when switching between 
  8824. reading and writing, you must include an intervening positioning function such 
  8825. as fseek, fsetpos, rewind, or fflush.  Output may immediately follow input if 
  8826. the end-of-file was detected. 
  8827.  
  8828. The keyword parameters are: 
  8829.  
  8830. blksize=value 
  8831.   Specifies the maximum length, in bytes, of a physical block of records. For 
  8832.   fixed-length records, the maximum size is 32760 bytes.  For variable-length 
  8833.   records, the maximum is 32756. The default buffer size is 4096 bytes. 
  8834. lrecl=value 
  8835.   Specifies the length, in bytes, for fixed-length records and the maximum 
  8836.   length for variable-length records. For fixed-length records, the maximum 
  8837.   length is 32760 bytes.  For variable-length records, the maximum is 32756. If 
  8838.   the value of LRECL is larger than the value of BLKSIZE, the LRECL value is 
  8839.   ignored 
  8840. recfm=value 
  8841.   value can be: 
  8842.  
  8843.    F    fixed-length, unblocked records 
  8844.    V    variable-length, unblocked records The default for the C/C++ Tools 
  8845.   compiler is fixed-length record format. 
  8846. type=value 
  8847.   value can be: 
  8848.  
  8849.   memory  This parameter identifies this file as a memory file that is 
  8850.   accessible only from C programs. This is the default. If you want to use a 
  8851.   memory file, you must compile with the /Sv option. 
  8852.  
  8853. The C/C++ Tools compiler does not support record I/O. 
  8854.  
  8855. The fopen function generally fails if parameters are mismatched. 
  8856.  
  8857. The file attributes can be altered only if the open mode specified with the 
  8858. fopen function is one of the write modes (w, w+, wb, or wb+). The system 
  8859. deletes the existing file and creates a new file with the attributes specified 
  8860. in fopen. 
  8861.  
  8862. The fopen function returns a pointer to a file structure that can be used to 
  8863. access the open file.  A NULL pointer return value indicates an error. 
  8864.  
  8865. Example of fopen 
  8866.  
  8867.  
  8868. ΓòÉΓòÉΓòÉ <hidden> Example of fopen ΓòÉΓòÉΓòÉ
  8869.  
  8870. /************************************************************************
  8871. *
  8872.  
  8873. This example attempts to open a file for reading: 
  8874.  
  8875.                                                                         *
  8876. ************************************************************************/
  8877.  
  8878. #include <stdio.h>
  8879.  
  8880. int main(void)
  8881. {
  8882.    FILE *stream;
  8883.  
  8884.    if ((stream = fopen("myfile.dat", "r")) == NULL)
  8885.       printf("Could not open data file\n");
  8886.  
  8887.    /* The following call opens a fixed record length file */
  8888.    /* for reading and writing.                            */
  8889.  
  8890.    stream = fopen("myfile.dat", "rb+, lrecl=80,  \
  8891.                blksize=240, recfm=f");
  8892. }
  8893.  
  8894.  
  8895. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8896.  
  8897. o _creat - Create New File 
  8898. o fclose  - Close Stream 
  8899. o fflush  - Write Buffer to File 
  8900. o fread  - Read Items 
  8901. o freopen  - Redirect Open Files 
  8902. o _open - Open File 
  8903. o _sopen - Open Shared File 
  8904. o fseek  - Reposition File Position 
  8905. o fsetpos  - Set File Position 
  8906. o fwrite  - Write Items 
  8907. o rewind  - Adjust Current File Position 
  8908. o stdio.h 
  8909.  
  8910.  
  8911. ΓòÉΓòÉΓòÉ 6.84. _fpatan - Calculate Arctangent ΓòÉΓòÉΓòÉ
  8912.  
  8913.  
  8914. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8915.  
  8916. #include <builtin.h>
  8917.  
  8918. double _fpatan(double x);
  8919.  
  8920.  
  8921. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8922.  
  8923. Language Level: Extension 
  8924.  
  8925. The _fpatan function calculates the arctangent of x, which is a value in 
  8926. radians between -╤â/2 and ╤â/2. This function causes the compiler to emit the 
  8927. appropriate 80387 instruction for the calculation of arctangent. 
  8928.  
  8929. Because it is a built-in function and has no backing code in the library: 
  8930.  
  8931. o You cannot take the address of _fpatan. 
  8932. o You cannot parenthesize a _fpatan function call, because parentheses specify 
  8933.   a call to the backing code for the function. 
  8934.  
  8935. This function returns the arctangent of x. 
  8936.  
  8937. Example of _fpatan 
  8938.  
  8939.  
  8940. ΓòÉΓòÉΓòÉ <hidden> Example of _fpatan ΓòÉΓòÉΓòÉ
  8941.  
  8942. /************************************************************************
  8943. *
  8944.  
  8945. This example calculates the arctangent of x. 
  8946.  
  8947.                                                                         *
  8948. ************************************************************************/
  8949.  
  8950. #include <stdio.h>
  8951. #include <builtin.h>
  8952. #include <math.h>
  8953.  
  8954. int main(void)
  8955.     {
  8956.     double a,c;
  8957.     c = 0.45;
  8958.  
  8959.     a = _fpatan(c);
  8960.  
  8961.     printf("The arctangent of %lf is %lf.\n", c, a);
  8962. }
  8963.  
  8964.  
  8965. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  8966.  
  8967. o atan - atan2  - Calculate Arctangent 
  8968. o _fptan - Calculate Tangent 
  8969. o tan  - Calculate Tangent 
  8970. o tanh  - Calculate Hyperbolic Tangent 
  8971.  
  8972.  
  8973. ΓòÉΓòÉΓòÉ 6.85. _fpreset - Reset Floating-Point Unit ΓòÉΓòÉΓòÉ
  8974.  
  8975.  
  8976. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  8977.  
  8978. #include <float.h>
  8979.  
  8980. void _fpreset(void);
  8981.  
  8982.  
  8983. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  8984.  
  8985. Language Level: Extension 
  8986.  
  8987. The _fpreset function resets the floating-point unit to the default state that 
  8988. the math library requires to function correctly. This function is often used 
  8989. within signal handlers. For more information on signal handlers, see the 
  8990. Programming Guide. 
  8991.  
  8992. If a program traps floating-point error signals (SIGFPE) with signal, the 
  8993. program can safely recover from floating-point errors by calling longjmp. 
  8994.  
  8995. The _fpreset function resets the floating-point unit of the current thread 
  8996. only.  It does not affect any other threads that may be processing. 
  8997.  
  8998. There is no return value. 
  8999.  
  9000. Example of _fpreset 
  9001.  
  9002.  
  9003. ΓòÉΓòÉΓòÉ <hidden> Example of _fpreset ΓòÉΓòÉΓòÉ
  9004.  
  9005. /************************************************************************
  9006. *
  9007. This example establishes the function fphandler as a floating-point error 
  9008. handler. The main program produces a floating-point error, which causes control 
  9009. to be passed to fphandler. The fphandler function calls _fpreset to reset the 
  9010. floating-point unit, and then returns to main. 
  9011.  
  9012.                                                                         *
  9013. ************************************************************************/
  9014.  
  9015. #include <stdio.h>
  9016. #include <signal.h>
  9017. #include <setjmp.h>
  9018. #include <float.h>
  9019.  
  9020. jmp_buf mark;
  9021.  
  9022. void fphandler(int sig)
  9023. {
  9024.     printf("Floating point signal = %d\n", sig);
  9025.     _fpreset();     /* Reinitialize floating-point package */
  9026.     longjmp(mark, -1);
  9027. }
  9028.  
  9029. int main(void)
  9030. {
  9031.     double a = 1.0, b = 0.0, c;
  9032.  
  9033.     if (signal(SIGFPE, fphandler) == SIG_ERR)
  9034.         exit(-1);
  9035.  
  9036.     if (setjmp(mark) == 0)
  9037.     {
  9038.         c = a / b;             /* generate floating-point error */
  9039.         printf("Should never get here\n");
  9040.     }
  9041.     printf("Recovered from floating-point error\n");
  9042.  
  9043.     return 0;
  9044.  
  9045.     /* The expected output is:
  9046.  
  9047.        Floating point signal = 3
  9048.        Recovered from floating-point error  */
  9049.  
  9050. }
  9051.  
  9052.  
  9053. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9054.  
  9055. o _clear87 - Clear Floating-Point Status Word 
  9056. o _control87 - Set Floating-Point Status Word 
  9057. o longjmp  - Restore Stack Environment 
  9058. o signal Install Interrupt Handlers 
  9059. o _status87 - Get Floating-Point Status Word 
  9060. o float.h 
  9061.  
  9062.  
  9063. ΓòÉΓòÉΓòÉ 6.86. fprintf  - Write Formatted Data ΓòÉΓòÉΓòÉ
  9064.  
  9065.  
  9066. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9067.  
  9068. #include <stdio.h>
  9069.  
  9070. int fprintf(FILE *stream, const char *format-string, argument-list);
  9071.  
  9072.  
  9073. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9074.  
  9075. Language Level: ANSI, SAA, Extension 
  9076.  
  9077. The fprintf function formats and writes a series of characters and values to 
  9078. the output stream.  The fprintf function converts each entry in argument-list, 
  9079. if any, and writes to the stream according to the corresponding format 
  9080. specification in the format-string. 
  9081.  
  9082. The format-string has the same form and function as the format-string argument 
  9083. for the printf function. 
  9084.  
  9085. In extended mode, fprintf also converts floating-point values of NaN and 
  9086. infinity to the strings "NAN" or "nan" and "INFINITY" or "infinity". The case 
  9087. and sign of the string is determined by the format specifiers.  See Infinity 
  9088. and NaN Support for more information on infinity and NaN values. 
  9089.  
  9090. The fprintf function returns the number of characters printed or a negative 
  9091. value if an output error occurs. 
  9092.  
  9093. Example of fprintf 
  9094.  
  9095.  
  9096. ΓòÉΓòÉΓòÉ <hidden> Example of fprintf ΓòÉΓòÉΓòÉ
  9097.  
  9098. /************************************************************************
  9099. *
  9100.  
  9101. This example sends a line of asterisks for each integer in the array count to 
  9102. the file myfile.  The number of asterisks printed on each line corresponds to 
  9103. an integer in the array. 
  9104.  
  9105.                                                                         *
  9106. ************************************************************************/
  9107.  
  9108. #include <stdio.h>
  9109.  
  9110. int count [10] = {1, 5, 8, 3, 0, 3, 5, 6, 8, 10};
  9111.  
  9112. int main(void)
  9113. {
  9114.    int i,j;
  9115.    FILE *stream;
  9116.  
  9117.    stream = fopen("myfile.dat", "w");
  9118.                   /* Open the stream for writing */
  9119.    for (i=0; i < sizeof(count) / sizeof(count[0]); i++)
  9120.    {
  9121.       for (j = 0; j < count[i]; j++)
  9122.          fprintf(stream,"*");
  9123.                   /* Print asterisk              */
  9124.          fprintf(stream,"\n");
  9125.                   /* Move to the next line       */
  9126.    }
  9127.    fclose (stream);
  9128. }
  9129.  
  9130. /*******************  Output should be similar to:  ***************
  9131.  
  9132. *
  9133. *****
  9134. ********
  9135. ***
  9136.  
  9137. ***
  9138. *****
  9139. ******
  9140. ********
  9141. **********
  9142. */
  9143.  
  9144.  
  9145. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9146.  
  9147. o _cprintf - Print Characters to Screen 
  9148. o fscanf  - Read Formatted Data 
  9149. o printf  - Formatted Print 
  9150. o sprintf  - Formatted Print to Buffer 
  9151. o vfprintf  - Print Argument Data 
  9152. o vprintf  - Print Argument Data 
  9153. o vsprintf  - Print Argument Data 
  9154. o Infinity and NaN Support 
  9155. o stdio.h 
  9156.  
  9157.  
  9158. ΓòÉΓòÉΓòÉ 6.87. _fptan - Calculate Tangent ΓòÉΓòÉΓòÉ
  9159.  
  9160.  
  9161. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9162.  
  9163. #include <builtin.h>
  9164.  
  9165. double _fptan(double x);
  9166.  
  9167.  
  9168. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9169.  
  9170. Language Level: Extension 
  9171.  
  9172. The _fptan function calculates the tangent of x, where x is expressed in 
  9173. radians. The value of x must be less than 2**63. This function causes the 
  9174. compiler to emit the appropriate 80387 instruction for the calculation of 
  9175. tangent. 
  9176.  
  9177. Because it is a built-in function and has no backing code in the library: 
  9178.  
  9179. o You cannot take the address of _fptan. 
  9180. o You cannot parenthesize a _fptan function call, because parentheses specify a 
  9181.   call to the backing code for the function in the library. 
  9182.  
  9183. This function returns the tangent of a variable x expressed in radians. 
  9184.  
  9185. Example of _fptan 
  9186.  
  9187.  
  9188. ΓòÉΓòÉΓòÉ <hidden> Example of _fptan ΓòÉΓòÉΓòÉ
  9189.  
  9190. /************************************************************************
  9191. *
  9192.  
  9193. This example calculates the tangent of pi/4. 
  9194.  
  9195.                                                                         *
  9196. ************************************************************************/
  9197.  
  9198. #include <stdio.h>
  9199. #include <math.h>
  9200. #include <builtin.h>
  9201.  
  9202. int main(void)
  9203.    {
  9204.    double pi, x;
  9205.  
  9206.    pi = 3.1415926;
  9207.    x = _fptan(pi/4.0);
  9208.  
  9209.    printf("The tangent of %lf is %lf\n", pi/4, x);
  9210. }
  9211.  
  9212.  
  9213. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9214.  
  9215. o atan - atan2  - Calculate Arctangent 
  9216. o _fpatan - Calculate Arctangent 
  9217. o tan  - Calculate Tangent 
  9218. o tanh  - Calculate Hyperbolic Tangent 
  9219.  
  9220.  
  9221. ΓòÉΓòÉΓòÉ 6.88. fputc  - Write a Character ΓòÉΓòÉΓòÉ
  9222.  
  9223.  
  9224. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9225.  
  9226. #include <stdio.h>
  9227.  
  9228. int fputc(int c, FILE *stream);
  9229.  
  9230.  
  9231. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9232.  
  9233. Language Level: ANSI, SAA 
  9234.  
  9235. The fputc function converts c to an unsigned char and then writes c to the 
  9236. output stream at the current position and advances the file position 
  9237. appropriately. If the stream is opened with one of the append modes, the 
  9238. character is appended to the end of the stream. 
  9239.  
  9240. The fputc function returns the character written.  A return value of EOF 
  9241. indicates an error. 
  9242.  
  9243. The fputc function is identical to putc but is guaranteed to be a function. 
  9244.  
  9245. Example of fputc 
  9246.  
  9247.  
  9248. ΓòÉΓòÉΓòÉ <hidden> Example of fputc ΓòÉΓòÉΓòÉ
  9249.  
  9250. /************************************************************************
  9251. *
  9252.  
  9253. This example writes the contents of buffer to a file called myfile. 
  9254.  
  9255. Note:  Because the output occurs as a side effect within the second expression 
  9256. of the for statement, the statement body is null. 
  9257.  
  9258.                                                                         *
  9259. ************************************************************************/
  9260.  
  9261. #include <stdio.h>
  9262.  
  9263. #define NUM_ALPHA  26
  9264.  
  9265. int main(void)
  9266. {
  9267.   FILE * stream;
  9268.   int i;
  9269.   int ch;
  9270.  
  9271.   char buffer[NUM_ALPHA + 1] = "abcdefghijklmnopqrstuvwxyz";
  9272.  
  9273.   if (( stream = fopen("myfile.dat", "w"))!= NULL )
  9274.   {
  9275.     /* Put buffer into file */
  9276.     for ( i = 0; ( i < sizeof(buffer) ) &&
  9277.            ((ch = fputc( buffer[i], stream)) != EOF ); ++i );
  9278.     fclose( stream );
  9279.   }
  9280.   else
  9281.     perror( "Error opening myfile" );
  9282.  
  9283. }
  9284.  
  9285.  
  9286. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9287.  
  9288. o fgetc  - Read a Character 
  9289. o _fputchar - Write Character 
  9290. o putc - putchar  - Write a Character 
  9291. o _putch - Write Character to Screen 
  9292. o stdio.h 
  9293.  
  9294.  
  9295. ΓòÉΓòÉΓòÉ 6.89. _fputchar - Write Character ΓòÉΓòÉΓòÉ
  9296.  
  9297.  
  9298. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9299.  
  9300. #include <stdio.h>
  9301.  
  9302. int _fputchar(int c);
  9303.  
  9304.  
  9305. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9306.  
  9307. Language Level: Extension 
  9308.  
  9309. The _fputchar function writes the single character c to the stdout stream at 
  9310. the current position. It is equivalent to a call to the SAA function fputc: 
  9311.  
  9312.    fputc(c, stdout);
  9313.  
  9314. For portability, replace _fputchar with the SAA equivalent. 
  9315.  
  9316. The function returns the character written.  A return value of EOF indicates 
  9317. that a write error has occurred. Use ferror and feof to tell whether this is an 
  9318. error condition or the end of the file. 
  9319.  
  9320. Example of _fputchar 
  9321.  
  9322.  
  9323. ΓòÉΓòÉΓòÉ <hidden> Example of _fputchar ΓòÉΓòÉΓòÉ
  9324.  
  9325. /************************************************************************
  9326. *
  9327. This example writes the contents of buffer to stdout: 
  9328.  
  9329.                                                                         *
  9330. ************************************************************************/
  9331.  
  9332. #include <stdio.h>
  9333.  
  9334. int main(void)
  9335. {
  9336.     char buffer[80];
  9337.     int i, ch = 1;
  9338.  
  9339.     for (i=0; i<80; i++)
  9340.         buffer[i] = 'c';
  9341.  
  9342.     for (i=0; (i<80) && (ch!=EOF); i++)
  9343.         ch = _fputchar(buffer[i]);
  9344.  
  9345.     printf("\n");
  9346.  
  9347.     return 0;
  9348.  
  9349. /************************  The output should be similar to:  *************
  9350.  
  9351.   ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
  9352. */
  9353. }
  9354.  
  9355.  
  9356. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9357.  
  9358. o _fgetchar - Read Single Character from stdin 
  9359. o fputc  - Write a Character 
  9360. o putc - putchar  - Write a Character 
  9361. o _putch - Write Character to Screen 
  9362. o stdio.h 
  9363.  
  9364.  
  9365. ΓòÉΓòÉΓòÉ 6.90. fputs  - Print Strings ΓòÉΓòÉΓòÉ
  9366.  
  9367.  
  9368. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9369.  
  9370. #include <stdio.h>
  9371.  
  9372. int fputs(const char *string, FILE *stream);
  9373.  
  9374.  
  9375. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9376.  
  9377. Language Level: ANSI, SAA 
  9378.  
  9379. The fputs function copies string to the output stream at the current position. 
  9380. It does not copy the null character (\0) at the end of the string. 
  9381.  
  9382. If an error occurs, the fputs function returns EOF;  otherwise, it returns a 
  9383. non-negative value. 
  9384.  
  9385. Example of fputs 
  9386.  
  9387.  
  9388. ΓòÉΓòÉΓòÉ <hidden> Example of fputs ΓòÉΓòÉΓòÉ
  9389.  
  9390. /************************************************************************
  9391. *
  9392.  
  9393. This example writes a string to a stream. 
  9394.  
  9395.                                                                         *
  9396. ************************************************************************/
  9397.  
  9398. #include <stdio.h>
  9399.  
  9400. #define NUM_ALPHA  26
  9401.  
  9402. int main(void)
  9403. {
  9404.   FILE * stream;
  9405.   int num;
  9406.  
  9407.   /* Do not forget that the '\0' char occupies one character */
  9408.   static char buffer[NUM_ALPHA + 1] = "abcdefghijklmnopqrstuvwxyz";
  9409.  
  9410.   if ((stream = fopen("myfile.dat", "w")) != NULL )
  9411.   {
  9412.      /* Put buffer into file */
  9413.      if ( (num = fputs( buffer, stream )) != EOF )
  9414.      {
  9415.        /* Note that fputs() does not copy the \0 character */
  9416.        printf( "Total number of characters written to file = %i\n", num );
  9417.        fclose( stream );
  9418.      }
  9419.      else   /* fputs failed */
  9420.        perror( "fputs failed" );
  9421.   }
  9422.   else
  9423.      perror( "Error opening myfile" );
  9424. }
  9425.  
  9426.  
  9427. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9428.  
  9429. o _cputs - Write String to Screen 
  9430. o fgets  - Read a String 
  9431. o gets  - Read a Line 
  9432. o puts  - Write a String 
  9433. o stdio.h 
  9434.  
  9435.  
  9436. ΓòÉΓòÉΓòÉ 6.91. fread  - Read Items ΓòÉΓòÉΓòÉ
  9437.  
  9438.  
  9439. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9440.  
  9441. #include <stdio.h>
  9442.  
  9443. size_t fread(void *buffer, size_t size, size_t count,
  9444.                 FILE *stream);
  9445.  
  9446.  
  9447. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9448.  
  9449. Language Level: ANSI, SAA 
  9450.  
  9451. The fread function reads up to count items of size length from the input stream 
  9452. and stores them in the given buffer.  The position in the file increases by the 
  9453. number of bytes read. 
  9454.  
  9455. The fread function returns the number of full items successfully read, which 
  9456. can be less than count if an error occurs or if the end-of-file is met before 
  9457. reaching count.  If size or count is 0, fread returns zero and the contents of 
  9458. the array and the state of the stream remain unchanged. 
  9459.  
  9460. The ferror and feof functions are used to distinguish between a read error and 
  9461. an end-of-file. 
  9462.  
  9463. Example of fread 
  9464.  
  9465.  
  9466. ΓòÉΓòÉΓòÉ <hidden> Example of fread ΓòÉΓòÉΓòÉ
  9467.  
  9468. /************************************************************************
  9469. *
  9470.  
  9471. This example attempts to read NUM_ALPHA characters from the file myfile. If 
  9472. there are any errors with either fread or fopen, a message is printed. 
  9473.  
  9474.                                                                         *
  9475. ************************************************************************/
  9476.  
  9477. #include <stdio.h>
  9478.  
  9479. #define NUM_ALPHA  26
  9480.  
  9481. int main(void)
  9482. {
  9483.   FILE * stream;
  9484.   int num;       /* number of characters read from stream */
  9485.  
  9486.   /* Do not forget that the '\0' char occupies one character too! */
  9487.   char buffer[NUM_ALPHA + 1];
  9488.  
  9489.   if (( stream = fopen("myfile.dat", "r"))!= NULL )
  9490.   {
  9491.     num = fread( buffer, sizeof( char ), NUM_ALPHA, stream );
  9492.     if ( num ) {  /* fread success */
  9493.       printf( "Number of characters has been read = %i\n", num );
  9494.       printf( "buffer = %s\n", buffer );
  9495.       fclose( stream );
  9496.     }
  9497.     else {  /* fread failed */
  9498.       if ( ferror(stream) )    /* possibility 1 */
  9499.         perror( "Error reading myfile" );
  9500.       else if ( feof(stream))  /* possibility 2 */
  9501.         perror( "EOF found" );
  9502.     }
  9503.   }
  9504.   else
  9505.     perror( "Error opening myfile" );
  9506.  
  9507. }
  9508.  
  9509.  
  9510. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9511.  
  9512. o feof  - Test End-of-File Indicator 
  9513. o ferror  - Test for Read/Write Errors 
  9514. o fopen  - Open Files 
  9515. o fwrite  - Write Items 
  9516. o _read - Read Into Buffer 
  9517. o stdio.h 
  9518.  
  9519.  
  9520. ΓòÉΓòÉΓòÉ 6.92. free  - Release Storage Blocks ΓòÉΓòÉΓòÉ
  9521.  
  9522.  
  9523. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9524.  
  9525. #include <stdlib.h>  /* also defined in <malloc.h> */
  9526.  
  9527. void free(void *ptr);
  9528.  
  9529.  
  9530. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9531.  
  9532. Language Level: ANSI, SAA, Extension 
  9533.  
  9534. The free function frees a block of storage.  The ptr variable points to a block 
  9535. previously reserved with a call to calloc, malloc, or realloc.  The number of 
  9536. bytes freed is the number of bytes specified when you reserved (or reallocated, 
  9537. in the case of realloc) the block of storage.  If ptr is NULL, free simply 
  9538. returns. 
  9539.  
  9540. There is no return value. 
  9541.  
  9542. Note:  Attempting to free a block of storage not allocated with calloc, malloc, 
  9543.        or realloc (or previously freed storage) can affect the subsequent 
  9544.        reserving of storage and lead to undefined results. 
  9545.  
  9546. Example of free 
  9547.  
  9548.  
  9549. ΓòÉΓòÉΓòÉ <hidden> Example of free ΓòÉΓòÉΓòÉ
  9550.  
  9551. /************************************************************************
  9552. *
  9553.  
  9554. This example uses calloc to allocate storage for x array elements and then 
  9555. calls free to free them. 
  9556.  
  9557.                                                                         *
  9558. ************************************************************************/
  9559.  
  9560. #include <stdio.h>
  9561. #include <stdlib.h>
  9562.  
  9563. int main(void)
  9564. {
  9565.   long * array;    /* start of the array */
  9566.   long * index;    /* index variable     */
  9567.   int    i;        /* index variable     */
  9568.   int  num;        /* number of entries of the array */
  9569.  
  9570.   printf( "Enter the size of the array\n" );
  9571.   scanf( "%i", &num );
  9572.  
  9573.   /* allocate num entries */
  9574.   if ( (index = array = calloc( num, sizeof( long ))) != NULL )
  9575.   {
  9576.     .
  9577.     .  /*  do something with the array  */
  9578.     .
  9579.     free( array );                        /* deallocates array  */
  9580.   }
  9581.   else
  9582.   { /* Out of storage */
  9583.     perror( "Error: out of storage" );
  9584.     abort();
  9585.   }
  9586. }
  9587.  
  9588.  
  9589. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9590.  
  9591. o _alloca - Temporarily Reserve Storage Block 
  9592. o calloc  - Reserve and Initialize Storage 
  9593. o _debug_free - Release Storage Blocks 
  9594. o malloc  - Reserve Storage Block 
  9595. o realloc  - Change Reserved Storage Block Size 
  9596. o malloc.h 
  9597. o _tfree - Free Tiled Storage Block 
  9598. o stdlib.h 
  9599.  
  9600.  
  9601. ΓòÉΓòÉΓòÉ 6.93. _freemod - Free User DLL ΓòÉΓòÉΓòÉ
  9602.  
  9603.  
  9604. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9605.  
  9606. #include <stdlib.h>
  9607.  
  9608. int _freemod(unsigned long module_handle);
  9609.  
  9610.  
  9611. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9612.  
  9613. Language Level: Extension 
  9614.  
  9615. The _freemod function frees all references to a user-created dynamic-link 
  9616. library (DLL) for the calling process. It is the counterpart of the _loadmod 
  9617. function, which loads a DLL for the process. The module_handle is the module 
  9618. handle of the DLL, which was returned by _loadmod. 
  9619.  
  9620. If successful, the _freemod function returns 0. If not, _freemod returns -1 and 
  9621. sets errno to EOS2ERR. 
  9622.  
  9623. Example of _freemod 
  9624.  
  9625.  
  9626. ΓòÉΓòÉΓòÉ <hidden> Example of _freemod ΓòÉΓòÉΓòÉ
  9627.  
  9628. /************************************************************************
  9629. *
  9630. This example loads the DLL mark with _loadmod, and uses the OS/2 function 
  9631. DosQueryProcAddr to get the address of the function dor from within the DLL. It 
  9632. then calls that function, which multiplies two integers passed to it. When the 
  9633. function and DLL are no longer needed, the program frees the DLL module. The 
  9634. macro INCL_DOS and the types PFN and APIRET are required for the OS/2 call, and 
  9635. are defined by including the <os2.h> header file. 
  9636.  
  9637. Note:  To run this program, you must first create mark.dll. Copy the code for 
  9638.        the PLUS function into a file called mark.c, and the code for the .DEF 
  9639.        file into mark.def.  Eliminate the comments from these two files. 
  9640.        Compile with the command: 
  9641.  
  9642.                  icc /Ge- mark.c mark.def
  9643.        You can then run the example: 
  9644.  
  9645.                                                                         *
  9646. ************************************************************************/
  9647.  
  9648. #define INCL_DOS
  9649. #include <os2.h>
  9650. #include <stdio.h>
  9651. #include <stdlib.h>
  9652.  
  9653. /* This is the code for MARK.DEF
  9654.  
  9655. LIBRARY MARK
  9656.  
  9657. PROTMODE
  9658.  
  9659. EXPORTS PLUS                       */
  9660.  
  9661. /* This is the code for PLUS function in the DLL
  9662.  
  9663.    #pragma linkage( PLUS, system )
  9664.    int PLUS( int a, int b )
  9665.    {
  9666.       return a + b;
  9667.    }                                               */
  9668.  
  9669. int main(void)
  9670. {
  9671.    int x = 4, y = 7;
  9672.  
  9673.    unsigned long handle;
  9674.    char * modname = "MARK" ;     /* DLL name              */
  9675.    char * fname = "PLUS"  ;      /* function name         */
  9676.  
  9677.    PFN faddr;                    /* pointer to function   */
  9678.    APIRET rc;                    /* return code           */
  9679.                                  /* from DosQueryProcAddr */
  9680.  
  9681.    /*  dynamically load the 'mark' DLL  */
  9682.    if (_loadmod(modname, &handle) )
  9683.    {
  9684.       printf("Error loading module %s\n", modname );
  9685.       exit (-1);
  9686.    }
  9687.  
  9688.    /*  get function address from DLL  */
  9689.    rc = DosQueryProcAddr( handle, 0, fname, &faddr );
  9690.  
  9691.    if (rc == 0)
  9692.       printf("Calling the function from the %s DLL to add %d
  9693.                and %d\n", modname,x,y);
  9694.       printf("The result of the function call is %d\n",
  9695.               faddr(x,y));
  9696.    else
  9697.    {
  9698.       printf("Error locating address of function %s\n",
  9699.                fname);
  9700.       _freemod( handle );
  9701.       exit(-1);
  9702.    }
  9703.  
  9704.    if( _freemod( handle ))
  9705.    {
  9706.       printf("Error in freeing the %s DLL module\n",
  9707.                modname);
  9708.       exit(-1);
  9709.    }
  9710.  
  9711.    printf("Reference to the %s DLL module has been freed\n",
  9712.             modname);
  9713.  
  9714.    return 0;
  9715.  
  9716. /**************  The expected output is  ********************
  9717.  
  9718.       Calling the function from the DLL to add 4 and 7
  9719.       The result of the function call is 11
  9720.       Reference to the MARK DLL module has been freed
  9721.  
  9722. */
  9723. }
  9724.  
  9725.  
  9726. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9727.  
  9728. o _loadmod - Load User DLL 
  9729. o stdlib.h 
  9730.  
  9731.  
  9732. ΓòÉΓòÉΓòÉ 6.94. freopen  - Redirect Open Files ΓòÉΓòÉΓòÉ
  9733.  
  9734.  
  9735. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9736.  
  9737. #include <stdio.h>
  9738.  
  9739. FILE *freopen(const char *filename, const char *mode, FILE *stream);
  9740.  
  9741.  
  9742. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9743.  
  9744. Language Level: ANSI, SAA 
  9745.  
  9746. The freopen function closes the file currently associated with stream and 
  9747. reassigns stream to the file specified by filename. The freopen function opens 
  9748. the new file associated with stream with the given mode, which is a character 
  9749. string specifying the type of access requested for the file. You can also use 
  9750. the freopen function to redirect the standard stream files stdin, stdout, and 
  9751. stderr to files that you specify. 
  9752.  
  9753. If filename is an empty string, freopen closes and reopens the stream to the 
  9754. new open mode, rather than reassigning it to a new file or device. You can use 
  9755. freopen with no file name specified to change the mode of a standard stream 
  9756. from text to binary without redirecting the stream, for example: 
  9757.  
  9758.    fp = freopen("", "rb", stdin);
  9759. You can use the same method to change the mode from binary back to text. 
  9760.  
  9761. Note:  This method is included in the SAA C definition, but not in the ANSI C 
  9762. standard. 
  9763.  
  9764. See fopen. for a description of the mode parameter. 
  9765.  
  9766. The freopen function returns the value of stream to the newly opened file. If 
  9767. an error occurs, freopen closes the original file and returns a NULL pointer 
  9768. value. 
  9769.  
  9770. Example of freopen 
  9771.  
  9772.  
  9773. ΓòÉΓòÉΓòÉ <hidden> Example of freopen ΓòÉΓòÉΓòÉ
  9774.  
  9775. /************************************************************************
  9776. *
  9777.  
  9778. This example closes the stream1 data stream and reassigns its stream pointer: 
  9779.  
  9780.                                                                         *
  9781. ************************************************************************/
  9782.  
  9783. #include <stdio.h>
  9784.  
  9785. int main(void)
  9786. {
  9787.    FILE *stream, *stream1, *stream2;
  9788.  
  9789.    stream = fopen("myfile.dat","r");
  9790.    stream1 = stream;
  9791.    stream2 = freopen("", "w+", stream1);
  9792. }
  9793.  
  9794. /************************************************************************
  9795. *
  9796. Note that stream1 and stream2 will have the same value, but they will not 
  9797. necessarily have the same value as stream. 
  9798.  
  9799.                                                                         *
  9800. ************************************************************************/
  9801.  
  9802.  
  9803. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9804.  
  9805. o _close - Closes File Associated with Handle 
  9806. o fclose  - Close Stream 
  9807. o _fcloseall - Close All Open Streams 
  9808. o fopen  - Open Files 
  9809. o _open - Open File 
  9810. o _sopen - Open Shared File 
  9811. o stdio.h 
  9812.  
  9813.  
  9814. ΓòÉΓòÉΓòÉ 6.95. frexp  - Separate Floating-Point Value ΓòÉΓòÉΓòÉ
  9815.  
  9816.  
  9817. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9818.  
  9819. #include <math.h>
  9820.  
  9821. double frexp(double x, int *expptr);
  9822.  
  9823.  
  9824. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9825.  
  9826. Language Level: ANSI, SAA 
  9827.  
  9828. The frexp function breaks down the floating-point value x into a term m for the 
  9829. mantissa and another term n for the exponent, such that the absolute value of m 
  9830. is greater than or equal to 0.5 and less than 1.0 or equal to 0, and x = m * 
  9831. (2**n). The frexp function stores the integer exponent n at the location to 
  9832. which expptr points. 
  9833.  
  9834. The frexp function returns the mantissa term m.  If x is 0, the function 
  9835. returns 0 for both the mantissa and exponent.  The mantissa has the same sign 
  9836. as the argument x.  The result of the frexp function cannot have a range error. 
  9837.  
  9838. Example of frexp 
  9839.  
  9840.  
  9841. ΓòÉΓòÉΓòÉ <hidden> Example of frexp ΓòÉΓòÉΓòÉ
  9842.  
  9843. /************************************************************************
  9844. *
  9845.  
  9846. This example decomposes the floating-point value of x, 16.4, into its mantissa 
  9847. 0.5125, and its exponent 5.  It stores the mantissa in y and the exponent in n. 
  9848.  
  9849.                                                                         *
  9850. ************************************************************************/
  9851.  
  9852. #include <math.h>
  9853. #include <stdio.h>
  9854.  
  9855. int main(void)
  9856. {
  9857.    double x, m;
  9858.    int n;
  9859.  
  9860.    x = 16.4;
  9861.    m = frexp(x, &n);
  9862.  
  9863.    printf("The mantissa is %lf and the exponent is %d\n", m, n);
  9864. }
  9865.  
  9866. /*******************  Output should be similar to:  ***************
  9867.  
  9868. The mantissa is 0.512500 and the exponent is 5
  9869. */
  9870.  
  9871.  
  9872. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9873.  
  9874. o ldexp  - Multiply by a Power of Two 
  9875. o modf  - Separate Floating-Point Value 
  9876. o math.h 
  9877.  
  9878.  
  9879. ΓòÉΓòÉΓòÉ 6.96. fscanf  - Read Formatted Data ΓòÉΓòÉΓòÉ
  9880.  
  9881.  
  9882. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9883.  
  9884. #include <stdio.h>
  9885.  
  9886. int fscanf (FILE *stream, const char *format-string, argument-list);
  9887.  
  9888.  
  9889. ΓòÉΓòÉΓòÉ <hidden> Desciption ΓòÉΓòÉΓòÉ
  9890.  
  9891. Language Level: ANSI, SAA, Extension 
  9892.  
  9893. The fscanf function reads data from the current position of the specified 
  9894. stream into the locations given by the entries in argument-list, if any.  Each 
  9895. entry in argument-list must be a pointer to a variable with a type that 
  9896. corresponds to a type specifier in format-string. 
  9897.  
  9898. The format-string controls the interpretation of the input fields and has the 
  9899. same form and function as the format-string argument for the scanf function. 
  9900. See scanf for a description of format-string. 
  9901.  
  9902. In extended mode, the fscanf function also reads in the strings "INFINITY", 
  9903. "INF", and "NAN" (in upper or lowercase) and converts them to the corresponding 
  9904. floating-point value.  The sign of the value is determined by the format 
  9905. specification. See Infinity and NaN Support for more information on infinity 
  9906. and NaN values. 
  9907.  
  9908. The fscanf function returns the number of fields that it successfully converted 
  9909. and assigned.  The return value does not include fields that fscanf read but 
  9910. did not assign. 
  9911.  
  9912. The return value is EOF if an input failure occurs before any conversion, or 
  9913. the number of input items assigned if successful. 
  9914.  
  9915. Example of fscanf 
  9916.  
  9917.  
  9918. ΓòÉΓòÉΓòÉ <hidden> Example of fscanf ΓòÉΓòÉΓòÉ
  9919.  
  9920. /************************************************************************
  9921. *
  9922.  
  9923. This example opens the file myfile for reading and then scans this file for a 
  9924. string, a long integer value, a character, and a floating-point value. 
  9925.  
  9926.                                                                         *
  9927. ************************************************************************/
  9928.  
  9929. #include <stdio.h>
  9930.  
  9931. #define  MAX_LEN  80
  9932.  
  9933. int main(void)
  9934. {
  9935.    FILE *stream;
  9936.    long l;
  9937.    float fp;
  9938.    char s[MAX_LEN + 1];
  9939.    char c;
  9940.  
  9941.    stream = fopen("myfile.dat", "r");
  9942.  
  9943.    /* Put in various data. */
  9944.  
  9945.    fscanf(stream, "%s", &s[0]);
  9946.    fscanf(stream, "%ld", &l);
  9947.    fscanf(stream, "%c", &c);
  9948.    fscanf(stream, "%f", &fp);
  9949.  
  9950.    printf("string = %s\n", s);
  9951.    printf("long double = %ld\n", l);
  9952.    printf("char = %c\n", c);
  9953.    printf("float = %f\n", fp);
  9954. }
  9955.  
  9956. /***************  If myfile contains  ************************
  9957. ****************abcdefghijklmnopqrstuvwxyz 343.2,  ***********
  9958. **********************  expected output is:  *********************
  9959.  
  9960. string = abcdefghijklmnopqrstuvwxyz
  9961. long double = 343
  9962. char = .
  9963. float = 2.000000
  9964. */
  9965.  
  9966.  
  9967. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  9968.  
  9969. o _cscanf - Read Data from Keyboard 
  9970. o fprintf  - Write Formatted Data 
  9971. o scanf  - Read Data 
  9972. o sscanf  - Read Data 
  9973. o Infinity and NaN Support 
  9974. o stdio.h 
  9975.  
  9976.  
  9977. ΓòÉΓòÉΓòÉ 6.97. fseek  - Reposition File Position ΓòÉΓòÉΓòÉ
  9978.  
  9979.  
  9980. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  9981.  
  9982. #include <stdio.h>
  9983.  
  9984. int fseek(FILE *stream, long int offset, int origin);
  9985.  
  9986.  
  9987. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  9988.  
  9989. Language Level: ANSI, SAA 
  9990.  
  9991. The fseek function changes the current file position associated with stream to 
  9992. a new location within the file. The next operation on the stream takes place at 
  9993. the new location.  On a stream open for update, the next operation can be 
  9994. either a reading or a writing operation. 
  9995.  
  9996. The origin must be one of the following constants defined in <stdio.h>: 
  9997.  
  9998. Origin            Definition 
  9999. SEEK_SET          Beginning of file 
  10000. SEEK_CUR          Current position of file pointer 
  10001. SEEK_END          End of file 
  10002.  
  10003. For a binary stream, you can also change the position beyond the end of the 
  10004. file.  An attempt to position before the beginning of the file causes an error. 
  10005. If successful, the fseek function clears the end-of-file indicator, even when 
  10006. origin is SEEK_END, and undoes the effect of any preceding ungetc function on 
  10007. the same stream. 
  10008.  
  10009. The fseek function returns the value 0 if it successfully moves the pointer.  A 
  10010. nonzero return value indicates an error.  On devices that cannot seek, such as 
  10011. terminals and printers, the return value is nonzero. 
  10012.  
  10013. Note:  For streams opened in text mode, fseek has limited use because some 
  10014.        system translations (such as those between carriage return/line feed and 
  10015.        new line) can produce unexpected results.  The only fseek operations 
  10016.        that can be relied upon to work on streams opened in text mode are 
  10017.        seeking with an offset of zero relative to any of the origin values or 
  10018.        seeking from the beginning of the file with an offset value returned 
  10019.        from a call to ftell. See the Programming Guide for more information. 
  10020.  
  10021. Example of fseek 
  10022.  
  10023.  
  10024. ΓòÉΓòÉΓòÉ <hidden> Example of fseek ΓòÉΓòÉΓòÉ
  10025.  
  10026. /************************************************************************
  10027. *
  10028.  
  10029. This example opens a file myfile for reading.  After performing input 
  10030. operations (not shown), it moves the file pointer to the beginning of the file. 
  10031.  
  10032.                                                                         *
  10033. ************************************************************************/
  10034.  
  10035. #include <stdio.h>
  10036.  
  10037. int main(void)
  10038. {
  10039.    FILE *stream;
  10040.    int result;
  10041.  
  10042.    stream = fopen("myfile.dat", "r");
  10043.    .
  10044.    .
  10045.    .
  10046.    result = fseek(stream, 0L, SEEK_SET);  /* moves the pointer to the */
  10047.                                           /* beginning of the file    */
  10048. }
  10049.  
  10050.  
  10051. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10052.  
  10053. o fgetpos  - Get File Position 
  10054. o fsetpos  - Set File Position 
  10055. o ftell  - Get Current Position 
  10056. o rewind  - Adjust Current File Position 
  10057. o ungetc  - Push Character onto Input Stream 
  10058. o stdio.h 
  10059.  
  10060.  
  10061. ΓòÉΓòÉΓòÉ 6.98. fsetpos  - Set File Position ΓòÉΓòÉΓòÉ
  10062.  
  10063.  
  10064. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10065.  
  10066. #include <stdio.h>
  10067.  
  10068. int fsetpos(FILE *stream, const fpos_t *pos);
  10069.  
  10070.  
  10071. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10072.  
  10073. Language Level: ANSI, SAA 
  10074.  
  10075. The fsetpos function moves any file position associated with stream to a new 
  10076. location within the file according to the value pointed to by pos.  The value 
  10077. of pos was obtained by a previous call to the fgetpos library function. 
  10078.  
  10079. If fsetpos successfully changes the current position of the file, it returns 
  10080. the value 0. If successful, the fsetpos function clears the end-of-file 
  10081. indicator, and undoes the effect of any previous ungetc function on the same 
  10082. stream.  A nonzero return value indicates an error. 
  10083.  
  10084. After the fsetpos call, the next operation on a stream in update mode may be 
  10085. input or output. 
  10086.  
  10087. Example of fsetpos 
  10088.  
  10089.  
  10090. ΓòÉΓòÉΓòÉ <hidden> Example of fsetpos ΓòÉΓòÉΓòÉ
  10091.  
  10092. /************************************************************************
  10093. *
  10094.  
  10095. This example opens a file myfile for reading.  After performing input 
  10096. operations (not shown), it moves the file pointer to the beginning of the file 
  10097. and rereads the first byte. 
  10098.  
  10099.                                                                          *
  10100. *************************************************************************/
  10101.  
  10102. #include <stdio.h>
  10103.  
  10104. FILE *stream;
  10105.  
  10106. int main(void)
  10107. {
  10108.    int retcode;
  10109.    fpos_t pos, pos1, pos2, pos3;
  10110.    char ptr[20];  /* existing file 'myfile.dat' has 20 byte records */
  10111.  
  10112.    /* Open file, get position of file pointer, and read first record */
  10113.  
  10114.    stream = fopen("myfile.dat", "rb");
  10115.    fgetpos(stream,&pos);
  10116.    pos1 = pos;
  10117.    if (!fread(ptr,sizeof(ptr),1,stream))
  10118.        perror("fread error");
  10119.  
  10120.    /* Perform a number of read operations
  10121.        - the value of 'pos' changes       */
  10122.    .
  10123.    .
  10124.    .
  10125.    /* Re-set pointer to start of file and re-read first record */
  10126.  
  10127.    fsetpos(stream,&pos1);
  10128.    if (!fread(ptr,sizeof(ptr),1,stream))
  10129.        perror("fread error");
  10130.  
  10131.    fclose(stream);
  10132. }
  10133.  
  10134.  
  10135. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10136.  
  10137. o fgetpos  - Get File Position 
  10138. o fseek  - Reposition File Position 
  10139. o ftell  - Get Current Position 
  10140. o rewind  - Adjust Current File Position 
  10141. o ungetc  - Push Character onto Input Stream 
  10142. o stdio.h 
  10143.  
  10144.  
  10145. ΓòÉΓòÉΓòÉ 6.99. _fsin - Calculate Sine ΓòÉΓòÉΓòÉ
  10146.  
  10147.  
  10148. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10149.  
  10150. #include <builtin.h>
  10151.  
  10152. double _fsin( double x);
  10153.  
  10154.  
  10155. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10156.  
  10157. Language Level: Extension 
  10158.  
  10159. The _fsin function calculates the sine of x, where x is expressed in radians. 
  10160. The value of x must be less than 2**63. This function causes the compiler to 
  10161. emit the appropriate 80387 instruction for the calculation of sine. 
  10162.  
  10163. Because it is a built-in function and has no backing code in the library: 
  10164.  
  10165. o You cannot take the address of _fsin. 
  10166. o You cannot parenthesize a _fsin function call, because parentheses specify a 
  10167.   call to the backing code for the function in the library. 
  10168.  
  10169. This function returns the sine of a variable x expressed in radians. 
  10170.  
  10171. Example of _fsin 
  10172.  
  10173.  
  10174. ΓòÉΓòÉΓòÉ <hidden> Example of _fsin ΓòÉΓòÉΓòÉ
  10175.  
  10176. /************************************************************************
  10177. *
  10178.  
  10179. This example calculates y as the sine of ╤â/2. 
  10180.  
  10181.                                                                         *
  10182. ************************************************************************/
  10183.  
  10184. #include <stdio.h>
  10185. #include <math.h>
  10186. #include <builtin.h>
  10187.  
  10188. int main(void)
  10189.    {
  10190.    double pi, x, y;
  10191.  
  10192.    pi = 3.1415926535;
  10193.    x = pi/2;
  10194.    y = _fsin(x);
  10195.  
  10196.    printf("The sine of %lf is %lf\n", x, y);
  10197. )
  10198.  
  10199.  
  10200. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10201.  
  10202. o _fasin - Calculate Arcsine 
  10203. o _fcossin - Calculate Cosine and Sine 
  10204. o _fsincos - Calculate Sine and Cosine 
  10205. o sin  - Calculate Sine 
  10206. o sinh  - Calculate Hyperbolic Sine 
  10207.  
  10208.  
  10209. ΓòÉΓòÉΓòÉ 6.100. _fsincos - Calculate Sine and Cosine ΓòÉΓòÉΓòÉ
  10210.  
  10211.  
  10212. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10213.  
  10214. #include <builtin.h>
  10215.  
  10216. double _fsincos(double x, double *y);
  10217.  
  10218.  
  10219. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10220.  
  10221. Language Level: Extension 
  10222.  
  10223. The _fsincos function calculates the sine of x, and stores the cosine in *y. 
  10224. This operation is faster than separately calculating the sine and cosine. Use 
  10225. _fsincos instead of _fcossin when you will be using the sine first, and then 
  10226. the cosine. 
  10227.  
  10228. Because it is a built-in function and has no backing code in the library: 
  10229.  
  10230. o You cannot take the address of _fsincos. 
  10231. o You cannot parenthesize a _fsincos function call because parentheses specify 
  10232.   a call to the backing code for the function. 
  10233.  
  10234. This function returns the sine of x. 
  10235.  
  10236. Example of _fsincos 
  10237.  
  10238.  
  10239. ΓòÉΓòÉΓòÉ <hidden> Example of _fsincos ΓòÉΓòÉΓòÉ
  10240.  
  10241. /************************************************************************
  10242. *
  10243.  
  10244. This example calculates the sine of x and stores the cosine of x in y. 
  10245.  
  10246.                                                                         *
  10247. ************************************************************************/
  10248.  
  10249. #include <stdio.h>
  10250. #include <stdlib.h>
  10251. #include <builtin.h>
  10252. #define MAX  1.0
  10253. #define MIN -1.0
  10254.  
  10255. int main(void)
  10256.   {
  10257.   double x,y;
  10258.  
  10259.   printf( "Enter x\n" );
  10260.   scanf( "%lf", &x );
  10261.  
  10262.   /* Output error if not in range */
  10263.   if ( x > MAX )
  10264.     printf( "Error: %lf too large for sine\n", x );
  10265.   else if ( x < MIN )
  10266.     printf( "Error: %lf too small for sine\n", x );
  10267.   else
  10268.     {
  10269.     z = _fsincos( x, *y);
  10270.     printf("The sine of %d is %lf\n", x, z);
  10271.     printf("The cosine of %d is %lf\n", x, *y);
  10272.     }
  10273. }
  10274.  
  10275.  
  10276. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10277.  
  10278. o acos  - Calculate Arccosine 
  10279. o asin  - Calculate Arcsine 
  10280. o cos  - Calculate Cosine 
  10281. o cosh  - Calculate Hyperbolic Cosine 
  10282. o _facos - Calculate Arccosine 
  10283. o _fasin - Calculate Arcsine 
  10284. o _fcos - Calculate Cosine 
  10285. o _fcossin - Calculate Cosine and Sine 
  10286. o _fsin - Calculate Sine 
  10287. o sin  - Calculate Sine 
  10288. o sinh  - Calculate Hyperbolic Sine 
  10289.  
  10290.  
  10291. ΓòÉΓòÉΓòÉ 6.101. _fsqrt -  Calculate Square Root ΓòÉΓòÉΓòÉ
  10292.  
  10293.  
  10294. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10295.  
  10296. #include <math.h>
  10297.  
  10298. double _fsqrt(double x);
  10299.  
  10300.  
  10301. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10302.  
  10303. Language Level: Extension 
  10304.  
  10305. The _fsqrt function computes the square root of x using the FSQRT 80387 
  10306. instruction. Note that this function does not set errno as the sqrt function 
  10307. does. If you pass a negative value to this function, an exception is generated. 
  10308.  
  10309. This function returns the value of the square root of x. 
  10310.  
  10311. Example of _fsqrt 
  10312.  
  10313.  
  10314. ΓòÉΓòÉΓòÉ <hidden> Example of _fsqrt ΓòÉΓòÉΓòÉ
  10315.  
  10316. /************************************************************************
  10317. *
  10318.  
  10319. This example calculates the square root of 4. 
  10320.  
  10321.                                                                         *
  10322. ************************************************************************/
  10323.  
  10324. #include <stdio.h>
  10325. #include <math.h>
  10326.  
  10327. int main(void)
  10328.    {
  10329.     double x, y;
  10330.     x = 4;
  10331.  
  10332.     y = _fsqrt( x );
  10333.  
  10334.     printf("The square root of %d is %d.\n", x, y);
  10335. }
  10336.  
  10337.  
  10338. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10339.  
  10340. o sqrt  - Calculate Square Root 
  10341.  
  10342.  
  10343. ΓòÉΓòÉΓòÉ 6.102. _fstat - Information about Open File ΓòÉΓòÉΓòÉ
  10344.  
  10345.  
  10346. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10347.  
  10348. #include <sys\stat.h>
  10349. #include <sys\types.h>
  10350.  
  10351. int _fstat(int handle, struct stat *buffer);
  10352.  
  10353.  
  10354. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10355.  
  10356. Language Level: Extension 
  10357.  
  10358. The _fstat function obtains information about the open file associated with the 
  10359. given handle and stores it in the structure to which buffer points.  The 
  10360. <sys\stat.h> include file defines the stat structure.  The stat structure 
  10361. contains the following fields: 
  10362.  
  10363. Field       Value 
  10364. st_mode     Bit mask for file mode information. The _fstat function sets the 
  10365.             S_IFCHR bit if handle refers to a device. The S_IFDIR bit is set if 
  10366.             pathname specifies a directory. It sets the S_IFREG bit if handle 
  10367.             refers to an ordinary file.  It sets user read/write bits according 
  10368.             to the permission mode of the file.  The other bits have undefined 
  10369.             values. 
  10370.  
  10371.                                   F E D C B A 9 8 7 6 5 4 3 2 1 0
  10372.                                   Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé
  10373.                                   ΓööΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓöÿ
  10374.                                            
  10375.                             S_IFREGΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ Γöé Γöé     Γöé Γöé ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇexecute/search permission,
  10376.                         (regular file)     Γöé Γöé     Γöé Γöé     owner (S_IEXEC)
  10377.                             S_IFDIRΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ Γöé     Γöé ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇwrite permission, owner
  10378.                             S_IFCHRΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ     ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇread permission, owner
  10379.  
  10380. st_dev      Drive number of the disk containing the file. 
  10381. st_rdev     Drive number of the disk containing the file (same as st_dev). 
  10382. st_nlink    Always 1. 
  10383. st_size     Size of the file in bytes. 
  10384. st_atime    Time of last modification of file. 
  10385. st_mtime    Same as st_atime if not provided by the file system. 
  10386. st_ctime    Same as st_atime if not provided by the file system. 
  10387.  
  10388. There are three additional fields in the fstat structure for portability to 
  10389. other operating systems; they have no meaning under the OS/2 operating system. 
  10390.  
  10391. Note:  If the given handle refers to a device, the size and time fields in the 
  10392. fstat structure are not meaningful. 
  10393.  
  10394. The _fstat function returns the value 0 if it obtains the file status 
  10395. information.  A return value of -1 indicates an error;  in this case, _fstat 
  10396. sets errno to EBADF, showing an incorrect file handle. 
  10397.  
  10398. Example of _fstat 
  10399.  
  10400.  
  10401. ΓòÉΓòÉΓòÉ <hidden> Example of _fstat ΓòÉΓòÉΓòÉ
  10402.  
  10403. /************************************************************************
  10404. *
  10405. This example uses _fstat to report the size of a file named data. 
  10406.  
  10407.                                                                         *
  10408. ************************************************************************/
  10409.  
  10410. #include <time.h>
  10411. #include <sys\types.h>
  10412. #include <sys\stat.h>
  10413. #include <stdio.h>
  10414.  
  10415. int main(void)
  10416. {
  10417.     struct stat buf;
  10418.     FILE *fp;
  10419.     int fh, result;
  10420.     char *buffer = "A line to output";
  10421.  
  10422.     fp = fopen("data", "w+");
  10423.     fprintf(fp, "%s", buffer);
  10424.     fflush(fp);
  10425.     fclose(fp);
  10426.  
  10427.     fp = fopen("data", "r");
  10428.     if (_fstat(_fileno(fp), &buf) == 0)
  10429.     {
  10430.         printf("file size is %ld\n", buf.st_size);
  10431.         printf("time modified is %s\n", ctime(&buf.st_atime));
  10432.     }
  10433.     else
  10434.         printf("Bad file handle\n");
  10435.  
  10436.     fclose(fp);
  10437.  
  10438.     return 0;
  10439.  
  10440.  
  10441. /**************  The output should be similar to:  **********************
  10442.  
  10443.    file size is 16
  10444.    time modified is Tue March 30 16:08:14 1993
  10445. */
  10446. }
  10447.  
  10448.  
  10449. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10450.  
  10451. o _stat - Get Information about File or Directory 
  10452. o sys\stat.h 
  10453. o sys\types.h 
  10454.  
  10455.  
  10456. ΓòÉΓòÉΓòÉ 6.103. ftell  - Get Current Position ΓòÉΓòÉΓòÉ
  10457.  
  10458.  
  10459. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10460.  
  10461. #include <stdio.h>
  10462.  
  10463. long int ftell(FILE *stream);
  10464.  
  10465.  
  10466. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10467.  
  10468. Language Level: ANSI, SAA 
  10469.  
  10470. The ftell function returns a value indicating the current position of the file 
  10471. associated with stream. For a fixed-length binary file, the value returned by 
  10472. ftell is an offset relative to the beginning of the stream. 
  10473.  
  10474. On error, ftell returns -1L and sets errno to a nonzero value. 
  10475.  
  10476. Example of ftell 
  10477.  
  10478.  
  10479. ΓòÉΓòÉΓòÉ <hidden> Example of ftell ΓòÉΓòÉΓòÉ
  10480.  
  10481. /************************************************************************
  10482. *
  10483.  
  10484. This example opens the file myfile for reading. It reads enough characters to 
  10485. fill half of the buffer and prints out the position in the stream and the 
  10486. buffer. 
  10487.  
  10488.                                                                         *
  10489. ************************************************************************/
  10490.  
  10491. #include <stdio.h>
  10492.  
  10493. #define NUM_ALPHA  26
  10494. #define NUM_CHAR    6
  10495.  
  10496. int main(void)
  10497. {
  10498.   FILE * stream;
  10499.   int i;
  10500.   char ch;
  10501.  
  10502.   char buffer[NUM_ALPHA];
  10503.   long position;
  10504.  
  10505.   if (( stream = fopen("myfile.dat", "r")) != NULL )
  10506.   {
  10507.     /* read into buffer */
  10508.     for ( i = 0; ( i < NUM_ALPHA/2 ) &&
  10509.            ((buffer[i] = fgetc(stream)) != EOF ); ++i )
  10510.         if (i==NUM_CHAR-1)  /* We want to be able to position the   */
  10511.                             /* file pointer to the character in     */
  10512.                             /* position NUM_CHAR                    */
  10513.            position = ftell(stream);
  10514.  
  10515.     buffer[i] = '\0';
  10516.  
  10517.     fseek (stream, position, SEEK_SET);
  10518.     ch = fgetc (stream);  /* get the character at position NUM_CHAR    */
  10519.  
  10520.     fclose( stream );
  10521.   }
  10522.   else
  10523.     perror( "Error opening myfile" );
  10524.  
  10525. }
  10526.  
  10527.  
  10528. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10529.  
  10530. o fseek  - Reposition File Position 
  10531. o fgetpos  - Get File Position 
  10532. o fopen  - Open Files 
  10533. o fsetpos  - Set File Position 
  10534. o stdio.h 
  10535.  
  10536.  
  10537. ΓòÉΓòÉΓòÉ 6.104. _ftime - Store Current Time ΓòÉΓòÉΓòÉ
  10538.  
  10539.  
  10540. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10541.  
  10542. #include <sys\timeb.h>
  10543. #include <sys\types.h>
  10544.  
  10545. void _ftime(struct timeb *timeptr);
  10546.  
  10547.  
  10548. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10549.  
  10550. Language Level: Extension 
  10551.  
  10552. The _ftime function gets the current time and stores it in the structure to 
  10553. which timeptr points.  The <sys\timeb.h> include file contains the definition 
  10554. of the timeb structure.  It contains four fields:  time, millitm, timezone, and 
  10555. dstflag. 
  10556.  
  10557. The time field gives the time in seconds since 00:00:00 Coordinated Universal 
  10558. Time, January 1, 1970.  The millitm field gives the fraction of a second, in 
  10559. milliseconds. The timezone field gives the difference in minutes between 
  10560. Coordinated Universal Time and local time, going from east to west.  The _ftime 
  10561. function sets the value of timezone from the value of the global variable 
  10562. _timezone. The dstflag is nonzero if daylight saving time is currently in 
  10563. effect for the local time zone.  For an explanation of how daylight saving time 
  10564. is determined, see _tzset - Assign Values to Locale Information. 
  10565.  
  10566. There is no return value. 
  10567.  
  10568. Example of _ftime 
  10569.  
  10570.  
  10571. ΓòÉΓòÉΓòÉ <hidden> Example of _ftime ΓòÉΓòÉΓòÉ
  10572.  
  10573. /************************************************************************
  10574. *
  10575. This example polls the system clock, converts the current time to a character 
  10576. string, prints the string, and saves the time data in the structure timebuffer: 
  10577.  
  10578.                                                                         *
  10579. ************************************************************************/
  10580.  
  10581. #include <sys\types.h>
  10582. #include <sys\timeb.h>
  10583. #include <stdio.h>
  10584. #include <time.h>
  10585.  
  10586. int main(void)
  10587. {
  10588.     struct timeb timebuffer;
  10589.  
  10590.     _ftime(&timebuffer);
  10591.     printf("the time is %s\n", ctime(&(timebuffer.time)));
  10592.  
  10593.     return 0;
  10594.  
  10595. /**************  The output should be similar to:  **********************
  10596.  
  10597.    the time is Tue March 30 16:08:17 1993
  10598. */
  10599. }
  10600.  
  10601.  
  10602. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10603.  
  10604. o asctime  - Convert Time 
  10605. o ctime  - Convert Time 
  10606. o gmtime  - Convert Time 
  10607. o localtime  - Convert Time 
  10608. o mktime  - Convert Local Time 
  10609. o time  - Determine Current Time 
  10610. o _tzset - Assign Values to Locale Information 
  10611. o sys\timeb.h 
  10612. o sys\types.h 
  10613.  
  10614.  
  10615. ΓòÉΓòÉΓòÉ 6.105. _fullpath - Get Full Path Name of Partial Path ΓòÉΓòÉΓòÉ
  10616.  
  10617.  
  10618. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10619.  
  10620. #include <stdlib.h>
  10621.  
  10622. char *_fullpath(char *pathbuf, char *partialpath, size_t n);
  10623.  
  10624.  
  10625. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10626.  
  10627. Language Level: Extension 
  10628.  
  10629. The _fullpath function gets the full path name of the given partial path name 
  10630. partialpath, and stores it in pathbuf. The integer argument n specifies the 
  10631. maximum length for the path name.  An error occurs if the length of the path 
  10632. name, including the terminating null character, exceeds n characters. 
  10633.  
  10634. If the pathbuf argument is NULL, _fullpath uses malloc to allocate a buffer of 
  10635. size _MAX_PATH bytes to store the path name. 
  10636.  
  10637. The _fullpath function returns a pointer to pathbuf.  If an error occurs, 
  10638. _fullpath returns NULL and sets errno to one of the following values: 
  10639.  
  10640. Value          Meaning 
  10641. ENOMEM         Unable to allocate storage for the buffer. 
  10642. ERANGE         The path name is longer than n characters. 
  10643. EOS2ERR        A system error occurred.  Check _doserrno for the specific OS/2 
  10644.                error code. 
  10645.  
  10646. Example of _fullpath 
  10647.  
  10648.  
  10649. ΓòÉΓòÉΓòÉ <hidden> Example of _fullpath ΓòÉΓòÉΓòÉ
  10650.  
  10651. /************************************************************************
  10652. *
  10653. This example uses _fullpath to get and store the full path name of the current 
  10654. directory. 
  10655.  
  10656.                                                                         *
  10657. ************************************************************************/
  10658.  
  10659. #include <stdio.h>
  10660. #include <stdlib.h>
  10661. #include <errno.h>
  10662.  
  10663. int main(void)
  10664. {
  10665.     char *retBuffer;
  10666.  
  10667.     retBuffer = _fullpath(NULL, ".", 0);
  10668.     if ( retBuffer == NULL )
  10669.        printf("An error has occurred, errno is set to %d.\n", errno);
  10670.     else
  10671.        printf("Full path name of current directory is %s.\n", retBuffer);
  10672.  
  10673.     return 0;
  10674.  
  10675.     /* If path of current directory is D:\BIN, the expected output is:
  10676.  
  10677.        Full path name of current directory is D:\BIN.                  */
  10678. }
  10679.  
  10680.  
  10681. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10682.  
  10683. o _getcwd - Get Path Name of Current Directory 
  10684. o _getdcwd - Get Full Path Name of Current Directory 
  10685. o _makepath - Create Path 
  10686. o malloc  - Reserve Storage Block 
  10687. o _splitpath - Decompose Path Name 
  10688. o stdlib.h 
  10689.  
  10690.  
  10691. ΓòÉΓòÉΓòÉ 6.106. fwrite  - Write Items ΓòÉΓòÉΓòÉ
  10692.  
  10693.  
  10694. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10695.  
  10696. #include <stdio.h>
  10697.  
  10698. size_t fwrite(const void *buffer, size_t size, size_t count,
  10699.                  FILE *stream);
  10700.  
  10701.  
  10702. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10703.  
  10704. Language Level: ANSI, SAA 
  10705.  
  10706. The fwrite function writes up to count items of size length from buffer to the 
  10707. output stream. 
  10708.  
  10709. The fwrite function returns the number of full items successfully written, 
  10710. which can be less than count if an error occurs. 
  10711.  
  10712. Example of fwrite 
  10713.  
  10714.  
  10715. ΓòÉΓòÉΓòÉ <hidden> Example of fwrite ΓòÉΓòÉΓòÉ
  10716.  
  10717. /************************************************************************
  10718. *
  10719.  
  10720. This example writes NUM long integers to a stream in binary format. 
  10721.  
  10722.                                                                         *
  10723. ************************************************************************/
  10724.  
  10725. #include <stdio.h>
  10726.  
  10727. #define  NUM  100
  10728.  
  10729. int main(void)
  10730. {
  10731.    FILE *stream;
  10732.    long list[NUM];
  10733.    int numwritten;
  10734.  
  10735.    stream = fopen("myfile.dat", "w+b");
  10736.       .
  10737.       .  /* assign values to list[] */
  10738.       .
  10739.    numwritten = fwrite(list, sizeof(long), NUM, stream);
  10740. }
  10741.  
  10742.  
  10743. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10744.  
  10745. o fopen  - Open Files 
  10746. o fread  - Read Items 
  10747. o _read - Read Into Buffer 
  10748. o stdio.h 
  10749. o _write - Writes from Buffer to File 
  10750.  
  10751.  
  10752. ΓòÉΓòÉΓòÉ 6.107. _fyl2x - Calculate y * log2(x) ΓòÉΓòÉΓòÉ
  10753.  
  10754.  
  10755. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10756.  
  10757. #include <builtin.h>
  10758.  
  10759. double _fyl2x(double x, double y);
  10760.  
  10761.  
  10762. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10763.  
  10764. Language Level: Extension 
  10765.  
  10766. The _fyl2x function computes the base-2 logarithm of x and multiplies it by y 
  10767. (y * log2(x)). The variable x cannot be negative. This instruction is designed 
  10768. with a built-in multiplication to optimize the calculation of logarithms with 
  10769. arbitrary positive base: log b (x) = (log2(b)**-1) * log2(x) 
  10770.  
  10771. Because it is a built-in function and has no backing code in the library: 
  10772.  
  10773. o You cannot take the address of _fyl2x. 
  10774. o You cannot parenthesize a _fyl2x function call, because parentheses specify a 
  10775.   call to the backing code for the function in the library. 
  10776.  
  10777. This function returns the result of the formula y * log2(x) 
  10778.  
  10779. Example of _fyl2x 
  10780.  
  10781.  
  10782. ΓòÉΓòÉΓòÉ <hidden> Example of _fyl2x ΓòÉΓòÉΓòÉ
  10783.  
  10784. /************************************************************************
  10785. *
  10786. This example calculates (y * log2(x)), after prompting the user for values of x 
  10787. and y. 
  10788.  
  10789.                                                                         *
  10790. ************************************************************************/
  10791.  
  10792. #include<stdio.h>
  10793. #include<math.h>
  10794. #include<builtin.h>
  10795.  
  10796. int main(void)
  10797.     {
  10798.     double x,y,z;
  10799.  
  10800.     printf("Enter a value for x, then a value for y: \n",);
  10801.     scanf("%d, %d", &x, 0x);
  10802.  
  10803.     z = _fyl2x(x,y);
  10804.  
  10805.     printf("%d * log2(%d) is %d.\n", x,y,z);
  10806. }
  10807.  
  10808.  
  10809. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10810.  
  10811. o _fyl2xp1 -  Calculate y * log2(x + 1) 
  10812. o _f2xm1 -  Calculate (2**x) - 1 
  10813. o builtin.h 
  10814.  
  10815.  
  10816. ΓòÉΓòÉΓòÉ 6.108. _fyl2xp1 -  Calculate y * log2(x + 1) ΓòÉΓòÉΓòÉ
  10817.  
  10818.  
  10819. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10820.  
  10821. #include <builtin.h>
  10822.  
  10823. double _fyl2xp1(double x, double y);
  10824.  
  10825.  
  10826. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10827.  
  10828. Language Level: Extension 
  10829.  
  10830. The _fyl2x function computes the base-2 logarithm of x+1 and multiplies it by y 
  10831. (y * log2(x+1)). The variable x must be in the range -(1-(sqrt(2)/2)) to 
  10832. (sqrt(2) - 1). This function provides improved accuracy over the _fyl2x 
  10833. function when computing logarithms of numbers very close to 1. When x is small, 
  10834. you can retain more significant digits by providing x to the _fyl2xp1 function 
  10835. than by providing x+1 as an argument to the _fyl2x function. 
  10836.  
  10837. Because it is a built-in function and has no backing code in the library: 
  10838.  
  10839. o You cannot take the address of _fyl2xp1. 
  10840. o You cannot parenthesize a _fyl2xp1 function call, because parentheses specify 
  10841.   a call to the backing code for the function in the library. 
  10842.  
  10843. This function returns the result of the formula y * log2(x+1). 
  10844.  
  10845. Example of _fyl2xp1 
  10846.  
  10847.  
  10848. ΓòÉΓòÉΓòÉ <hidden> Example of _fyl2xp1 ΓòÉΓòÉΓòÉ
  10849.  
  10850. /************************************************************************
  10851. *
  10852. This example calculates (y * log2(x + 1)), after prompting the user for values 
  10853. of x and y. 
  10854.  
  10855.                                                                         *
  10856. ************************************************************************/
  10857.  
  10858. #include<stdio.h>
  10859. #include<math.h>
  10860. #include<builtin.h>
  10861.  
  10862. int main(void)
  10863.     {
  10864.     double x,y,z;
  10865.  
  10866.     printf("Enter a value for x, then a value for y: \n",);
  10867.     scanf("%d, %d", &x, 0x);
  10868.  
  10869.     z = _fyl2xp1(x,y);
  10870.  
  10871.     printf("%d * log2(%d + 1) is %d.\n", x,y,z);
  10872. }
  10873.  
  10874.  
  10875. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10876.  
  10877. o _fyl2x - Calculate y * log2(x) 
  10878. o _f2xm1 -  Calculate (2**x) - 1 
  10879. o builtin.h 
  10880.  
  10881.  
  10882. ΓòÉΓòÉΓòÉ 6.109. _f2xm1 -  Calculate (2**x) - 1 ΓòÉΓòÉΓòÉ
  10883.  
  10884.  
  10885. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10886.  
  10887. #include <builtin.h>
  10888.  
  10889. double _f2xm1(double x);
  10890.  
  10891.  
  10892. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10893.  
  10894. Language Level: Extension 
  10895.  
  10896. The _f2xm1 function calculates 2 raised to the power of x, minus 1 ((2**x)-1). 
  10897. The variable x must be in the range -1 to 1. This instruction is designed to 
  10898. produce very accurate results when x is close to 0. Large errors may occur for 
  10899. operands with magnitudes close to 1. You can exponentiate values other than 2 
  10900. by using the formula x**y = 2**(y * log2(x)). 
  10901.  
  10902. Because it is a built-in function and has no backing code in the library: 
  10903.  
  10904. o You cannot take the address of _f2xm1. 
  10905. o You cannot parenthesize a _f2xm1 function call, because parentheses specify a 
  10906.   call to the backing code for the function in the library. 
  10907.  
  10908. This function returns the value of the formula (2**x)-1. 
  10909.  
  10910. Example of _f2xm1 
  10911.  
  10912.  
  10913. ΓòÉΓòÉΓòÉ <hidden> Example of _f2xm1 ΓòÉΓòÉΓòÉ
  10914.  
  10915. /************************************************************************
  10916. *
  10917. This example calculates (2**x)-1 after prompting the user for a value for x. 
  10918.  
  10919.                                                                         *
  10920. ************************************************************************/
  10921.  
  10922. #include<stdio.h>
  10923. #include<math.h>
  10924. #include<builtin.h>
  10925.  
  10926. int main(void)
  10927.     {
  10928.     double x,y;
  10929.  
  10930.     printf("Enter a value for x: \n",);
  10931.     scanf("%d", &x);
  10932.  
  10933.     y = _f2xm1(x);
  10934.  
  10935.     printf("2**x - 1 is %d.\n", y);
  10936. }
  10937.  
  10938.  
  10939. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10940.  
  10941. o _fyl2x - Calculate y * log2(x) 
  10942. o _fyl2xp1 -  Calculate y * log2(x + 1) 
  10943. o builtin.h 
  10944.  
  10945.  
  10946. ΓòÉΓòÉΓòÉ 6.110. gamma  - Gamma Function ΓòÉΓòÉΓòÉ
  10947.  
  10948.  
  10949. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  10950.  
  10951. #include <math.h> /* SAA extension to ANSI */
  10952.  
  10953. double gamma(double x);
  10954.  
  10955.  
  10956. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  10957.  
  10958. Language Level: SAA 
  10959.  
  10960. The gamma function computes ln( |G(x)| ). The argument x must be a positive 
  10961. real value. If x is a negative value, errno is set to EDOM.  If the result 
  10962. causes an overflow, the function returns HUGE_VAL and sets errno to ERANGE. 
  10963.  
  10964. The C/C++ Tools compiler allows x to be a negative integer. 
  10965.  
  10966. Example of gamma 
  10967.  
  10968.  
  10969. ΓòÉΓòÉΓòÉ <hidden> Example of gamma ΓòÉΓòÉΓòÉ
  10970.  
  10971. /************************************************************************
  10972. *
  10973.  
  10974. This example uses gamma to calculate ln(|G(x)|), where x = 42. 
  10975.  
  10976.                                                                         *
  10977. ************************************************************************/
  10978.  
  10979. #include <math.h>
  10980. #include <stdio.h>
  10981.  
  10982. int main(void)
  10983. {
  10984.    double x=42, g_at_x;
  10985.  
  10986.    g_at_x = exp(gamma(x));       /* g_at_x = 3.345253e+49 */
  10987.    printf ("The value of G(%4.2lf) is %7.2e\n", x, g_at_x);
  10988. }
  10989.  
  10990. /************************  Output should be similar to:  **********
  10991.  
  10992. The value of G(42.00) is 3.35e+49
  10993. */
  10994.  
  10995.  
  10996. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  10997.  
  10998. o Bessel Functions 
  10999. o erf  - Calculate Error Functions 
  11000. o math.h 
  11001.  
  11002.  
  11003. ΓòÉΓòÉΓòÉ 6.111. _gcvt - Convert Floating-Point to String ΓòÉΓòÉΓòÉ
  11004.  
  11005.  
  11006. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11007.  
  11008. #include <stdlib.h>
  11009.  
  11010. char *_gcvt(double value, int ndec, char *buffer);
  11011.  
  11012.  
  11013. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11014.  
  11015. Language Level: Extension 
  11016.  
  11017. The _gcvt function converts a floating-point value to a character string 
  11018. pointed to by buffer. The buffer should be large enough to hold the converted 
  11019. value and a null character (\0), that _gcvt automatically adds to the end of 
  11020. the string. There is no provision for overflow. 
  11021.  
  11022. The _gcvt function tries to produce ndec significant digits in FORTRAN F 
  11023. format. Failing that, it produces ndec significant digits in FORTRAN E format. 
  11024. Trailing zeros might be suppressed in the conversion if they are significant. 
  11025.  
  11026. A FORTRAN F number has the following format: 
  11027.  
  11028.        ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ    ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  11029.  ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdigitΓöÇΓö┤ΓöÇΓöÇΓöÇ.ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  11030.    Γö£ΓöÇΓöÇ+ΓöÇΓöÇΓöñ          ΓööΓöÇdigitΓöÇΓöÿ
  11031.    ΓööΓöÇΓöÇ-ΓöÇΓöÇΓöÿ
  11032.  
  11033. A FORTRAN E number has the following format: 
  11034.  
  11035.             ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ          ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  11036.  ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇdigitsΓöÇΓöÇ.ΓöÇΓöÇdigitsΓöÇΓö┤ΓöÇEΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇdigitsΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇ
  11037.   Γö£ΓöÇΓöÇ+ΓöÇΓöÇΓöñ             Γö£ΓöÇΓöÇ+ΓöÇΓöÇΓöñ     ΓööΓöÇdigitsΓöÇΓöÿ
  11038.   ΓööΓöÇΓöÇ-ΓöÇΓöÇΓöÿ             ΓööΓöÇΓöÇ-ΓöÇΓöÇΓöÿ
  11039.  
  11040. The _gcvt function also converts NaN and infinity values to the strings NAN and 
  11041. INFINITY, respectively. For more information on NaN and infinity values, see 
  11042. Infinity and NaN Support. 
  11043.  
  11044. Warning: For each thread, the _ecvt, _fcvt and _gcvt functions use a single, 
  11045. dynamically allocated buffer for the conversion. Any subsequent call that the 
  11046. same thread makes to these functions destroys the result of the previous call. 
  11047.  
  11048. The _gcvt function returns a pointer to the string of digits. A failure to 
  11049. allocate memory returns an empty string and sets errno to ENOMEM. 
  11050.  
  11051. Example of _gcvt 
  11052.  
  11053.  
  11054. ΓòÉΓòÉΓòÉ <hidden> Example of _gcvt ΓòÉΓòÉΓòÉ
  11055.  
  11056. /************************************************************************
  11057. *
  11058. This example converts the value -3.1415e3 to a character string and places it 
  11059. in the character array buffer1. It then converts the macro value _INF to a 
  11060. character string and places it in buffer2. 
  11061.  
  11062.                                                                         *
  11063. ************************************************************************/
  11064.  
  11065. #include <stdio.h>
  11066. #include <stdlib.h>
  11067. #include <float.h>    /* for the definition of _INF */
  11068.  
  11069. int main(void)
  11070. {
  11071.     char buffer1[10], buffer2[10];
  11072.  
  11073.     _gcvt(-3.1415e3, 7, buffer1);
  11074.     printf("The first result is %s \n", buffer1);
  11075.  
  11076.     _gcvt(_INF, 5, buffer2);
  11077.     printf("The second result is %s \n", buffer2);
  11078.  
  11079.     return 0;
  11080.  
  11081.     /* The expected output is:
  11082.  
  11083.        The first result is -3141.5
  11084.        The second result is INFINITY */
  11085.  
  11086. }
  11087.  
  11088.  
  11089. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11090.  
  11091. o _ecvt - Convert Floating-Point to Character 
  11092. o _fcvt - Convert Floating-Point to String 
  11093. o Infinity and NaN Support 
  11094. o stdlib.h 
  11095.  
  11096.  
  11097. ΓòÉΓòÉΓòÉ 6.112. getc  - Read a Character ΓòÉΓòÉΓòÉ
  11098.  
  11099.  
  11100. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11101.  
  11102. #include <stdio.h>
  11103.  
  11104. int getc(FILE *stream);
  11105.  
  11106. int getchar(void);
  11107.  
  11108.  
  11109. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11110.  
  11111. Language Level: ANSI, SAA 
  11112.  
  11113. The getc function reads a single character from the current stream position and 
  11114. advances the stream position to the next character.  The getchar function is 
  11115. identical to getc(stdin). 
  11116.  
  11117. The difference between the getc and the fgetc functions is that the getc 
  11118. function can be implemented so that its arguments can be evaluated multiple 
  11119. times.  The stream argument to getc should not be an expression with side 
  11120. effects. 
  11121.  
  11122. The getc and getchar functions return the character read.  A return value of 
  11123. EOF indicates an error or end-of-file condition.  Use ferror or feof to 
  11124. determine whether an error or an end-of-file condition occurred. 
  11125.  
  11126. Example of getc - getchar 
  11127.  
  11128.  
  11129. ΓòÉΓòÉΓòÉ <hidden> Example of getc - getchar ΓòÉΓòÉΓòÉ
  11130.  
  11131. /************************************************************************
  11132. *
  11133.  
  11134. This example gets a line of input from the stdin stream.  You can also use 
  11135. getc(stdin) instead of getchar() in the for statement to get a line of input 
  11136. from stdin. 
  11137.  
  11138.                                                                         *
  11139. ************************************************************************/
  11140.  
  11141. #include <stdio.h>
  11142.  
  11143. #define LINE 80
  11144.  
  11145. int main(void)
  11146. {
  11147.   char buffer[LINE+1];
  11148.   int i;
  11149.   int ch;
  11150.  
  11151.   printf( "Please enter string\n" );
  11152.  
  11153.   /* Keep reading until either:
  11154.      1. the length of LINE is exceeded  or
  11155.      2. the input character is EOF  or
  11156.      3. the input character is a new-line character
  11157.    */
  11158.  
  11159.   for ( i = 0; ( i < LINE ) && (( ch = getchar()) != EOF) &&
  11160.                ( ch !='\n' ); ++i )
  11161.     buffer[i] = ch;
  11162.  
  11163.   buffer[i] = '\0';  /* a string should always end with '\0' ! */
  11164.  
  11165.   printf( "The string is %s\n", buffer );
  11166. }
  11167.  
  11168. /************************  Output should be similar to:  **********
  11169.  
  11170. Please enter string
  11171. hello world
  11172. The string is hello world
  11173. */
  11174.  
  11175.  
  11176. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11177.  
  11178. o fgetc  - Read a Character 
  11179. o _fgetchar - Read Single Character from stdin 
  11180. o _getch - _getche - Read Character from Keyboard 
  11181. o putc - putchar  - Write a Character 
  11182. o ungetc  - Push Character onto Input Stream 
  11183. o gets  - Read a Line 
  11184. o stdio.h 
  11185.  
  11186.  
  11187. ΓòÉΓòÉΓòÉ 6.113. _getch - _getche - Read Character from Keyboard ΓòÉΓòÉΓòÉ
  11188.  
  11189.  
  11190. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11191.  
  11192. #include <conio.h>
  11193.  
  11194. int _getch(void);
  11195.  
  11196. int _getche(void);
  11197.  
  11198.  
  11199. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11200.  
  11201. Language Level: Extension 
  11202.  
  11203. The _getch function reads a single character from the keyboard, without 
  11204. echoing.  The _getche function reads a single character from the keyboard and 
  11205. displays the character read. Neither function can be used to read Ctrl-Break. 
  11206.  
  11207. When a program is reading a function key or cursor-moving key, the _getch and 
  11208. _getche functions must be called twice.  The first call returns 0 or E0H, and 
  11209. the second call returns the particular extended key code. 
  11210.  
  11211. Example of _getch - _getche 
  11212.  
  11213.  
  11214. ΓòÉΓòÉΓòÉ <hidden> Example of _getch - _getche ΓòÉΓòÉΓòÉ
  11215.  
  11216. /************************************************************************
  11217. *
  11218.  
  11219. This example gets characters from the keyboard until it finds the character 
  11220. 'x'. 
  11221.  
  11222.                                                                         *
  11223. ************************************************************************/
  11224.  
  11225. #include <conio.h>
  11226. #include <stdio.h>
  11227.  
  11228. int main(void)
  11229. {
  11230.    int ch;
  11231.  
  11232.    _cprintf("\nType in some letters.");
  11233.    printf("\n");
  11234.    _cprintf("If you type in an 'x', the program ends.\n");
  11235.    printf("\n");
  11236.  
  11237.    for(;;)
  11238.    {
  11239.       ch = _getch();
  11240.  
  11241.       if (ch == 'x')
  11242.       {
  11243.          _ungetch(ch);
  11244.          break;
  11245.       }
  11246.       _putch(ch);
  11247.    }
  11248.  
  11249.    ch=_getch();
  11250.  
  11251.    printf("\n");
  11252.    _cprintf("\nThe last character was '%c'.", ch);
  11253.  
  11254.    return 0;
  11255.  
  11256. /**************  The output should be similar to:  **********************
  11257.  
  11258.    Type in some letters.
  11259.    If you type in an 'x', the program ends.
  11260.  
  11261.    One Two Three Four Five Si
  11262.  
  11263.    The last character was 'x'.
  11264. */
  11265. }
  11266.  
  11267.  
  11268. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11269.  
  11270. o _cgets - Read String of Characters from Keyboard 
  11271. o fgetc  - Read a Character 
  11272. o getc  - Read a Character 
  11273. o _putch - Write Character to Screen 
  11274. o _ungetch - Push Character Back to Keyboard 
  11275. o conio.h 
  11276.  
  11277.  
  11278. ΓòÉΓòÉΓòÉ 6.114. _getcwd - Get Path Name of Current Directory ΓòÉΓòÉΓòÉ
  11279.  
  11280.  
  11281. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11282.  
  11283. #include <direct.h>
  11284.  
  11285. char *_getcwd(char *pathbuf, int n);
  11286.  
  11287.  
  11288. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11289.  
  11290. Language Level: Extension 
  11291.  
  11292. The _getcwd function gets the full path name of the current working directory 
  11293. and stores it in the buffer pointed to by pathbuf.  The integer argument n 
  11294. specifies the maximum length for the path name.  An error occurs if the length 
  11295. of the path name, including the terminating null character, exceeds n 
  11296. characters. 
  11297.  
  11298. If the pathbuf argument is NULL, _getcwd uses malloc to reserve a buffer of at 
  11299. least n bytes to store the path name.  If the current working directory string 
  11300. is more than n bytes, a large enough buffer will be allocated to contain the 
  11301. string.  You can later free this buffer using the _getcwd return value as the 
  11302. argument to free. 
  11303.  
  11304. The _getcwd function returns pathbuf.  If an error occurs, _getcwd returns NULL 
  11305. and sets errno to one of the following values: 
  11306.  
  11307. Value       Meaning 
  11308. ENOMEM      Not enough storage space available to reserve n bytes (when pathbuf 
  11309.             argument is NULL). 
  11310. ERANGE      The path name is longer than n characters. 
  11311. EOS2ERR     An OS/2 call failed. Use _doserrno to obtain more information about 
  11312.             the return code. 
  11313.  
  11314. Example of _getcwd 
  11315.  
  11316.  
  11317. ΓòÉΓòÉΓòÉ <hidden> Example of _getcwd ΓòÉΓòÉΓòÉ
  11318.  
  11319. /************************************************************************
  11320. *
  11321. This example stores the name of the current working directory (up to _MAX_PATH 
  11322. characters) in a buffer.  The value of _MAX_PATH is defined in <stdlib.h>. 
  11323.  
  11324.                                                                         *
  11325. ************************************************************************/
  11326.  
  11327. #include <direct.h>
  11328. #include <stdio.h>
  11329. #include <stdlib.h>
  11330.  
  11331. int main(void)
  11332. {
  11333.     char buffer[_MAX_PATH];
  11334.  
  11335.     if (_getcwd(buffer, _MAX_PATH) == NULL)
  11336.        perror("getcwd error");
  11337.  
  11338.     printf("The current directory is %s\n", buffer);
  11339.  
  11340.     return 0;
  11341.  
  11342. /****************  The output should be similar to:  ********************
  11343.  
  11344.    The current directory is E:\C_OS2\MIG_XMPS
  11345. */
  11346. }
  11347.  
  11348.  
  11349. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11350.  
  11351. o _chdir - Change Current Working Directory 
  11352. o _fullpath - Get Full Path Name of Partial Path 
  11353. o _getdcwd - Get Full Path Name of Current Directory 
  11354. o _getdrive - Get Current Working Drive 
  11355. o malloc  - Reserve Storage Block 
  11356. o direct.h 
  11357.  
  11358.  
  11359. ΓòÉΓòÉΓòÉ 6.115. _getdcwd - Get Full Path Name of Current Directory ΓòÉΓòÉΓòÉ
  11360.  
  11361.  
  11362. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11363.  
  11364. #include <direct.h>
  11365.  
  11366. char *_getdcwd(int drive, char *pathbuf, int n);
  11367.  
  11368.  
  11369. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11370.  
  11371. Language Level: Extension 
  11372.  
  11373. The _getdcwd function gets the full path name for the current directory of the 
  11374. specified drive, and stores it in the location pointed to by pathbuf. The drive 
  11375. argument is an integer value representing the drive (A: is 1, B: is 2, and so 
  11376. on). 
  11377.  
  11378. The integer argument n specifies the maximum length for the path name. An error 
  11379. occurs if the length of the path name, including the terminating null 
  11380. character, exceeds n characters. 
  11381.  
  11382. If the pathbuf argument is NULL, _getdcwd uses malloc to reserve a buffer of at 
  11383. least n bytes to store the path name.  If the current working directory string 
  11384. is more than n bytes, a large enough buffer will be allocated to contain the 
  11385. string. You can later free this buffer using the _getdcwd return value as the 
  11386. argument to free. 
  11387.  
  11388. An alternative to this function is the DosQueryCurrentDir and 
  11389. DosQueryCurrentDisk API calls. 
  11390.  
  11391. The _getdcwd function returns pathbuf.  If an error occurs, _getdcwd returns 
  11392. NULL and sets errno to one of the following values: 
  11393.  
  11394. Value          Meaning 
  11395. ENOMEM         Not enough storage space available to reserve n bytes (when 
  11396.                pathbuf argument is NULL). 
  11397. ERANGE         The path name is longer than n characters. 
  11398. EOS2ERR        An OS/2 call failed. Use _doserrno to obtain more information 
  11399.                about the return code. 
  11400.  
  11401. Example of _getcwd 
  11402.  
  11403.  
  11404. ΓòÉΓòÉΓòÉ <hidden> Example of _getcwd ΓòÉΓòÉΓòÉ
  11405.  
  11406. /************************************************************************
  11407. *
  11408. This example uses _getdcwd to obtain the current working directory of drive C. 
  11409.  
  11410.                                                                         *
  11411. ************************************************************************/
  11412.  
  11413. #include <stdio.h>
  11414. #include <direct.h>
  11415. #include <errno.h>
  11416.  
  11417. int main(void)
  11418. {
  11419.     char *retBuffer;
  11420.  
  11421.     retBuffer = _getdcwd(3,NULL,0);
  11422.     if ( retBuffer == NULL )
  11423.        printf("An error has occurred, errno is set to %d.\n",
  11424.                errno);
  11425.     else
  11426.        printf("Current working directory of drive C is %s.\n",
  11427.                retBuffer);
  11428.  
  11429.     return 0;
  11430.  
  11431.  
  11432. /***************  The output should be similar to:  *********************
  11433.  
  11434.     Current working directory of drive C is C:\.
  11435. */
  11436. }
  11437.  
  11438.  
  11439. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11440.  
  11441. o _chdir - Change Current Working Directory 
  11442. o _chdrive - Change Current Working Drive 
  11443. o _fullpath - Get Full Path Name of Partial Path 
  11444. o _getcwd - Get Path Name of Current Directory 
  11445. o _getdrive - Get Current Working Drive 
  11446. o malloc  - Reserve Storage Block 
  11447. o direct.h 
  11448.  
  11449.  
  11450. ΓòÉΓòÉΓòÉ 6.116. _getdrive - Get Current Working Drive ΓòÉΓòÉΓòÉ
  11451.  
  11452.  
  11453. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11454.  
  11455. #include <direct.h>
  11456.  
  11457. int _getdrive(void);
  11458.  
  11459.  
  11460. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11461.  
  11462. Language Level: Extension 
  11463.  
  11464. Gets the drive number for the current working drive. 
  11465.  
  11466. The _getdrive function returns an integer corresponding to alphabetical 
  11467. position of the letter representing the current working drive. For example, A: 
  11468. is 1, B: is 2, J: is 10, and so on. 
  11469.  
  11470. An alternative to this function is the DosQueryCurrentDisk API call. 
  11471.  
  11472. Example of _getdrive 
  11473.  
  11474.  
  11475. ΓòÉΓòÉΓòÉ <hidden> Example of _getdrive ΓòÉΓòÉΓòÉ
  11476.  
  11477. /************************************************************************
  11478. *
  11479. This example gets and prints the current working drive number. 
  11480.  
  11481.                                                                         *
  11482. ************************************************************************/
  11483.  
  11484. #include <stdio.h>
  11485. #include <direct.h>
  11486.  
  11487. int main(void)
  11488. {
  11489.    printf("Current working drive is %d.\n", _getdrive() );
  11490.  
  11491.     return 0;
  11492.  
  11493. /********  If the current working drive is E:, then  **************
  11494. ***************  the output should be similar to:  **********************
  11495.  
  11496.    Current working drive is 5.
  11497. */
  11498. }
  11499.  
  11500.  
  11501. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11502.  
  11503. o _chdir - Change Current Working Directory 
  11504. o _chdrive - Change Current Working Drive 
  11505. o _getcwd - Get Path Name of Current Directory 
  11506. o _getdcwd - Get Full Path Name of Current Directory 
  11507. o direct.h 
  11508.  
  11509.  
  11510. ΓòÉΓòÉΓòÉ 6.117. getenv  - Search for Environment Variables ΓòÉΓòÉΓòÉ
  11511.  
  11512.  
  11513. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11514.  
  11515. #include <stdlib.h>
  11516.  
  11517. char *getenv(const char *varname);
  11518.  
  11519.  
  11520. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11521.  
  11522. Language Level: ANSI, SAA 
  11523.  
  11524. The getenv function searches the list of environment variables for an entry 
  11525. corresponding to varname. 
  11526.  
  11527. The getenv function returns a pointer to the environment table entry containing 
  11528. the current string value of varname.  The return value is NULL if the given 
  11529. variable is not currently defined or if the system does not support environment 
  11530. variables. 
  11531.  
  11532. You should copy the string that is returned because it may be written over by a 
  11533. subsequent call to getenv. 
  11534.  
  11535. Example of getenv 
  11536.  
  11537.  
  11538. ΓòÉΓòÉΓòÉ <hidden> Example of getenv ΓòÉΓòÉΓòÉ
  11539.  
  11540. /************************************************************************
  11541. *
  11542.  
  11543. In this example, pathvar points to the value of the PATH environment variable: 
  11544.  
  11545.                                                                         *
  11546. ************************************************************************/
  11547.  
  11548. #include <stdlib.h>
  11549.  
  11550. int main(void)
  11551. {
  11552.    char *pathvar;
  11553.  
  11554.    pathvar = getenv("PATH");
  11555. }
  11556.  
  11557.  
  11558. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11559.  
  11560. o _putenv - Modify Environment Variables 
  11561. o envp Parameter to main 
  11562. o stdlib.h 
  11563.  
  11564.  
  11565. ΓòÉΓòÉΓòÉ 6.118. _getpid - Get Process Identifier ΓòÉΓòÉΓòÉ
  11566.  
  11567.  
  11568. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11569.  
  11570. #include <process.h>
  11571.  
  11572. int _getpid(void);
  11573.  
  11574.  
  11575. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11576.  
  11577. Language Level: Extension 
  11578.  
  11579. The _getpid function gets the process identifier that uniquely identifies the 
  11580. calling process. 
  11581.  
  11582. The _getpid function returns the process identifier as an integer value.  There 
  11583. is no error return value. 
  11584.  
  11585. Example of _getpid 
  11586.  
  11587.  
  11588. ΓòÉΓòÉΓòÉ <hidden> Example of _getpid ΓòÉΓòÉΓòÉ
  11589.  
  11590. /************************************************************************
  11591. *
  11592. This example prints the process identifier: 
  11593.  
  11594.                                                                         *
  11595. ************************************************************************/
  11596.  
  11597. #include <process.h>
  11598. #include <string.h>
  11599. #include <stdio.h>
  11600. #include <stdlib.h>
  11601.  
  11602. int main(void)
  11603. {
  11604.     printf("Process identifier is %d\n", _getpid());
  11605.  
  11606.     return 0;
  11607.  
  11608. /****************  The output should be similar to:  ********************
  11609.  
  11610.    Process identifier is 242
  11611. */
  11612. }
  11613.  
  11614.  
  11615. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11616.  
  11617. o _cwait - Wait for Child Process 
  11618. o _execl - _execvp - Load and Run Child Process 
  11619. o _spawnl -_spawnvpe -Start and Run Child Processes 
  11620. o _wait - Wait for Child Process 
  11621. o process.h 
  11622.  
  11623.  
  11624. ΓòÉΓòÉΓòÉ 6.119. gets  - Read a Line ΓòÉΓòÉΓòÉ
  11625.  
  11626.  
  11627. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11628.  
  11629. #include <stdio.h>
  11630.  
  11631. char *gets(char *buffer);
  11632.  
  11633.  
  11634. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11635.  
  11636. Language Level: ANSI, SAA 
  11637.  
  11638. The gets function reads a line from the standard input stream stdin and stores 
  11639. it in buffer.  The line consists of all characters up to and including the 
  11640. first new-line character (\n) or EOF. The gets function then replaces the 
  11641. new-line character, if read, with a null character (\0), before returning the 
  11642. line. 
  11643.  
  11644. If successful, the gets function returns its argument.  A NULL pointer return 
  11645. value indicates an error or an end-of-file condition with no characters read. 
  11646. Use ferror or feof to determine which of these conditions occurred. If there is 
  11647. an error, the value stored in buffer is undefined.  If an end-of-file condition 
  11648. occurs, buffer is not changed. 
  11649.  
  11650. Example of gets 
  11651.  
  11652.  
  11653. ΓòÉΓòÉΓòÉ <hidden> Example of gets ΓòÉΓòÉΓòÉ
  11654.  
  11655. /************************************************************************
  11656. *
  11657.  
  11658. This example gets a line of input from stdin. 
  11659.  
  11660.                                                                         *
  11661. ************************************************************************/
  11662.  
  11663. #include <stdio.h>
  11664.  
  11665. #define MAX_LINE 100
  11666.  
  11667. int main(void)
  11668. {
  11669.    char line[MAX_LINE];
  11670.    char *result;
  11671.  
  11672.    if ((result = gets(line)) != NULL)
  11673.    {
  11674.       if (ferror(stdin))
  11675.         perror("Error");
  11676.    }
  11677. }
  11678.  
  11679.  
  11680. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11681.  
  11682. o _cgets - Read String of Characters from Keyboard 
  11683. o fgets  - Read a String 
  11684. o feof  - Test End-of-File Indicator 
  11685. o ferror  - Test for Read/Write Errors 
  11686. o fputs  - Print Strings 
  11687. o getc  - Read a Character 
  11688. o puts  - Write a String 
  11689. o stdio.h 
  11690.  
  11691.  
  11692. ΓòÉΓòÉΓòÉ 6.120. _getTIBvalue - Get TIB Value ΓòÉΓòÉΓòÉ
  11693.  
  11694.  
  11695. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11696.  
  11697. #include <builtin.h>
  11698.  
  11699. unsigned long _getTIBvalue(const unsigned int offset);
  11700.  
  11701.  
  11702. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11703.  
  11704. Language Level: Extension 
  11705.  
  11706. The _getTIBvalue function retrieves an unsigned long value from the thread 
  11707. information block (TIB) at the offset specified. The selector value for the TIB 
  11708. belonging to the current thread of execution is stored in the FS segment 
  11709. register. You should use the offsetof macro to calculate offset. 
  11710.  
  11711. Because it is a built-in function and has no backing code in the library: 
  11712.  
  11713. o You cannot take the address of _getTIBvalue. 
  11714. o You cannot parenthesize a _getTIBvalue function call, because parentheses 
  11715.   specify a call to the backing code for the function. 
  11716.  
  11717. This function returns an unsigned long value.  There is no error return value 
  11718. and this function does not set errno.  If offset is too large, it will cause an 
  11719. access violation when running the program. 
  11720.  
  11721. Example of _getTIBvalue 
  11722.  
  11723.  
  11724. ΓòÉΓòÉΓòÉ <hidden> Example of _getTIBvalue ΓòÉΓòÉΓòÉ
  11725.  
  11726. /************************************************************************
  11727. *
  11728.  
  11729. This example prints out all the values in the TIB structure. 
  11730.  
  11731.                                                                         *
  11732. ************************************************************************/
  11733.  
  11734. #define INCL_DOSPROCESS
  11735. #include <os2.h>
  11736. #include <stdio.h>
  11737. #include <builtin.h>
  11738.  
  11739. int main( void )
  11740. {
  11741.    printf( "Values in Thread Information Block are:\n\n" );
  11742.  
  11743.    printf( "Exception chain pointer: %lx\n",
  11744.            _getTIBvalue( offsetof( TIB, tib_pexchain ) ) );
  11745.    printf( "Base stack address: %lx\n",
  11746.            _getTIBvalue( offsetof( TIB, tib_pstack ) ) );
  11747.    printf( "End of stack address: %lx\n",
  11748.            _getTIBvalue( offsetof( TIB, tib_pstacklimit ) ) );
  11749.    printf( "System specific TIB pointer: %p\n",
  11750.            _getTIBvalue( offsetof( TIB, tib_ptib2 ) ) );
  11751.    printf( "Version number: %lu\n",
  11752.            _getTIBvalue( offsetof( TIB, tib_version ) ) );
  11753.    printf( "Ordinal number: %lu\n",
  11754.            _getTIBvalue( offsetof( TIB, tib_ordinal ) ) );
  11755.  
  11756.    return 0;
  11757. }
  11758.  
  11759.  
  11760. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11761.  
  11762. o _threadstore - Access Thread-Specific Storage 
  11763.  
  11764. o builtin.h 
  11765.  
  11766.  
  11767. ΓòÉΓòÉΓòÉ 6.121. gmtime  - Convert Time ΓòÉΓòÉΓòÉ
  11768.  
  11769.  
  11770. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11771.  
  11772. #include <time.h>
  11773.  
  11774. struct tm *gmtime(const time_t *time);
  11775.  
  11776.  
  11777. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11778.  
  11779. Language Level: ANSI, SAA 
  11780.  
  11781. The gmtime function converts a time value to a struct tm.  The value time is 
  11782. usually obtained from a call to time. 
  11783.  
  11784. The gmtime function breaks down the time value and stores it in a tm structure, 
  11785. defined in time.h.  The structure pointed to by the return value reflects 
  11786. Coordinated Universal Time, not local time. 
  11787.  
  11788. The fields of the tm structure include: 
  11789.  
  11790. Field            Value Stored 
  11791. tm_sec           Seconds (0-61) 
  11792. tm_min           Minutes (0-59) 
  11793. tm_hour          Hours (0-23) 
  11794. tm_mday          Day of month (1-31) 
  11795. tm_mon           Month (0-11;  January = 0) 
  11796. tm_year          Year (current year minus 1900) 
  11797. tm_wday          Day of week (0-6;  Sunday = 0) 
  11798. tm_yday          Day of year (0-365;  January 1 = 0) 
  11799. tm_isdst         Zero if Daylight Saving Time is not in effect;  positive if 
  11800.                  Daylight Saving Time is in effect;  negative if the 
  11801.                  information is not available. 
  11802.  
  11803. The gmtime function returns a pointer to the structure result.  The gmtime 
  11804. function returns NULL if Coordinated Universal Time is not available. 
  11805.  
  11806. Note: 
  11807.  
  11808.  1. The range (0-61) for tm_sec allows for as many as two leap seconds. 
  11809.  
  11810.  2. The gmtime and localtime functions may use a common, statically allocated 
  11811.     buffer for the conversion. Each call to one of these functions may alter 
  11812.     the result of the previous call. 
  11813.  
  11814.  3. The time and date functions begin at 00:00:00 Coordinated Universal Time, 
  11815.     January 1, 1970. 
  11816.  
  11817. Example of gmtime 
  11818.  
  11819.  
  11820. ΓòÉΓòÉΓòÉ <hidden> Example of gmtime ΓòÉΓòÉΓòÉ
  11821.  
  11822. /************************************************************************
  11823. *
  11824.  
  11825. This example uses the gmtime function to adjust a time_t representation to a 
  11826. Coordinated Universal Time character string and then converts it to a printable 
  11827. string using asctime. 
  11828.  
  11829.                                                                         *
  11830. ************************************************************************/
  11831.  
  11832. #include <stdio.h>
  11833. #include <time.h>
  11834.  
  11835. int main(void)
  11836. {
  11837.    time_t ltime;
  11838.  
  11839.    time(<ime);
  11840.    printf ("Coordinated Universal Time is %s\n",
  11841.             asctime(gmtime(<ime)));
  11842. }
  11843.  
  11844. /************************  Output should be similar to:  **********
  11845.  
  11846. Coordinated Universal Time is Wed Aug 18 21:01:44 1993
  11847. */
  11848.  
  11849.  
  11850. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11851.  
  11852. o asctime  - Convert Time 
  11853. o ctime  - Convert Time 
  11854. o localtime  - Convert Time 
  11855. o mktime  - Convert Local Time 
  11856. o time  - Determine Current Time 
  11857. o time.h 
  11858.  
  11859.  
  11860. ΓòÉΓòÉΓòÉ 6.122. _heap_check - Validate Run-Time Storage Heap ΓòÉΓòÉΓòÉ
  11861.  
  11862.  
  11863. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11864.  
  11865. #define __DEBUG_ALLOC__
  11866. #include <stdlib.h>  /* also defined in <malloc.h> */
  11867.  
  11868. void *_heap_check(void);
  11869.  
  11870.  
  11871. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11872.  
  11873. The _heap_check function checks all memory blocks allocated or freed by the 
  11874. debug memory management functions to make sure that overwriting has not 
  11875. occurred outside the bounds of allocated blocks and that free memory blocks 
  11876. have not been overwritten. 
  11877.  
  11878. The _heap_check function is automatically called whenever a debug function is 
  11879. called.  You can also explicitly call _heap_check. 
  11880.  
  11881. Note:  You should place calls to the _heap_check function throughout your code, 
  11882. especially in areas that may cause memory problems. 
  11883.  
  11884. There is no return value. 
  11885.  
  11886. For an explanation of how to interpret the output from _heap_check, see Sample 
  11887. _heap_check Output. 
  11888.  
  11889. Example of _heap_check 
  11890.  
  11891.  
  11892. ΓòÉΓòÉΓòÉ <hidden> Example of _heap_check ΓòÉΓòÉΓòÉ
  11893.  
  11894. /************************************************************************
  11895. *
  11896. This example allocates 5000 bytes of storage, and then attempts to write to 
  11897. storage that was not allocated. The call to _heap_check detects the error, 
  11898. generates several messages, and stops the program. 
  11899.  
  11900.                                                                         *
  11901. ************************************************************************/
  11902.  
  11903. #ifndef __DEBUG_ALLOC__      /* this macro could also be defined */
  11904.    #define __DEBUG_ALLOC__   /*      from the command line       */
  11905. #endif
  11906. #include <stdlib.h>
  11907. #include <stdio.h>
  11908.  
  11909. int main(void)
  11910. {
  11911.    char *ptr;
  11912.  
  11913.    if (( ptr = malloc(5000) ) == NULL)
  11914.    {
  11915.       printf("Could not allocate memory block.\n");
  11916.       return EXIT_FAILURE;
  11917.    }
  11918.  
  11919.    *(ptr - 1) = 'a';    /* overwrites storage that was not allocated */
  11920.    _heap_check();
  11921.  
  11922.    printf("_heap_check did not detect that a memory block was overwritten.\n");
  11923.  
  11924.    return EXIT_FAILURE;
  11925.  
  11926.    /* Possible output is:
  11927.  
  11928.       Memory was overwritten before the allocated memory block that starts
  11929.             at address 0x00150010.
  11930.       The first eight bytes of the memory block (in hex) are: 0000000000000000.
  11931.       This memory block was (re)allocated at line number 11 in THPCHK.C.        */
  11932.  
  11933. }
  11934.  
  11935.  
  11936. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  11937.  
  11938. o _debug_calloc - Reserve and Initialize Storage 
  11939. o _debug_free - Release Storage Blocks 
  11940. o _debug_heapmin - Release Unused Memory in the Heap 
  11941. o _debug_malloc - Reserve Storage Blocks 
  11942. o _debug_realloc - Change Reserved Storage Block Size 
  11943. o _dump_allocated - Get Information about Allocated Storage 
  11944. o Using the Debug Memory Management Functions 
  11945. o malloc.h 
  11946. o stdlib.h 
  11947.  
  11948.  
  11949. ΓòÉΓòÉΓòÉ 6.123. _heapmin - Release Unused Memory in the Heap ΓòÉΓòÉΓòÉ
  11950.  
  11951.  
  11952. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  11953.  
  11954. #include <stdlib.h>  /* also defined in <malloc.h> */
  11955.  
  11956. int _heapmin(void);
  11957.  
  11958.  
  11959. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  11960.  
  11961. Language Level: Extension 
  11962.  
  11963. The _heapmin function returns all unused memory from the runtime heap to the 
  11964. operating system. 
  11965.  
  11966. If successful, _heapmin returns 0; if not, it returns -1. 
  11967.  
  11968. Example of _heapmin 
  11969.  
  11970.  
  11971. ΓòÉΓòÉΓòÉ <hidden> Example of _heapmin ΓòÉΓòÉΓòÉ
  11972.  
  11973. /************************************************************************
  11974. *
  11975. This example shows how to use the _heapmin function. 
  11976.  
  11977.                                                                         *
  11978. ************************************************************************/
  11979.  
  11980. #include <stdio.h>
  11981. #include <stdlib.h>
  11982.  
  11983. int main(void)
  11984. {
  11985.    if ( _heapmin() )
  11986.       printf("_heapmin failed.\n");
  11987.    else
  11988.       printf("_heapmin was successful.\n");
  11989.  
  11990.    return 0;
  11991.  
  11992.    /* The expected output is:
  11993.  
  11994.       _heapmin was successful. */
  11995.  
  11996. }
  11997.  
  11998.  
  11999. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12000.  
  12001. o _debug_heapmin - Release Unused Memory in the Heap 
  12002. o malloc.h 
  12003. o stdlib.h 
  12004.  
  12005.  
  12006. ΓòÉΓòÉΓòÉ 6.124. hypot  - Calculate Hypotenuse ΓòÉΓòÉΓòÉ
  12007.  
  12008.  
  12009. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12010.  
  12011. #include <math.h> /* SAA extension to ANSI */
  12012.  
  12013. double hypot(double side1, double side2);
  12014.  
  12015.  
  12016. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12017.  
  12018. Language Level: SAA 
  12019.  
  12020. The hypot function calculates the length of the hypotenuse of a right-angled 
  12021. triangle based on the lengths of two sides side1 and side2.  A call to hypot is 
  12022. equal to: 
  12023.  
  12024.    sqrt(side1 * side1 + side2 * side2);
  12025.  
  12026. The hypot function returns the length of the hypotenuse.  If an overflow 
  12027. results, the function sets errno to ERANGE and returns the value HUGE_VAL. 
  12028.  
  12029. Example of hypot 
  12030.  
  12031.  
  12032. ΓòÉΓòÉΓòÉ <hidden> Example of hypot ΓòÉΓòÉΓòÉ
  12033.  
  12034. /************************************************************************
  12035. *
  12036.  
  12037. This example calculates the hypotenuse of a right-angled triangle with sides of 
  12038. 3.0 and 4.0. 
  12039.  
  12040.                                                                         *
  12041. ************************************************************************/
  12042.  
  12043. #include <math.h>
  12044.  
  12045. int main(void)
  12046. {
  12047.    double x, y, z;
  12048.  
  12049.    x = 3.0;
  12050.    y = 4.0;
  12051.    z = hypot(x,y);
  12052.  
  12053.    printf("The hypotenuse of the triangle with sides %lf and %lf"
  12054.           " is %lf\n", x, y, z);
  12055. }
  12056.  
  12057. /********************  Output should be similar to:  **************
  12058.  
  12059. The hypotenuse of the triangle with sides 3.000000 and 4.000000 is 5.000000
  12060. */
  12061.  
  12062.  
  12063. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12064.  
  12065. o _fsqrt -  Calculate Square Root 
  12066. o sqrt  - Calculate Square Root 
  12067. o math.h 
  12068.  
  12069.  
  12070. ΓòÉΓòÉΓòÉ 6.125. _inp - Read Byte from Input Port ΓòÉΓòÉΓòÉ
  12071.  
  12072.  
  12073. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12074.  
  12075. #include <conio.h>              /*  Declared in both  */
  12076. #include <builtin.h>
  12077.  
  12078. int _inp(const unsigned int port);
  12079.  
  12080.  
  12081. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12082.  
  12083. Language Level: Extension 
  12084.  
  12085. The _inp function reads a byte from the specified input port. The port number 
  12086. must be an unsigned int value in the range 0 to 65 535 inclusive. 
  12087.  
  12088. Because it is a built-in function and has no backing code in the library: 
  12089.  
  12090. o You cannot take the address of _inp. 
  12091. o You cannot parenthesize an _inp function call, because parentheses specify a 
  12092.   call to the backing code for the function. 
  12093.  
  12094. You can run code containing this function only at ring zero. Otherwise, an 
  12095. invalid instruction exception is generated. 
  12096.  
  12097. The _inp function returns the byte value as an integer that was read from the 
  12098. specified port. There is no error return value and this function does not set 
  12099. errno. 
  12100.  
  12101. Example of _inp 
  12102.  
  12103.  
  12104. ΓòÉΓòÉΓòÉ <hidden> Example of _inp ΓòÉΓòÉΓòÉ
  12105.  
  12106. /************************************************************************
  12107. *
  12108.  
  12109. This example uses the _inp function to read a byte from a specified input port 
  12110. and return the data read. 
  12111.  
  12112.                                                                         *
  12113. ************************************************************************/
  12114.  
  12115. #include <builtin.h>
  12116. #define LOWER 0
  12117. #define UPPER 65535
  12118.  
  12119. int Add1(int j);
  12120. int g;
  12121. enum fruit {apples=10, bananas, cantalopes};
  12122. int arr[]={cantalopes, bananas, apples};
  12123.  
  12124. struct
  12125.    {
  12126.    int i;
  12127.    char ch;
  12128.    } st;
  12129.  
  12130. int main(void)
  12131.    {
  12132.    int i;
  12133.    volatile const int c = 0;
  12134.  
  12135.    i = _inp(0);
  12136.  
  12137.    g = _inp(LOWER + 1);    /* put the data read in a global variable  */
  12138.  
  12139.    i = _inp(apples);          /* passing enumerated type as the       */
  12140.                               /* port number                          */
  12141.                               /* ===================================  */
  12142.                               /* Types of port number passed :        */
  12143.                               /* -----------------------------------  */
  12144.    i = _inp(c);               /* - constant                           */
  12145.    i = _inp(arr[c]);          /* - element of array                   */
  12146.    st.i = Add1(c);            /*                                      */
  12147.    i = _inp(st.i);            /* - element of structure               */
  12148.    i = _inp(Add1(LOWER));     /* - return value from a function call  */
  12149.    i = _inp(UPPER);           /* - #define constant                   */
  12150.    i = _inp(256);             /* - the exact port number              */
  12151.                               /* -----------------------------------  */
  12152.    return 0;
  12153. }
  12154.  
  12155. int Add1(int j)
  12156.    {
  12157.    j += 1;
  12158.    return j;
  12159.    }
  12160.  
  12161.  
  12162. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12163.  
  12164. o _inpw - Read Unsigned Short from Input Port 
  12165. o _inpd - Read Double Word from Input Port 
  12166. o _outp - Write Byte to Output Port 
  12167. o _outpw - Write Word to Output Port 
  12168. o _outpd - Write Double Word to Output Port 
  12169.  
  12170.  
  12171. ΓòÉΓòÉΓòÉ 6.126. _inpd - Read Double Word from Input Port ΓòÉΓòÉΓòÉ
  12172.  
  12173.  
  12174. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12175.  
  12176. #include <conio.h>            /*  Declared in both  */
  12177. #include <builtin.h>
  12178.  
  12179. unsigned long _inpd(const unsigned int port);
  12180.  
  12181. Language Level: Extension 
  12182.  
  12183.  
  12184. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12185.  
  12186. The _inpd function reads a 4-byte (double word) unsigned value from the 
  12187. specified input port. The port number must be an unsigned short value within 
  12188. the range 0 to 65 535 inclusive. 
  12189.  
  12190. Because it is a built-in function and has no backing code in the library: 
  12191.  
  12192. o You cannot take the address of _inpd. 
  12193. o You cannot parenthesize an _inpd function call, because parentheses specify a 
  12194.   call to the backing code for the function. 
  12195.  
  12196. You can run code containing this function only at ring zero. Otherwise, an 
  12197. invalid instruction exception is generated. 
  12198.  
  12199. The _inpd function returns the unsigned long value that was read from the 
  12200. specified port. There is no error return value and this function does not set 
  12201. errno. 
  12202.  
  12203. Example of _inpd 
  12204.  
  12205.  
  12206. ΓòÉΓòÉΓòÉ <hidden> Example of _inpdx ΓòÉΓòÉΓòÉ
  12207.  
  12208. /************************************************************************
  12209. *
  12210.  
  12211. This example uses the _inpd function to read a double-word value from the 
  12212. specified input port and return the data read. 
  12213.  
  12214.                                                                         *
  12215. ************************************************************************/
  12216.  
  12217. #include <builtin.h>
  12218. #define LOWER 0
  12219. #define UPPER 65535
  12220.  
  12221. int Add1(int j);
  12222. static long g;
  12223. enum fruit {apples=10, bananas, cantalopes};
  12224. int arr[]={cantalopes, bananas, apples};
  12225. union
  12226.    {
  12227.    int i;
  12228.    char ch;
  12229.    } un;
  12230.  
  12231. int main(void)
  12232.    {
  12233.    unsigned long l;
  12234.    volatile const int c = 0;
  12235.    un.i = 65534;
  12236.    g = _inpd(255);         /* put the data read in a global variable  */
  12237.  
  12238.                                        /* =========================== */
  12239.                                        /* Types of port number passed:*/
  12240.                                        /* --------------------------- */
  12241.    l = _inpd(c);                       /* - constant                  */
  12242.    l = _inpd(un.i);                    /* - element of union          */
  12243.    l = _inpd(Add1(cantalopes));        /* - return value from a       */
  12244.                                        /*   function call             */
  12245.    l = _inpd(_inp(arr[Add1(LOWER)]));  /* - return value from a       */
  12246.                                        /*   builtin function call     */
  12247.                                        /* --------------------------- */
  12248.    return 0;
  12249. }
  12250.  
  12251. int Add1(int j)
  12252.    {
  12253.    j += 1;
  12254.    return j;
  12255.    }
  12256.  
  12257.  
  12258. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12259.  
  12260. o _inp - Read Byte from Input Port 
  12261. o _inpw - Read Unsigned Short from Input Port 
  12262. o _outp - Write Byte to Output Port 
  12263. o _outpw - Write Word to Output Port 
  12264. o _outpd - Write Double Word to Output Port 
  12265.  
  12266.  
  12267. ΓòÉΓòÉΓòÉ 6.127. _inpw - Read Unsigned Short from Input Port ΓòÉΓòÉΓòÉ
  12268.  
  12269.  
  12270. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12271.  
  12272. #include <conio.h>              /*  Declared in both  */
  12273. #include <builtin.h>
  12274.  
  12275. unsigned short _inpw(const unsigned int port);
  12276.  
  12277.  
  12278. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12279.  
  12280. Language Level: Extension 
  12281.  
  12282. The _inpw function reads an unsigned short value from the specified input port. 
  12283. The port number must be an unsigned short value within the range 0 to 65 535 
  12284. inclusive. 
  12285.  
  12286. Because it is a built-in function and has no backing code in the library: 
  12287.  
  12288. o You cannot take the address of _inpw. 
  12289. o You cannot parenthesize an _inpw function call, because parentheses specify a 
  12290.   call to the backing code for the function. 
  12291.  
  12292. You can run code containing this function only at ring zero. Otherwise, an 
  12293. invalid instruction exception is generated. 
  12294.  
  12295. This function returns the unsigned short value that was read from the specified 
  12296. port. There is no error return value and this function does not set errno. 
  12297.  
  12298. Example of _inpw 
  12299.  
  12300.  
  12301. ΓòÉΓòÉΓòÉ <hidden> Example of _inpw ΓòÉΓòÉΓòÉ
  12302.  
  12303. /************************************************************************
  12304. *
  12305.  
  12306. This example uses the _inpw to read an unsigned short value from the specified 
  12307. input port and return the data read. 
  12308.  
  12309.                                                                         *
  12310. ************************************************************************/
  12311.  
  12312. #include <builtin.h>
  12313. #define LOWER 0
  12314. #define UPPER 65535
  12315.  
  12316. int Add1(int j);
  12317. volatile short g;
  12318.  
  12319. int main(void)
  12320.    {
  12321.    volatile unsigned short s;
  12322.    volatile const int c = 0;
  12323.    int i = 65534;
  12324.    enum fruit {apples, bananas, cantalopes};
  12325.    int arr[] ={cantalopes, bananas, apples};
  12326.  
  12327.    g = _inpw(LOWER);       /* put the data read in a global variable  */
  12328.  
  12329.    s = _inpw(bananas);                 /* passing enumerated type     */
  12330.                                        /* as the port number          */
  12331.  
  12332.                                        /* =========================== */
  12333.                                        /* Types of port number passed:*/
  12334.                                        /* --------------------------- */
  12335.    s = _inpw(c);                       /* - constant                  */
  12336.    s = _inpw(i+1);                     /* - integer                   */
  12337.    s = _inpw(arr[bananas]);            /* - element of array          */
  12338.    s = _inpw(_outp(UPPER,cantalopes)); /* - return value from a       */
  12339.                                        /*   builtin function call     */
  12340.                                        /* --------------------------- */
  12341.    return 0;
  12342. }
  12343.  
  12344. int Add1(int j)
  12345.    {
  12346.    j += 1;
  12347.    return j;
  12348.    }
  12349.  
  12350.  
  12351. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12352.  
  12353. o _inp - Read Byte from Input Port 
  12354. o _inpd - Read Double Word from Input Port 
  12355. o _outp - Write Byte to Output Port 
  12356. o _outpw - Write Word to Output Port 
  12357. o _outpd - Write Double Word to Output Port 
  12358. o builtin.h 
  12359. o conio.h 
  12360.  
  12361.  
  12362. ΓòÉΓòÉΓòÉ 6.128. _interrupt - Call Interrupt  Procedure ΓòÉΓòÉΓòÉ
  12363.  
  12364.  
  12365. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12366.  
  12367. #include <builtin.h>
  12368.  
  12369. void _interrupt(const unsigned int intnum);
  12370.  
  12371. Language Level: Extension 
  12372.  
  12373.  
  12374. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12375.  
  12376. The _interrupt function calls the interrupt procedure specified by intnum using 
  12377. the INT machine instruction. The integer intnum must have a value within the 
  12378. range 0 to 255 inclusive. 
  12379.  
  12380. Because it is a built-in function and has no backing code in the library: 
  12381.  
  12382. o You cannot take the address of _interrupt. 
  12383. o You cannot parenthesize an _interrupt function call, because parentheses 
  12384.   specify a call to the backing code for the function. 
  12385.  
  12386. This function has no return value and it does not set errno. 
  12387.  
  12388. Example of _interrupt 
  12389.  
  12390.  
  12391. ΓòÉΓòÉΓòÉ <hidden> Example of _interrupt ΓòÉΓòÉΓòÉ
  12392.  
  12393. /************************************************************************
  12394. *
  12395.  
  12396. This example shows how to call interrupt 3, which is a breakpoint. 
  12397.  
  12398.                                                                         *
  12399. ************************************************************************/
  12400.  
  12401. #include <builtin.h>
  12402.  
  12403. int main( void )
  12404. {
  12405.    /* A breakpoint will occur when running this program */
  12406.    /* within a debugger.                                */
  12407.    _interrupt(3);
  12408.  
  12409.    return 0;
  12410. }
  12411.  
  12412.  
  12413. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12414.  
  12415. o _disable - Disable Interrupts 
  12416. o _enable - Enable Interrupts 
  12417.  
  12418.  
  12419. ΓòÉΓòÉΓòÉ 6.129. isalnum to isxdigit  - Test Integer Value ΓòÉΓòÉΓòÉ
  12420.  
  12421.  
  12422. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12423.  
  12424. #include <ctype.h>
  12425.  
  12426. int isalnum(int c);
  12427.          /* Test for upper- or lowercase letters, or decimal digit */
  12428. int isalpha(int c);
  12429.          /* Test for alphabetic character */
  12430. int iscntrl(int c);
  12431.          /* Test for any control character */
  12432. int isdigit(int c);
  12433.          /* Test for decimal digit */
  12434. int isgraph(int c);
  12435.          /* Test for printable character excluding space */
  12436. int islower(int c);
  12437.          /* Test for lowercase */
  12438. int isprint(int c);
  12439.          /* Test for printable character including space */
  12440. int ispunct(int c);
  12441.          /* Test for any nonalphanumeric printable character */
  12442.                                           /* excluding space */
  12443. int isspace(int c);
  12444.          /* Test for whitespace character */
  12445. int isupper(int c);
  12446.          /* Test for uppercase */
  12447. int isxdigit(int c);
  12448.          /* Test for hexadecimal digit */
  12449.  
  12450.  
  12451. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12452.  
  12453. Language Level: ANSI, SAA 
  12454.  
  12455. The <ctype.h> functions listed test a given integer value. They return a 
  12456. nonzero value if the integer satisfies the test condition, or a zero value if 
  12457. it does not. 
  12458.  
  12459. c must be representable as an unsigned char. 
  12460.  
  12461. Note:  EOF is a valid input value. 
  12462.  
  12463. Example of isalnum to isxdigit 
  12464.  
  12465.  
  12466. ΓòÉΓòÉΓòÉ <hidden> Example of isalnum to isxdigit ΓòÉΓòÉΓòÉ
  12467.  
  12468. /************************************************************************
  12469. *
  12470.  
  12471. This example analyzes all characters between code 0x0 and code UPPER_LIMIT, 
  12472. printing A for alphabetic characters, AN for alphanumerics, U for uppercase, L 
  12473. for lowercase, D for digits, X for hexadecimal digits, S for spaces, PU for 
  12474. punctuation, PR for printable characters, G for graphics characters, and C for 
  12475. control characters.  This example prints the code if printable. 
  12476.  
  12477. The output of this example is a 256-line table showing the characters from 0 to 
  12478. 255 that possess the attributes tested. 
  12479.  
  12480.                                                                         *
  12481. ************************************************************************/
  12482.  
  12483. #include <stdio.h>
  12484. #include <ctype.h>
  12485.  
  12486. #define UPPER_LIMIT   0xFF
  12487.  
  12488. int main(void)
  12489. {
  12490.    int ch;
  12491.  
  12492.    for ( ch = 0; ch <= UPPER_LIMIT; ++ch )
  12493.    {
  12494.       printf("%3d ", ch);
  12495.       printf("%#04x ", ch);
  12496.       printf("%3s ", isalnum(ch)  ? "AN" : " ");
  12497.       printf("%2s ", isalpha(ch)  ? "A"  : " ");
  12498.       printf("%2s",  iscntrl(ch)  ? "C"  : " ");
  12499.       printf("%2s",  isdigit(ch)  ? "D"  : " ");
  12500.       printf("%2s",  isgraph(ch)  ? "G"  : " ");
  12501.       printf("%2s",  islower(ch)  ? "L"  : " ");
  12502.       printf(" %c",  isprint(ch)  ? ch   : ' ');
  12503.       printf("%3s",  ispunct(ch)  ? "PU" : " ");
  12504.       printf("%2s",  isspace(ch)  ? "S"  : " ");
  12505.       printf("%3s",  isprint(ch)  ? "PR" : " ");
  12506.       printf("%2s",  isupper(ch)  ? "U"  : " ");
  12507.       printf("%2s",  isxdigit(ch) ? "X"  : " ");
  12508.  
  12509.       putchar('\n');
  12510.    }
  12511. }
  12512.  
  12513.  
  12514. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12515.  
  12516. o _isascii - Test Integer Values 
  12517. o _iscsym - _iscsymf - Test Integer 
  12518. o tolower - toupper  - Convert Character Case 
  12519. o _toascii - _tolower - _toupper - Convert Character 
  12520. o ctype.h 
  12521.  
  12522.  
  12523. ΓòÉΓòÉΓòÉ 6.130. _isascii - Test Integer Values ΓòÉΓòÉΓòÉ
  12524.  
  12525.  
  12526. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12527.  
  12528. #include <ctype.h>
  12529.  
  12530. int _isascii(int c);
  12531.  
  12532. Language Level: Extension 
  12533.  
  12534.  
  12535. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12536.  
  12537. The _isascii macro tests if an integer is within the ASCII range.  This macro 
  12538. assumes that the system uses the ASCII character set. 
  12539.  
  12540. The _isascii macro returns a nonzero value if the integer is within the ASCII 
  12541. set, and 0 if it is not. 
  12542.  
  12543. Language Level: Extension 
  12544.  
  12545. Example of _isascii 
  12546.  
  12547.  
  12548. ΓòÉΓòÉΓòÉ <hidden> Example of _isascii ΓòÉΓòÉΓòÉ
  12549.  
  12550. /************************************************************************
  12551. *
  12552. This example tests the integers from 0x7c to 0x82, and prints the corresponding 
  12553. ASCII character if the integer is within the ASCII range. 
  12554.  
  12555.                                                                         *
  12556. ************************************************************************/
  12557.  
  12558. #include <stdio.h>
  12559. #include <ctype.h>
  12560.  
  12561. int main(void)
  12562. {
  12563.     int ch;
  12564.  
  12565.     for (ch = 0x7c; ch <= 0x82; ch++)
  12566.     {
  12567.         printf("%#04x    ", ch);
  12568.         if (isascii(ch))
  12569.             printf("The ASCII character is %c\n", ch);
  12570.         else
  12571.             printf("Not an ASCII character\n");
  12572.     }
  12573.  
  12574.     return 0;
  12575.  
  12576.  
  12577. /****************  The output should be similar to:  ********************
  12578.  
  12579.    0x7c    The ASCII character is |
  12580.    0x7d    The ASCII character is }
  12581.    0x7e    The ASCII character is ~
  12582.    0x7f    The ASCII character is 
  12583.    0x80    Not an ASCII character
  12584.    0x81    Not an ASCII character
  12585.    0x82    Not an ASCII character
  12586. */
  12587. }
  12588.  
  12589.  
  12590. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12591.  
  12592. o isalnum to isxdigit  - Test Integer Value 
  12593. o _iscsym - _iscsymf - Test Integer 
  12594. o _toascii - _tolower - _toupper - Convert Character 
  12595. o tolower - toupper  - Convert Character Case 
  12596. o ctype.h 
  12597.  
  12598.  
  12599. ΓòÉΓòÉΓòÉ 6.131. _isatty - Test Handle for Character Device ΓòÉΓòÉΓòÉ
  12600.  
  12601.  
  12602. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12603.  
  12604. #include <io.h>
  12605.  
  12606. int _isatty(int handle);
  12607.  
  12608.  
  12609. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12610.  
  12611. Language Level: Extension 
  12612.  
  12613. The _isatty function determines whether the given handle is associated with a 
  12614. character device (a keyboard, display, printer or serial port). 
  12615.  
  12616. The _isatty function returns a nonzero value if the device is a character 
  12617. device. Otherwise, the return value is 0. 
  12618.  
  12619. Example of _isatty 
  12620.  
  12621.  
  12622. ΓòÉΓòÉΓòÉ <hidden> Example of _isatty ΓòÉΓòÉΓòÉ
  12623.  
  12624. /************************************************************************
  12625. *
  12626.  
  12627. This example opens the console and tries to determine if it is a character 
  12628. device: 
  12629.  
  12630.                                                                         *
  12631. ************************************************************************/
  12632.  
  12633. #include <io.h>
  12634. #include <stdio.h>
  12635. #include <fcntl.h>
  12636. #include <sys\stat.h>
  12637.  
  12638. int main(void)
  12639. {
  12640.    int  fh, result;
  12641.  
  12642.    if (-1 == (fh = _open("CON", O_RDWR,(S_IREAD | S_IWRITE))))
  12643.    {
  12644.       perror("Error opening console\n");
  12645.       return 1;
  12646.    }
  12647.  
  12648.    result = _isatty(fh)    ;
  12649.  
  12650.    if (0 != result)
  12651.       printf("CON is a character device.\n");
  12652.    else
  12653.       printf("CON is not a character device.\n");
  12654.  
  12655.    _close (fh);
  12656.    return 0;
  12657.  
  12658. /********************  The expected output is:  *************************
  12659.  
  12660.       CON is a character device.
  12661. */
  12662. }
  12663.  
  12664.  
  12665. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12666.  
  12667. o _inp - Read Byte from Input Port 
  12668. o _inpd - Read Double Word from Input Port 
  12669. o _inpw - Read Unsigned Short from Input Port 
  12670. o _outp - Write Byte to Output Port 
  12671. o _outpd - Write Double Word to Output Port 
  12672. o _outpw - Write Word to Output Port 
  12673. o io.h 
  12674.  
  12675.  
  12676. ΓòÉΓòÉΓòÉ 6.132. _iscsym - _iscsymf - Test Integer ΓòÉΓòÉΓòÉ
  12677.  
  12678.  
  12679. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12680.  
  12681. #include <ctype.h>
  12682.  
  12683. int _iscsym(int c);
  12684.  
  12685. int _iscsymf(int c);
  12686.  
  12687.  
  12688. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12689.  
  12690. Language Level: Extension 
  12691.  
  12692. These macros test if an integer is within a particular ASCII set. The macros 
  12693. assume that the system uses the ASCII character set. 
  12694.  
  12695. The _iscsymf macro tests if a character is alphabetic or an underscore (_). The 
  12696. _iscsym macro tests if a character is alphabetic, a digit, or an underscore. 
  12697.  
  12698. The _iscsym and _iscsymf macros return a nonzero value if the integer is within 
  12699. the ASCII set for which it tests, and 0 otherwise. 
  12700.  
  12701. Example of _iscsym - _iscsymf 
  12702.  
  12703.  
  12704. ΓòÉΓòÉΓòÉ <hidden> Example of _iscsym - _iscsymf ΓòÉΓòÉΓòÉ
  12705.  
  12706. /************************************************************************
  12707. *
  12708. This example uses _iscsym and _iscsymf to test the characters a, _, and 1. If 
  12709. the character falls within the ASCII set tested for, the macro returns TRUE. 
  12710. Otherwise, it returns FALSE. 
  12711.  
  12712.                                                                         *
  12713. ************************************************************************/
  12714.  
  12715. #include <stdio.h>
  12716. #include <ctype.h>
  12717.  
  12718. int main(void)
  12719. {
  12720.     int ch[3] = {'a', '_', '1'};
  12721.     int i;
  12722.  
  12723.     for (i = 0; i < 3; i++)
  12724.     {
  12725.         printf("_iscsym('%c') returns %s\n",
  12726.                      ch[i], _iscsym(ch[i]) ? "TRUE" : "FALSE");
  12727.  
  12728.         printf("_iscsymf('%c') returns %s\n\n",
  12729.                      ch[i], _iscsymf(ch[i]) ? "TRUE" : "FALSE");
  12730.     }
  12731.  
  12732.     return 0;
  12733.  
  12734. /******************  The output should be similar to:  ******************
  12735.  
  12736.    _iscsym('a') returns TRUE
  12737.    _iscsymf('a') returns TRUE
  12738.  
  12739.    _iscsym('_') returns TRUE
  12740.    _iscsymf('_') returns TRUE
  12741.  
  12742.    _iscsym('1') returns TRUE
  12743.    _iscsymf('1') returns FALSE
  12744. */
  12745. }
  12746.  
  12747.  
  12748. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12749.  
  12750. o isalnum to isxdigit  - Test Integer Value 
  12751. o _isascii - Test Integer Values 
  12752. o tolower - toupper  - Convert Character Case 
  12753. o _toascii - _tolower - _toupper - Convert Character 
  12754. o ctype.h 
  12755.  
  12756.  
  12757. ΓòÉΓòÉΓòÉ 6.133. _itoa - Convert Integer to String ΓòÉΓòÉΓòÉ
  12758.  
  12759.  
  12760. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12761.  
  12762. #include <stdlib.h>
  12763.  
  12764. char *_itoa(int value, char * string, int radix);
  12765.  
  12766.  
  12767. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12768.  
  12769. Language Level: Extension 
  12770.  
  12771. The _itoa function converts the digits of the given value to a character string 
  12772. that ends with a null character and stores the result in string. The radix 
  12773. argument specifies the base of value; it must be in the range 2 to 36. If radix 
  12774. equals 10 and value is negative, the first character of the stored string is 
  12775. the minus sign (-). 
  12776.  
  12777. Note:  The space reserved for string must be large enough to hold the returned 
  12778. string. The function can return up to 33 bytes including the null character 
  12779. (\0). 
  12780.  
  12781. The _itoa function returns a pointer to string. There is no error return value. 
  12782.  
  12783. Example of _itoa 
  12784.  
  12785.  
  12786. ΓòÉΓòÉΓòÉ <hidden> Example of _itoa ΓòÉΓòÉΓòÉ
  12787.  
  12788. /************************************************************************
  12789. *
  12790. This example converts the integer value -255 to a decimal, a binary, and a hex 
  12791. number, storing its character representation in the array buffer. 
  12792.  
  12793.                                                                         *
  12794. ************************************************************************/
  12795.  
  12796. #include <stdio.h>
  12797. #include <stdlib.h>
  12798.  
  12799. int main(void)
  12800. {
  12801.     char buffer[35];
  12802.     char *p;
  12803.  
  12804.     p = _itoa(-255, buffer, 10);
  12805.     printf("The result of _itoa(-255) with radix of 10
  12806.              is %s\n", p);
  12807.  
  12808.     p = _itoa(-255, buffer, 2);
  12809.     printf("The result of _itoa(-255) with radix of 2\n
  12810.              is %s\n", p);
  12811.  
  12812.     p = _itoa(-255, buffer, 16);
  12813.     printf("The result of _itoa(-255) with radix of 16
  12814.              is %s\n", p);
  12815.  
  12816.     return 0;
  12817.  
  12818.     /* The expected output is:
  12819.  
  12820.        The result of _itoa(-255) with radix of 10 is -255
  12821.        The result of _itoa(-255) with radix of 2
  12822.            is 11111111111111111111111100000001
  12823.        The result of _itoa(-255) with radix of 16 is ffffff01
  12824.                                                                           */
  12825. }
  12826.  
  12827.  
  12828. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12829.  
  12830. o _ecvt - Convert Floating-Point to Character 
  12831. o _fcvt - Convert Floating-Point to String 
  12832. o _gcvt - Convert Floating-Point to String 
  12833. o _ltoa - Convert Long Integer to String 
  12834. o _ultoa - Convert Unsigned Long Integer to String 
  12835. o stdlib.h 
  12836.  
  12837.  
  12838. ΓòÉΓòÉΓòÉ 6.134. _kbhit - Test for Keystroke ΓòÉΓòÉΓòÉ
  12839.  
  12840.  
  12841. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12842.  
  12843. include <conio.h>
  12844.  
  12845. int _kbhit(void);
  12846.  
  12847.  
  12848. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12849.  
  12850. Language Level: Extension 
  12851.  
  12852. The _kbhit function tests if a key has been pressed on the keyboard.  If the 
  12853. result is nonzero, a keystroke is waiting in the buffer.  You can get the 
  12854. keystroke using the _getch or _getche function.  If you call _getch or _getche 
  12855. without first calling _kbhit, the program waits for a key to be pressed. 
  12856.  
  12857. The _kbhit function returns a nonzero value if a key has been pressed. 
  12858. Otherwise, it returns 0. 
  12859.  
  12860. Example of _kbhit 
  12861.  
  12862.  
  12863. ΓòÉΓòÉΓòÉ <hidden> Example of _kbhit ΓòÉΓòÉΓòÉ
  12864.  
  12865. /************************************************************************
  12866. *
  12867.  
  12868. This example uses _kbhit to test for the pressing of a key on the keyboard and 
  12869. to print a statement with the result of the test. 
  12870.  
  12871.                                                                         *
  12872. ************************************************************************/
  12873.  
  12874.  #include <conio.h>
  12875.  #include <stdio.h>
  12876.  
  12877.  int main(void)
  12878.     {
  12879.     int ch;
  12880.  
  12881.     printf("Type in some letters.\n");
  12882.     printf("If you type in an 'x', the program ends.\n");
  12883.  
  12884.     for (;;)
  12885.        {
  12886.        while (_kbhit() == 0)
  12887.           {
  12888.           /* Processing without waiting for a key to be pressed */
  12889.           }
  12890.  
  12891.        ch = _getch();
  12892.  
  12893.        printf("You have pressed the '%c' key.\n",ch);
  12894.  
  12895.        if (ch == 'x')
  12896.           break;
  12897.  
  12898.        }
  12899.     return 0;
  12900.  
  12901. /*******************  Possible output:  ********************************
  12902.  
  12903.     Type in some letters.
  12904.     If you type in an 'x', the program ends.
  12905.     You have pressed the 'f' key.
  12906.     You have pressed the 'e' key.
  12907.     You have pressed the 'l' key.
  12908.     You have pressed the 'i' key.
  12909.     You have pressed the 'x' key.
  12910.  
  12911. ***********************  Program ends  ********************************/
  12912.     }
  12913.  
  12914.  
  12915. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12916.  
  12917. o _getch - _getche - Read Character from Keyboard 
  12918. o conio.h 
  12919.  
  12920.  
  12921. ΓòÉΓòÉΓòÉ 6.135. labs  - Calculate long Absolute Value ΓòÉΓòÉΓòÉ
  12922.  
  12923.  
  12924. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12925.  
  12926. #include <stdlib.h>
  12927.  
  12928. long int labs(long int n);
  12929.  
  12930.  
  12931. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12932.  
  12933. Language Level: ANSI, SAA 
  12934.  
  12935. The labs function produces the absolute value of its long integer argument n. 
  12936.  
  12937. The result may be undefined when the argument is equal to LONG_MIN, the 
  12938. smallest available long integer (-2 147 483 647). The value LONG_MIN is defined 
  12939. in the <limits.h> include file. There is no return value. 
  12940.  
  12941. Example of labs 
  12942.  
  12943.  
  12944. ΓòÉΓòÉΓòÉ <hidden> Example of labs ΓòÉΓòÉΓòÉ
  12945.  
  12946. /************************************************************************
  12947. *
  12948.  
  12949. This example computes y as the absolute value of the long integer -41567. 
  12950.  
  12951.                                                                         *
  12952. ************************************************************************/
  12953.  
  12954. #include <stdlib.h>
  12955. #include <stdio.h>
  12956.  
  12957. int main(void)
  12958. {
  12959.    long x, y;
  12960.  
  12961.    x = -41567L;
  12962.    y = labs(x);
  12963.  
  12964.    printf("The absolute value of %ld is %ld\n", x, y);
  12965. }
  12966.  
  12967. /********************  Output should be similar to:  **************
  12968.  
  12969. The absolute value of -41567 is 41567
  12970. */
  12971.  
  12972.  
  12973. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  12974.  
  12975. o abs  - Calculate Integer Absolute Value 
  12976. o _cabs - Calculate Absolute Value of Complex Number 
  12977. o fabs  - Calculate Floating-Point Absolute Value 
  12978. o limits.h 
  12979.  
  12980.  
  12981. ΓòÉΓòÉΓòÉ 6.136. ldexp  - Multiply by a Power of Two ΓòÉΓòÉΓòÉ
  12982.  
  12983.  
  12984. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  12985.  
  12986. #include <math.h>
  12987.  
  12988. double ldexp(double x, int exp);
  12989.  
  12990.  
  12991. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  12992.  
  12993. Language Level: ANSI, SAA 
  12994.  
  12995. The ldexp function calculates the value of x * (2**exp). If an overflow 
  12996. results, the function returns +HUGE_VAL for a large result or -HUGE_VAL for a 
  12997. small result, and sets errno to ERANGE. 
  12998.  
  12999. Example of ldexp 
  13000.  
  13001.  
  13002. ΓòÉΓòÉΓòÉ <hidden> Example of ldexp ΓòÉΓòÉΓòÉ
  13003.  
  13004. /************************************************************************
  13005. *
  13006.  
  13007. This example computes y as 1.5 times 2 to the fifth power (1.5 * (2**5)): 
  13008.  
  13009.                                                                         *
  13010. ************************************************************************/
  13011.  
  13012. #include <math.h>
  13013.  
  13014. int main(void)
  13015. {
  13016.    double x, y;
  13017.    int p;
  13018.  
  13019.    x = 1.5;
  13020.    p = 5;
  13021.    y = ldexp(x,p);
  13022.  
  13023.    printf("%lf times 2 to the power of %d is %lf\n", x, p, y);
  13024. }
  13025.  
  13026. /********************  Output should be similar to:  **************
  13027.  
  13028. 1.500000 times 2 to the power of 5 is 48.000000
  13029. */
  13030.  
  13031.  
  13032. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13033.  
  13034. o frexp  - Separate Floating-Point Value 
  13035. o modf  - Separate Floating-Point Value 
  13036. o math.h 
  13037.  
  13038.  
  13039. ΓòÉΓòÉΓòÉ 6.137. ldiv  - Long Division ΓòÉΓòÉΓòÉ
  13040.  
  13041.  
  13042. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13043.  
  13044. #include <stdlib.h>
  13045.  
  13046. ldiv_t ldiv(long int numerator, long int denominator);
  13047.  
  13048.  
  13049. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13050.  
  13051. Language Level: ANSI, SAA 
  13052.  
  13053. The ldiv function calculates the quotient and remainder of the division of 
  13054. numerator by denominator. 
  13055.  
  13056. The ldiv function returns a structure of type ldiv_t, containing both the 
  13057. quotient long int quot and the remainder long int rem.  If the value cannot be 
  13058. represented, the return value is undefined. If denominator is 0, an exception 
  13059. is raised. 
  13060.  
  13061. Example of ldiv 
  13062.  
  13063.  
  13064. ΓòÉΓòÉΓòÉ <hidden> Example of ldiv ΓòÉΓòÉΓòÉ
  13065.  
  13066. /************************************************************************
  13067. *
  13068.  
  13069. This example uses the ldiv function to calculate the quotients and remainders 
  13070. for a set of two dividends and two divisors. 
  13071.  
  13072.                                                                         *
  13073. ************************************************************************/
  13074.  
  13075. #include <stdio.h>
  13076. #include <stdlib.h>
  13077.  
  13078. int main(void)
  13079. {
  13080.    long int num[2] = {45,-45};
  13081.    long int den[2] = {7,-7};
  13082.    ldiv_t ans;   /* ldiv_t is a struct type containing two long ints:
  13083.                     'quot' stores quotient; 'rem' stores remainder */
  13084.    short i,j;
  13085.  
  13086.    printf("Results of long division:\n");
  13087.    for (i = 0; i < 2; i++)
  13088.       for (j = 0; j < 2; j++)
  13089.       {
  13090.          ans = ldiv(num[i], den[j]);
  13091.          printf("Dividend: %6ld  Divisor: %6ld", num[i], den[j]);
  13092.          printf("  Quotient: %6ld  Remainder: %6ld\n", ans.quot, ans.rem);
  13093.       }
  13094. }
  13095.  
  13096. /********************  Expected output:  **************************
  13097.  
  13098. Results of long division:
  13099. Dividend:  45  Divisor:   7  Quotient:   6  Remainder:   3
  13100. Dividend:  45  Divisor:  -7  Quotient:  -6  Remainder:   3
  13101. Dividend: -45  Divisor:   7  Quotient:  -6  Remainder:  -3
  13102. Dividend: -45  Divisor:  -7  Quotient:   6  Remainder:  -3
  13103. */
  13104.  
  13105.  
  13106. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13107.  
  13108. o div  - Calculate Quotient and Remainder 
  13109. o stdlib.h 
  13110.  
  13111.  
  13112. ΓòÉΓòÉΓòÉ 6.138. _lfind - _lsearch - Find Key in Array ΓòÉΓòÉΓòÉ
  13113.  
  13114.  
  13115. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13116.  
  13117. #include <search.h>
  13118.  
  13119. char *_lfind(char *search_key, char *base, unsigned int *num,
  13120.                  unsigned int *width, int (*)(const void *key,
  13121.                  const void *compare));
  13122.  
  13123. char *_lsearch(char *search_key, char *base, unsigned int *num,
  13124.                  unsigned int *width, int (*)(const void *key,
  13125.                  const void *compare));
  13126.  
  13127.  
  13128. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13129.  
  13130. Language Level: Extension 
  13131.  
  13132. The _lfind and _lsearch functions perform a linear search for the value 
  13133. search_key in an array of num elements, each of width bytes in size.  Unlike 
  13134. bsearch, _lsearch and _lfind do not require that you sort the array first.  The 
  13135. argument base points to the base of the array to be searched. 
  13136.  
  13137. If _lsearch does not find the search_key, it adds the search_key to the end of 
  13138. the array and increments num by one.  If _lfind does not find the search_key, 
  13139. it does not add the search_key to the array. 
  13140.  
  13141. The argument compare is a pointer to a function that you supply.  This function 
  13142. compares the specified key with an array element and returns a value specifying 
  13143. their relationship.  Both _lsearch and _lfind call the compare function one or 
  13144. more times during the search, passing pointers to two array elements on each 
  13145. call. 
  13146.  
  13147. The compare argument is returned as one of the following values: 
  13148.  
  13149. Value          Meaning 
  13150. Nonzero        key and element are different. 
  13151. 0              key and element are identical. 
  13152.  
  13153. If the search_key is found, both _lsearch and _lfind return a pointer to that 
  13154. element of the array to which base points. If the search_key is not found, 
  13155. _lsearch returns a pointer to a newly added item at the end of the array, while 
  13156. _lfind returns NULL. 
  13157.  
  13158. Example of _lfind 
  13159.  
  13160.  
  13161. ΓòÉΓòÉΓòÉ <hidden> Example of _lfind ΓòÉΓòÉΓòÉ
  13162.  
  13163. /************************************************************************
  13164. *
  13165. This example uses the _lfind function to search for the keyword PATH in the 
  13166. command-line arguments. 
  13167.  
  13168.                                                                         *
  13169. ************************************************************************/
  13170.  
  13171. #include <search.h>
  13172. #include <string.h>
  13173. #include <stdio.h>
  13174.  
  13175. #define CNT 2
  13176.  
  13177. /* Must declare 'compare' as a function  */
  13178. int compare(const void *, const void *);
  13179.  
  13180. int main(void)
  13181. {
  13182.    char **result;
  13183.    char *key = "PATH";
  13184.  
  13185.    unsigned int num = CNT;
  13186.  
  13187.    char *string[CNT] =
  13188.             {
  13189.              "PATH = d:\\david\\heather\\ed\\simon",
  13190.              "LIB = PATH\\abc"
  13191.             };
  13192.  
  13193.    /* The following statement finds the argument
  13194.             that starts with "PATH" */
  13195.    if ((result = (char **)_lfind((char *)&key,
  13196.                                 (char *)string, &num,
  13197.                                 sizeof(char *), compare)) != NULL)
  13198.        printf("%s found\n", *result);
  13199.    else
  13200.        printf("PATH not found \n");
  13201.  
  13202.    return 0;
  13203. }
  13204.  
  13205. /* The following is a sample 'compare' function */
  13206.  
  13207. int compare(const void *arg1, const void *arg2)
  13208. {
  13209.     return(strncmp(*(char **)arg1, *(char **)arg2,
  13210.             strlen(*(char **)arg1)));
  13211. }
  13212.  
  13213. /*****************  The output should be similar to:  *******************
  13214.  
  13215.     PATH = d:\david\heather\ed\simon found
  13216. */
  13217.  
  13218.  
  13219. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13220.  
  13221. o bsearch  - Search Arrays 
  13222. o qsort  - Sort Array 
  13223. o search.h 
  13224.  
  13225.  
  13226. ΓòÉΓòÉΓòÉ 6.139. _loadmod - Load User DLL ΓòÉΓòÉΓòÉ
  13227.  
  13228.  
  13229. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13230.  
  13231. #include <stdlib.h>
  13232.  
  13233. int _loadmod(char *module_name, unsigned long *module_handle);
  13234.  
  13235.  
  13236. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13237.  
  13238. Language Level: Extension 
  13239.  
  13240. The _loadmod function loads a user-created dynamic link library (DLL) for the 
  13241. calling process. The module_name is the name of the DLL to be loaded, and the 
  13242. module_handle is the file handle associated with the DLL. 
  13243.  
  13244. If the operation is successful, _loadmod returns the handle of the loaded DLL 
  13245. to the calling process.  The process can use this handle with the OS/2 API 
  13246. DosQueryProcAddr to get the address of the required function from within the 
  13247. DLL.  Once the reference is established, the calling process can then call the 
  13248. specific function. 
  13249.  
  13250. The return value of _loadmod is 0 if the DLL was successfully loaded.  If 
  13251. unsuccessful, _loadmod returns -1, and sets errno to one of the following 
  13252. values: 
  13253.  
  13254. Value             Meaning 
  13255. EMODNAME          The specified module_name is not valid. 
  13256. EOS2ERR           A system error occurred.  Check _doserrno for the specific 
  13257.                   OS/2 error code. 
  13258.  
  13259. Example of _loadmod 
  13260.  
  13261.  
  13262. ΓòÉΓòÉΓòÉ <hidden> Example of _loadmod ΓòÉΓòÉΓòÉ
  13263.  
  13264. /************************************************************************
  13265. *
  13266. In this example, _loadmod loads the DLL mark and gets the address of the 
  13267. function PLUS within the DLL.  It then calls that function, which adds two 
  13268. integers passed to it. The types PFN and APIRET, are required to use the OS/2 
  13269. DosQueryProcAddr API, and are defined by including the <os2.h> header file. 
  13270.  
  13271. Note:  To run this program, you must first create mark.dll. Copy the code for 
  13272. the PLUS function into a file called mark.c, and the code for the .DEF file 
  13273. into mark.def.  Eliminate the comments from these two files. Compile with the 
  13274. command: 
  13275.  
  13276.    icc /Ge- mark.c mark.def
  13277. You can then run the example: 
  13278.  
  13279.                                                                         *
  13280. ************************************************************************/
  13281.  
  13282. #define INCL_DOS
  13283. #include <os2.h>
  13284. #include <stdio.h>
  13285. #include <stdlib.h>
  13286.  
  13287. /* This is the code for MARK.DEF
  13288.  
  13289. LIBRARY MARK
  13290.  
  13291. PROTMODE
  13292.  
  13293. EXPORTS PLUS                       */
  13294.  
  13295. /* This is the code for PLUS function in the DLL
  13296.  
  13297.    #pragma linkage( PLUS, system )
  13298.    int PLUS( int a, int b )
  13299.    {
  13300.       return a + b;
  13301.    }                                               */
  13302.  
  13303. int main(void)
  13304. {
  13305.    int x = 4, y = 7;
  13306.  
  13307.    unsigned long handle;
  13308.    char * modname = "MARK" ;     /* DLL name              */
  13309.    char * fname = "PLUS"  ;      /* function name         */
  13310.  
  13311.    PFN faddr;                    /* pointer to function   */
  13312.    APIRET rc;                    /* return code           */
  13313.                                  /* from DosQueryProcAddr */
  13314.  
  13315.    /*  dynamically load the 'mark' DLL  */
  13316.    if (_loadmod(modname, &handle) )
  13317.    {
  13318.       printf("Error loading module %s\n", modname );
  13319.       exit (-1);
  13320.    }
  13321.  
  13322.    /*  get function address from DLL  */
  13323.    rc = DosQueryProcAddr( handle, 0, fname, &faddr );
  13324.  
  13325.    if (rc == 0)
  13326.       printf("Calling the function from the %s DLL to add %d
  13327.                and %d\n", modname,x,y);
  13328.       printf("The result of the function call is %d\n",
  13329.               faddr(x,y));
  13330.    else
  13331.    {
  13332.       printf("Error locating address of function %s\n",
  13333.                fname);
  13334.       _freemod( handle );
  13335.       exit(-1);
  13336.    }
  13337.  
  13338.    if( _freemod( handle ))
  13339.    {
  13340.       printf("Error in freeing the %s DLL module\n",
  13341.                modname);
  13342.       exit(-1);
  13343.    }
  13344.  
  13345.    printf("Reference to the %s DLL module has been freed\n",
  13346.             modname);
  13347.  
  13348.    return 0;
  13349.  
  13350. /**************  The expected output is  ********************
  13351.  
  13352.       Calling the function from the DLL to add 4 and 7
  13353.       The result of the function call is 11
  13354.       Reference to the MARK DLL module has been freed
  13355.  
  13356. */
  13357. }
  13358.  
  13359.  
  13360. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13361.  
  13362. o _freemod - Free User DLL 
  13363. o stdlib.h 
  13364.  
  13365.  
  13366. ΓòÉΓòÉΓòÉ 6.140. localeconv  - Query Locale Conventions ΓòÉΓòÉΓòÉ
  13367.  
  13368.  
  13369. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13370.  
  13371. #include <locale.h>
  13372.  
  13373. struct lconv *localeconv(void);
  13374.  
  13375.  
  13376. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13377.  
  13378. Language Level: ANSI, SAA 
  13379.  
  13380. The localeconv function sets the components of a structure having type struct 
  13381. lconv to values appropriate for the current locale.  The structure may be 
  13382. overwritten by another call to localeconv or by calling setlocale and passing 
  13383. LC_ALL, LC_MONETARY, or LC_NUMERIC. 
  13384.  
  13385. The structure contains the following elements (defaults shown are for the C 
  13386. locale): 
  13387.  
  13388. ELEMENT          PURPOSE OF ELEMENT             DEFAULT
  13389. "char *decimal_point"   Decimal-point character used to format   "."
  13390.              nonmonetary quantities.
  13391. "char *thousands_sep"   Character used to separate groups of    ""
  13392.              digits to the left of the decimal-point
  13393.              character in formatted nonmonetary quan-
  13394.              tities.
  13395. "char *grouping"     String indicating the size of each group  ""
  13396.              of digits in formatted nonmonetary quan-
  13397.              tities.  The value of each character in
  13398.              the string determines the number of
  13399.              digits in a group.  A value of
  13400.              "CHAR_MAX" indicates that there are no
  13401.              further groupings.  "0" indicates that
  13402.              the previous element is to be used for
  13403.              the remainder of the digits.
  13404. "char           International currency symbol for the    ""
  13405. *int_curr_symbol"     current locale.  The first three charac-
  13406.              ters contain the alphabetic interna-
  13407.              tional currency symbol.  The fourth
  13408.              character (usually a space) is the char-
  13409.              acter used to separate the international
  13410.              currency symbol from the monetary quan-
  13411.              tity.
  13412. "char           Local currency symbol of the current    ""
  13413. *currency_symbol"     locale.
  13414. "char           Separator for digits in formatted mone-   ""
  13415. *mon_thousands_sep"    tary quantities.
  13416. "char *mon_grouping"   String indicating the size of each group  ""
  13417.              of digits in formatted monetary quanti-
  13418.              ties.  The value of each character in
  13419.              the string determines the number of
  13420.              digits in a group.  A value of
  13421.              "CHAR_MAX" indicates that there are no
  13422.              further groupings.  "0" indicates that
  13423.              the previous element is to be used for
  13424.              the remainder of the digits.
  13425. "char *positive_sign"   String indicating the positive sign used  ""
  13426.              in monetary quantities.
  13427. "char *negative_sign"   String indicating the negative sign used  ""
  13428.              in monetary quantities.
  13429. "char int_frac_digits"  The number of displayed digits to the    "UCHAR_MAX"
  13430.              right of the decimal place for interna-
  13431.              tionally formatted monetary quantities.
  13432. "char frac_digits"    Number of digits to the right of the    "UCHAR_MAX"
  13433.              decimal place in monetary quantities.
  13434. "char p_cs_precedes"   1 if the "currency_symbol" precedes the   "UCHAR_MAX"
  13435.              value for a nonnegative formatted mone-
  13436.              tary quantity; "0" if it does not.
  13437. "char p_sep_by_space"   1 if the "currency_symbol" is separated   "UCHAR_MAX"
  13438.              by a space from the value of a nonnega-
  13439.              tive formatted monetary quantity;  "0"
  13440.              if it does not.
  13441. "char n_cs_precedes"   1 if the "currency_symbol" precedes the   "UCHAR_MAX"
  13442.              value for a negative formatted monetary
  13443.              quantity; "0" if it does not.
  13444. "char n_sep_by_space"   1 if the "currency_symbol" is separated   "UCHAR_MAX"
  13445.              by a space from the value of a negative
  13446.              formatted monetary quantity;  "0" if it
  13447.              does not.
  13448. "char p_sign_posn"    Value indicating the position of the    "UCHAR_MAX"
  13449.              "positive_sign" for a nonnegative for-
  13450.              matted monetary quantity.
  13451. "char n_sign_posn"    Value indicating the position of the    "UCHAR_MAX"
  13452.              "negative_sign" for a negative formatted
  13453.              monetary quantity.
  13454.  
  13455. The n_sign_posn and p_sign_posn elements can have the following values: 
  13456.  
  13457. Value Meaning 
  13458.  0   The quantity and currency_symbol are enclosed in parentheses. 
  13459.  1   The sign precedes the quantity and currency_symbol. 
  13460.  2   The sign follows the quantity and currency_symbol. 
  13461.  3   The sign precedes the currency_symbol. 
  13462.  4   The sign follows the currency_symbol. 
  13463.  
  13464. The localeconv function returns a pointer to the structure. 
  13465.  
  13466. Example of localeconv 
  13467.  
  13468.  
  13469. ΓòÉΓòÉΓòÉ <hidden> Example of localeconv ΓòÉΓòÉΓòÉ
  13470.  
  13471. /************************************************************************
  13472. *
  13473.  
  13474. This example prints out the default decimal point for your locale and then the 
  13475. decimal point for the LC_C_FRANCE locale. 
  13476.  
  13477.                                                                         *
  13478. ************************************************************************/
  13479.  
  13480. #include <stdio.h>
  13481. #include <locale.h>
  13482.  
  13483. int main(void)
  13484. {
  13485.   char * string;
  13486.   struct lconv * mylocale;
  13487.  
  13488.   mylocale = localeconv();
  13489.   /* Default decimal point */
  13490.   printf( "Default decimal point is a %s\n",
  13491.             mylocale->decimal_point );
  13492.  
  13493.   string = setlocale(LC_ALL, LC_C_FRANCE );
  13494.   mylocale = localeconv();
  13495.   /* A comma is set to be the decimal point
  13496.         when the locale is LC_C_FRANCE */
  13497.   printf( "France's decimal point is a %s\n",
  13498.             mylocale->decimal_point );
  13499. }
  13500.  
  13501. /********************  Output should be similar to:  **************
  13502.  
  13503. Default decimal point is a .
  13504. France's decimal point is a ,
  13505. */
  13506.  
  13507.  
  13508. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13509.  
  13510. o setlocale  - Set Locale 
  13511. o locale.h 
  13512.  
  13513.  
  13514. ΓòÉΓòÉΓòÉ 6.141. localtime  - Convert Time ΓòÉΓòÉΓòÉ
  13515.  
  13516.  
  13517. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13518.  
  13519. #include <time.h>
  13520.  
  13521. struct tm *localtime(const time_t *timeval);
  13522.  
  13523.  
  13524. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13525.  
  13526. Language Level: ANSI, SAA 
  13527.  
  13528. The localtime function converts a time value stored as a time_t value to a 
  13529. structure.  The time value is usually obtained by a call to the time function. 
  13530.  
  13531. The localtime function breaks down the timeval value, corrects for the local 
  13532. time zone and Daylight Saving Time, if appropriate, and stores the corrected 
  13533. time in a structure of type tm.  See gmtime for a description of the fields in 
  13534. a tm structure. 
  13535.  
  13536. The localtime function returns a pointer to the structure result.  There is no 
  13537. error return value. 
  13538.  
  13539. Note: 
  13540.  
  13541.  1. The gmtime and localtime functions may use a common, statically allocated 
  13542.     buffer for the conversion.  Each call to one of these functions may alter 
  13543.     the result of the previous call. 
  13544.  
  13545.  2. The time and date functions begin at 00:00:00 Coordinated Universal Time, 
  13546.     January 1, 1970. 
  13547.  
  13548. Example of localtime 
  13549.  
  13550.  
  13551. ΓòÉΓòÉΓòÉ <hidden> Example of localtime ΓòÉΓòÉΓòÉ
  13552.  
  13553. /************************************************************************
  13554. *
  13555.  
  13556. This example queries the system clock and displays the local time. 
  13557.  
  13558.                                                                         *
  13559. ************************************************************************/
  13560.  
  13561. #include <time.h>
  13562. #include <stdio.h>
  13563.  
  13564. int main(void)
  13565. {
  13566.    struct tm *newtime;
  13567.    time_t ltime;
  13568.  
  13569.    time(<ime);
  13570.    newtime = localtime(<ime);
  13571.    printf("The date and time is %s", asctime(newtime));
  13572. }
  13573.  
  13574. /**************  If the local time is 3:00 p.m. May 31, 1993,  **********
  13575. *************************  output should be:  *********************
  13576.  
  13577. The date and time is Mon May 31 15:00:00 1993
  13578. */
  13579.  
  13580.  
  13581. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13582.  
  13583. o asctime  - Convert Time 
  13584. o ctime  - Convert Time 
  13585. o gmtime  - Convert Time 
  13586. o mktime  - Convert Local Time 
  13587. o time  - Determine Current Time 
  13588. o time.h 
  13589.  
  13590.  
  13591. ΓòÉΓòÉΓòÉ 6.142. log  - Calculate Natural Logarithm ΓòÉΓòÉΓòÉ
  13592.  
  13593.  
  13594. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13595.  
  13596. #include <math.h>
  13597.  
  13598. double log(double x);
  13599.  
  13600.  
  13601. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13602.  
  13603. Language Level: ANSI, SAA 
  13604.  
  13605. The log function calculates the natural logarithm (base e) of x. 
  13606.  
  13607. The log function returns the computed value.  If x is negative, it will set 
  13608. errno to EDOM and may return the value -HUGE_VAL. If x is zero, log returns the 
  13609. value -HUGE_VAL, and may set errno to ERANGE. 
  13610.  
  13611. Example of log 
  13612.  
  13613.  
  13614. ΓòÉΓòÉΓòÉ <hidden> Example of log ΓòÉΓòÉΓòÉ
  13615.  
  13616. /************************************************************************
  13617. *
  13618.  
  13619. This example calculates the natural logarithm of 1000.0. 
  13620.  
  13621.                                                                         *
  13622. ************************************************************************/
  13623.  
  13624. #include <math.h>
  13625. #include <stdio.h>
  13626.  
  13627. int main(void)
  13628. {
  13629.    double x = 1000.0, y;
  13630.  
  13631.    y = log(x);
  13632.  
  13633.    printf("The natural logarithm of %lf is %lf\n", x, y);
  13634. }
  13635.  
  13636. /********************  Output should be similar to:  **************
  13637.  
  13638. The natural logarithm of 1000.000000 is 6.907755
  13639. */
  13640.  
  13641.  
  13642. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13643.  
  13644. o exp  - Exponential Function 
  13645. o log10  - Calculate Base 10 Logarithm 
  13646. o pow  - Compute Power 
  13647. o math.h 
  13648.  
  13649.  
  13650. ΓòÉΓòÉΓòÉ 6.143. log10  - Calculate Base 10 Logarithm ΓòÉΓòÉΓòÉ
  13651.  
  13652.  
  13653. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13654.  
  13655. #include <math.h>
  13656.  
  13657. double log10(double x);
  13658.  
  13659.  
  13660. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13661.  
  13662. Language Level: ANSI, SAA 
  13663.  
  13664. The log10 function calculates the base 10 logarithm of x. 
  13665.  
  13666. The log10 function returns the computed value.  If x is negative, it will set 
  13667. errno to EDOM and may return the value -HUGE_VAL. If x is zero, log10 returns 
  13668. the value -HUGE_VAL, and may set errno to ERANGE. 
  13669.  
  13670. Example of log10 
  13671.  
  13672.  
  13673. ΓòÉΓòÉΓòÉ <hidden> Example of log10 ΓòÉΓòÉΓòÉ
  13674.  
  13675. /************************************************************************
  13676. *
  13677.  
  13678. This example calculates the base 10 logarithm of 1000.0. 
  13679.  
  13680.                                                                         *
  13681. ************************************************************************/
  13682.  
  13683. #include <math.h>
  13684. #include <stdio.h>
  13685.  
  13686. int main(void)
  13687. {
  13688.    double x = 1000.0, y;
  13689.  
  13690.    y = log10(x);
  13691.  
  13692.    printf("The base 10 logarithm of %lf is %lf\n", x, y);
  13693. }
  13694.  
  13695. /********************  Output should be similar to:  **************
  13696.  
  13697. The base 10 logarithm of 1000.000000 is 3.000000
  13698. */
  13699.  
  13700.  
  13701. ΓòÉΓòÉΓòÉ <hidden> Relative Information ΓòÉΓòÉΓòÉ
  13702.  
  13703. o exp  - Exponential Function 
  13704. o log  - Calculate Natural Logarithm 
  13705. o pow  - Compute Power 
  13706. o math.h 
  13707.  
  13708.  
  13709. ΓòÉΓòÉΓòÉ 6.144. longjmp  - Restore Stack Environment ΓòÉΓòÉΓòÉ
  13710.  
  13711.  
  13712. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13713.  
  13714. #include <setjmp.h>
  13715.  
  13716. void longjmp(jmp_buf env, int value);
  13717.  
  13718.  
  13719. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13720.  
  13721. Language Level: ANSI, SAA 
  13722.  
  13723. The longjmp function restores a stack environment previously saved in env by 
  13724. setjmp.  The setjmp macro and longjmp function provide a way to perform a 
  13725. nonlocal goto. They are often used in signal handlers. 
  13726.  
  13727. A call to setjmp causes the current stack environment to be saved in env.  A 
  13728. subsequent call to longjmp restores the saved environment and returns control 
  13729. to a point in the program corresponding to the setjmp call.  Execution resumes 
  13730. as if the setjmp call had just returned the given value.  All variables (except 
  13731. register variables) that are accessible to the function that receives control 
  13732. contain the values they had when longjmp was called.  The values of register 
  13733. variables are unpredictable.  Nonvolatile auto variables that are changed 
  13734. between calls to setjmp and longjmp are also unpredictable. 
  13735.  
  13736. Note:  Ensure that the function that calls setjmp does not return before you 
  13737.        call the corresponding longjmp function. Calling longjmp after the 
  13738.        function calling setjmp returns causes unpredictable program behavior. 
  13739.  
  13740. The value argument passed to longjmp must be nonzero.  If you give a zero 
  13741. argument for value, longjmp substitutes a 1 in its place. 
  13742.  
  13743. The longjmp function does not use the normal function call and return 
  13744. mechanisms;  it has no return value. 
  13745.  
  13746. Example of longjmp 
  13747.  
  13748.  
  13749. ΓòÉΓòÉΓòÉ <hidden> Example of longjmp ΓòÉΓòÉΓòÉ
  13750.  
  13751. /************************************************************************
  13752. *
  13753.  
  13754. This example provides for saving the stack environment at the statement: 
  13755.  
  13756.   if(setjmp(mark) != 0) ...
  13757.  
  13758. When the system first performs the if statement, it saves the environment in 
  13759. mark and sets the condition to FALSE because setjmp returns a 0 when it saves 
  13760. the environment.  The program prints the message: 
  13761.  
  13762.   setjmp has been called
  13763.  
  13764. The subsequent call to function p tests for a local error condition, which can 
  13765. cause it to perform the longjmp function.  Then, control returns to the 
  13766. original setjmp function using the environment saved in mark.  This time the 
  13767. condition is TRUE because -1 is the return value from the longjmp function. The 
  13768. example then performs the statements in the block and prints: 
  13769.  
  13770.   longjmp has been called
  13771.  
  13772. It then performs the recover function and leaves the program. 
  13773.  
  13774.                                                                         *
  13775. ************************************************************************/
  13776.  
  13777. #include <stdio.h>
  13778. #include <setjmp.h>
  13779.  
  13780. jmp_buf mark;
  13781.  
  13782. void p(void);
  13783. void recover(void);
  13784.  
  13785. int main(void)
  13786. {
  13787.    if (setjmp(mark) != 0)
  13788.    {
  13789.       printf("longjmp has been called\n");
  13790.       recover();
  13791.       exit(1);
  13792.       }
  13793.    printf("setjmp has been called\n");
  13794.    .
  13795.    .
  13796.    .
  13797.    p();
  13798.    .
  13799.    .
  13800.    .
  13801. }
  13802.  
  13803. void p(void)
  13804. {
  13805.    int error = 0;
  13806.    .
  13807.    .
  13808.    .
  13809.    error = 9;
  13810.    .
  13811.    .
  13812.    .
  13813.    if (error != 0)
  13814.       longjmp(mark, -1);
  13815.    .
  13816.    .
  13817.    .
  13818. }
  13819.  
  13820. void recover(void)
  13821. {
  13822.    .
  13823.    .
  13824.    .
  13825. }
  13826.  
  13827.  
  13828. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13829.  
  13830. o setjmp  - Preserve Environment 
  13831. o goto 
  13832. o volatile and const Qualifiers 
  13833. o auto Storage Class Specifier 
  13834. o setjmp.h 
  13835.  
  13836.  
  13837. ΓòÉΓòÉΓòÉ 6.145. _lrotl - _lrotr - Rotate Bits ΓòÉΓòÉΓòÉ
  13838.  
  13839.  
  13840. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13841.  
  13842. #include <stdlib.h>
  13843.  
  13844. unsigned long _lrotl(unsigned long value, int shift);
  13845.  
  13846. unsigned long _lrotr(unsigned long value, int shift);
  13847.  
  13848.  
  13849. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13850.  
  13851. Language Level: Extension 
  13852.  
  13853. These functions rotate value by shift bits. The _lrotl function rotates to the 
  13854. left, and _lrotr to the right. 
  13855.  
  13856. Both functions return the rotated value.  There is no error return value. 
  13857.  
  13858. Example of _lrotl - _lrotr 
  13859.  
  13860.  
  13861. ΓòÉΓòÉΓòÉ <hidden> Example of _lrotl - _lrotr ΓòÉΓòÉΓòÉ
  13862.  
  13863. /************************************************************************
  13864. *
  13865. This example uses _lrotl and _lrotr with different shift values to rotate the 
  13866. long integer value 0x01234567: 
  13867.  
  13868.                                                                         *
  13869. ************************************************************************/
  13870.  
  13871. #include <stdio.h>
  13872. #include <stdlib.h>
  13873.  
  13874. int main(void)
  13875. {
  13876.     unsigned long val = 0X01234567;
  13877.  
  13878.     printf("The value of 0x%8.8lx rotated 4 bits to the left is
  13879.              0x%8.8lx\n", val,  _lrotl(val, 4));
  13880.  
  13881.     printf("The value of 0x%8.8lx rotated 16 bits to the right is
  13882.              0x%8.8lx\n", val,  _lrotr(val, 16));
  13883.  
  13884.  
  13885.     return 0;
  13886.  
  13887. /*************  The output should be similar to:  ***********************
  13888.  
  13889.    The value of 0x01234567 rotated 4 bits to the left is 0x12345670
  13890.    The value of 0x01234567 rotated 16 bits to the right is 0x45670123
  13891. */
  13892. }
  13893.  
  13894.  
  13895. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  13896.  
  13897. o _rotl - _rotr - Bit Rotation 
  13898. o stdlib.h 
  13899.  
  13900.  
  13901. ΓòÉΓòÉΓòÉ 6.146. _lseek - Move File Pointer ΓòÉΓòÉΓòÉ
  13902.  
  13903.  
  13904. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  13905.  
  13906. #include <io.h>
  13907. #include <stdio.h>
  13908.  
  13909. long _lseek(int handle, long offset, int origin);
  13910.  
  13911.  
  13912. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  13913.  
  13914. Language Level: Extension 
  13915.  
  13916. The _lseek function moves any file pointer associated with handle to a new 
  13917. location that is offset bytes from the origin. The next operation on the file 
  13918. takes place at the new location. Origin must be one of the following constants, 
  13919. defined in <stdio.h>: 
  13920.  
  13921. Origin         Definition 
  13922. SEEK_SET       Beginning of file 
  13923. SEEK_CUR       Current position of file pointer 
  13924. SEEK_END       End of file. 
  13925.  
  13926. The _lseek function can reposition the pointer anywhere in a file. The pointer 
  13927. can also be positioned beyond the end of the file; the data between the eof and 
  13928. the new file position is undefined. (See _chsize - Alter Length of File for 
  13929. more information on extending the length of the file.) However, an attempt to 
  13930. position the pointer before the beginning of the file causes an error. 
  13931.  
  13932. The _lseek function returns the offset, in bytes, of the new position from the 
  13933. beginning of the file. A return value of -1L indicates an error, and errno is 
  13934. set to one of the following values: 
  13935.  
  13936. Value          Meaning 
  13937. EBADF          The file handle is incorrect. 
  13938. EINVAL         The value for origin is incorrect, or the position specified by 
  13939.                offset is before the beginning of the file. 
  13940. EOS2ERR        The call to the operating system was not successful. 
  13941.  
  13942. On devices incapable of seeking (such as keyboards and printers), the return 
  13943. value is -1, and errno is set to EOS2ERR. 
  13944.  
  13945. Example of _lseek 
  13946.  
  13947.  
  13948. ΓòÉΓòÉΓòÉ <hidden> Example of _lseek ΓòÉΓòÉΓòÉ
  13949.  
  13950. /************************************************************************
  13951. *
  13952.  
  13953. This example opens the file sample.dat and if successful, moves the file 
  13954. pointer to the eighth position in the file. The example then attempts to read 
  13955. bytes from the file, starting at the new pointer position, and reads them into 
  13956. the buffer. 
  13957.  
  13958.                                                                         *
  13959. ************************************************************************/
  13960.  
  13961. #include <io.h>
  13962. #include <stdio.h>
  13963. #include <stdlib.h>
  13964. #include <fcntl.h>
  13965. #include <string.h>
  13966.  
  13967. int main(void)
  13968.    {
  13969.    long length;
  13970.    int  fh;
  13971.    char buffer[20];
  13972.  
  13973.    memset(buffer,'\0',20);  /* Initialize the buffer */
  13974.  
  13975.    printf("\nCreating sample.dat.\n");
  13976.    system("echo Sample Program > sample.dat");
  13977.  
  13978.  
  13979.    if (-1 == (fh = _open("sample.dat",O_RDWR | O_APPEND)))
  13980.       {
  13981.       perror("Unable to open sample.dat.");
  13982.       _exit(1);
  13983.       }
  13984.  
  13985.    if ( -1 == _lseek(fh,7,SEEK_SET) ) /* place the file pointer at the */
  13986.       {                              /* eighth position in the file   */
  13987.       perror("Unable to _lseek");
  13988.       _close(fh);
  13989.       return 1;
  13990.       }
  13991.  
  13992.    if (8 != _read(fh,buffer,8))
  13993.       {
  13994.       perror("Unable to read from sample.dat.");
  13995.       _close(fh);
  13996.       return 1;
  13997.       }
  13998.  
  13999.    printf("Successfully read in the following:\n%s\n ",buffer);
  14000.  
  14001.    _close(fh);
  14002.  
  14003.    return 0;
  14004.  
  14005. /***********  The expected output is:  *****************
  14006.  
  14007.       Creating sample.dat.
  14008.       Successfully read in the following:
  14009.       Program
  14010. */
  14011.    }
  14012.  
  14013.  
  14014. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14015.  
  14016. o _chsize - Alter Length of File 
  14017. o fseek  - Reposition File Position 
  14018. o _tell - Get Pointer Position 
  14019. o io.h 
  14020. o stdio.h 
  14021.  
  14022.  
  14023. ΓòÉΓòÉΓòÉ 6.147. _ltoa - Convert Long Integer to String ΓòÉΓòÉΓòÉ
  14024.  
  14025.  
  14026. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14027.  
  14028. #include <stdlib.h>
  14029.  
  14030. char *_ltoa(long value, char *string, int radix);
  14031.  
  14032.  
  14033. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14034.  
  14035. Language Level: Extension 
  14036.  
  14037. The _ltoa function converts the digits of the given long integer value to a 
  14038. character string that ends with a null character and stores the result in 
  14039. string.  The radix argument specifies the base of value; it must be in the 
  14040. range 2 to 36. If radix equals 10 and value is negative, the first character of 
  14041. the stored string is the minus sign (-). 
  14042.  
  14043. Note:  The space allocated for string must be large enough to hold the returned 
  14044. string. The function can return up to 33 bytes including the null character 
  14045. (\0). 
  14046.  
  14047. The _ltoa function returns a pointer to string.  There is no error return 
  14048. value. 
  14049.  
  14050. Example of _ltoa 
  14051.  
  14052.  
  14053. ΓòÉΓòÉΓòÉ <hidden> Example of _ltoa ΓòÉΓòÉΓòÉ
  14054.  
  14055. /************************************************************************
  14056. *
  14057. This example converts the long integer -255L to a decimal, binary, and hex 
  14058. value, and stores its character representation in the array buffer. 
  14059.  
  14060.                                                                         *
  14061. ************************************************************************/
  14062.  
  14063. #include <stdio.h>
  14064. #include <stdlib.h>
  14065.  
  14066. int main(void)
  14067. {
  14068.     char buffer[35];
  14069.     char *p;
  14070.  
  14071.     p = _ltoa(-255L, buffer, 10);
  14072.     printf("The result of _ltoa(-255) with radix of 10 is %s\n", p);
  14073.  
  14074.     p = _ltoa(-255L, buffer, 2);
  14075.     printf("The result of _ltoa(-255) with radix of 2\n    is %s\n", p);
  14076.  
  14077.     p = _ltoa(-255L, buffer, 16);
  14078.     printf("The result of _ltoa(-255) with radix of 16 is %s\n", p);
  14079.  
  14080.     return 0;
  14081.  
  14082.     /* The expected output is:
  14083.  
  14084.        The result of _ltoa(-255) with radix of 10 is -255
  14085.        The result of _ltoa(-255) with radix of 2
  14086.            is 11111111111111111111111100000001
  14087.        The result of _ltoa(-255) with radix of 16 is ffffff01  */
  14088.  
  14089. }
  14090.  
  14091.  
  14092. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14093.  
  14094. o atol  - Convert Character Strings 
  14095. o _ecvt - Convert Floating-Point to Character 
  14096. o _fcvt - Convert Floating-Point to String 
  14097. o _gcvt - Convert Floating-Point to String 
  14098. o _itoa - Convert Integer to String 
  14099. o _ultoa - Convert Unsigned Long Integer to String 
  14100. o stdlib.h 
  14101.  
  14102.  
  14103. ΓòÉΓòÉΓòÉ 6.148. _makepath - Create Path ΓòÉΓòÉΓòÉ
  14104.  
  14105.  
  14106. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14107.  
  14108. #include <stdlib.h>
  14109.  
  14110. void _makepath(char *path, char *drive, char *dir, char *fname, char *ext);
  14111.  
  14112.  
  14113. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14114.  
  14115. Language Level: Extension 
  14116.  
  14117. The _makepath function creates a single path name, composed of a drive letter, 
  14118. directory path, file name, and file name extension. 
  14119.  
  14120. The path argument should point to an empty buffer large enough to hold the 
  14121. complete path name. The constant _MAX_PATH, defined in <stdlib.h>, specifies 
  14122. the maximum size allowed for path. The other arguments point to the following 
  14123. buffers containing the path name elements: 
  14124.  
  14125. Buffer         Description 
  14126. drive          Contains a letter (A, B, ...) corresponding to the desired drive 
  14127.                and an optional following colon.  The _makepath routine inserts 
  14128.                the colon automatically in the composite path name if it is 
  14129.                missing.  If drive is a null character or an empty string, no 
  14130.                drive letter or colon appears in the composite path string. 
  14131. dir            Contains the path of directories, not including the drive 
  14132.                designator or the actual file name.  The trailing slash is 
  14133.                optional, and either slash (/) or backslash (\) or both can be 
  14134.                used in a single dir argument.  If a trailing slash or backslash 
  14135.                (/ or \) is not specified, it is inserted automatically.  If dir 
  14136.                is a null character or an empty string, no slash is inserted in 
  14137.                the composite path string. 
  14138. fname          Contains the base file name without any extensions. 
  14139. ext            Contains the actual file name extension, with or without a 
  14140.                leading period.  The _makepath function inserts the period 
  14141.                automatically if it does not appear in ext.  If ext is a null 
  14142.                character or an empty string, no period is inserted in the 
  14143.                composite path string. 
  14144.  
  14145. The size limits on the above four fields are those specified by the constants 
  14146. _MAX_DRIVE, _MAX_DIR, _MAX_FNAME, and _MAX_EXT, which are defined in 
  14147. <stdlib.h>. The composite path should be no larger than the _MAX_PATH constant 
  14148. also defined in <stdlib.h>; otherwise, the operating system does not handle it 
  14149. correctly. 
  14150.  
  14151. Note:  No checking is done to see if the syntax of the file name is correct. 
  14152.  
  14153. There is no return value. 
  14154.  
  14155. Example of _makepath 
  14156.  
  14157.  
  14158. ΓòÉΓòÉΓòÉ <hidden> Example of _makepath ΓòÉΓòÉΓòÉ
  14159.  
  14160. /************************************************************************
  14161. *
  14162. This example builds a file name path from the specified components: 
  14163.  
  14164.                                                                         *
  14165. ************************************************************************/
  14166.  
  14167. #include <stdio.h>
  14168. #include <stdlib.h>
  14169.  
  14170. int main(void)
  14171. {
  14172.    char path_buffer [_MAX_PATH];
  14173.    char drive [_MAX_DRIVE];
  14174.    char dir [_MAX_DIR];
  14175.    char fname [_MAX_FNAME];
  14176.    char ext [_MAX_EXT];
  14177.  
  14178.    _makepath (path_buffer, "c",
  14179.         "qc\\bob\\eclibref\\e", "makepath", "c");
  14180.    printf ("Path created with _makepath: %s\n\n",
  14181.         path_buffer);
  14182.  
  14183.    _splitpath (path_buffer, drive, dir, fname, ext);
  14184.    printf ("Path extracted with _splitpath:\n");
  14185.    printf ("drive: %s\n", drive);
  14186.    printf ("directory: %s\n", dir);
  14187.    printf ("file name: %s\n", fname);
  14188.    printf ("extension: %s\n", ext);
  14189.  
  14190.    return 0;
  14191.  
  14192. /************  The output should be similar to:  ********
  14193.  
  14194.    Path created with _makepath:
  14195.          c:qc\bob\eclibref\e\makepath.c
  14196.  
  14197.    Path extracted with _splitpath:
  14198.    drive: c:
  14199.    directory: qc\bob\eclibref\e\
  14200.    file name: makepath
  14201.    extension: .c
  14202. */
  14203.  
  14204. }
  14205.  
  14206.  
  14207. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14208.  
  14209. o _fullpath - Get Full Path Name of Partial Path 
  14210. o _splitpath - Decompose Path Name 
  14211. o stdlib.h 
  14212.  
  14213.  
  14214. ΓòÉΓòÉΓòÉ 6.149. malloc  - Reserve Storage Block ΓòÉΓòÉΓòÉ
  14215.  
  14216.  
  14217. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14218.  
  14219. #include <stdlib.h>  /* also defined in <malloc.h> */
  14220.  
  14221. void *malloc(size_t size);
  14222.  
  14223.  
  14224. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14225.  
  14226. Language Level: ANSI, SAA, Extension 
  14227.  
  14228. The malloc function reserves a block of storage of size bytes. Unlike the 
  14229. calloc function, malloc does not necessarily give all the bits of each element 
  14230. an initial value of 0. 
  14231.  
  14232. The malloc function returns a pointer to the reserved space.  The storage space 
  14233. to which the return value points is guaranteed to be suitably aligned for 
  14234. storage of any type of object. 
  14235.  
  14236. The return value is NULL if there is not enough storage available, or if size 
  14237. was specified as zero. 
  14238.  
  14239. Example of malloc 
  14240.  
  14241.  
  14242. ΓòÉΓòÉΓòÉ <hidden> Example of malloc ΓòÉΓòÉΓòÉ
  14243.  
  14244. /************************************************************************
  14245. *
  14246.  
  14247. This example prompts for the number of array entries you want and then reserves 
  14248. enough space in storage for the entries. If malloc was successful, the example 
  14249. assigns values to the entries and prints out each entry;  otherwise, it prints 
  14250. out an error. 
  14251.  
  14252.                                                                         *
  14253. ************************************************************************/
  14254.  
  14255. #include <stdio.h>
  14256. #include <stdlib.h>
  14257.  
  14258. int main(void)
  14259. {
  14260.   long * array;    /* start of the array */
  14261.   long * index;    /* index variable     */
  14262.   int    i;        /* index variable     */
  14263.   int  num;        /* number of entries of the array */
  14264.  
  14265.   printf( "Enter the size of the array\n" );
  14266.   scanf( "%i", &num );
  14267.  
  14268.   /* allocate num entries */
  14269.   if ( (index = array = malloc( num * sizeof( long ))) != NULL )
  14270.   {
  14271.  
  14272.     for ( i = 0; i < num; ++i )           /* put values in array    */
  14273.        *index++ = i;                      /* using pointer notation */
  14274.  
  14275.     for ( i = 0; i < num; ++i )           /* print the array out    */
  14276.       printf( "array[ %i ] = %i\n", i, array[i] );
  14277.   }
  14278.   else { /* malloc error */
  14279.     perror( "Out of storage" );
  14280.     abort();
  14281.   }
  14282. }
  14283.  
  14284. /********************  Output should be similar to:  **************
  14285.  
  14286. Enter the size of the array
  14287. array[ 0 ] = 0
  14288. array[ 1 ] = 1
  14289. array[ 2 ] = 2
  14290. array[ 3 ] = 3
  14291. array[ 4 ] = 4
  14292. */
  14293.  
  14294.  
  14295. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14296.  
  14297. o calloc  - Reserve and Initialize Storage 
  14298. o _debug_malloc - Reserve Storage Blocks 
  14299. o free  - Release Storage Blocks 
  14300. o _msize - Return Number of Bytes Allocated 
  14301. o realloc  - Change Reserved Storage Block Size 
  14302. o _tmalloc - Reserve Tiled Storage Block 
  14303. o malloc.h 
  14304. o stdlib.h 
  14305.  
  14306.  
  14307. ΓòÉΓòÉΓòÉ 6.150. _matherr - Process Math Library Errors ΓòÉΓòÉΓòÉ
  14308.  
  14309.  
  14310. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14311.  
  14312. #include <math.h>
  14313.  
  14314. int _matherr(struct exception *x);
  14315.  
  14316.  
  14317. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14318.  
  14319. Language Level: Extension 
  14320.  
  14321. You can use the _matherr function to process errors generated by the functions 
  14322. in the math library. The math functions call _matherr whenever they detect an 
  14323. error. The _matherr function supplied with the C/C++ Tools library performs no 
  14324. error handling and returns 0 to the calling function. 
  14325.  
  14326. You can provide a different definition of the _matherr function to carry out 
  14327. special error handling. Be sure to use the /NOE link option, if you are using 
  14328. your own _matherr function. For the C/C++ Tools compiler, you can use the /B 
  14329. option on the icc command line to pass the /NOE option to the linker, as in the 
  14330. following: 
  14331.  
  14332.    icc /B"/NOE" yourfile.c
  14333.  
  14334. When an error occurs in a math routine, _matherr is called with a pointer to 
  14335. the following structure (defined in <math.h>) as an argument: 
  14336.  
  14337.    struct exception {
  14338.        int type;
  14339.        char *name;
  14340.        double arg1, arg2, retval;
  14341.    };
  14342.  
  14343. The type variable specifies the type of math error. It is one of the following 
  14344. values, defined in <math.h>: 
  14345.  
  14346. Value          Meaning 
  14347. DOMAIN         Argument domain error 
  14348. OVERFLOW       Overflow range error 
  14349. UNDERFLOW      Underflow range error 
  14350. TLOSS          Total loss of significance 
  14351. PLOSS          Partial loss of significance 
  14352. SING           Argument singularity. 
  14353.  
  14354. Because PLOSS is used by the C/2 compiler, it is provided to prevent errors 
  14355. during compiling. The C/C++ Tools compiler does not actually generate this 
  14356. value. 
  14357.  
  14358. The name is a pointer to a null-ended string containing the name of the 
  14359. function that caused the error. The arg1 and arg2 variables specify the 
  14360. argument values that caused the error. If only one argument is given, it is 
  14361. stored in arg1. 
  14362.  
  14363. The retval is the default return value; you can change the return value. The 
  14364. return value from _matherr must specify whether or not an error actually 
  14365. occurred. If _matherr returns 0, an error message appears, and errno is set to 
  14366. an appropriate error value. If _matherr returns a nonzero value, no error 
  14367. message appears and errno remains unchanged. 
  14368.  
  14369. Example of _matherr 
  14370.  
  14371.  
  14372. ΓòÉΓòÉΓòÉ <hidden> Example of _matherr ΓòÉΓòÉΓòÉ
  14373.  
  14374. /************************************************************************
  14375. *
  14376. This example is a definition that you can create to handle errors from the log 
  14377. or log10 functions. The arguments to these logarithmic functions must be 
  14378. positive double values. This routine processes a negative value in an argument 
  14379. (a domain error) by returning the log of its absolute value. It suppresses the 
  14380. error message normally displayed when this error occurs. If the error is a zero 
  14381. argument or if some other routine produced the error, the example takes the 
  14382. default actions. 
  14383.  
  14384.                                                                         *
  14385. ************************************************************************/
  14386.  
  14387. /*                                                      */
  14388. /*   Note: Use "icc /B"/NOE" yourfile.c" to compile */
  14389. /*   and link this example.                             */
  14390. /*                                                      */
  14391.  
  14392. #include <math.h>
  14393. #include <string.h>
  14394. #include <stdio.h>
  14395.  
  14396. int main(void)
  14397. {
  14398.      int value;
  14399.  
  14400.      printf("Trying to evaluate log10(-1000.00) will create
  14401.              a math exception.\n");
  14402.      value = log10(-1000.00);
  14403.      printf("The _matherr() exception handler evaluates
  14404.              the expression to\n");
  14405.      printf("log10(-1000.00) = %d\n", value);
  14406.  
  14407.      return 0;
  14408. }
  14409.  
  14410.  
  14411. int _matherr(struct exception *x)
  14412. {
  14413.     printf("inside _matherr\n");
  14414.     if (x->type == DOMAIN)
  14415.     {
  14416.         if (strcmp(x->name, "log") == 0)
  14417.         {
  14418.             x->retval = log(-(x->arg1));
  14419.             return(1);
  14420.         }
  14421.         else if (strcmp(x->name, "log10") == 0)
  14422.         {
  14423.             x->retval = log10(-(x->arg1));
  14424.             return(1);
  14425.         }
  14426.     }
  14427.     return 0;     /* Use default actions */
  14428.  
  14429.  
  14430. /********************  The output should be similar to:  ****************
  14431.  
  14432.    Trying to evaluate log10(-1000.00) will create a math exception.
  14433.    inside _matherr
  14434.    The _matherr() exception handler evaluates the expression to
  14435.    log10(-1000.00) = 3
  14436. */
  14437. }
  14438.  
  14439.  
  14440. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14441.  
  14442. o log  - Calculate Natural Logarithm 
  14443. o log10  - Calculate Base 10 Logarithm 
  14444. o math.h 
  14445.  
  14446.  
  14447. ΓòÉΓòÉΓòÉ 6.151. max - Return Larger of Two Values ΓòÉΓòÉΓòÉ
  14448.  
  14449.  
  14450. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14451.  
  14452. #include <stdlib.h>
  14453.  
  14454. type max(type a, type b);
  14455.  
  14456.  
  14457. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14458.  
  14459. Language Level: Extension 
  14460.  
  14461. The max macro compares two values and determines the larger of the two. The 
  14462. data type can be any arithmetic data type, signed or unsigned.  Both arguments 
  14463. must have the same type for each call to max. 
  14464.  
  14465. Note:  Because max is a macro, if the evaluation of the arguments contains side 
  14466. effects (post-increment operators, for example), the results of both the side 
  14467. effects and the macro will be undefined. 
  14468.  
  14469. The max macro returns the larger of the two values. 
  14470.  
  14471. Example of max 
  14472.  
  14473.  
  14474. ΓòÉΓòÉΓòÉ <hidden> Example of max ΓòÉΓòÉΓòÉ
  14475.  
  14476. /************************************************************************
  14477. *
  14478. This example prints the larger of the two values, a and b. 
  14479.  
  14480.                                                                         *
  14481. ************************************************************************/
  14482.  
  14483. #include <stdlib.h>
  14484. #include <stdio.h>
  14485.  
  14486. int main (void)
  14487. {
  14488.     int a = 10;
  14489.     int b = 21;
  14490.  
  14491.     printf ("The larger of %d and %d is %d\n", a, b, max(a, b));
  14492.  
  14493.     return 0;
  14494.  
  14495.     /* The expected output is:
  14496.  
  14497.        The larger of 10 and 21 is 21  */
  14498.  
  14499. }
  14500.  
  14501.  
  14502. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14503.  
  14504. o min - Return Lesser of Two Values 
  14505. o stdlib.h 
  14506.  
  14507.  
  14508. ΓòÉΓòÉΓòÉ 6.152. mblen  - Multibyte String Length ΓòÉΓòÉΓòÉ
  14509.  
  14510.  
  14511. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14512.  
  14513. #include <stdlib.h>
  14514.  
  14515. int mblen(const char *string, size_t n);
  14516.  
  14517.  
  14518. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14519.  
  14520. Language Level: ANSI, SAA 
  14521.  
  14522. The mblen function determines the length in bytes of the multibyte character 
  14523. pointed to by string. A maximum of n bytes is examined. 
  14524.  
  14525. If string is NULL, the mblen function returns: 
  14526.  
  14527. o Nonzero when DBCS-host code (EBCDIC systems) is used 
  14528. o Zero otherwise. 
  14529.  
  14530. If string is not NULL, the mblen function returns: 
  14531.  
  14532. o Zero if string points to the null character 
  14533. o The number of bytes comprising the multibyte character 
  14534. o -1 if string does not point to a valid multibyte character. 
  14535.  
  14536. Example of mblen 
  14537.  
  14538.  
  14539. ΓòÉΓòÉΓòÉ <hidden> Example of mblen ΓòÉΓòÉΓòÉ
  14540.  
  14541. /************************************************************************
  14542. *
  14543.  
  14544. This example uses mblen and mbtowc to convert a multibyte character into a 
  14545. single wide character. 
  14546.  
  14547.                                                                         *
  14548. ************************************************************************/
  14549.  
  14550. #include <stdio.h>
  14551. #include <stdlib.h>
  14552.  
  14553. int length, temp;
  14554. char string [6] = "w";
  14555. wchar_t arr[6];
  14556.  
  14557. int main(void)
  14558.  
  14559. {
  14560.    /* Set string to point to a multibyte character  */
  14561.    .
  14562.    .
  14563.    .
  14564.    length = mblen(string, MB_CUR_MAX);
  14565.    temp = mbtowc(arr,string,length);
  14566.    printf("wide character string: %ls",arr);
  14567. }
  14568.  
  14569.  
  14570. ΓòÉΓòÉΓòÉ <hidden> Related Infromation ΓòÉΓòÉΓòÉ
  14571.  
  14572. o mbtowc  - Convert Multibyte Character to wchar_t 
  14573. o mbstowcs  - Convert Multibyte Characters to wchar_t Characters 
  14574. o strlen  - Determine String Length 
  14575. o wcslen  - Calculate Length of wchar_t String 
  14576. o wctomb  - Convert wchar_t Character to Multibyte Character 
  14577. o stdlib.h 
  14578.  
  14579.  
  14580. ΓòÉΓòÉΓòÉ 6.153. mbstowcs  - Convert Multibyte Characters to wchar_t Characters ΓòÉΓòÉΓòÉ
  14581.  
  14582.  
  14583. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14584.  
  14585. #include <stdlib.h>
  14586.  
  14587. size_t mbstowcs(wchar_t *pwc, const char *string, size_t n);
  14588.  
  14589.  
  14590. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14591.  
  14592. Language Level: ANSI, SAA 
  14593.  
  14594. The mbstowcs function determines the length of the sequence of the multibyte 
  14595. characters pointed to by string.  It then stores the code for the sequence of 
  14596. multibyte characters in the wchar_t object pointed to by pwc.  A maximum of n 
  14597. wchar_t characters is examined. 
  14598.  
  14599. The mbstowcs function returns the number of wchar_t characters generated not 
  14600. including any terminating zero codes.  If a multibyte character that is not 
  14601. valid is encountered, the function returns (size_t)-1. 
  14602.  
  14603. Example of mbstowcs 
  14604.  
  14605.  
  14606. ΓòÉΓòÉΓòÉ <hidden> Example of mbstowcs ΓòÉΓòÉΓòÉ
  14607.  
  14608. /************************************************************************
  14609. *
  14610.  
  14611. This example uses mblen and mbstowcs to convert a multibyte character string 
  14612. into a wide character string. 
  14613.  
  14614.                                                                         *
  14615. ************************************************************************/
  14616.  
  14617. #include <stdio.h>
  14618. #include <stdlib.h>
  14619.  
  14620. int length, temp;
  14621. char string [80];
  14622. wchar_t arr[80];
  14623.  
  14624. int main(void)
  14625. {
  14626.    /* Set string to point to a multibyte character string. */
  14627.    .
  14628.    .
  14629.    .
  14630.    length = mblen(string, MB_CUR_MAX);
  14631.    temp = mbstowcs(arr,string,length);
  14632.    printf("wide character string: %ls",arr);
  14633. }
  14634.  
  14635.  
  14636. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14637.  
  14638. o mblen  - Multibyte String Length 
  14639. o mbtowc  - Convert Multibyte Character to wchar_t 
  14640. o wcslen  - Calculate Length of wchar_t String 
  14641. o wcstombs  - Convert wchar_t String to Multibyte Character String 
  14642. o stdlib.h 
  14643.  
  14644.  
  14645. ΓòÉΓòÉΓòÉ 6.154. mbtowc  - Convert Multibyte Character to wchar_t ΓòÉΓòÉΓòÉ
  14646.  
  14647.  
  14648. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14649.  
  14650. #include <stdlib.h>
  14651.  
  14652. int mbtowc(wchar_t *pwc, const char *string, size_t n);
  14653.  
  14654.  
  14655. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14656.  
  14657. Language Level: ANSI, SAA 
  14658.  
  14659. The mbtowc function first determines the length of the multibyte character 
  14660. pointed to by string.  It then stores the code for the multibyte character in 
  14661. the wchar_t object pointed to by pwc.  A maximum of n bytes is examined. 
  14662.  
  14663. If string is NULL, the mbtowc function returns: 
  14664.  
  14665. o Nonzero when DBCS-host code (EBCDIC systems) is used 
  14666. o 0 otherwise. 
  14667.  
  14668. If string is not NULL, the mbtowc function returns: 
  14669.  
  14670. o 0 if string points to the null character 
  14671. o The number of bytes comprising the converted multibyte character 
  14672. o -1 if string does not point to a valid multibyte character. 
  14673.  
  14674. Example of mbtowc 
  14675.  
  14676.  
  14677. ΓòÉΓòÉΓòÉ <hidden> Example of mbtowc ΓòÉΓòÉΓòÉ
  14678.  
  14679. /************************************************************************
  14680. *
  14681.  
  14682. This example uses mblen and mbtowc to convert a multibyte character into a 
  14683. single wide character. 
  14684.  
  14685.                                                                         *
  14686. ************************************************************************/
  14687.  
  14688. #include <stdio.h>
  14689. #include <stdlib.h>
  14690.  
  14691. int length, temp;
  14692. char string [6];
  14693. wchar_t arr[6];
  14694.  
  14695. int main(void)
  14696. {
  14697.    /* Set string to point to a multibyte character. */
  14698.    .
  14699.    .
  14700.    .
  14701.    length = mblen(string, MB_CUR_MAX);
  14702.    temp = mbtowc(arr,string,length);
  14703.    printf("wide character string: %ls",arr);
  14704. }
  14705.  
  14706.  
  14707. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14708.  
  14709. o mblen  - Multibyte String Length 
  14710. o mbstowcs  - Convert Multibyte Characters to wchar_t Characters 
  14711. o wcslen  - Calculate Length of wchar_t String 
  14712. o wctomb  - Convert wchar_t Character to Multibyte Character 
  14713. o stdlib.h 
  14714.  
  14715.  
  14716. ΓòÉΓòÉΓòÉ 6.155. memccpy - Copy Bytes ΓòÉΓòÉΓòÉ
  14717.  
  14718.  
  14719. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14720.  
  14721. #include <string.h>     /* also defined in <memory.h> */
  14722.  
  14723. void *memccpy(void *dest, void *src, int c, unsigned cnt);
  14724.  
  14725.  
  14726. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14727.  
  14728. Language Level: Extension 
  14729.  
  14730. The memccpy function copies bytes from src to dest up to and including the 
  14731. first occurrence of the character c or until cnt bytes have been copied, 
  14732. whichever comes first. 
  14733.  
  14734. If the character c is copied, memccpy returns a pointer to the byte in dest 
  14735. that immediately follows the character. If c is not copied, memccpy returns 
  14736. NULL. <memory.h>) 
  14737.  
  14738. Example of memccpy 
  14739.  
  14740.  
  14741. ΓòÉΓòÉΓòÉ <hidden> Example of memccpy ΓòÉΓòÉΓòÉ
  14742.  
  14743. /************************************************************************
  14744. *
  14745. This example copies up to 55 characters, or until it copies the '.' character, 
  14746. from the source to the buffer. 
  14747.  
  14748.                                                                         *
  14749. ************************************************************************/
  14750.  
  14751. #include <stdio.h>
  14752. #include <stdlib.h>
  14753. #include <string.h>
  14754.  
  14755. char source[60];
  14756. char result[60];
  14757.  
  14758. int main(void)
  14759. {
  14760.     memcpy(source,"This is the string. This part won't be copied.", 55);
  14761.  
  14762.     if (memccpy(result, source, '.', 55) == NULL)
  14763.     {
  14764.        printf("Error in copying source.\n");
  14765.        exit(1);
  14766.     }
  14767.     else
  14768.        printf("%s\n", result);
  14769.  
  14770.     return 0;
  14771.  
  14772.     /* The expected output is:
  14773.  
  14774.        This is the string.     */
  14775.  
  14776. }
  14777.  
  14778.  
  14779. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14780.  
  14781. o memchr  - Search Buffer 
  14782. o memcmp  - Compare Buffers 
  14783. o memcpy  - Copy Bytes 
  14784. o memmove  - Copy Bytes 
  14785. o memset  - Set Bytes to Value 
  14786. o memory.h 
  14787. o string.h 
  14788.  
  14789.  
  14790. ΓòÉΓòÉΓòÉ 6.156. memchr  - Search Buffer ΓòÉΓòÉΓòÉ
  14791.  
  14792.  
  14793. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14794.  
  14795. #include <string.h>  /* also defined in <memory.h> */
  14796.  
  14797. void *memchr(const void *buf, int c, size_t count);
  14798.  
  14799.  
  14800. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14801.  
  14802. Language Level: ANSI, SAA, Extension 
  14803.  
  14804. The memchr function searches the first count bytes of buf for the first 
  14805. occurrence of c converted to an unsigned character.  The search continues until 
  14806. it finds c or examines count bytes. 
  14807.  
  14808. The memchr function returns a pointer to the location of c in buf.  It returns 
  14809. NULL if c is not within the first count bytes of buf. 
  14810.  
  14811. Example of memchr 
  14812.  
  14813.  
  14814. ΓòÉΓòÉΓòÉ <hidden> Example of memchr ΓòÉΓòÉΓòÉ
  14815.  
  14816. /************************************************************************
  14817. *
  14818.  
  14819. This example finds the first occurrence of "x" in the string that you provide. 
  14820. If it is found, the string that starts with that character is printed. 
  14821.  
  14822.                                                                         *
  14823. ************************************************************************/
  14824.  
  14825. #include <stdio.h>
  14826. #include <string.h>
  14827.  
  14828. int main(int argc, char ** argv)
  14829. {
  14830.   char * result;
  14831.  
  14832.   if ( argc != 2 )
  14833.     printf( "Usage: %s string\n", argv[0] );
  14834.   else
  14835.   {
  14836.     if ((result = memchr( argv[1], 'x', strlen(argv[1])) ) != NULL)
  14837.       printf( "The string starting with x is %s\n", result );
  14838.     else
  14839.       printf( "The letter x cannot be found in the string\n" );
  14840.   }
  14841. }
  14842.  
  14843. /********************  Output should be similar to:  **************
  14844.  
  14845. The string starting with x is xing
  14846. */
  14847.  
  14848.  
  14849. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14850.  
  14851. o memccpy - Copy Bytes 
  14852. o memicmp - Compare Bytes 
  14853. o memmove  - Copy Bytes 
  14854. o memset  - Set Bytes to Value 
  14855. o strchr  - Search for Character 
  14856. o memory.h 
  14857. o string.h 
  14858.  
  14859.  
  14860. ΓòÉΓòÉΓòÉ 6.157. memcmp  - Compare Buffers ΓòÉΓòÉΓòÉ
  14861.  
  14862.  
  14863. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14864.  
  14865. #include <string.h>  /* also defined in <memory.h> */
  14866.  
  14867. int memcmp(const void *buf1, const void *buf2, size_t count);
  14868.  
  14869.  
  14870. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14871.  
  14872. Language Level: ANSI, SAA, Extension 
  14873.  
  14874. The memcmp function compares the first count bytes of buf1 and buf2 and returns 
  14875. a value indicating their relationship as follows: 
  14876.  
  14877. Value               Meaning 
  14878. Less than 0         buf1 less than buf2 
  14879. 0                   buf1 identical to buf2 
  14880. Greater than 0      buf1 greater than buf2 
  14881.  
  14882. Example of memcmp 
  14883.  
  14884.  
  14885. ΓòÉΓòÉΓòÉ <hidden> Example of memcmp ΓòÉΓòÉΓòÉ
  14886.  
  14887. /************************************************************************
  14888. *
  14889.  
  14890. This example compares first and second arguments passed to main to determine 
  14891. which, if either, is greater. 
  14892.  
  14893.                                                                         *
  14894. ************************************************************************/
  14895.  
  14896. #include <stdio.h>
  14897. #include <string.h>
  14898.  
  14899. int main(int argc, char ** argv)
  14900. {
  14901.   int  len;
  14902.   int  result;
  14903.  
  14904.   if ( argc != 3 )
  14905.   {
  14906.      printf( "Usage: %s string1 string2\n", argv[0] );
  14907.   }
  14908.   else
  14909.   {
  14910.      /* Determine the length to be used for comparison */
  14911.      if (strlen( argv[1] ) < strlen( argv[2] ))
  14912.        len = strlen( argv[1] );
  14913.      else
  14914.        len = strlen( argv[2] );
  14915.  
  14916.      result = memcmp( argv[1], argv[2], len );
  14917.  
  14918.      printf( "When the first %i characters are compared,\n", len );
  14919.      if ( result == 0 )
  14920.        printf( "\"%s\" is identical to \"%s\"\n", argv[1], argv[2] );
  14921.      else if ( result < 0 )
  14922.        printf( "\"%s\" is less than \"%s\"\n", argv[1], argv[2] );
  14923.      else
  14924.        printf( "\"%s\" is greater than \"%s\"\n", argv[1], argv[2] );
  14925.   }
  14926. }
  14927.  
  14928. /****************  If the program is passed the arguments  **************
  14929. *************  firststring and secondstring,  *****
  14930. ********************  output should be:  *************************
  14931.  
  14932. When the first 11 characters are compared,
  14933. "firststring" is less than "secondstring"
  14934. */
  14935.  
  14936.  
  14937. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  14938.  
  14939. o memccpy - Copy Bytes 
  14940. o memchr  - Search Buffer 
  14941. o memcpy  - Copy Bytes 
  14942. o memicmp - Compare Bytes 
  14943. o memmove  - Copy Bytes 
  14944. o memset  - Set Bytes to Value 
  14945. o strcmp  - Compare Strings 
  14946. o memory.h 
  14947. o string.h 
  14948.  
  14949.  
  14950. ΓòÉΓòÉΓòÉ 6.158. memcpy  - Copy Bytes ΓòÉΓòÉΓòÉ
  14951.  
  14952.  
  14953. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  14954.  
  14955. #include <string.h>  /* also defined in <memory.h> */
  14956.  
  14957. void *memcpy(void *dest, const void *src, size_t count);
  14958.  
  14959.  
  14960. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  14961.  
  14962. Language Level: ANSI, SAA, Extension 
  14963.  
  14964. The memcpy function copies count bytes of src to dest.  For memcpy, the 
  14965. behavior is undefined if copying takes place between objects that overlap. 
  14966. (The memmove function allows copying between objects that may overlap.) 
  14967.  
  14968. The memcpy function returns a pointer to dest. 
  14969.  
  14970. Example of memcpy 
  14971.  
  14972.  
  14973. ΓòÉΓòÉΓòÉ <hidden> Example of memcpy ΓòÉΓòÉΓòÉ
  14974.  
  14975. /************************************************************************
  14976. *
  14977.  
  14978. This example copies the contents of source to target. 
  14979.  
  14980.                                                                         *
  14981. ************************************************************************/
  14982.  
  14983. #include <string.h>
  14984. #include <stdio.h>
  14985.  
  14986. #define MAX_LEN 80
  14987.  
  14988. char source[ MAX_LEN ] = "This is the source string";
  14989. char target[ MAX_LEN ] = "This is the target string";
  14990.  
  14991. int main(void)
  14992. {
  14993.   printf( "Before memcpy, target is \"%s\"\n", target );
  14994.   memcpy( target, source, sizeof(source));
  14995.   printf( "After memcpy, target becomes \"%s\"\n", target );
  14996. }
  14997.  
  14998. /*********************  Expected output:  ************************
  14999.  
  15000. Before memcpy, target is "This is the target string"
  15001. After memcpy, target becomes "This is the source string"
  15002. */
  15003.  
  15004.  
  15005. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15006.  
  15007. o memccpy - Copy Bytes 
  15008. o memchr  - Search Buffer 
  15009. o memcmp  - Compare Buffers 
  15010. o memicmp - Compare Bytes 
  15011. o memmove  - Copy Bytes 
  15012. o strcpy  - Copy Strings 
  15013. o memory.h 
  15014. o string.h 
  15015.  
  15016.  
  15017. ΓòÉΓòÉΓòÉ 6.159. memicmp - Compare Bytes ΓòÉΓòÉΓòÉ
  15018.  
  15019.  
  15020. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15021.  
  15022. #include <string.h>    /* Also defined in <memory.h> */
  15023.  
  15024. int memicmp(void *buf1, void *buf2, unsigned int cnt);
  15025.  
  15026.  
  15027. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15028.  
  15029. Language Level: Extension 
  15030.  
  15031. The memicmp function compares the first cnt bytes of buf1 and buf2 without 
  15032. regard to the case of letters in the two buffers.  The function converts all 
  15033. uppercase characters into lowercase and then performs the comparison. 
  15034.  
  15035. The return value of memicmp indicates the result as follows: 
  15036.  
  15037. Value                 Meaning 
  15038. Less than 0           buf1 less than buf2 
  15039. 0                     buf1 identical to buf2 
  15040. Greater than 0        buf1 greater than buf2. 
  15041.  
  15042. Example of memicmp 
  15043.  
  15044.  
  15045. ΓòÉΓòÉΓòÉ <hidden> Example of memicmp ΓòÉΓòÉΓòÉ
  15046.  
  15047. /************************************************************************
  15048. *
  15049. This example copies two strings that each contain a substring of 29 characters 
  15050. that are the same except for case. The example then compares the first 29 bytes 
  15051. without regard to case. 
  15052.  
  15053.                                                                         *
  15054. ************************************************************************/
  15055.  
  15056. #include <stdio.h>
  15057. #include <string.h>
  15058.  
  15059. char first[100], second[100];
  15060.  
  15061. int main(void)
  15062. {
  15063.     int result;
  15064.  
  15065.     strcpy(first, "Those Who Will Not Learn From History");
  15066.     strcpy(second,"THOSE WHO WILL NOT LEARN FROM their mistakes");
  15067.  
  15068.     printf("Comparing the first 29 characters of two strings.\n");
  15069.     result = memicmp(first, second, 29);
  15070.  
  15071.     printf("The first 29 characters of String 1 are ");
  15072.     if (result < 0)
  15073.        printf("less than String 2.\n");
  15074.     else
  15075.        if (result == 0)
  15076.           printf("equal to String 2.\n");
  15077.        else
  15078.           printf("greater than String 2.\n");
  15079.  
  15080.     return 0;
  15081.  
  15082.     /* The expected output is:
  15083.  
  15084.        Comparing the first 29 characters of two strings.
  15085.        The first 29 characters of String 1 are equal to String 2  */
  15086.  
  15087. }
  15088.  
  15089.  
  15090. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15091.  
  15092. o memchr  - Search Buffer 
  15093. o memcmp  - Compare Buffers 
  15094. o memcpy  - Copy Bytes 
  15095. o memmove  - Copy Bytes 
  15096. o memset  - Set Bytes to Value 
  15097. o memory.h 
  15098. o string.h 
  15099.  
  15100.  
  15101. ΓòÉΓòÉΓòÉ 6.160. memmove  - Copy Bytes ΓòÉΓòÉΓòÉ
  15102.  
  15103.  
  15104. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15105.  
  15106. #include <string.h>  /* also defined in <memory.h> */
  15107.  
  15108. void *memmove(void *dest, const void *src, size_t count);
  15109.  
  15110.  
  15111. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15112.  
  15113. Language Level: ANSI, SAA, Extension 
  15114.  
  15115. The memmove function copies count bytes of src to dest. The memmove function 
  15116. allows copying between objects that may overlap as if src is first copied into 
  15117. a temporary array. 
  15118.  
  15119. The memmove function returns a pointer to dest. 
  15120.  
  15121. Example of memmove 
  15122.  
  15123.  
  15124. ΓòÉΓòÉΓòÉ <hidden> Example of memmove ΓòÉΓòÉΓòÉ
  15125.  
  15126. /************************************************************************
  15127. *
  15128.  
  15129. This example copies the word shiny from position target + 2 to position target 
  15130. + 8. 
  15131.  
  15132.                                                                         *
  15133. ************************************************************************/
  15134.  
  15135. #include <string.h>
  15136. #include <stdio.h>
  15137.  
  15138. #define SIZE    21
  15139.  
  15140. char target[SIZE] = "a shiny white sphere";
  15141.  
  15142. int main( void )
  15143. {
  15144.   char * p = target + 8;  /* p points at the starting character
  15145.                           of the word we want to replace */
  15146.   char * source = target + 2; /* start of "shiny" */
  15147.  
  15148.   printf( "Before memmove, target is \"%s\"\n", target );
  15149.   memmove( p, source, 5 );
  15150.   printf( "After memmove, target becomes \"%s\"\n", target );
  15151. }
  15152.  
  15153. /*********************  Expected output:  ************************
  15154.  
  15155. Before memmove, target is "a shiny white sphere"
  15156. After memmove, target becomes "a shiny shiny sphere"
  15157. */
  15158.  
  15159.  
  15160. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15161.  
  15162. o memccpy - Copy Bytes 
  15163. o memchr  - Search Buffer 
  15164. o memcmp  - Compare Buffers 
  15165. o memcpy  - Copy Bytes 
  15166. o memicmp - Compare Bytes 
  15167. o memset  - Set Bytes to Value 
  15168. o strcpy  - Copy Strings 
  15169. o memory.h 
  15170. o string.h 
  15171.  
  15172.  
  15173. ΓòÉΓòÉΓòÉ 6.161. memset  - Set Bytes to Value ΓòÉΓòÉΓòÉ
  15174.  
  15175.  
  15176. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15177.  
  15178. #include <string.h>  /* also defined in <memory.h> */
  15179.  
  15180. void *memset(void *dest, int c, size_t count);
  15181.  
  15182.  
  15183. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15184.  
  15185. Language Level: ANSI, SAA, Extension 
  15186.  
  15187. The memset function sets the first count bytes of dest to the value c.  The 
  15188. value of c is converted to an unsigned character. 
  15189.  
  15190. The memset function returns a pointer to dest. 
  15191.  
  15192. Example of memset 
  15193.  
  15194.  
  15195. ΓòÉΓòÉΓòÉ <hidden> Example of memset ΓòÉΓòÉΓòÉ
  15196.  
  15197. /************************************************************************
  15198. *
  15199.  
  15200. This example sets 10 bytes of the buffer to "A" and the next 10 bytes to "B". 
  15201.  
  15202.                                                                         *
  15203. ************************************************************************/
  15204.  
  15205. #include <string.h>
  15206. #include <stdio.h>
  15207.  
  15208. #define  BUF_SIZE  20
  15209.  
  15210. int main(void)
  15211. {
  15212.    char buffer[BUF_SIZE + 1];
  15213.    char *string;
  15214.  
  15215.    memset(buffer, 0, sizeof(buffer));
  15216.    string = memset(buffer,'A', 10);
  15217.    printf("\nBuffer contents: %s\n", string);
  15218.    memset(buffer+10, 'B', 10);
  15219.    printf("\nBuffer contents: %s\n", buffer);
  15220. }
  15221.  
  15222. /*******************  Output should be similar to:  ***************
  15223.  
  15224. Buffer contents: AAAAAAAAAA
  15225.  
  15226. Buffer contents: AAAAAAAAAABBBBBBBBBB
  15227. */
  15228.  
  15229.  
  15230. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15231.  
  15232. o memccpy - Copy Bytes 
  15233. o memcpy  - Copy Bytes 
  15234. o memicmp - Compare Bytes 
  15235. o memmove  - Copy Bytes 
  15236. o memory.h 
  15237. o strnset - strset - Set Characters in String 
  15238. o string.h 
  15239.  
  15240.  
  15241. ΓòÉΓòÉΓòÉ 6.162. min - Return Lesser of Two Values ΓòÉΓòÉΓòÉ
  15242.  
  15243.  
  15244. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15245.  
  15246. #include <stdlib.h>
  15247.  
  15248. type min(type a, type b);
  15249.  
  15250.  
  15251. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15252.  
  15253. Language Level: Extension 
  15254.  
  15255. The min macro compares two values and determines the smaller of the two. The 
  15256. data type can be any arithmetic data type, signed or unsigned. The type must be 
  15257. the same for both arguments to min. 
  15258.  
  15259. Note:  Because min is a macro, if the evaluation of the arguments contains side 
  15260. effects (post-increment operators, for example), the results of both the side 
  15261. effects and the macro will be undefined. 
  15262.  
  15263. The min macro returns the smaller of the two values. 
  15264.  
  15265. Example of min 
  15266.  
  15267.  
  15268. ΓòÉΓòÉΓòÉ <hidden> Example of min ΓòÉΓòÉΓòÉ
  15269.  
  15270. /************************************************************************
  15271. *
  15272. This example prints the smaller of the two values, a and b. 
  15273.  
  15274.                                                                         *
  15275. ************************************************************************/
  15276.  
  15277. #include <stdlib.h>
  15278. #include <stdio.h>
  15279.  
  15280. int main(void)
  15281. {
  15282.     int a = 10;
  15283.     int b = 21;
  15284.  
  15285.     printf ("The smaller of %d and %d is %d\n", a, b, min (a, b));
  15286.  
  15287.     return 0;
  15288.  
  15289.     /* The expected output is:
  15290.  
  15291.        The smaller of 10 and 21 is 10  */
  15292.  
  15293. }
  15294.  
  15295.  
  15296. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15297.  
  15298. o max - Return Larger of Two Values 
  15299. o stdlib.h 
  15300.  
  15301.  
  15302. ΓòÉΓòÉΓòÉ 6.163. _mkdir - Create New Directory ΓòÉΓòÉΓòÉ
  15303.  
  15304.  
  15305. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15306.  
  15307. #include <direct.h>
  15308.  
  15309. int _mkdir(char *pathname);
  15310.  
  15311.  
  15312. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15313.  
  15314. Language Level: Extension 
  15315.  
  15316. The _mkdir function creates a new directory with the specified pathname. 
  15317. Because only one directory can be created at a time, only the last component of 
  15318. pathname can name a new directory. 
  15319.  
  15320. The _mkdir function returns the value 0 if the directory was created.  A return 
  15321. value of -1 indicates an error, and errno is set to one of the following 
  15322. values: 
  15323.  
  15324. Value          Meaning 
  15325. EACCESS        The directory was not created;  the given name is the name of an 
  15326.                existing file, directory, or device. 
  15327. ENOENT         The pathname was not found. 
  15328.  
  15329. Example of _mkdir 
  15330.  
  15331.  
  15332. ΓòÉΓòÉΓòÉ <hidden> Example of _mkdir ΓòÉΓòÉΓòÉ
  15333.  
  15334. /************************************************************************
  15335. *
  15336. This example creates two new directories:  one at the root on drive B:, and one 
  15337. in the tmp subdirectory of the current working directory. 
  15338.  
  15339.                                                                         *
  15340. ************************************************************************/
  15341.  
  15342. #include <stdio.h>
  15343. #include <direct.h>
  15344. #include <string.h>
  15345.  
  15346. int main(void)
  15347. {
  15348.     char *dir1, *dir2;
  15349.  
  15350. /*  Create the directory "aleng" in the root directory of the C: drive. */
  15351.     dir1 = "c:\\aleng";
  15352.     if ((_mkdir(dir1)) == 0)
  15353.         printf("%s directory was created.\n",dir1);
  15354.     else
  15355.         printf("%s directory was not created.\n",dir1);
  15356.  
  15357. /*  Create the subdirectory "simon" in the current directory. */
  15358.     dir2 = "simon";
  15359.     if ((_mkdir(dir2)) == 0)
  15360.         printf("%s directory was created.\n",dir2);
  15361.     else
  15362.         printf("%s directory was not created.\n",dir2);
  15363.  
  15364. /*  Remove the directory "aleng" from the root directory
  15365.                    of the C: drive. */
  15366.     printf("Removing directory 'aleng' from the root directory.\n");
  15367.  
  15368.     if (_rmdir(dir1))
  15369.        perror(NULL);
  15370.     else
  15371.        printf("%s directory was removed.\n",dir1);
  15372.  
  15373. /*  Remove the subdirectory "simon" from the current directory. */
  15374.     printf("Removing subdirectory 'simon' from the current directory.\n");
  15375.  
  15376.     if (_rmdir(dir2))
  15377.        perror(NULL);
  15378.     else
  15379.        printf("%s directory was removed.\n",dir2);
  15380.  
  15381.     return 0;
  15382.  
  15383. /*************** The output should be similar to:  ********************
  15384.  
  15385.    c:\aleng directory was created.
  15386.    simon directory was created.
  15387.    Removing directory 'aleng' from the root directory.
  15388.    c:\aleng directory was removed.
  15389.    Removing subdirectory 'simon' from the current directory.
  15390.    simon directory was removed.
  15391. */
  15392. }
  15393.  
  15394.  
  15395. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15396.  
  15397.  
  15398. o _chdir - Change Current Working Directory 
  15399. o _getcwd - Get Path Name of Current Directory 
  15400. o _getdcwd - Get Full Path Name of Current Directory 
  15401. o _rmdir - Remove Directory 
  15402. o direct.h 
  15403.  
  15404.  
  15405. ΓòÉΓòÉΓòÉ 6.164. mktime  - Convert Local Time ΓòÉΓòÉΓòÉ
  15406.  
  15407.  
  15408. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15409.  
  15410. #include <time.h>
  15411.  
  15412. time_t mktime(struct tm *time);
  15413.  
  15414.  
  15415. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15416.  
  15417. Language Level: ANSI, SAA 
  15418.  
  15419. The mktime function converts local time, stored as a structure pointed to by 
  15420. time, into a time_t structure suitable for use with other time functions. The 
  15421. values of some structure elements pointed to by time are not restricted to the 
  15422. ranges shown on gmtime. 
  15423.  
  15424. The values of tm_wday and tm_yday passed to mktime are ignored and are assigned 
  15425. their correct values on return. 
  15426.  
  15427. The mktime function returns the calendar time having type time_t.  The value 
  15428. (time_t)(-1) is returned if the calendar time cannot be represented. 
  15429.  
  15430. Note:  The time and date functions begin at 00:00:00 Coordinated Universal 
  15431. Time, January 1, 1970. 
  15432.  
  15433. Example of mktime 
  15434.  
  15435.  
  15436. ΓòÉΓòÉΓòÉ <hidden> Example of mktime ΓòÉΓòÉΓòÉ
  15437.  
  15438. /************************************************************************
  15439. *
  15440.  
  15441. This example prints the day of the week that is 40 days and 16 hours from the 
  15442. current date. 
  15443.  
  15444.                                                                         *
  15445. ************************************************************************/
  15446.  
  15447. #include <stdio.h>
  15448. #include <time.h>
  15449.  
  15450. char *wday[] = { "Sunday", "Monday", "Tuesday", "Wednesday",
  15451.                  "Thursday", "Friday", "Saturday" };
  15452.  
  15453. int main(void)
  15454. {
  15455.   time_t t1, t3;
  15456.   struct tm *t2;
  15457.  
  15458.   t1 = time(NULL);
  15459.   t2 = localtime(&t1);
  15460.   t2 -> tm_mday += 40;
  15461.   t2 -> tm_hour += 16;
  15462.   t3 = mktime(t2);
  15463.  
  15464.   printf("40 days and 16 hours from now, it will be a %s \n",
  15465.           wday[t2 -> tm_wday]);
  15466. }
  15467.  
  15468. /*******************  Output should be similar to:  ***************
  15469.  
  15470. 40 days and 16 hours from now, it will be a Sunday
  15471. */
  15472.  
  15473.  
  15474. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15475.  
  15476. o asctime  - Convert Time 
  15477. o ctime  - Convert Time 
  15478. o gmtime  - Convert Time 
  15479. o localtime  - Convert Time 
  15480. o time  - Determine Current Time 
  15481. o time.h 
  15482.  
  15483.  
  15484. ΓòÉΓòÉΓòÉ 6.165. modf  - Separate Floating-Point Value ΓòÉΓòÉΓòÉ
  15485.  
  15486.  
  15487. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15488.  
  15489. #include <math.h>
  15490.  
  15491. double modf(double x, double *intptr);
  15492.  
  15493.  
  15494. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15495.  
  15496. Language Level: ANSI, SAA 
  15497.  
  15498. The modf function breaks down the floating-point value x into fractional and 
  15499. integral parts.  The signed fractional portion of x is returned.  The integer 
  15500. portion is stored as a double value pointed to by intptr.  Both the fractional 
  15501. and integral parts are given the same sign as x. 
  15502.  
  15503. Example of modf 
  15504.  
  15505.  
  15506. ΓòÉΓòÉΓòÉ <hidden> Example of modf ΓòÉΓòÉΓòÉ
  15507.  
  15508. /************************************************************************
  15509. *
  15510.  
  15511. This example breaks the floating-point number -14.876 into its fractional and 
  15512. integral components. 
  15513.  
  15514.                                                                         *
  15515. ************************************************************************/
  15516.  
  15517. #include <math.h>
  15518. #include <stdio.h>
  15519.  
  15520. int main(void)
  15521. {
  15522.    double x, y, d;
  15523.  
  15524.    x = -14.876;
  15525.    y = modf(x, &d);
  15526.  
  15527.    printf("x = %lf\n", x);
  15528.    printf("Integral part = %lf\n", d);
  15529.    printf("Fractional part = %lf\n", y);
  15530. }
  15531.  
  15532. /****************  Output should be similar to:  ******************
  15533.  
  15534. x = -14.876000
  15535. Integral part = -14.000000
  15536. Fractional part = -0.876000
  15537. */
  15538.  
  15539.  
  15540. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15541.  
  15542. o fmod  - Floating-Point Remainder 
  15543. o frexp  - Separate Floating-Point Value 
  15544. o ldexp  - Multiply by a Power of Two 
  15545. o math.h 
  15546.  
  15547.  
  15548. ΓòÉΓòÉΓòÉ 6.166. _msize - Return Number of Bytes Allocated ΓòÉΓòÉΓòÉ
  15549.  
  15550.  
  15551. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15552.  
  15553. #include <stdlib.h>  or ##include <malloc.h>
  15554.  
  15555. size_t _msize(void *ptr)
  15556.  
  15557.  
  15558. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15559.  
  15560. Language Level: Extension 
  15561.  
  15562. The _msize function returns the number of bytes that were allocated to the 
  15563. pointer argument passed. This function requires a pointer that was returned 
  15564. from any of the calloc, malloc, realloc, _tcalloc, _tmalloc, and _trealloc 
  15565. functions. 
  15566.  
  15567. You cannot pass the argument of an object that has been freed. 
  15568.  
  15569. The _msize function returns the number of bytes allocated. If the argument is 
  15570. not a valid pointer returned from the malloc, calloc, and realloc functions, 
  15571. the return value is undefined. If NULL is passed, _msize returns 0. 
  15572.  
  15573. Example of _msize 
  15574.  
  15575.  
  15576. ΓòÉΓòÉΓòÉ <hidden> Example of _msize ΓòÉΓòÉΓòÉ
  15577.  
  15578. /************************************************************************
  15579. *
  15580.  
  15581. This example displays the size of an allocated object from malloc. 
  15582.  
  15583.                                                                         *
  15584. ************************************************************************/
  15585.  
  15586.  
  15587. #include <stdio.h>
  15588. #include <stdlib.h>
  15589.  
  15590. int main(void)
  15591. {
  15592.  
  15593.  char *myptr;
  15594.  
  15595.  /* allocate an object */
  15596.  myptr = malloc(5);
  15597.  
  15598.  printf("The size of the allocated object is %u\n",_msize(myptr));
  15599.  
  15600.  return(0);
  15601.  
  15602.  /************** The output should be:  ****************************
  15603.  
  15604.      The size of the allocated object is 5
  15605.  
  15606.  */
  15607. }
  15608.  
  15609.  
  15610. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15611.  
  15612. o calloc  - Reserve and Initialize Storage 
  15613. o malloc  - Reserve Storage Block 
  15614. o realloc  - Change Reserved Storage Block Size 
  15615. o _tcalloc - Reserve Tiled Storage Block 
  15616. o _tmalloc - Reserve Tiled Storage Block 
  15617. o _trealloc - Reallocate Tiled Storage Block 
  15618. o malloc.h 
  15619. o stdlib.h 
  15620.  
  15621.  
  15622. ΓòÉΓòÉΓòÉ 6.167. _onexit - Record Termination Function ΓòÉΓòÉΓòÉ
  15623.  
  15624.  
  15625. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15626.  
  15627. #include <stdlib.h>
  15628.  
  15629. onexit_t _onexit(onexit_t func);
  15630.  
  15631.  
  15632. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15633.  
  15634. Language Level: Extension 
  15635.  
  15636. The _onexit function records the address of a function func to call when the 
  15637. program ends normally.  Successive calls to _onexit create a stack of functions 
  15638. that run in a last-in, first-out order. The functions passed to _onexit cannot 
  15639. take parameters. 
  15640.  
  15641. You can record up to 32 termination functions with calls to _onexit and atexit. 
  15642. If you exceed 32 functions, _onexit returns the value NULL. 
  15643.  
  15644. Note:  For portability, use the ANSI-standard atexit function, which is 
  15645. equivalent to _onexit. 
  15646.  
  15647. If successful, _onexit returns a pointer to the function; otherwise, it returns 
  15648. a NULL value. 
  15649.  
  15650. Example of _onexit 
  15651.  
  15652.  
  15653. ΓòÉΓòÉΓòÉ <hidden> Example of _onexit ΓòÉΓòÉΓòÉ
  15654.  
  15655. /************************************************************************
  15656. *
  15657. This example specifies and defines four distinct functions that run 
  15658. consecutively at the completion of main: 
  15659.  
  15660.                                                                         *
  15661. ************************************************************************/
  15662.  
  15663. #include <stdio.h>
  15664. #include <stdlib.h>
  15665.  
  15666. int fn1(void)
  15667. {
  15668.     printf("next.\n");
  15669. }
  15670.  
  15671. int fn2(void)
  15672. {
  15673.     printf("run ");
  15674. }
  15675.  
  15676. int fn3(void)
  15677. {
  15678.     printf("is ");
  15679. }
  15680.  
  15681. int fn4(void)
  15682. {
  15683.     printf("This ");
  15684. }
  15685.  
  15686. int main(void)
  15687. {
  15688.     _onexit(fn1);
  15689.     _onexit(fn2);
  15690.     _onexit(fn3);
  15691.     _onexit(fn4);
  15692.     printf("This is run first.\n");
  15693.  
  15694.     return 0;
  15695.  
  15696. /*****************  The output should be similar to:  *******************
  15697.  
  15698.    This is run first.
  15699.    This is run next.
  15700. */
  15701. }
  15702.  
  15703.  
  15704. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15705.  
  15706. o abort  - Stop a Program 
  15707. o atexit  - Record Program Termination Function 
  15708. o exit  - End Program 
  15709. o _exit - End Process 
  15710. o stdlib.h 
  15711.  
  15712.  
  15713. ΓòÉΓòÉΓòÉ 6.168. _open - Open File ΓòÉΓòÉΓòÉ
  15714.  
  15715.  
  15716. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15717.  
  15718. #include <io.h>
  15719. #include <fcntl.h>
  15720. #include <sys\stat.h>
  15721.  
  15722. int _open(char *pathname, int oflag, int pmode);
  15723.  
  15724.  
  15725. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15726.  
  15727. Language Level: Extension 
  15728.  
  15729. The _open function opens the file specified by pathname and prepares the file 
  15730. for subsequent reading or writing as defined by oflag. The _open function can 
  15731. also prepare the file for reading and writing. The oflag is an integer 
  15732. expression formed by combining one or more of the following constants, defined 
  15733. in <fcntl.h>. When more than one constant is given, the constants are joined 
  15734. with the bitwise OR operator (|). 
  15735.  
  15736. Oflag         Meaning 
  15737. O_APPEND      Reposition the file pointer to the end of the file before every 
  15738.               write operation. 
  15739. O_CREAT       Create and open a new file.  This flag has no effect if the file 
  15740.               specified by pathname exists. 
  15741. O_EXCL        Return an error value if the file specified by pathname exists. 
  15742.               This flag applies only when used with O_CREAT. 
  15743. O_RDONLY      Open the file for reading only.  If this flag is given, neither 
  15744.               O_RDWR nor O_WRONLY can be given. 
  15745. O_RDWR        Open the file for reading and writing.  If this flag is given, 
  15746.               neither O_RDONLY nor O_WRONLY can be given. 
  15747. O_TRUNC       Open and truncate an existing file to 0 length. The file must 
  15748.               have write permission. The contents of the file are destroyed, 
  15749.               and O_TRUNC cannot be specified with O_RDONLY. 
  15750. O_WRONLY      Open the file for writing only.  If this flag is given, neither 
  15751.               O_RDONLY nor O_RDWR can be given. 
  15752. O_BINARY      Open the file in binary (untranslated) mode. (See fopen.) 
  15753. O_TEXT        Open the file in text (translated) mode. (See fopen.) 
  15754.  
  15755. If neither O_BINARY or O_TEXT is specified, the default will be O_TEXT; it is 
  15756. an error to specify both O_BINARY and O_TEXT. 
  15757.  
  15758. You must specify one of the access mode flags, O_RDONLY, O_WRONLY, or O_RDWR. 
  15759. There is no default. 
  15760.  
  15761. Warning: Use O_TRUNC with care; it destroys the complete contents of an 
  15762. existing file. 
  15763.  
  15764. The pmode argument is an integer expression containing one or both of the 
  15765. constants S_IWRITE and S_IREAD, defined in <sys\stat.h>. The pmode is required 
  15766. only when O_CREAT is specified. If the file exists, pmode is ignored. 
  15767. Otherwise, pmode specifies the permission settings for the file. These are set 
  15768. when the new file is closed for the first time. The meaning of the pmode 
  15769. argument is as follows: 
  15770.  
  15771. Value                   Meaning 
  15772. S_IWRITE                Writing permitted 
  15773. S_IREAD                 Reading permitted 
  15774. S_IREAD | S_IWRITE      Reading and writing permitted. 
  15775.  
  15776. If write permission is not given, the file is read-only. Under the OS/2 
  15777. operating system, all files are readable; you cannot give write-only 
  15778. permission. The modes S_IWRITE and S_IREAD | S_IWRITE are equivalent. 
  15779.  
  15780. The _open function applies the current file permission mask to pmode before 
  15781. setting the permissions.  (See _umask - Sets File Mask of Current Process). 
  15782.  
  15783. The _open function returns a file handle for the opened file. A return value of 
  15784. -1 indicates an error, and errno is set to one of the following values: 
  15785.  
  15786. Value          Meaning 
  15787. EACCESS        The given pathname is a directory; or the file is read-only but 
  15788.                an open for writing was attempted; or a sharing violation 
  15789.                occurred. 
  15790. EEXIST         The O_CREAT and O_EXCL flags are specified, but the named file 
  15791.                already exists. 
  15792. EMFILE         No more file handles are available. 
  15793. EINVAL         An incorrect argument was passed. 
  15794. ENOENT         The file or pathname were not found. 
  15795. EOS2ERR        The call to the operating system was not successful. 
  15796.  
  15797. Example of _open 
  15798.  
  15799.  
  15800. ΓòÉΓòÉΓòÉ <hidden> Example of _open ΓòÉΓòÉΓòÉ
  15801.  
  15802. /************************************************************************
  15803. *
  15804.  
  15805. This example tries to open the file edopen.dat by creating it as a new file, 
  15806. truncating it if it exists and opening it so it can be read and written to. The 
  15807. _open command issued also grants permission to read from and write to the file. 
  15808.  
  15809.                                                                         *
  15810. ************************************************************************/
  15811.  
  15812. #include <io.h>
  15813. #include <stdio.h>
  15814. #include <fcntl.h>
  15815. #include <sys\stat.h>
  15816.  
  15817. int main(void)
  15818. {
  15819.    int fh;
  15820.  
  15821.    if ( -1 == (fh = _open("edopen.dat",
  15822.       O_CREAT | O_TRUNC | O_RDWR,
  15823.       S_IREAD | S_IWRITE)))
  15824.    {
  15825.       perror("Unable to open edopen.dat");
  15826.       return 1;
  15827.    }
  15828.  
  15829.    printf("File was successfully opened.\n");
  15830.  
  15831.    if (-1 == _close(fh))
  15832.    {
  15833.       perror("close error");
  15834.       return 1;
  15835.    }
  15836.    return 0;
  15837.  
  15838.    /* The expected ouptut is:
  15839.  
  15840.       File was successfully opened.  */
  15841. }
  15842.  
  15843.  
  15844. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15845.  
  15846. o _close - Closes File Associated with Handle 
  15847. o _creat - Create New File 
  15848. o _fdopen - Associates Input Or Output With File 
  15849. o fopen  - Open Files 
  15850. o _sopen - Open Shared File 
  15851. o _umask - Sets File Mask of Current Process 
  15852. o fcntl.h 
  15853. o io.h 
  15854. o sys\stat.h 
  15855.  
  15856.  
  15857. ΓòÉΓòÉΓòÉ 6.169. _outp - Write Byte to Output Port ΓòÉΓòÉΓòÉ
  15858.  
  15859.  
  15860. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15861.  
  15862. #include <conio.h>             /*  Declared in both  */
  15863. #include <builtin.h>
  15864.  
  15865. int _outp( const unsigned int port, const int value );
  15866.  
  15867.  
  15868. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15869.  
  15870. Language Level: Extension 
  15871.  
  15872. The _outp function writes a byte value to the specified port. The port number 
  15873. must be an unsigned int value within the range 0 to 65 535 inclusive. The byte 
  15874. value must be within the range 0 to 255 inclusive. 
  15875.  
  15876. Because it is a built-in function and has no backing code in the library: 
  15877.  
  15878. o You cannot take the address of _outp. 
  15879. o You cannot parenthesize an _outp function call, because parentheses specify a 
  15880.   call to the backing code for the function. 
  15881.  
  15882. You can run code containing this function only at ring zero. Otherwise, an 
  15883. invalid instruction exception is generated. 
  15884.  
  15885. The _outp function returns the integer value that was output to the specified 
  15886. port. There is no error return value and this function does not set errno. 
  15887.  
  15888. Example of _outp 
  15889.  
  15890.  
  15891. ΓòÉΓòÉΓòÉ <hidden> Example of _outp ΓòÉΓòÉΓòÉ
  15892.  
  15893. /************************************************************************
  15894. *
  15895.  
  15896. This example uses the _outp function to write a byte to a specified output port 
  15897. and return the data written. 
  15898.  
  15899.                                                                         *
  15900. ************************************************************************/
  15901.  
  15902. #include <builtin.h>
  15903. #define LOWER  0
  15904. #define UPPER1 255
  15905. #define UPPER2 65535
  15906.  
  15907. int Add1(int j);
  15908. static int g;
  15909. enum fruit {apples=10, bananas, cantalopes};
  15910. enum fruit f = cantalopes;
  15911.  
  15912. int arr[]={cantalopes, bananas, apples};
  15913.  
  15914. struct
  15915.    {
  15916.    int i;
  15917.    char ch;
  15918.    } st;
  15919.  
  15920. int main(void)
  15921.    {
  15922.    static int i;
  15923.    volatile const int c = 0;
  15924.    st.i = c - bananas;
  15925.  
  15926.    g = _outp(LOWER,apples);
  15927.  
  15928.    i = _outp(255, 0);
  15929.                                      /* ============================= */
  15930.                                      /* Types of port number passed : */
  15931.                                      /* ----------------------------- */
  15932.    i = _outp(UPPER2,UPPER1);         /* - #define constant            */
  15933.    i = _outp(st.i, bananas);         /* - element of structure        */
  15934.    i = _outp(f,arr[1]);              /* - enumerated variable         */
  15935.    i = _outp(_inp(arr[2]),apples);   /* - return value from a         */
  15936.                                      /*   builtin function call       */
  15937.                                      /* ----------------------------- */
  15938.  
  15939.    i = _outp(_outp(apples,Add1(LOWER)),6);
  15940.  
  15941.    return 0;
  15942. }
  15943.  
  15944.  
  15945. int Add1(int j)
  15946.    {
  15947.    j += 1;
  15948.    return j;
  15949.    }
  15950.  
  15951.  
  15952. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  15953.  
  15954. o _inp - Read Byte from Input Port 
  15955. o _inpw - Read Unsigned Short from Input Port 
  15956. o _inpd - Read Double Word from Input Port 
  15957. o _outpw - Write Word to Output Port 
  15958. o _outpd - Write Double Word to Output Port 
  15959.  
  15960.  
  15961. ΓòÉΓòÉΓòÉ 6.170. _outpd - Write Double Word to Output Port ΓòÉΓòÉΓòÉ
  15962.  
  15963.  
  15964. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  15965.  
  15966. #include <conio.h>          /*  Declared in both  */
  15967. #include <builtin.h>
  15968.  
  15969. unsigned long _outpd( const unsigned int port, const unsigned long value );
  15970.  
  15971.  
  15972. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  15973.  
  15974. Language Level: Extension 
  15975.  
  15976. The _outpd function writes an unsigned long value to the specified port. The 
  15977. port number must be a value within the range 0 to 65 535 inclusive. The 
  15978. unsigned long value must be within the range 0 to 4 294 967 295 inclusive. 
  15979.  
  15980. Because it is a built-in function and has no backing code in the library: 
  15981.  
  15982. o You cannot take the address of _outpd. 
  15983. o You cannot parenthesize an _outpd function call, because parentheses specify 
  15984.   a call to the backing code for the function in the library, and _outpd has no 
  15985.   backing code. 
  15986.  
  15987. You can run code containing this function only at ring zero. Otherwise, an 
  15988. invalid instruction exception is generated. 
  15989.  
  15990. The _outpd function returns the unsigned long value that was output to the 
  15991. specified port.  There is no error return value and this function does not set 
  15992. errno. 
  15993.  
  15994. Example of _outpd 
  15995.  
  15996.  
  15997. ΓòÉΓòÉΓòÉ <hidden> Example of _outpd ΓòÉΓòÉΓòÉ
  15998.  
  15999. /************************************************************************
  16000. *
  16001.  
  16002. This example uses the _outpd function to write a doubleword value to a 
  16003. specified output port and return the data written. 
  16004.  
  16005.                                                                         *
  16006. ************************************************************************/
  16007.  
  16008. #include <builtin.h>
  16009. #define LOWER  0
  16010. #define UPPER1 65535
  16011. #define UPPER2 4294967295
  16012.  
  16013. int Add1(int j);
  16014. volatile int g;
  16015. enum fruit {apples=10, bananas, cantalopes};
  16016. enum fruit f = cantalopes;
  16017.  
  16018. int arr[]={cantalopes, bananas, apples};
  16019.  
  16020. union
  16021.    {
  16022.    volatile int i;
  16023.    volatile char ch;
  16024.    } un;
  16025.  
  16026. int main(void)
  16027.    {
  16028.    unsigned long l;
  16029.    volatile const short c = 0;
  16030.    un.i = bananas * f;
  16031.  
  16032.    g = _outpd(0,LOWER);
  16033.  
  16034.                                      /* ============================= */
  16035.                                      /* Types of port number passed : */
  16036.                                      /* ----------------------------- */
  16037.    l = _outpd(UPPER1, UPPER2);       /* - #define constant            */
  16038.    l = _outpd(un.i ,f);              /* - element of union            */
  16039.    l = _outpd(Add1(c), apples);      /* - return value from a         */
  16040.                                      /*   function call               */
  16041.                                      /* ----------------------------- */
  16042.  
  16043.    l = _outpd(_outpw(255,Add1(LOWER)),6);
  16044.  
  16045.  
  16046.    return 0;
  16047. }
  16048.  
  16049. int Add1(int j)
  16050.    {
  16051.    j += 1;
  16052.    return j;
  16053.    }
  16054.  
  16055.  
  16056. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16057.  
  16058. o _inp - Read Byte from Input Port 
  16059. o _inpw - Read Unsigned Short from Input Port 
  16060. o _inpd - Read Double Word from Input Port 
  16061. o _outp - Write Byte to Output Port 
  16062. o _outpw - Write Word to Output Port 
  16063.  
  16064.  
  16065. ΓòÉΓòÉΓòÉ 6.171. _outpw - Write Word to Output Port ΓòÉΓòÉΓòÉ
  16066.  
  16067.  
  16068. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16069.  
  16070. #include <conio.h>        /*  Declared in both  */
  16071. #include <builtin.h>
  16072.  
  16073. unsigned short _outpw( const unsigned int port,
  16074. const unsigned short word );
  16075.  
  16076.  
  16077. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16078.  
  16079. Language Level: Extension 
  16080.  
  16081. The _outpw function writes an unsigned short word to the specified port. The 
  16082. port number must be an unsigned int value within the range 0 to 65 535 
  16083. inclusive. The unsigned short word must be in the range 0 to 65 535. 
  16084.  
  16085. Because it is a built-in function and has no backing code in the library: 
  16086.  
  16087. o You cannot take the address of _outpw. 
  16088. o You cannot parenthesize a _outpw function call, because parentheses specify a 
  16089.   call to the backing code for the function. 
  16090.  
  16091. You can run code containing this function only at ring zero. Otherwise, an 
  16092. invalid instruction exception is generated. 
  16093.  
  16094. This function returns the unsigned short value that was output to the specified 
  16095. port. There is no error return value and this function does not set errno. 
  16096.  
  16097. Example of _outpw 
  16098.  
  16099.  
  16100. ΓòÉΓòÉΓòÉ <hidden> Example of _outpw ΓòÉΓòÉΓòÉ
  16101.  
  16102. /************************************************************************
  16103. *
  16104.  
  16105. This example uses the _outpw function to write an unsigned short value to a 
  16106. specified output port and return the data written. 
  16107.  
  16108.                                                                         *
  16109. ************************************************************************/
  16110.  
  16111. #include <builtin.h>
  16112. #define LOWER 0
  16113. #define UPPER 65535
  16114.  
  16115. int Add1(int j);
  16116. unsigned int g;
  16117.  
  16118. int main(void)
  16119.    {
  16120.    enum fruit {apples=10, bananas, cantalopes};
  16121.    enum fruit f = cantalopes;
  16122.  
  16123.    int arr[]={cantalopes, bananas, apples};
  16124.  
  16125.    unsigned short s;
  16126.    static int i = 0;
  16127.    volatile const int c = 255;
  16128.  
  16129.    g = _outpw(cantalopes, i);
  16130.  
  16131.                                      /* ============================= */
  16132.                                      /* Types of port number passed : */
  16133.                                      /* ----------------------------- */
  16134.    s = _outpw(UPPER, LOWER);         /* - #define constant            */
  16135.    s = _outpw(c, Add1(255));         /* - constant                    */
  16136.    s = _outpw(_inpw(arr[2]),apples); /* - return value from a         */
  16137.                                      /*   builtin function call       */
  16138.                                      /* ----------------------------- */
  16139.  
  16140.    s = _outpw(_outpw(bananas ,UPPER),6);
  16141.  
  16142.    return 0;
  16143. }
  16144.  
  16145. int Add1(int j)
  16146.    {
  16147.    j += 1;
  16148.    return j;
  16149.    }
  16150.  
  16151.  
  16152. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16153.  
  16154. o _inp - Read Byte from Input Port 
  16155. o _inpw - Read Unsigned Short from Input Port 
  16156. o _inpd - Read Double Word from Input Port 
  16157. o _outp - Write Byte to Output Port 
  16158. o _outpd - Write Double Word to Output Port 
  16159.  
  16160.  
  16161. ΓòÉΓòÉΓòÉ 6.172. __parmdwords - Get Number of dwords in Parameter List ΓòÉΓòÉΓòÉ
  16162.  
  16163.  
  16164. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16165.  
  16166. #include <stdlib.h>  /* also defined in <builtin.h> */
  16167.  
  16168. unsigned char __parmdwords(void);
  16169.  
  16170.  
  16171. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16172.  
  16173. Language Level: Extension 
  16174.  
  16175. The __parmdwords function returns the hidden parameter passed in the AL 
  16176. register for _System linkage calls. The hidden parameter contains the size of 
  16177. the parameter list that is passed to the function containing the call to 
  16178. __parmdwords.  The size is in doublewords (dwords), and can be between 0 and 
  16179. 255. If the parameter list is larger than 255 dwords, the hidden parameter 
  16180. contains the 8 least significant bits of the value. 
  16181.  
  16182. This function allows the implementer of a function to increase the number of 
  16183. parameters the function takes without changing the name of the function. The 
  16184. new version of the function can call __parmdwords to check the size of the 
  16185. parameter list and determine whether the call was written for the earlier 
  16186. version of the function or for the extended version. 
  16187.  
  16188. Warning: The __parmdwords function has several limitations: 
  16189.  
  16190.  1. Because it is a built-in function and has no backing code in the library: 
  16191.  
  16192.    o You cannot take the address of __parmdwords. 
  16193.    o You cannot parenthesize a __parmdwords function call because parentheses 
  16194.      specify a call to the backing code for the function. 
  16195.  
  16196.  2. The __parmdwords function can only be used for functions with the _System 
  16197.     linkage type. If you use it with other linkage types, an error message is 
  16198.     generated, and your program will not compile correctly. 
  16199.  
  16200. The __parmdwords function returns the size of the parameter list passed to the 
  16201. function in units of dwords. 
  16202.  
  16203. Example of __parmdwords 
  16204.  
  16205.  
  16206. ΓòÉΓòÉΓòÉ <hidden> Example of __parmdwords ΓòÉΓòÉΓòÉ
  16207.  
  16208. /************************************************************************
  16209. *
  16210.  
  16211. This example shows two versions of an API that prints out messages.  The second 
  16212. version uses __parmdwords to determine whether the call was intended for the 
  16213. original or the updated version. 
  16214.  
  16215.                                                                         *
  16216. ************************************************************************/
  16217.  
  16218. #include <stdlib.h>
  16219. #include <stdio.h>
  16220.  
  16221. #pragma linkage(ErrorHandler, system)
  16222. int ErrorHandler(int MessageNum, int Severity);
  16223. /* Extended version of API */
  16224.  
  16225. /* Old version API prototype --  int ErrorHandler(int MessageNum); */
  16226.  
  16227. #define MESSAGE1 1
  16228. #define MESSAGE2 2
  16229.  
  16230. #define INFORMATIONAL 3
  16231. #define WARNING       2
  16232. #define ERROR         1
  16233. #define FATAL         0
  16234.  
  16235. int ErrorHandler(int MessageNum, int Severity)
  16236. {
  16237.    int rc = 0;
  16238.    switch ((int)__parmdwords())
  16239.    {
  16240.    case 2: /* Extended version with Severity parameter */
  16241.       switch (Severity)
  16242.       {
  16243.          case FATAL:
  16244.             printf("Fatal Error:");
  16245.             break;
  16246.          case ERROR:
  16247.             printf("Error:");
  16248.             break;
  16249.          case WARNING:
  16250.             printf("Warning:");
  16251.             break;
  16252.          case INFORMATIONAL:
  16253.             printf("Informational:");
  16254.             break;
  16255.          default:
  16256.             rc = 1;
  16257.             printf("Bad Severity Number");
  16258.       }
  16259.       /* intentional fall through */
  16260.    case 1: /* Old version of API without Severity parameter */
  16261.       switch (MessageNum)
  16262.       {
  16263.          case MESSAGE1:
  16264.             printf("Some immensely profound message\n");
  16265.             break;
  16266.          case MESSAGE2:
  16267.             printf("Some other immensely profound message\n");
  16268.             break;
  16269.          default:
  16270.             printf("Very trivial message,
  16271.                      why not try MESSAGE1 or MESSAGE2?\n");
  16272.             rc = 1;
  16273.       }
  16274.    }
  16275.    return rc;
  16276. }
  16277.  
  16278. /* Old version of main:
  16279.      int main(void)
  16280.      {
  16281.         return ErrorHandler(MESSAGE1);
  16282.      }                               */
  16283.  
  16284.      /* The expected output from the old version is:
  16285.  
  16286.         Some immensely profound message              */
  16287.  
  16288. /* New version of main:  */
  16289.  
  16290. int main(void)
  16291. {
  16292.    return ErrorHandler(MESSAGE1, FATAL);
  16293.  
  16294.    /* The expected output is:
  16295.  
  16296.       Fatal Error:Some immensely profound message  */
  16297.  
  16298. }
  16299.  
  16300.  
  16301. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16302.  
  16303. o "Calling Conventions" in the Programming Guide 
  16304. o stdlib.h 
  16305.  
  16306.  
  16307. ΓòÉΓòÉΓòÉ 6.173. perror  - Print Error Message ΓòÉΓòÉΓòÉ
  16308.  
  16309.  
  16310. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16311.  
  16312. #include <stdio.h>
  16313.  
  16314. void perror(const char *string);
  16315.  
  16316.  
  16317. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16318.  
  16319. Language Level: ANSI, SAA 
  16320.  
  16321. The perror function prints an error message to stderr.  If string is not NULL 
  16322. and string does not point to a null character, the string pointed to by string 
  16323. is printed to the standard error stream, followed by a colon and a space.  The 
  16324. message associated with the value in errno is then printed followed by a 
  16325. new-line character. 
  16326.  
  16327. To produce accurate results, you should ensure that perror is called 
  16328. immediately after a library function returns with an error;  otherwise, 
  16329. subsequent calls may alter the errno value. 
  16330.  
  16331. The perror function returns no value. 
  16332.  
  16333. Example of perror 
  16334.  
  16335.  
  16336. ΓòÉΓòÉΓòÉ <hidden> Example of perror ΓòÉΓòÉΓòÉ
  16337.  
  16338. /************************************************************************
  16339. *
  16340.  
  16341. This example tries to open a stream.  If the fopen function fails, the example 
  16342. prints a message and ends the program. 
  16343.  
  16344.                                                                         *
  16345. ************************************************************************/
  16346.  
  16347. #include <stdio.h>
  16348. #include <stdlib.h>
  16349.  
  16350. int main(void)
  16351. {
  16352.    FILE *fh;
  16353.  
  16354.    if ((fh = fopen("myfile.dat","r")) == NULL)
  16355.    {
  16356.       perror("Could not open data file");
  16357.       abort();
  16358.    }
  16359. }
  16360.  
  16361.  
  16362. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16363.  
  16364. o clearerr  - Reset Error Indicators 
  16365. o ferror  - Test for Read/Write Errors 
  16366. o strerror  - Set Pointer to Runtime Error Message 
  16367. o _strerror - Set Pointer to System Error String 
  16368. o Runtime Return Codes and Messages 
  16369. o stdio.h 
  16370.  
  16371.  
  16372. ΓòÉΓòÉΓòÉ 6.174. pow  - Compute Power ΓòÉΓòÉΓòÉ
  16373.  
  16374.  
  16375. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16376.  
  16377. #include <math.h>
  16378.  
  16379. double pow(double x, double y);
  16380.  
  16381.  
  16382. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16383.  
  16384. Language Level: ANSI, SAA 
  16385.  
  16386. The pow function returns the value of x**y (x to the power of y). If y is 0, 
  16387. pow returns the value 1.  If x is 0 and y is negative, pow sets errno to EDOM 
  16388. and returns 0.  If both x and y are 0, or if x is negative and y is not an 
  16389. integer, pow sets errno to EDOM, and returns 0. 
  16390.  
  16391. If an overflow results, pow sets errno to ERANGE and 
  16392.  
  16393. Example of pow 
  16394.  
  16395.  
  16396. ΓòÉΓòÉΓòÉ <hidden> Example of pow ΓòÉΓòÉΓòÉ
  16397.  
  16398. /************************************************************************
  16399. *
  16400.  
  16401. This example calculates the value of 2**3. 
  16402.  
  16403.                                                                         *
  16404. ************************************************************************/
  16405.  
  16406. #include <math.h>
  16407. #include <stdio.h>
  16408.  
  16409. int main(void)
  16410. {
  16411.    double x, y, z;
  16412.  
  16413.    x = 2.0;
  16414.    y = 3.0;
  16415.    z = pow(x,y);
  16416.  
  16417.    printf("%lf to the power of %lf is %lf\n", x, y, z);
  16418. }
  16419.  
  16420. /*****************  Output should be similar to:  *****************
  16421.  
  16422. 2.000000 to the power of 3.000000 is 8.000000
  16423. */
  16424.  
  16425.  
  16426. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16427.  
  16428. o exp  - Exponential Function 
  16429. o _fsqrt -  Calculate Square Root 
  16430. o log  - Calculate Natural Logarithm 
  16431. o log10  - Calculate Base 10 Logarithm 
  16432. o sqrt  - Calculate Square Root 
  16433. o math.h 
  16434.  
  16435.  
  16436. ΓòÉΓòÉΓòÉ 6.175. printf  - Formatted Print ΓòÉΓòÉΓòÉ
  16437.  
  16438.  
  16439. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16440.  
  16441. #include <stdio.h>
  16442.  
  16443. int printf(const char *format-string, argument-list);
  16444.  
  16445.  
  16446. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16447.  
  16448. Language Level: ANSI, SAA, Extension 
  16449.  
  16450. The printf function formats and prints a series of characters and values to the 
  16451. standard output stream stdout.  The format-string consists of ordinary 
  16452. characters, escape sequences, and format specifications.  The ordinary 
  16453. characters are copied in order of their appearance to stdout.  Format 
  16454. specifications, beginning with a percent sign (%), determine the output format 
  16455. for any argument-list following the format-string.  The format-string is a 
  16456. multibyte character string beginning and ending in its initial shift state. 
  16457.  
  16458. The format-string is read left to right.  When the first format specification 
  16459. is found, the value of the first argument after the format-string is converted 
  16460. and output according to the format specification.  The second format 
  16461. specification causes the second argument after the format-string to be 
  16462. converted and output, and so on through the end of the format-string.  If there 
  16463. are more arguments than there are format specifications, the extra arguments 
  16464. are evaluated and ignored.  The results are undefined if there are not enough 
  16465. arguments for all the format specifications.  A format specification has the 
  16466. following form: 
  16467.  
  16468. ΓöÇΓöÇ%ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇtypeΓöÇΓöÇ
  16469.     Γöé     Γöé  Γöé     Γöé  Γöé         Γöé  Γöé   Γöé
  16470.     ΓööΓöÇΓöÇflagsΓöÇΓöÇΓöÿ  ΓööΓöÇΓöÇwidthΓöÇΓöÇΓöÿ  ΓööΓöÇΓöÇ.ΓöÇΓöÇprecisionΓöÇΓöÇΓöÿ  Γö£ΓöÇΓöÇhΓöÇΓöÇΓöñ
  16471.                            Γöé   Γöé
  16472.                            Γö£ΓöÇΓöÇLΓöÇΓöÇΓöñ
  16473.                            Γöé   Γöé
  16474.                            ΓööΓöÇΓöÇlΓöÇΓöÇΓöÿ
  16475. Each field of the format specification is a single character or number 
  16476. signifying a particular format option.  The type character, which appears after 
  16477. the last optional format field, determines whether the associated argument is 
  16478. interpreted as a character, a string, a number, or pointer.  The simplest 
  16479. format specification contains only the percent sign and a type character (for 
  16480. example, %s). 
  16481.  
  16482. The following optional fields control other aspects of the formatting: 
  16483.  
  16484. Field       Description 
  16485. flags       Justification of output and printing of signs, blanks, decimal 
  16486.             points, octal, and hexadecimal prefixes, and the semantics for 
  16487.             wchar_t precision unit. 
  16488. width       Minimum number of characters (bytes) output. 
  16489. precision   Maximum number of characters (bytes) printed for all or part of the 
  16490.             output field, or minimum number of digits printed for integer 
  16491.             values. 
  16492. h,l,L       Size of argument expected. 
  16493.  
  16494. If a percent sign (%) is followed by a character that has no meaning as a 
  16495. format field, the character is simply copied to stdout.  For example, to print 
  16496. a percent sign character, use %%. 
  16497.  
  16498. In extended mode, printf also converts floating-point values of NaN and 
  16499. infinity to the strings "NAN" or "nan" and "INFINITY" or "infinity". The case 
  16500. and sign of the string is determined by the format specifiers.  See Infinity 
  16501. and NaN Support for more information on infinity and NaN values. 
  16502.  
  16503. The printf function returns the number of characters (bytes) printed. 
  16504.  
  16505. Example of printf 
  16506.  
  16507.  
  16508. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16509.  
  16510. o fprintf  - Write Formatted Data 
  16511. o fscanf  - Read Formatted Data 
  16512. o scanf  - Read Data 
  16513. o sprintf  - Formatted Print to Buffer 
  16514. o sscanf  - Read Data 
  16515. o Infinity and NaN Support 
  16516. o stdio.h 
  16517.  
  16518.  
  16519. ΓòÉΓòÉΓòÉ 6.175.1. Format Specification - Types ΓòÉΓòÉΓòÉ
  16520.  
  16521. The type characters and their meanings are given in the following table: 
  16522.  
  16523. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  16524. Γöé CHAR- Γöé ARGUMENT  Γöé OUTPUT FORMAT                      Γöé
  16525. Γöé ACTER Γöé       Γöé                             Γöé
  16526. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16527. Γöé d, i  Γöé Integer   Γöé Signed decimal integer.                 Γöé
  16528. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16529. Γöé u   Γöé Integer   Γöé Unsigned decimal integer.                Γöé
  16530. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16531. Γöé o   Γöé Integer   Γöé Unsigned octal integer.                 Γöé
  16532. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16533. Γöé x   Γöé Integer   Γöé Unsigned hexadecimal integer, using abcdef.       Γöé
  16534. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16535. Γöé X   Γöé Integer   Γöé Unsigned hexadecimal integer, using ABCDEF.       Γöé
  16536. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16537. Γöé f   Γöé Double   Γöé Signed value having the form [-]dddd.dddd, where dddd  Γöé
  16538. Γöé    Γöé       Γöé is one or more decimal digits.  The number of digits   Γöé
  16539. Γöé    Γöé       Γöé before the decimal point depends on the magnitude of   Γöé
  16540. Γöé    Γöé       Γöé the number.  The number of digits after the decimal   Γöé
  16541. Γöé    Γöé       Γöé point is equal to the requested precision.        Γöé
  16542. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16543. Γöé e   Γöé Double   Γöé Signed value having the form [-]d.dddd"e"[sign]ddd,   Γöé
  16544. Γöé    Γöé       Γöé where d is a single-decimal digit, dddd is one or more  Γöé
  16545. Γöé    Γöé       Γöé decimal digits, ddd is 2 or 3 decimal digits, and sign  Γöé
  16546. Γöé    Γöé       Γöé is + or -.                        Γöé
  16547. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16548. Γöé E   Γöé Double   Γöé Identical to the "e" format except that "E" introduces  Γöé
  16549. Γöé    Γöé       Γöé the exponent instead of "e".               Γöé
  16550. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16551. Γöé g   Γöé Double   Γöé Signed value printed in "f" or "e" format.  The "e"   Γöé
  16552. Γöé    Γöé       Γöé format is used only when the exponent of the value is  Γöé
  16553. Γöé    Γöé       Γöé less than -4 or greater than precision.  Trailing zeros Γöé
  16554. Γöé    Γöé       Γöé are truncated, and the decimal point appears only if   Γöé
  16555. Γöé    Γöé       Γöé one or more digits follow it.              Γöé
  16556. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16557. Γöé G   Γöé Double   Γöé Identical to the "g" format except that "E" introduces  Γöé
  16558. Γöé    Γöé       Γöé the exponent (where appropriate) instead of "e".     Γöé
  16559. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16560. Γöé c   Γöé Character  Γöé Single character.                    Γöé
  16561. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16562. Γöé s   Γöé String   Γöé Characters printed up to the first null character    Γöé
  16563. Γöé    Γöé       Γöé (\"0") or until precision is reached.          Γöé
  16564. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16565. Γöé n   Γöé Pointer to Γöé Number of characters successfully written so far to the Γöé
  16566. Γöé    Γöé integer   Γöé stream or buffer; this value is stored in the integer  Γöé
  16567. Γöé    Γöé       Γöé whose address is given as the argument.         Γöé
  16568. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16569. Γöé p   Γöé Pointer   Γöé Pointer to void converted to a sequence of printable   Γöé
  16570. Γöé    Γöé       Γöé characters.                       Γöé
  16571. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16572. Γöé "lc"  Γöé Wide char- Γöé Multibyte character.                   Γöé
  16573. Γöé    Γöé acter    Γöé                             Γöé
  16574. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16575. Γöé "ls"  Γöé Wide    Γöé Multibyte characters printed up to the first "wchar_t"  Γöé
  16576. Γöé    Γöé string   Γöé null character ("L\0") or until precision is reached.  Γöé
  16577. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  16578.  
  16579.  
  16580. ΓòÉΓòÉΓòÉ 6.175.2. Format Specification - Flags ΓòÉΓòÉΓòÉ
  16581.  
  16582. The flag characters and their meanings are as follows (notice that more than 
  16583. one flag can appear in a format specification): 
  16584.  
  16585. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  16586. Γöé FLAG    Γöé MEANING                  Γöé DEFAULT        Γöé
  16587. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16588. Γöé -     Γöé Left-justify the result within the field  Γöé Right-justify.    Γöé
  16589. Γöé      Γöé width.                   Γöé            Γöé
  16590. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16591. Γöé +     Γöé Prefix the output value with a sign (+ or Γöé Sign appears only   Γöé
  16592. Γöé      Γöé -) if the output value is of a signed   Γöé for negative signed  Γöé
  16593. Γöé      Γöé type.                   Γöé values (-).      Γöé
  16594. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16595. Γöé blank(' ')Γöé Prefix the output value with a blank if  Γöé No blank.       Γöé
  16596. Γöé      Γöé the output value is signed and positive.  Γöé            Γöé
  16597. Γöé      Γöé The "+" flag overrides the blank flag if  Γöé            Γöé
  16598. Γöé      Γöé both appear, and a positive signed value  Γöé            Γöé
  16599. Γöé      Γöé will be output with a sign.        Γöé            Γöé
  16600. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16601. Γöé #     Γöé When used with the "o", "x", or "X"    Γöé No prefix.      Γöé
  16602. Γöé      Γöé formats, the "#" flag prefixes any     Γöé            Γöé
  16603. Γöé      Γöé nonzero output value with "0", "0"x, or  Γöé            Γöé
  16604. Γöé      Γöé "0"X, respectively.            Γöé            Γöé
  16605. Γöé      Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16606. Γöé      Γöé When used with the "f", "e", or "E"    Γöé Decimal point     Γöé
  16607. Γöé      Γöé formats, the "#" flag forces the output  Γöé appears only if    Γöé
  16608. Γöé      Γöé value to contain a decimal point in all  Γöé digits follow it.   Γöé
  16609. Γöé      Γöé cases.                   Γöé            Γöé
  16610. Γöé      Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16611. Γöé      Γöé When used with the "g" or "G" formats,   Γöé Decimal point     Γöé
  16612. Γöé      Γöé the "#" flag forces the output value to  Γöé appears only if    Γöé
  16613. Γöé      Γöé contain a decimal point in all cases and  Γöé digits follow it;   Γöé
  16614. Γöé      Γöé prevents the truncation of trailing    Γöé trailing zeros are  Γöé
  16615. Γöé      Γöé zeros.                   Γöé truncated.      Γöé
  16616. Γöé      Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16617. Γöé      Γöé When used with the "ls" format, the "#"  Γöé Precision indicates  Γöé
  16618. Γöé      Γöé flag causes precision to be measured in  Γöé the maximum number  Γöé
  16619. Γöé      Γöé "wchar_t" characters.           Γöé of bytes to be    Γöé
  16620. Γöé      Γöé                      Γöé output.        Γöé
  16621. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16622. Γöé "0"    Γöé When used with the "d", "i", "o", "u",   Γöé Space padding.    Γöé
  16623. Γöé      Γöé "x", "X", "e", "E", "f", "g", or "G"    Γöé            Γöé
  16624. Γöé      Γöé formats, the "0" flag causes leading    Γöé            Γöé
  16625. Γöé      Γöé "0"'s to pad the output to the field    Γöé            Γöé
  16626. Γöé      Γöé width.  The "0" flag is ignored if preci- Γöé            Γöé
  16627. Γöé      Γöé sion is specified for an integer or if   Γöé            Γöé
  16628. Γöé      Γöé the "-" flag is specified.         Γöé            Γöé
  16629. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  16630.  
  16631. The # flag should not be used with c, lc, d, i, u, s, or p types. 
  16632.  
  16633.  
  16634. ΓòÉΓòÉΓòÉ 6.175.3. Format Specification - Width ΓòÉΓòÉΓòÉ
  16635.  
  16636. Width is a nonnegative decimal integer controlling the minimum number of 
  16637. characters printed.  If the number of characters in the output value is less 
  16638. than the specified width, blanks are added on the left or the right (depending 
  16639. on whether the - flag is specified) until the minimum width is reached. 
  16640.  
  16641. Width never causes a value to be truncated;  if the number of characters in the 
  16642. output value is greater than the specified width, or width is not given, all 
  16643. characters of the value are printed (subject to the precision specification). 
  16644.  
  16645. For the ls type, width is specified in bytes. If the number of bytes in the 
  16646. output value is less than the specified width, single-byte blanks are added on 
  16647. the left or the right (depending on whether the - flag is specified) until the 
  16648. minimum width is reached. 
  16649.  
  16650. The width specification can be an asterisk (*), in which case an argument from 
  16651. the argument list supplies the value.  The width argument must precede the 
  16652. value being formatted in the argument list. 
  16653.  
  16654.  
  16655. ΓòÉΓòÉΓòÉ 6.175.4. Format Specification - Precision ΓòÉΓòÉΓòÉ
  16656.  
  16657. Precision is a nonnegative decimal integer preceded by a period, which 
  16658. specifies the number of characters to be printed or the number of decimal 
  16659. places.  Unlike the width specification, the precision can cause truncation of 
  16660. the output value or rounding of a floating-point value. 
  16661.  
  16662. The precision specification can be an asterisk (*), in which case an argument 
  16663. from the argument list supplies the value.  The precision argument must precede 
  16664. the value being formatted in the argument list. 
  16665.  
  16666. The interpretation of the precision value and the default when the precision is 
  16667. omitted depend upon the type, as shown in the following table: 
  16668.  
  16669. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  16670. Γöé TYPE  Γöé MEANING                    Γöé DEFAULT        Γöé
  16671. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16672. Γöé   i  Γöé Precision specifies the minimum number of   Γöé If precision is "0"  Γöé
  16673. Γöé   d  Γöé digits to be printed.  If the number of    Γöé or omitted entirely, Γöé
  16674. Γöé   u  Γöé digits in the argument is less than      Γöé or if the period (.) Γöé
  16675. Γöé   o  Γöé precision, the output value is padded on the  Γöé appears without a   Γöé
  16676. Γöé   x  Γöé left with zeros.  The value is not truncated  Γöé number following it, Γöé
  16677. Γöé   X  Γöé when the number of digits exceeds precision.  Γöé the precision is set Γöé
  16678. Γöé    Γöé                        Γöé to 1.         Γöé
  16679. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16680. Γöé   f  Γöé Precision specifies the number of digits to  Γöé Default precision is Γöé
  16681. Γöé   e  Γöé be printed after the decimal point.  The last Γöé six.  If precision  Γöé
  16682. Γöé   E  Γöé digit printed is rounded.           Γöé is "0" or the period Γöé
  16683. Γöé    Γöé                        Γöé appears without a   Γöé
  16684. Γöé    Γöé                        Γöé number following it, Γöé
  16685. Γöé    Γöé                        Γöé no decimal point is  Γöé
  16686. Γöé    Γöé                        Γöé printed.       Γöé
  16687. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16688. Γöé   g  Γöé Precision specifies the maximum number of   Γöé All significant    Γöé
  16689. Γöé   G  Γöé significant digits printed.          Γöé digits are printed.  Γöé
  16690. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16691. Γöé   c  Γöé No effect.                   Γöé The character is   Γöé
  16692. Γöé    Γöé                        Γöé printed.       Γöé
  16693. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16694. Γöé   lc Γöé No effect.                   Γöé The "wchar_t" char-  Γöé
  16695. Γöé    Γöé                        Γöé acter is printed.   Γöé
  16696. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16697. Γöé   s  Γöé Precision specifies the maximum number of   Γöé Characters are    Γöé
  16698. Γöé    Γöé characters to be printed.  Characters in    Γöé printed until a null Γöé
  16699. Γöé    Γöé excess of precision are not printed.      Γöé character is     Γöé
  16700. Γöé    Γöé                        Γöé encountered.     Γöé
  16701. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  16702. Γöé   ls Γöé Precision specifies the maximum number of   Γöé "wchar_t" characters Γöé
  16703. Γöé    Γöé bytes to be printed.  Bytes in excess of pre- Γöé are printed until a  Γöé
  16704. Γöé    Γöé cision are not printed; however, multibyte   Γöé null character is   Γöé
  16705. Γöé    Γöé integrity is always preserved.         Γöé encountered.     Γöé
  16706. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  16707.  
  16708.  
  16709. ΓòÉΓòÉΓòÉ 6.175.5. Format Specification - h, l, L ΓòÉΓòÉΓòÉ
  16710.  
  16711. The h, l, and L characters specify the size of the expected argument.  Their 
  16712. meanings are as follows: 
  16713.  
  16714. h    A prefix with the integer types d, i, o, u, x, X, and n that specifies 
  16715.      that the argument is short int or unsigned short int. 
  16716. l    A prefix with d, i, o, u, x, X, and n types that specifies that the 
  16717.      argument is a long int or unsigned long int. 
  16718. L    A prefix with e, E, f, g, or G types that specifies that the argument is 
  16719.      long double. 
  16720.  
  16721.  
  16722. ΓòÉΓòÉΓòÉ <hidden> Example of printf ΓòÉΓòÉΓòÉ
  16723.  
  16724. /************************************************************************
  16725. *
  16726. This example prints data in a variety of formats. 
  16727.  
  16728.                                                                         *
  16729. ************************************************************************/
  16730.  
  16731. #include <stdio.h>
  16732.  
  16733. int main(void)
  16734. {
  16735.    char ch = 'h', *string = "computer";
  16736.    int count = 234, hex = 0x10, oct = 010, dec = 10;
  16737.    double fp = 251.7366;
  16738.  
  16739.  
  16740.    printf("%d   %+d    %06d     %X    %x     %o\n\n",
  16741.       count, count, count, count, count, count);
  16742.  
  16743.    printf("1234567890123%n4567890123456789\n\n", &count);
  16744.  
  16745.    printf("Value of count should be 13; count = %d\n\n", count);
  16746.  
  16747.    printf("%10c%5c\n\n", ch, ch);
  16748.  
  16749.    printf("%25s\n%25.4s\n\n", string, string);
  16750.  
  16751.  
  16752.    printf("%f    %.2f    %e    %E\n\n", fp, fp, fp, fp);
  16753.  
  16754.    printf("%i    %i     %i\n\n", hex, oct, dec);
  16755.  
  16756. }
  16757.  
  16758. /*****************  Output should be similar to:  *****************
  16759.  
  16760. 234   +234    000234     EA    ea     352
  16761.  
  16762. 12345678901234567890123456789
  16763.  
  16764. Value of count should be 13; count = 13
  16765.  
  16766.          h    h
  16767.  
  16768.                  computer
  16769.                      comp
  16770.  
  16771. 251.736600    251.74    2.517366e+02    2.517366E+02
  16772.  
  16773. 16    8     10
  16774.  
  16775.  
  16776. ΓòÉΓòÉΓòÉ 6.176. putc - putchar  - Write a Character ΓòÉΓòÉΓòÉ
  16777.  
  16778.  
  16779. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16780.  
  16781. #include <stdio.h>
  16782.  
  16783. int putc(int c, FILE *stream);
  16784.  
  16785. int putchar(int c);
  16786.  
  16787.  
  16788. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16789.  
  16790. Language Level: ANSI, SAA 
  16791.  
  16792. The putc function converts c to unsigned char and then writes c to the output 
  16793. stream at the current position.  The putchar function is identical to 
  16794. putc(c, stdout). 
  16795.  
  16796. The putc and putchar functions return the character written.  A return value of 
  16797. EOF indicates an error. 
  16798.  
  16799. The putc function can be implemented as a macro so the argument may be 
  16800. evaluated multiple times. 
  16801.  
  16802. Example of putc - putchar 
  16803.  
  16804.  
  16805. ΓòÉΓòÉΓòÉ <hidden> Example of putc - putchar ΓòÉΓòÉΓòÉ
  16806.  
  16807. /************************************************************************
  16808. *
  16809.  
  16810. This example writes the contents of a buffer to a data stream.  In this 
  16811. example, the body of the for statement is null because the example carries out 
  16812. the writing operation in the test expression. 
  16813.  
  16814.                                                                         *
  16815. ************************************************************************/
  16816.  
  16817. #include <stdio.h>
  16818. #include <string.h>
  16819.  
  16820. #define  LENGTH 80
  16821.  
  16822. int main(void)
  16823. {
  16824.    FILE *stream = stdout;
  16825.    int i, ch;
  16826.    char buffer[LENGTH + 1] = "Hello world";
  16827.  
  16828.    /* This could be replaced by using the fwrite routine */
  16829.    for ( i = 0;
  16830.         (i < strlen(buffer)) && ((ch = putc(buffer[i], stream)) != EOF);
  16831.          ++i);
  16832. }
  16833.  
  16834. /********************  Expected output:  **************************
  16835.  
  16836. Hello world
  16837. */
  16838.  
  16839.  
  16840. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16841.  
  16842. o fputc  - Write a Character 
  16843. o _fputchar - Write Character 
  16844. o fwrite  - Write Items 
  16845. o getc  - Read a Character 
  16846. o _putch - Write Character to Screen 
  16847. o puts  - Write a String 
  16848. o stdio.h 
  16849. o _write - Writes from Buffer to File 
  16850.  
  16851.  
  16852. ΓòÉΓòÉΓòÉ 6.177. _putch - Write Character to Screen ΓòÉΓòÉΓòÉ
  16853.  
  16854.  
  16855. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16856.  
  16857. #include <conio.h>
  16858.  
  16859. int _putch(int c);
  16860.  
  16861.  
  16862. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16863.  
  16864. Language Level: Extension 
  16865.  
  16866. The _putch function writes the character c directly to the screen. 
  16867.  
  16868. If successful, _putch returns c. If an error occurs, _putch returns EOF. 
  16869.  
  16870. Example of _putch 
  16871.  
  16872.  
  16873. ΓòÉΓòÉΓòÉ <hidden> Example of _putch ΓòÉΓòÉΓòÉ
  16874.  
  16875. /************************************************************************
  16876. *
  16877. This example defines a function gchar that is similar to _getche using the 
  16878. _putch and _getch functions: 
  16879.  
  16880.                                                                         *
  16881. ************************************************************************/
  16882.  
  16883. #include <conio.h>
  16884.  
  16885. int gchar(void)
  16886. {
  16887.    int ch;
  16888.  
  16889.    ch = _getch();
  16890.    _putch(ch);
  16891.    return(ch);
  16892. }
  16893.  
  16894.  
  16895. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  16896.  
  16897. o _cputs - Write String to Screen 
  16898. o _cprintf - Print Characters to Screen 
  16899. o fputc  - Write a Character 
  16900. o _getch - _getche - Read Character from Keyboard 
  16901. o putc - putchar  - Write a Character 
  16902. o puts  - Write a String 
  16903. o _write - Writes from Buffer to File 
  16904. o conio.h 
  16905.  
  16906.  
  16907. ΓòÉΓòÉΓòÉ 6.178. _putenv - Modify Environment Variables ΓòÉΓòÉΓòÉ
  16908.  
  16909.  
  16910. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  16911.  
  16912. #include <stdlib.h>
  16913.  
  16914. int _putenv(char *envstring);
  16915.  
  16916.  
  16917. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  16918.  
  16919. Language Level: Extension 
  16920.  
  16921. The _putenv function adds new environment variables or modifies the values of 
  16922. existing environment variables. Environment variables define the environment in 
  16923. which a process runs (for example, the default search path for libraries to be 
  16924. linked with a program). 
  16925.  
  16926. The envstring argument must be a pointer to a string with the form: 
  16927.  
  16928.    varname=string
  16929.  
  16930. where varname is the name of the environment variable to be added or modified 
  16931. and string is the value of the variable. See the Notes below. 
  16932.  
  16933. If varname is already part of the environment, string replaces its current 
  16934. value; if not, the new varname is added to the environment with the value 
  16935. string. To set a variable to an empty value, specify an empty string. A 
  16936. variable can be removed from the environment by specifying varname only, for 
  16937. example, 
  16938.  
  16939.    _putenv("PATH");
  16940.  
  16941. Do not free a pointer to an environment entry while the environment entry is 
  16942. still in use, or the environment variable will point into freed space. A 
  16943. similar problem can occur if you pass a pointer to a local variable to _putenv 
  16944. and then exit from the function in which the variable is declared. 
  16945.  
  16946. The environment manipulated by _putenv is local to the process currently 
  16947. running. You cannot enter new items in your command level environment using 
  16948. _putenv. When the program ends, the environment reverts to the parent process 
  16949. environment. This environment is passed on to some child processes created by 
  16950. the _spawn, _exec, or system functions, and they get any new environment 
  16951. variables added using _putenv. 
  16952.  
  16953. DosScanEnv will not reflect any changes made using the _putenv function, but 
  16954. getenv will reflect any changes made by _putenv. 
  16955.  
  16956. Notes 
  16957.  
  16958.  1. The _putenv function can change the value of _environ, thus invalidating 
  16959.     the envp argument to the main function. 
  16960.  
  16961.  2. %envvar%, where envvar is any OS/2 environment variable, cannot be used 
  16962.     with _putenv to concatenate new envstring and old envstring. 
  16963.  
  16964. The _putenv function returns 0 if it is successful.  A return value of -1 
  16965. indicates an error. 
  16966.  
  16967. Example of _putenv 
  16968.  
  16969.  
  16970. ΓòÉΓòÉΓòÉ <hidden> Example of _putenv ΓòÉΓòÉΓòÉ
  16971.  
  16972. /************************************************************************
  16973. *
  16974. This example tries to change the environment variable PATH, and then uses 
  16975. getenv to get the current path. If the call to _putenv fails, the example 
  16976. writes an error message. 
  16977.  
  16978.                                                                         *
  16979. ************************************************************************/
  16980.  
  16981. #include <stdlib.h>
  16982. #include <stdio.h>
  16983.  
  16984. int main(void)
  16985. {
  16986.     char *pathvar;
  16987.  
  16988.     if ( _putenv("PATH=a:\\bin;b:\\andy") == -1 )
  16989.     {
  16990.         printf("_putenv failed - out of memory\n");
  16991.         exit(-1);
  16992.     }
  16993.  
  16994.     /* getting and printing the current environment path  */
  16995.     pathvar = getenv("PATH");
  16996.     printf("The current path is: %s\n", pathvar);
  16997.  
  16998.     return 0;
  16999.  
  17000.     /* The expected output is:
  17001.  
  17002.        The current path is: a:\bin;b:\andy   */
  17003.  
  17004. }
  17005.  
  17006.  
  17007. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17008.  
  17009. o _execl - _execvp - Load and Run Child Process 
  17010. o getenv  - Search for Environment Variables 
  17011. o _spawnl -_spawnvpe -Start and Run Child Processes 
  17012. o system - Invoke the Command Processor 
  17013. o envp Parameter to main 
  17014. o stdlib.h 
  17015.  
  17016.  
  17017. ΓòÉΓòÉΓòÉ 6.179. puts  - Write a String ΓòÉΓòÉΓòÉ
  17018.  
  17019.  
  17020. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17021.  
  17022. #include <stdio.h>
  17023.  
  17024. int puts(const char *string);
  17025.  
  17026.  
  17027. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17028.  
  17029. Language Level: ANSI, SAA 
  17030.  
  17031. The puts function writes the given string to the standard output stream stdout; 
  17032. it also appends a new-line character to the output.  The terminating null 
  17033. character is not written. 
  17034.  
  17035. The puts function returns EOF if an error occurs.  A nonnegative return value 
  17036. indicates that no error has occurred. 
  17037.  
  17038. Example of puts 
  17039.  
  17040.  
  17041. ΓòÉΓòÉΓòÉ <hidden> Example of puts ΓòÉΓòÉΓòÉ
  17042.  
  17043. /************************************************************************
  17044. *
  17045.  
  17046. This example writes Hello World to stdout. 
  17047.  
  17048.                                                                         *
  17049. ************************************************************************/
  17050.  
  17051. #include <stdio.h>
  17052.  
  17053. int main(void)
  17054. {
  17055.   if ( puts("Hello World") == EOF )
  17056.     printf( "Error in puts\n" );
  17057. }
  17058.  
  17059. /************************  Expected output:  *********************
  17060.  
  17061. Hello World
  17062. */
  17063.  
  17064.  
  17065. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17066.  
  17067. o _cputs - Write String to Screen 
  17068. o fputs  - Print Strings 
  17069. o gets  - Read a Line 
  17070. o putc - putchar  - Write a Character 
  17071. o stdio.h 
  17072.  
  17073.  
  17074. ΓòÉΓòÉΓòÉ 6.180. qsort  - Sort Array ΓòÉΓòÉΓòÉ
  17075.  
  17076.  
  17077. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17078.  
  17079. #include <stdlib.h>
  17080.  
  17081. void qsort(void *base, size_t num, size_t width,
  17082.            int(*compare)(const void *element1, const void *element2));
  17083.  
  17084.  
  17085. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17086.  
  17087. Language Level: ANSI, SAA, Extension 
  17088.  
  17089. The qsort function sorts an array of num elements, each of width bytes in size. 
  17090. The base pointer is a pointer to the array to be sorted.  The qsort function 
  17091. overwrites this array with the sorted elements. 
  17092.  
  17093. The compare pointer points to a function, which you supply, that compares two 
  17094. array elements and returns an integer value specifying their relationship.  The 
  17095. qsort function calls the compare function one or more times during the sort, 
  17096. passing pointers to two array elements on each call.  The function must compare 
  17097. the elements, and then return one of the following values: 
  17098.  
  17099. Value               Meaning 
  17100. Less than 0         element1 less than element2 
  17101. 0                   element1 equal to element2 
  17102. Greater than 0      element1 greater than element2 
  17103.  
  17104. The sorted array elements are stored in ascending order, as defined by your 
  17105. comparison function.  You can sort in reverse order by reversing the sense of 
  17106. "greater than" and "less than" in the comparison function.  The order of the 
  17107. elements is unspecified when two elements compare equally. 
  17108.  
  17109. There is no return value. 
  17110.  
  17111. Example of qsort 
  17112.  
  17113.  
  17114. ΓòÉΓòÉΓòÉ <hidden> Example of qsort ΓòÉΓòÉΓòÉ
  17115.  
  17116. /************************************************************************
  17117. *
  17118.  
  17119. This example sorts the arguments (argv) in ascending lexical sequence, using 
  17120. the comparison function compare() supplied in the example. 
  17121.  
  17122.                                                                         *
  17123. ************************************************************************/
  17124.  
  17125. #include <stdio.h>
  17126. #include <stdlib.h>
  17127. #include <string.h>
  17128.  
  17129.                /* Declaration of compare() as a function */
  17130. int compare(const void *, const void *);
  17131.  
  17132. int main (int argc, char *argv[ ])
  17133. {
  17134.    int i;
  17135.    argv++;
  17136.    argc--;
  17137.    qsort((char *)argv, argc, sizeof(char *), compare);
  17138.    for (i = 0; i < argc; ++i)
  17139.       printf("%s\n", argv[i]);
  17140.    return 0;
  17141. }
  17142.  
  17143. int compare (const void *arg1, const void *arg2)
  17144. {
  17145.                /* Compare all of both strings */
  17146.    return(strcmp(*(char **)arg1, *(char **)arg2));
  17147. }
  17148.  
  17149. /***********  If the program is passed the arguments:  ************
  17150. ************  Does, this, really, sort, the, arguments, correctly?,  ****
  17151. ****************  then the expected output is:  *******************
  17152.  
  17153. arguments
  17154. correctly?
  17155. really
  17156. sort
  17157. the
  17158. this
  17159. Does
  17160. */
  17161.  
  17162.  
  17163. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17164.  
  17165. o bsearch  - Search Arrays 
  17166. o _lfind - _lsearch - Find Key in Array 
  17167. o search.h 
  17168. o stdlib.h 
  17169.  
  17170.  
  17171. ΓòÉΓòÉΓòÉ 6.181. raise  - Send Signal ΓòÉΓòÉΓòÉ
  17172.  
  17173.  
  17174. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17175.  
  17176. #include <signal.h>
  17177.  
  17178. int raise(int sig);
  17179.  
  17180.  
  17181. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17182.  
  17183. Language Level: ANSI, SAA 
  17184.  
  17185. The raise function sends the signal sig to the running program. The return 
  17186. value is zero if successful, nonzero if unsuccessful. 
  17187.  
  17188. Example of raise 
  17189.  
  17190.  
  17191. ΓòÉΓòÉΓòÉ <hidden> Example of raise ΓòÉΓòÉΓòÉ
  17192.  
  17193. /************************************************************************
  17194. *
  17195.  
  17196. This example establishes a signal handler called sig_hand for the signal 
  17197. SIGUSR1. The signal handler is called whenever the SIGUSR1 signal is raised and 
  17198. will ignore the first nine occurrences of the signal.  On the tenth raised 
  17199. signal, it exits the program with an error code of 10.  Note that the signal 
  17200. handler must be reestablished each time it is called. 
  17201.  
  17202.                                                                         *
  17203. ************************************************************************/
  17204.  
  17205. #include <signal.h>
  17206. #include <stdio.h>
  17207.  
  17208. void sig_hand(int);  /* declaration of sig_hand() as a function */
  17209.  
  17210. int main(void)
  17211. {
  17212.    signal(SIGUSR1, sig_hand); /* set up handler for SIGUSR1 */
  17213.    .
  17214.    .
  17215.    .
  17216.    raise(SIGUSR1);   /* signal SIGUSR1 is raised */
  17217.                      /* sig_hand() is called     */
  17218. }
  17219.  
  17220. void sig_hand(int sig)
  17221. {
  17222.    static int count = 0;  /* initialized only once */
  17223.  
  17224.    count++;
  17225.    if (count == 10)  /* ignore the first 9 occurrences of this signal */
  17226.       exit(10);
  17227.    else
  17228.       signal(SIGUSR1, sig_hand);  /* set up the handler again */
  17229. }
  17230.  
  17231.  
  17232. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17233.  
  17234. o signal Install Interrupt Handlers 
  17235. o signal.h 
  17236.  
  17237.  
  17238. ΓòÉΓòÉΓòÉ 6.182. rand  - Generate Random Number ΓòÉΓòÉΓòÉ
  17239.  
  17240.  
  17241. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17242.  
  17243. #include <stdlib.h>
  17244.  
  17245. int rand(void);
  17246.  
  17247.  
  17248. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17249.  
  17250. Language Level: ANSI, SAA 
  17251.  
  17252. The rand function generates a pseudo-random integer in the range 0 to RAND_MAX 
  17253. (macro defined in <stdlib.h>).  Use the srand function before calling rand to 
  17254. set a starting point for the random number generator. If you do not make a call 
  17255. to srand, the default seed is 1. 
  17256.  
  17257. Example of rand 
  17258.  
  17259.  
  17260. ΓòÉΓòÉΓòÉ <hidden> Example of rand ΓòÉΓòÉΓòÉ
  17261.  
  17262. /************************************************************************
  17263. *
  17264.  
  17265. This example prints the first 10 random numbers generated. 
  17266.  
  17267.                                                                         *
  17268. ************************************************************************/
  17269.  
  17270. #include <stdlib.h>
  17271. #include <stdio.h>
  17272.  
  17273. int main(void)
  17274. {
  17275.    int x;
  17276.  
  17277.    for (x = 1; x <= 10; x++)
  17278.       printf("iteration %d, rand=%d\n", x, rand());
  17279. }
  17280.  
  17281. /*********************  Output should be similar to:  ************
  17282.  
  17283. iteration 1, rand=16838
  17284. iteration 2, rand=5758
  17285. iteration 3, rand=10113
  17286. iteration 4, rand=17515
  17287. iteration 5, rand=31051
  17288. iteration 6, rand=5627
  17289. iteration 7, rand=23010
  17290. iteration 8, rand=7419
  17291. iteration 9, rand=16212
  17292. iteration 10, rand=4086
  17293. */
  17294.  
  17295.  
  17296. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17297.  
  17298. o srand  - Set Seed for rand Function 
  17299. o stdlib.h 
  17300.  
  17301.  
  17302. ΓòÉΓòÉΓòÉ 6.183. _read - Read Into Buffer ΓòÉΓòÉΓòÉ
  17303.  
  17304.  
  17305. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17306.  
  17307. #include <io.h>
  17308.  
  17309. int _read(int handle, char *buffer, unsigned int count);
  17310.  
  17311.  
  17312. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17313.  
  17314. Language Level: Extension 
  17315.  
  17316. The _read function reads count bytes from the file associated with handle into 
  17317. buffer. The read operation begins at the current position of the file pointer 
  17318. associated with the given file. After the read operation, the file pointer 
  17319. points to the next unread character. 
  17320.  
  17321. The _read function returns the number of bytes placed in buffer. This number 
  17322. can be less than count if there are fewer than count  bytes left in the file or 
  17323. if the file was opened in text mode (see the note below). The return value 0 
  17324. indicates an attempt to read at end-of-file. A return value -1 indicates an 
  17325. error. If -1 is returned, the current file position is undefined, and errno is 
  17326. set to one of the following values: 
  17327.  
  17328. Value          Meaning 
  17329. EBADF          The given handle is incorrect, or the file is not open for 
  17330.                reading, or the file is locked. 
  17331. EOS2ERR        The call to the operating system was not successful. 
  17332.  
  17333. Note:  If the file was opened in text mode, the return value might not 
  17334. correspond to the number of bytes actually read. When text mode is in effect, 
  17335. carriage return characters are deleted from the input stream without affecting 
  17336. the file pointer. 
  17337.  
  17338. Example of _read 
  17339.  
  17340.  
  17341. ΓòÉΓòÉΓòÉ <hidden> Example of _read ΓòÉΓòÉΓòÉ
  17342.  
  17343. /************************************************************************
  17344. *
  17345.  
  17346. This example opens the file sample.dat and attempts to read from it. 
  17347.  
  17348.                                                                         *
  17349. ************************************************************************/
  17350.  
  17351. #include <io.h>
  17352. #include <stdio.h>
  17353. #include <stdlib.h>
  17354. #include <fcntl.h>
  17355. #include <string.h>
  17356.  
  17357. int main(void)
  17358. {
  17359.    int  fh;
  17360.    char buffer[20];
  17361.  
  17362.    memset(buffer,'\0',20);
  17363.  
  17364.    printf("\nCreating sample.dat.\n");
  17365.    system("echo Sample Program > sample.dat");
  17366.  
  17367.    if (-1 == (fh = _open("sample.dat",O_RDWR | O_APPEND)))
  17368.    {
  17369.       perror("Unable to open sample.dat.");
  17370.       return 1;
  17371.    }
  17372.  
  17373.    if (7 != _read(fh,buffer,7))
  17374.    {
  17375.       perror("Unable to read from sample.dat.");
  17376.       _close(fh);
  17377.       return 1;
  17378.    }
  17379.  
  17380.    printf("Successfully read in the following:\n%s\n ",buffer);
  17381.  
  17382.    _close(fh);
  17383.    return 0;
  17384.  
  17385. /*****************  The expected output is:  ****************************
  17386.  
  17387.       Creating sample.dat.
  17388.       Successfully read in the following:
  17389.       Sample
  17390. */
  17391. }
  17392.  
  17393.  
  17394. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17395.  
  17396. o _creat - Create New File 
  17397. o fread  - Read Items 
  17398. o _open - Open File 
  17399. o _sopen - Open Shared File 
  17400. o _write - Writes from Buffer to File 
  17401. o io.h 
  17402.  
  17403.  
  17404. ΓòÉΓòÉΓòÉ 6.184. realloc  - Change Reserved Storage Block Size ΓòÉΓòÉΓòÉ
  17405.  
  17406.  
  17407. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17408.  
  17409. #include <stdlib.h>  /* also defined in <malloc.h> */
  17410.  
  17411. void *realloc(void *ptr, size_t size);
  17412.  
  17413.  
  17414. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17415.  
  17416. Language Level: ANSI, SAA , Extension 
  17417.  
  17418. The realloc function changes the size of a previously reserved storage block. 
  17419. The ptr argument points to the beginning of the block.  The size argument gives 
  17420. the new size of the block, in bytes.  The contents of the block are unchanged 
  17421. up to the shorter of the new and old sizes. 
  17422.  
  17423. If the ptr is NULL, realloc reserves a block of storage of size bytes. It does 
  17424. not necessarily give all bits of each element an initial value of 0. 
  17425.  
  17426. If size is 0 and the ptr is not NULL, the storage allocated to ptr is freed and 
  17427. NULL is returned. 
  17428.  
  17429. The realloc function returns a pointer to the reallocated storage block.  The 
  17430. storage location of the block might be moved by the realloc function.  Thus, 
  17431. the ptr argument to realloc is not necessarily the same as the return value. 
  17432.  
  17433. The return value is NULL if size is 0. If there is not enough storage to expand 
  17434. the block to the given size, the original block is unchanged and NULL is 
  17435. returned. 
  17436.  
  17437. The storage to which the return value points is guaranteed to be aligned for 
  17438. storage of any type of object. 
  17439.  
  17440. Example of realloc 
  17441.  
  17442.  
  17443. ΓòÉΓòÉΓòÉ <hidden> Example of realloc ΓòÉΓòÉΓòÉ
  17444.  
  17445. /************************************************************************
  17446. *
  17447.  
  17448. This example allocates storage for the prompted size of array and then uses 
  17449. realloc to reallocate the block to hold the new size of the array. The contents 
  17450. of the array are printed after each allocation. 
  17451.  
  17452.                                                                         *
  17453. ************************************************************************/
  17454.  
  17455. #include <stdio.h>
  17456. #include <stdlib.h>
  17457.  
  17458. int main(void)
  17459. {
  17460.   long * array;    /* start of the array */
  17461.   long * ptr;      /* pointer to array   */
  17462.   int    i;        /* index variable     */
  17463.   int  num1, num2; /* number of entries of the array */
  17464.  
  17465.   void print_array( long *ptr_array, int size);
  17466.  
  17467.   printf( "Enter the size of the array\n" );
  17468.   scanf( "%i", &num1 );
  17469.  
  17470.   /* allocate num1 entries using malloc() */
  17471.   if ( (array = malloc( num1 * sizeof( long ))) != NULL )
  17472.   {
  17473.      for ( ptr = array, i = 0; i < num1 ; ++i ) /* assign values */
  17474.         *ptr++ = i;
  17475.      print_array( array, num1 );
  17476.      printf("\n");
  17477.   }
  17478.   else { /*  malloc error  */
  17479.     perror( "Out of storage" );
  17480.     abort();
  17481.   }
  17482.  
  17483.   /* Change the size of the array ... */
  17484.   printf( "Enter the size of the new array\n" );
  17485.   scanf( "%i", &num2);
  17486.  
  17487.   if ( (array = realloc( array, num2* sizeof( long ))) != NULL )
  17488.   {
  17489.      for ( ptr = array + num1, i = num1; i <= num2; ++i )
  17490.         *ptr++ = i + 2000;  /* assign values to new elements */
  17491.      print_array( array, num2 );
  17492.   }
  17493.  
  17494.   else { /* realloc error */
  17495.     perror( "Out of storage" );
  17496.     abort();
  17497.   }
  17498. }
  17499.  
  17500. void print_array( long  * ptr_array, int size )
  17501. {
  17502.   int i;
  17503.   long * index = ptr_array;
  17504.  
  17505.   printf("The array of size %d is:\n", size);
  17506.   for ( i = 0; i < size; ++i )           /* print the array out    */
  17507.     printf( "  array[ %i ] = %li\n", i, ptr_array[i] );
  17508. }
  17509.  
  17510. /******************  If the initial value entered  *********************
  17511. **************  is 2 and the second value entered is 4,  ****************
  17512. *******************  then the expected output is:  ****************
  17513.  
  17514. Enter the size of the array
  17515. The array of size 2 is:
  17516.   array[ 0 ] = 0
  17517.   array[ 1 ] = 1
  17518.  
  17519. Enter the size of the new array
  17520. The array of size 4 is:
  17521.   array[ 0 ] = 0
  17522.   array[ 1 ] = 1
  17523.   array[ 2 ] = 2002
  17524.   array[ 3 ] = 2003
  17525. */
  17526.  
  17527.  
  17528. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17529.  
  17530. o calloc  - Reserve and Initialize Storage 
  17531. o _debug_realloc - Change Reserved Storage Block Size 
  17532. o free  - Release Storage Blocks 
  17533. o malloc  - Reserve Storage Block 
  17534. o _msize - Return Number of Bytes Allocated 
  17535. o _trealloc - Reallocate Tiled Storage Block 
  17536. o malloc.h 
  17537. o stdlib.h 
  17538.  
  17539.  
  17540. ΓòÉΓòÉΓòÉ 6.185. remove  - Delete File ΓòÉΓòÉΓòÉ
  17541.  
  17542.  
  17543. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17544.  
  17545. #include <stdio.h>
  17546.  
  17547. int remove(const char *filename);
  17548.  
  17549.  
  17550. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17551.  
  17552. Language Level: ANSI, SAA 
  17553.  
  17554. The remove function deletes the file specified by filename. The remove function 
  17555. returns the value 0 if it successfully deletes the file.  A return value of 
  17556. nonzero indicates an error. 
  17557.  
  17558. Note:  You cannot remove a nonexistent file or a file that is open. 
  17559.  
  17560. Example of remove 
  17561.  
  17562.  
  17563. ΓòÉΓòÉΓòÉ <hidden> Example of remove ΓòÉΓòÉΓòÉ
  17564.  
  17565. /************************************************************************
  17566. *
  17567.  
  17568. When you invoke this example with a file name, the program attempts to remove 
  17569. that file. It issues a message if an error occurs. 
  17570.  
  17571.                                                                         *
  17572. ************************************************************************/
  17573.  
  17574. #include <stdio.h>
  17575.  
  17576. int main(int argc, char ** argv)
  17577. {
  17578.   if ( argc != 2 )
  17579.     printf( "Usage: %s fn\n", argv[0] );
  17580.   else
  17581.     if ( remove( argv[1] ) != 0 )
  17582.       perror( "Could not remove file" );
  17583. }
  17584.  
  17585.  
  17586. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17587.  
  17588. o fopen  - Open Files 
  17589. o rename  - Rename File 
  17590. o _rmtmp - Remove Temporary Files 
  17591. o _unlink - Delete File 
  17592. o stdio.h 
  17593.  
  17594.  
  17595. ΓòÉΓòÉΓòÉ 6.186. rename  - Rename File ΓòÉΓòÉΓòÉ
  17596.  
  17597.  
  17598. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17599.  
  17600. #include <stdio.h>  /* also defined in <io.h> */
  17601.  
  17602. int rename(const char *oldname, const char *newname);
  17603.  
  17604.  
  17605. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17606.  
  17607. Language Level: ANSI, SAA 
  17608.  
  17609. The rename function renames the file specified by oldname to the name given by 
  17610. newname.  The oldname pointer must specify the name of an existing file.  The 
  17611. newname pointer must not specify the name of an existing file. You cannot 
  17612. rename a file with the name of an existing file. You also cannot rename an open 
  17613. file. 
  17614.  
  17615. The rename function returns 0 if it is successful.  On an error, it returns a 
  17616. nonzero value. 
  17617.  
  17618. Example of rename 
  17619.  
  17620.  
  17621. ΓòÉΓòÉΓòÉ <hidden> Example of rename ΓòÉΓòÉΓòÉ
  17622.  
  17623. /************************************************************************
  17624. *
  17625.  
  17626. This example takes two file names as input and uses rename to change the file 
  17627. name from the first name to the second name. 
  17628.  
  17629.                                                                         *
  17630. ************************************************************************/
  17631.  
  17632. #include <stdio.h>
  17633.  
  17634. int main(int argc, char ** argv )
  17635. {
  17636.   if ( argc != 3 )
  17637.     printf( "Usage: %s old_fn new_fn\n", argv[0] );
  17638.   else if ( rename( argv[1], argv[2] ) != 0 )
  17639.     perror ( "Could not rename file" );
  17640. }
  17641.  
  17642.  
  17643. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17644.  
  17645. o fopen  - Open Files 
  17646. o remove  - Delete File 
  17647. o stdio.h 
  17648.  
  17649.  
  17650. ΓòÉΓòÉΓòÉ 6.187. rewind  - Adjust Current File Position ΓòÉΓòÉΓòÉ
  17651.  
  17652.  
  17653. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17654.  
  17655. #include <stdio.h>
  17656.  
  17657. void rewind(FILE *stream);
  17658.  
  17659.  
  17660. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17661.  
  17662. Language Level: ANSI, SAA 
  17663.  
  17664. The rewind function repositions the file pointer associated with stream to the 
  17665. beginning of the file.  A call to rewind is the same as: 
  17666.  
  17667.    (void) fseek(stream, 0L, SEEK_SET);
  17668.  
  17669. except that rewind also clears the error indicator for the stream. 
  17670.  
  17671. There is no return value. 
  17672.  
  17673. Example of rewind 
  17674.  
  17675.  
  17676. ΓòÉΓòÉΓòÉ <hidden> Example of rewind ΓòÉΓòÉΓòÉ
  17677.  
  17678. /************************************************************************
  17679. *
  17680.  
  17681. This example first opens a file myfile for input and output.  It writes 
  17682. integers to the file, uses rewind to reposition the file pointer to the 
  17683. beginning of the file, and then reads the data back in. 
  17684.  
  17685.                                                                         *
  17686. ************************************************************************/
  17687.  
  17688. #include <stdio.h>
  17689.  
  17690. FILE *stream;
  17691.  
  17692. int data1, data2, data3, data4;
  17693. int main(void)
  17694. {
  17695.    data1 = 1; data2 = -37;
  17696.  
  17697.       /* Place data in the file */
  17698.    stream = fopen("myfile.dat", "w+");
  17699.    fprintf(stream, "%d %d\n", data1, data2);
  17700.  
  17701.       /* Now read the data file */
  17702.    rewind(stream);
  17703.    fscanf(stream, "%d", &data3);
  17704.    fscanf(stream, "%d", &data4);
  17705.    printf("The values read back in are: %d and %d\n",
  17706.        data3, data4);
  17707. }
  17708.  
  17709. /********************  Output should be similar to:  **************
  17710.  
  17711. The values read back in are: 1 and -37
  17712. */
  17713.  
  17714.  
  17715. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17716.  
  17717. o fgetpos  - Get File Position 
  17718. o fseek  - Reposition File Position 
  17719. o fsetpos  - Set File Position 
  17720. o ftell  - Get Current Position 
  17721. o _lseek - Move File Pointer 
  17722. o _tell - Get Pointer Position 
  17723. o stdio.h 
  17724.  
  17725.  
  17726. ΓòÉΓòÉΓòÉ 6.188. _rmdir - Remove Directory ΓòÉΓòÉΓòÉ
  17727.  
  17728.  
  17729. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17730.  
  17731. #include <direct.h>
  17732.  
  17733. int _rmdir(char *pathname);
  17734.  
  17735.  
  17736. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17737.  
  17738. Language Level: Extension 
  17739.  
  17740. The _rmdir function deletes the directory specified by pathname.  The directory 
  17741. must be empty, and it must not be the current working directory or the root 
  17742. directory. 
  17743.  
  17744. The _rmdir function returns the value 0 if the directory is successfully 
  17745. deleted.  A return value of -1 indicates an error, and errno is set to one of 
  17746. the following values: 
  17747.  
  17748. Value          Meaning 
  17749. EACCESS        One of the following has occurred: 
  17750.  
  17751.    o The given path name is not a directory. 
  17752.    o The directory is not empty. 
  17753.    o The directory is read only. 
  17754.    o The directory is the current working directory or root directory being 
  17755.      used by a process. 
  17756. ENOENT         The path name was not found. 
  17757.  
  17758. Example of _rmdir 
  17759.  
  17760.  
  17761. ΓòÉΓòÉΓòÉ <hidden> Example of _rmdir ΓòÉΓòÉΓòÉ
  17762.  
  17763. /************************************************************************
  17764. *
  17765. This example deletes two directories. One is in the root directory and the 
  17766. other one in the current working directory. 
  17767.  
  17768.                                                                         *
  17769. ************************************************************************/
  17770.  
  17771. #include <stdio.h>
  17772. #include <direct.h>
  17773. #include <string.h>
  17774.  
  17775. int main(void)
  17776. {
  17777.     char *dir1, *dir2;
  17778.  
  17779. /*  Create the directory "aleng" in the root directory of the C: drive. */
  17780.     dir1 = "c:\\aleng";
  17781.     if ((_mkdir(dir1)) == 0)
  17782.         printf("%s directory was created.\n",dir1);
  17783.     else
  17784.         printf("%s directory was not created.\n",dir1);
  17785.  
  17786. /*  Create the subdirectory "simon" in the current directory. */
  17787.     dir2 = "simon";
  17788.     if ((_mkdir(dir2)) == 0)
  17789.         printf("%s directory was created.\n",dir2);
  17790.     else
  17791.         printf("%s directory was not created.\n",dir2);
  17792.  
  17793. /*  Remove the directory "aleng" from the root directory
  17794.                    of the C: drive. */
  17795.     printf("Removing directory 'aleng' from the root directory.\n");
  17796.  
  17797.     if (_rmdir(dir1))
  17798.        perror(NULL);
  17799.     else
  17800.        printf("%s directory was removed.\n",dir1);
  17801.  
  17802. /*  Remove the subdirectory "simon" from the current directory. */
  17803.     printf("Removing subdirectory 'simon' from the current directory.\n");
  17804.  
  17805.     if (_rmdir(dir2))
  17806.        perror(NULL);
  17807.     else
  17808.        printf("%s directory was removed.\n",dir2);
  17809.  
  17810.     return 0;
  17811.  
  17812. /*************** The output should be similar to:  ********************
  17813.  
  17814.    c:\aleng directory was created.
  17815.    simon directory was created.
  17816.    Removing directory 'aleng' from the root directory.
  17817.    c:\aleng directory was removed.
  17818.    Removing subdirectory 'simon' from the current directory.
  17819.    simon directory was removed.
  17820. */
  17821. }
  17822.  
  17823.  
  17824. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17825.  
  17826. o _chdir - Change Current Working Directory 
  17827. o _getdcwd - Get Full Path Name of Current Directory 
  17828. o _getcwd - Get Path Name of Current Directory 
  17829. o _mkdir - Create New Directory 
  17830. o direct.h 
  17831.  
  17832.  
  17833. ΓòÉΓòÉΓòÉ 6.189. _rmtmp - Remove Temporary Files ΓòÉΓòÉΓòÉ
  17834.  
  17835.  
  17836. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17837.  
  17838. #include <stdio.h>
  17839.  
  17840. int _rmtmp(void);
  17841.  
  17842.  
  17843. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17844.  
  17845. Language Level: Extension 
  17846.  
  17847. The _rmtmp function closes and deletes all temporary files in all directories 
  17848. that are held open by the calling process. 
  17849.  
  17850. The _rmtmp function returns the number of temporary files removed and deleted. 
  17851.  
  17852. Example of _rmtmp 
  17853.  
  17854.  
  17855. ΓòÉΓòÉΓòÉ <hidden> Example of _rmtmp ΓòÉΓòÉΓòÉ
  17856.  
  17857. /************************************************************************
  17858. *
  17859. This example uses _rmtmp to remove a number of temporary files. 
  17860.  
  17861.                                                                         *
  17862. ************************************************************************/
  17863.  
  17864. #include <stdio.h>
  17865.  
  17866. int main(void)
  17867. {
  17868.     int num;
  17869.     FILE *stream;
  17870.  
  17871.     if ( (stream = tmpfile()) == NULL )
  17872.         printf("Could not open new temporary file\n");
  17873.     else
  17874.     {
  17875.         num = _rmtmp();
  17876.         printf("Number of temporary files removed = %d\n", num);
  17877.     }
  17878.  
  17879.     return 0;
  17880.  
  17881.     /* The expected output is:
  17882.  
  17883.        Number of temporary files removed = 1   */
  17884.  
  17885. }
  17886.  
  17887.  
  17888. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17889.  
  17890. o _flushall - Write Buffers to Files 
  17891. o remove  - Delete File 
  17892. o tmpfile  - Create Temporary File 
  17893. o tmpnam  - Produce Temporary File Name 
  17894. o _unlink - Delete File 
  17895. o stdio.h 
  17896.  
  17897.  
  17898. ΓòÉΓòÉΓòÉ 6.190. _rotl - _rotr - Bit Rotation ΓòÉΓòÉΓòÉ
  17899.  
  17900.  
  17901. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17902.  
  17903. #include <stdlib.h>
  17904.  
  17905. unsigned int _rotl(unsigned int value, int shift);
  17906.  
  17907. unsigned int _rotr(unsigned int value, int shift);
  17908.  
  17909.  
  17910. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17911.  
  17912. Language Level: Extension 
  17913.  
  17914. These functions take a 4-byte integer value and rotate it by shift bits. 
  17915.  
  17916. Note:  Because the size of an int is only 2 bytes in 16-bit compilers, if you 
  17917. are migrating 16-bit programs, some parts of your programs may have to be 
  17918. rewritten if they use this function. 
  17919.  
  17920. Both functions return the rotated value.  There is no error return. 
  17921.  
  17922. Example of _rotl - _rotr 
  17923.  
  17924.  
  17925. ΓòÉΓòÉΓòÉ <hidden> Example of _rotl - _rotr ΓòÉΓòÉΓòÉ
  17926.  
  17927. /************************************************************************
  17928. *
  17929. This example uses _rotr and _rotl with different shift values to rotate the 
  17930. integer value 0x01234567: 
  17931.  
  17932.                                                                         *
  17933. ************************************************************************/
  17934.  
  17935. #include <stdio.h>
  17936. #include <stdlib.h>
  17937.  
  17938. int main(void)
  17939. {
  17940.     unsigned int val = 0X01234567;
  17941.  
  17942.     printf("The value of 0x%8.8lx rotated 4 bits to the left
  17943.              is 0x%8.8lx\n", val, _rotl(val, 4));
  17944.  
  17945.     printf("The value of 0x%8.8lx rotated 16 bits to the right
  17946.              is 0x%8.8lx\n", val, _rotr(val, 16));
  17947.  
  17948.     return 0;
  17949.  
  17950.  
  17951. /***************  The output should be similar to:  ****************
  17952.  
  17953.    The value of 0x01234567 rotated 4 bits to the left is 0x12345670
  17954.    The value of 0x01234567 rotated 16 bits to the right is 0x45670123
  17955. */
  17956. }
  17957.  
  17958.  
  17959. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  17960.  
  17961. o _lrotl - _lrotr - Rotate Bits 
  17962. o _swab - Swap Adjacent Bytes 
  17963. o stdlib.h 
  17964.  
  17965.  
  17966. ΓòÉΓòÉΓòÉ 6.191. scanf  - Read Data ΓòÉΓòÉΓòÉ
  17967.  
  17968.  
  17969. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  17970.  
  17971. #include <stdio.h>
  17972.  
  17973. int scanf(const char *format-string, argument-list);
  17974.  
  17975.  
  17976. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  17977.  
  17978. Language Level: ANSI, SAA, Extension 
  17979.  
  17980. The scanf function reads data from the standard input stream stdin into the 
  17981. locations given by each entry in argument-list.  Each argument must be a 
  17982. pointer to a variable with a type that corresponds to a type specifier in 
  17983. format-string.  The format-string controls the interpretation of the input 
  17984. fields, and is a multibyte character string beginning and ending in its initial 
  17985. shift state. 
  17986.  
  17987. The format-string can contain one or more of the following: 
  17988.  
  17989. o White-space characters, as specified by isspace (such as blanks and new-line 
  17990.   characters). A white-space character causes scanf to read, but not to store, 
  17991.   all consecutive white-space characters in the input up to the next character 
  17992.   that is not white space.  One white-space character in format-string matches 
  17993.   any combination of white-space characters in the input. 
  17994.  
  17995. o Characters that are not white space, except for the percent sign character 
  17996.   (%).  A non-white-space character causes scanf to read, but not to store, a 
  17997.   matching non-white-space character.  If the next character in stdin does not 
  17998.   match, scanf ends. 
  17999.  
  18000. o Format specifications, introduced by the percent sign (%).  A format 
  18001.   specification causes scanf to read and convert characters in the input into 
  18002.   values of a specified type.  The value is assigned to an argument in the 
  18003.   argument list. 
  18004.  
  18005. The scanf function reads format-string from left to right.  Characters outside 
  18006. of format specifications are expected to match the sequence of characters in 
  18007. stdin;  the matched characters in stdin are scanned but not stored.  If a 
  18008. character in stdin conflicts with format-string, scanf ends.  The conflicting 
  18009. character is left in stdin as if it had not been read. 
  18010.  
  18011. When the first format specification is found, the value of the first input 
  18012. field is converted according to the format specification and stored in the 
  18013. location specified by the first entry in argument-list.  The second format 
  18014. specification converts the second input field and stores it in the second entry 
  18015. in argument-list, and so on through the end of format-string. 
  18016.  
  18017. An input field is defined as all characters up to the first white-space 
  18018. character (space, tab, or new line), up to the first character that cannot be 
  18019. converted according to the format specification, or until the field width is 
  18020. reached, whichever comes first.  If there are too many arguments for the format 
  18021. specifications, the extra arguments are ignored.  The results are undefined if 
  18022. there are not enough arguments for the format specifications. 
  18023.  
  18024. A format specification has the following form: 
  18025.  
  18026. ΓöÇΓöÇ%ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇtypeΓöÇΓöÇ
  18027.     Γöé   Γöé  Γöé     Γöé  Γöé   Γöé
  18028.     ΓööΓöÇΓöÇ*ΓöÇΓöÇΓöÿ  ΓööΓöÇΓöÇwidthΓöÇΓöÇΓöÿ  Γö£ΓöÇΓöÇhΓöÇΓöÇΓöñ
  18029.                Γöé   Γöé
  18030.                Γö£ΓöÇΓöÇlΓöÇΓöÇΓöñ
  18031.                Γöé   Γöé
  18032.                ΓööΓöÇΓöÇLΓöÇΓöÇΓöÿ
  18033.  
  18034. Each field of the format specification is a single character or a number 
  18035. signifying a particular format option.  The type character, which appears after 
  18036. the last optional format field, determines whether the input field is 
  18037. interpreted as a character, a string, or a number.  The simplest format 
  18038. specification contains only the percent sign and a type character (for example, 
  18039. %s). 
  18040.  
  18041. Each field of the format specification is discussed in Format Specification 
  18042. Fields. If a percent sign (%) is followed by a character that has no meaning as 
  18043. a format control character, that character and following characters up to the 
  18044. next percent sign are treated as an ordinary sequence of characters;  that is, 
  18045. a sequence of characters that must match the input.  For example, to specify a 
  18046. percent-sign character, use %%. 
  18047.  
  18048. The scanf function scans each input field character by character.  It might 
  18049. stop reading a particular input field either before it reaches a space 
  18050. character, when the specified width is reached, or when the next character 
  18051. cannot be converted as specified.  When a conflict occurs between the 
  18052. specification and the input character, the next input field begins at the first 
  18053. unread character.  The conflicting character, if there was one, is considered 
  18054. unread and is the first character of the next input field or the first 
  18055. character in subsequent read operations on stdin. 
  18056.  
  18057. In extended mode, scanf also reads in the strings the strings "INFINITY", 
  18058. "INF", and "NAN" (in upper or lowercase) and converts them to the corresponding 
  18059. floating-point value.  The sign of the value is determined by the format 
  18060. specification. See Infinity and NaN Support for more information on infinity 
  18061. and NaN values. 
  18062.  
  18063. The scanf function returns the number of fields that were successfully 
  18064. converted and assigned.  The return value does not include fields that were 
  18065. read but not assigned. 
  18066.  
  18067. The return value is EOF for an attempt to read at end-of-file if no conversion 
  18068. was performed. A return value of 0 means that no fields were assigned. 
  18069.  
  18070. Example of scanf 
  18071.  
  18072.  
  18073. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18074.  
  18075. o fscanf  - Read Formatted Data 
  18076. o printf  - Formatted Print 
  18077. o sscanf  - Read Data 
  18078. o Infinity and NaN Support 
  18079. o stdio.h 
  18080.  
  18081.  
  18082. ΓòÉΓòÉΓòÉ 6.191.1. Format Specification Fields ΓòÉΓòÉΓòÉ
  18083.  
  18084. The scanf format specification fields are described below. 
  18085.  
  18086.  
  18087. An asterisk (*) following the percent sign suppresses assignment of the next 
  18088. input field, which is interpreted as a field of the specified type.  The field 
  18089. is scanned but not stored. 
  18090.  
  18091. width 
  18092.  
  18093. The width is a positive decimal integer controlling the maximum number of 
  18094. characters to be read from stdin.  No more than width characters are converted 
  18095. and stored at the corresponding argument.  Fewer than width characters are read 
  18096. if a white-space character (space, tab, or new line), or a character that 
  18097. cannot be converted according to the given format occurs before width is 
  18098. reached. 
  18099.  
  18100. h, l, L 
  18101.  
  18102. The optional prefix l shows that you use the long version of the following 
  18103. type, while the prefix h indicates that the short version is to be used.  The 
  18104. corresponding argument should point to a long or double object (for the l 
  18105. character), a long double object (for the L character), or a short object (with 
  18106. the h character).  The l and h modifiers can be used with the d, i, o, x, and u 
  18107. type characters. The l modifier can also be used with the e, f, and g type 
  18108. characters.  The L modifier can be used with the e, f and g type characters. 
  18109. The l and h modifiers are ignored if specified for any other type. Note that 
  18110. the l modifier is also used with the c and s characters to indicate a multibyte 
  18111. character or string. 
  18112.  
  18113. type 
  18114.  
  18115. The type characters and their meanings are in the following table: 
  18116.  
  18117. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  18118. Γöé CHAR-  Γöé TYPE OF INPUT EXPECTED      Γöé TYPE OF ARGUMENT         Γöé
  18119. Γöé ACTER  Γöé                  Γöé                  Γöé
  18120. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  18121. Γöé "d"   Γöé Decimal integer          Γöé Pointer to "int"         Γöé
  18122. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  18123. Γöé "o"   Γöé Octal integer           Γöé Pointer to "unsigned int"     Γöé
  18124. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  18125. Γöé "x",  Γöé Hexadecimal integer        Γöé Pointer to "unsigned int"     Γöé
  18126. Γöé "X"   Γöé                  Γöé                  Γöé
  18127. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  18128. Γöé "i"   Γöé Decimal, hexadecimal, or octal  Γöé Pointer to "int"         Γöé
  18129. Γöé     Γöé integer              Γöé                  Γöé
  18130. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  18131. Γöé "u"   Γöé Unsigned decimal integer     Γöé Pointer to "unsigned int"     Γöé
  18132. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  18133. Γöé "e, f, Γöé Floating-point value consisting  Γöé Pointer to "float"        Γöé
  18134. Γöé g"   Γöé of an optional sign (+ or -);  a Γöé                  Γöé
  18135. Γöé     Γöé series of one or more decimal   Γöé                  Γöé
  18136. Γöé "E, G" Γöé digits possibly containing a   Γöé                  Γöé
  18137. Γöé     Γöé decimal point;  and an optional  Γöé                  Γöé
  18138. Γöé     Γöé exponent (e or E) followed by a  Γöé                  Γöé
  18139. Γöé     Γöé possibly signed integer value   Γöé                  Γöé
  18140. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  18141. Γöé "d(n,p)Γöé Packed decimal value consisting  Γöé Pointer to "decimal(n,p)".    Γöé
  18142. Γöé     Γöé of an optional sign (+ or -);   Γöé                  Γöé
  18143. Γöé     Γöé then a nonempty sequence of    Γöé                  Γöé
  18144. Γöé     Γöé digits optionally a series of   Γöé                  Γöé
  18145. Γöé     Γöé one or more decimal digits pos-  Γöé                  Γöé
  18146. Γöé     Γöé sibly containing a decimal    Γöé                  Γöé
  18147. Γöé     Γöé point, but not a decimal suffix. Γöé                  Γöé
  18148. Γöé     Γöé The subject sequence is defined  Γöé                  Γöé
  18149. Γöé     Γöé as the longest initial subse-   Γöé                  Γöé
  18150. Γöé     Γöé quence of the input string,    Γöé                  Γöé
  18151. Γöé     Γöé starting with the first non-   Γöé                  Γöé
  18152. Γöé     Γöé white-space character, in the   Γöé                  Γöé
  18153. Γöé     Γöé expected form.  It contains no  Γöé                  Γöé
  18154. Γöé     Γöé characters if the input string  Γöé                  Γöé
  18155. Γöé     Γöé is empty or consists entirely of Γöé                  Γöé
  18156. Γöé     Γöé white space, or if the first   Γöé                  Γöé
  18157. Γöé     Γöé non-white-space character is   Γöé                  Γöé
  18158. Γöé     Γöé anything other than a sign, a   Γöé                  Γöé
  18159. Γöé     Γöé digit, or a decimal point char-  Γöé                  Γöé
  18160. Γöé     Γöé acter.              Γöé                  Γöé
  18161. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  18162. Γöé "c"   Γöé Character;  white-space charac-  Γöé Pointer to "char" large enough  Γöé
  18163. Γöé     Γöé ters that are ordinarily skipped Γöé for input field          Γöé
  18164. Γöé     Γöé are read when "c" is specified  Γöé                  Γöé
  18165. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  18166. Γöé "s"   Γöé String              Γöé Pointer to character array large Γöé
  18167. Γöé     Γöé                  Γöé enough for input field plus a   Γöé
  18168. Γöé     Γöé                  Γöé terminating null character    Γöé
  18169. Γöé     Γöé                  Γöé ("\0"), which is automatically  Γöé
  18170. Γöé     Γöé                  Γöé appended             Γöé
  18171. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  18172. Γöé "n"   Γöé No input read from stream or   Γöé Pointer to "int", into which is  Γöé
  18173. Γöé     Γöé buffer              Γöé stored the number of characters  Γöé
  18174. Γöé     Γöé                  Γöé successfully read from the    Γöé
  18175. Γöé     Γöé                  Γöé stream or buffer up to that    Γöé
  18176. Γöé     Γöé                  Γöé point in the call to "scanf"   Γöé
  18177. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  18178. Γöé "p"   Γöé Pointer to "void" converted to  Γöé Pointer to "void"         Γöé
  18179. Γöé     Γöé series of characters       Γöé                  Γöé
  18180. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  18181. Γöé "lc"  Γöé Multibyte character constant   Γöé Pointer to "wchar_t"       Γöé
  18182. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  18183. Γöé "ls"  Γöé Multibyte string constant     Γöé Pointer to "wchar_t" string    Γöé
  18184. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  18185.  
  18186. To read strings not delimited by space characters, substitute a set of 
  18187. characters in brackets ([ ]) for the s (string) type character.  The 
  18188. corresponding input field is read up to the first character that does not 
  18189. appear in the bracketed character set.  If the first character in the set is a 
  18190. caret (^), the effect is reversed:  the input field is read up to the first 
  18191. character that does appear in the rest of the character set. 
  18192.  
  18193. To store a string without storing an ending null character (\0), use the 
  18194. specification %ac, where a is a decimal integer.  In this instance, the c type 
  18195. character means that the argument is a pointer to a character array.  The next 
  18196. a characters are read from the input stream into the specified location, and no 
  18197. null character is added. 
  18198.  
  18199. The input for a %x format specifier is interpreted as a hexadecimal number. 
  18200.  
  18201.  
  18202. ΓòÉΓòÉΓòÉ <hidden> Example of scanf ΓòÉΓòÉΓòÉ
  18203.  
  18204. /************************************************************************
  18205. *
  18206.  
  18207. This example scans various types of data: 
  18208.  
  18209.                                                                         *
  18210. ************************************************************************/
  18211.  
  18212. #include <stdio.h>
  18213.  
  18214. int main(void)
  18215. {
  18216.    int i;
  18217.    float fp;
  18218.    char c, s[81];
  18219.  
  18220.    printf("Enter an integer, a real number, a character "
  18221.           "and a string : \n");
  18222.    if (scanf("%d %f %c %s", &i, &fp, &c, s) != 4)
  18223.       printf("Not all of the fields were not assigned\n");
  18224.    else
  18225.    {
  18226.       printf("integer = %d\n", i);
  18227.       printf("real number = %f\n", fp);
  18228.       printf("character = %c\n", c);
  18229.       printf("string = %s\n",s);
  18230.    }
  18231. }
  18232.  
  18233. /*****************  If input is: 12 2.5 a yes,  *******************
  18234. **************  then output should be similar to:  ****************
  18235.  
  18236. Enter an integer, a real number, a character and a string :
  18237. integer = 12
  18238. real number = 2.500000
  18239. character = a
  18240. string = yes
  18241. */
  18242.  
  18243. /************************************************************************
  18244. *
  18245. This example converts a hexadecimal integer to a decimal integer.  The while 
  18246. loop ends if the input value is not a hexadecimal integer. 
  18247.  
  18248.                                                                         *
  18249. ************************************************************************/
  18250.  
  18251. #include <stdio.h>
  18252.  
  18253. int main(void)
  18254. {
  18255.    int number;
  18256.  
  18257.    printf("Enter a hexadecimal number or anything else to quit:\n");
  18258.    while (scanf("%x",&number))
  18259.       {
  18260.       printf("Hexadecimal Number = %x\n",number);
  18261.       printf("Decimal Number     = %d\n",number);
  18262.       }
  18263. }
  18264.  
  18265. /***************  If input is: 0x231 0xf5e 0x1 q,  ****************
  18266. ****************  then output should be similar to:  **************
  18267.  
  18268. Enter a hexadecimal number or anything else to quit:
  18269. Hexadecimal Number = 231
  18270. Decimal Number     = 561
  18271. Hexadecimal Number = f5e
  18272. Decimal Number     = 3934
  18273. Hexadecimal Number = 1
  18274. Decimal Number     = 1
  18275. */
  18276.  
  18277.  
  18278. ΓòÉΓòÉΓòÉ 6.192. _searchenv - Search for File ΓòÉΓòÉΓòÉ
  18279.  
  18280.  
  18281. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18282.  
  18283. #include <stdlib.h>
  18284.  
  18285. void _searchenv(char *name, char *env_var, char *path);
  18286.  
  18287.  
  18288. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18289.  
  18290. Language Level: Extension 
  18291.  
  18292. The _searchenv function searches for the target file in the specified domain. 
  18293. The env_var variable can be any environment variable that specifies a list of 
  18294. directory paths, such as PATH, LIB, INCLUDE, or other user-defined variables. 
  18295. Most often, it is PATH, causing a search for name in all directories specified 
  18296. in the PATH variable. 
  18297.  
  18298. The routine first searches for the file in the current working directory.  If 
  18299. it does not find the file, it next looks through the directories specified by 
  18300. the environment variable. 
  18301.  
  18302. If the target file is found in one of the directories, the newly created path 
  18303. is copied into the buffer that path points to.  You must ensure sufficient 
  18304. space for the constructed path name.  If the target file is not found, path 
  18305. contains an empty null-terminated string. 
  18306.  
  18307. There is no return value. 
  18308.  
  18309. Example of _searchenv 
  18310.  
  18311.  
  18312. ΓòÉΓòÉΓòÉ <hidden> Example of _searchenv ΓòÉΓòÉΓòÉ
  18313.  
  18314. /************************************************************************
  18315. *
  18316.  
  18317. This example searches for the files searchen.c and cmd.exe. 
  18318.  
  18319.                                                                         *
  18320. ************************************************************************/
  18321.  
  18322. #include <stdio.h>
  18323. #include <stdlib.h>
  18324.  
  18325. int main(void)
  18326. {
  18327.     char path_buffer [_MAX_PATH];
  18328.  
  18329.     _searchenv ("cmd.exe", "PATH", path_buffer);
  18330.     printf ("path: %s\n", path_buffer);
  18331.  
  18332.     _searchenv ("searchen.c", "DPATH", path_buffer);
  18333.     printf ("path: %s\n", path_buffer);
  18334.  
  18335.     return 0;
  18336.  
  18337. /*****************  Output  ************************
  18338. *  If the first path that contains cmd.exe is      *
  18339. *  in the C: environment and this program is       *
  18340. *  not run from another directory with a cmd.exe   *
  18341. *  file, the first line of the output should be    *
  18342. *  similar to:                                     *
  18343.  
  18344.    path: C:\OS2\cmd.exe                                                    */
  18345.  
  18346.  
  18347. *  Assuming the file searchen.c does not exist in  *
  18348. *  the current directory or any of the directories *
  18349. *  in the environment, the next line of the output *
  18350. *  should be similar to:   *
  18351.  
  18352.    path:
  18353. */
  18354. }
  18355.  
  18356.  
  18357. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18358.  
  18359. o getenv  - Search for Environment Variables 
  18360. o _putenv - Modify Environment Variables 
  18361. o stdlib.h 
  18362.  
  18363.  
  18364. ΓòÉΓòÉΓòÉ 6.193. setbuf  - Control Buffering ΓòÉΓòÉΓòÉ
  18365.  
  18366.  
  18367. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18368.  
  18369. #include <stdio.h>
  18370.  
  18371. void setbuf(FILE *stream, char *buffer);
  18372.  
  18373.  
  18374. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18375.  
  18376. Language Level: ANSI, SAA 
  18377.  
  18378. The setbuf function allows you to control buffering for the specified stream. 
  18379. The stream pointer must refer to an open file before any I/O or repositioning 
  18380. has been done. 
  18381.  
  18382. If the buffer argument is NULL, the stream is unbuffered.  If not, the buffer 
  18383. must point to a character array of length BUFSIZ, which is the buffer size 
  18384. defined in the stdio.h header file.  The system uses the buffer, which you 
  18385. specify, for input/output buffering instead of the default system-allocated 
  18386. buffer for the given stream. 
  18387.  
  18388. The setvbuf function is more flexible than setbuf. 
  18389.  
  18390. There is no return value. 
  18391.  
  18392. Example of setbuf 
  18393.  
  18394.  
  18395. ΓòÉΓòÉΓòÉ <hidden> Example of setbuf ΓòÉΓòÉΓòÉ
  18396.  
  18397. /************************************************************************
  18398. *
  18399.  
  18400. This example opens the file myfile for writing. It then calls the setbuf 
  18401. function to establish a buffer of length BUFSIZ. When string is written to the 
  18402. stream, the buffer buf is used and contains the string before it is flushed to 
  18403. the file. 
  18404.  
  18405.                                                                         *
  18406. ************************************************************************/
  18407.  
  18408. #include <stdio.h>
  18409.  
  18410. int main(void)
  18411. {
  18412.    char buf[BUFSIZ];
  18413.    char string[] = "hello world";
  18414.    FILE *stream;
  18415.  
  18416.    memset(buf,'\0',BUFSIZ);  /* initialize buf to null characters */
  18417.  
  18418.    stream = fopen("myfile.dat", "wb");
  18419.  
  18420.    setbuf(stream,buf);       /* set up buffer */
  18421.  
  18422.    fwrite(string, sizeof(string), 1, stream);
  18423.  
  18424.    printf("%s\n",buf);       /* string is found in buf now */
  18425.  
  18426.    fclose(stream);           /* buffer is flushed out to myfile.dat */
  18427. }
  18428.  
  18429.  
  18430. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18431.  
  18432. o fclose  - Close Stream 
  18433. o fflush  - Write Buffer to File 
  18434. o _flushall - Write Buffers to Files 
  18435. o fopen  - Open Files 
  18436. o setvbuf  - Control Buffering 
  18437. o stdio.h 
  18438.  
  18439.  
  18440. ΓòÉΓòÉΓòÉ 6.194. _set_crt_msg_handle - Change Runtime Message Output Handle ΓòÉΓòÉΓòÉ
  18441.  
  18442.  
  18443. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18444.  
  18445. #include <stdio.h>
  18446.  
  18447. int _set_crt_msg_handle(int fh);
  18448.  
  18449.  
  18450. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18451.  
  18452. Language Level: Extension 
  18453.  
  18454. The _set_crt_msg_handle function changes the file handle to which runtime 
  18455. messages are sent, which is usually file handle 2, to fh. Runtime messages 
  18456. include exception handling messages and output from debug memory management 
  18457. routines. 
  18458.  
  18459. Use _set_crt_msg_handle to trap runtime message output in applications where 
  18460. handle 2 is not defined, such as Presentation Manager applications. 
  18461.  
  18462. The file handle fh must be a writable file or pipe handle. Set fh only for the 
  18463. current library environment. 
  18464.  
  18465. The _set_crt_msg_handle function returns the handle to be used for runtime 
  18466. message output. If an handle that is not valid is passed as an argument, it is 
  18467. ignored and no change takes place. 
  18468.  
  18469. Example of _set_crt_msg_handle 
  18470.  
  18471.  
  18472. ΓòÉΓòÉΓòÉ <hidden> Example of _set_crt_msg_handle ΓòÉΓòÉΓòÉ
  18473.  
  18474. /************************************************************************
  18475. *
  18476.  
  18477. This example causes an exception by dereferencing a null pointer and uses 
  18478. _set_crt_msg_handle to send the exception messages to the file crt.out. 
  18479.  
  18480.                                                                         *
  18481. ************************************************************************/
  18482.  
  18483.  
  18484. #include <io.h>
  18485. #include <stdio.h>
  18486. #include <fcntl.h>
  18487. #include <sys\stat.h>
  18488.  
  18489. main()
  18490. {
  18491.  
  18492.  int fh;
  18493.  char *p=NULL;
  18494.  
  18495.  if (-1 == (fh = open("crt.out",O_CREAT|O_TRUNC|O_RDWR,
  18496.                       S_IREAD|S_IWRITE)))
  18497.  {
  18498.    perror("Unable to open crt.out");
  18499.    return 1;
  18500.  }
  18501.  
  18502.  /* change file handle where messages are sent */
  18503.  if (_set_crt_msg_handle(fh)!=fh)
  18504.  {
  18505.    perror("could not change msg handle");
  18506.    return 1;
  18507.  }
  18508.  
  18509.  *p='x';   /* cause an exception, output should be in crt.out */
  18510.  
  18511.  if (-1 == close(fh))
  18512.  {
  18513.    perror("Unable to close crt.out");
  18514.    return(1);
  18515.  }
  18516.  
  18517.  return(0);
  18518.  
  18519. }
  18520.  
  18521.  
  18522. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18523.  
  18524. o _open - Open File 
  18525. o _fileno - Determine File Handle 
  18526. o _sopen - Open Shared File 
  18527. o stdio.h 
  18528.  
  18529.  
  18530. ΓòÉΓòÉΓòÉ 6.195. setjmp  - Preserve Environment ΓòÉΓòÉΓòÉ
  18531.  
  18532.  
  18533. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18534.  
  18535. #include <setjmp.h>
  18536.  
  18537. int setjmp(jmp_buf env);
  18538.  
  18539.  
  18540. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18541.  
  18542. Language Level: ANSI, SAA 
  18543.  
  18544. The setjmp macro saves a stack environment that can subsequently be restored by 
  18545. longjmp.  The setjmp macro and longjmp function provide a way to perform a 
  18546. nonlocal goto. They are often used in signal handlers. 
  18547.  
  18548. A call to setjmp causes it to save the current stack environment in env.  A 
  18549. subsequent call to longjmp restores the saved environment and returns control 
  18550. to a point corresponding to the setjmp call.  The values of all variables 
  18551. (except register variables) accessible to the function receiving control 
  18552. contain the values they had when longjmp was called.  The values of register 
  18553. variables are unpredictable.  Nonvolatile auto variables that are changed 
  18554. between calls to setjmp and longjmp are also unpredictable. 
  18555.  
  18556. The setjmp macro returns the value 0 after saving the stack environment.  If 
  18557. setjmp returns as a result of a longjmp call, it returns the value argument of 
  18558. longjmp, or 1 if the value argument of longjmp is 0.  There is no return value. 
  18559.  
  18560. Example of setjmp 
  18561.  
  18562.  
  18563. ΓòÉΓòÉΓòÉ <hidden> Example of setjmp ΓòÉΓòÉΓòÉ
  18564.  
  18565. /************************************************************************
  18566. *
  18567.  
  18568. This example stores the stack environment at the statement: 
  18569.  
  18570.   if(setjmp(mark) != 0) ...
  18571.  
  18572. When the system first performs the if statement, it saves the environment in 
  18573. mark and sets the condition to FALSE because setjmp returns a 0 when it saves 
  18574. the environment. The program prints the message: 
  18575.  
  18576.   setjmp has been called
  18577.  
  18578. The subsequent call to function p tests for a local error condition, which can 
  18579. cause it to perform the longjmp function.  Then, control returns to the 
  18580. original setjmp function using the environment saved in mark.  This time the 
  18581. condition is TRUE because -1 is the return value from the longjmp function. The 
  18582. program then performs the statements in the block and prints: 
  18583.  
  18584.   longjmp has been called
  18585.  
  18586. Then the program calls the recover function and exits. 
  18587.  
  18588.                                                                         *
  18589. ************************************************************************/
  18590.  
  18591. #include <stdio.h>
  18592. #include <setjmp.h>
  18593.  
  18594. jmp_buf mark;
  18595.  
  18596. void p(void);
  18597. void recover(void);
  18598.  
  18599. int main(void)
  18600. {
  18601.    if (setjmp(mark) != 0)
  18602.    {
  18603.       printf("longjmp has been called\n");
  18604.       recover();
  18605.       exit(1);
  18606.    }
  18607.    printf("setjmp has been called\n");
  18608.    .
  18609.    .
  18610.    .
  18611.    p();
  18612.    .
  18613.    .
  18614.    .
  18615. }
  18616.  
  18617. void p(void)
  18618. {
  18619.    int error = 0;
  18620.    .
  18621.    .
  18622.    .
  18623.    error = 9;
  18624.    .
  18625.    .
  18626.    .
  18627.    if (error != 0)
  18628.       longjmp(mark, -1);
  18629.    .
  18630.    .
  18631.    .
  18632. }
  18633.  
  18634. void recover(void)
  18635. {
  18636.    .
  18637.    .
  18638.    .
  18639. }
  18640.  
  18641.  
  18642. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18643.  
  18644. o longjmp  - Restore Stack Environment 
  18645. o goto 
  18646. o volitile and constant Qualifiers 
  18647. o auto Storage Class Specifier 
  18648. o setjmp.h 
  18649.  
  18650.  
  18651. ΓòÉΓòÉΓòÉ 6.196. setlocale  - Set Locale ΓòÉΓòÉΓòÉ
  18652.  
  18653.  
  18654. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18655.  
  18656. #include <locale.h>
  18657.  
  18658. char *setlocale(int category, const char *locale);
  18659.  
  18660.  
  18661. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18662.  
  18663. Language Level: ANSI, SAA 
  18664.  
  18665. The setlocale function changes or queries variables, defined in the locale.h 
  18666. header file, that indicate location.  The values for category are listed below. 
  18667.  
  18668. Category            Purpose 
  18669. LC_ALL              Names entire locale of program. 
  18670. LC_COLLATE          Affects behavior of the strcoll and strxfrm functions. 
  18671. LC_CTYPE            Affects behavior of the character handling functions. 
  18672. LC_MONETARY         Affects monetary information returned by localeconv. 
  18673. LC_NUMERIC          Affects the decimal-point character for the formatted 
  18674.                     input/output and string conversion functions, and the 
  18675.                     nonmonetary formatting information returned by the 
  18676.                     localeconv function. 
  18677. LC_TIME             Affects behavior of the strftime function. 
  18678. LC_TOD              Affects the behavior of the time functions. 
  18679.  
  18680. You can set the value of locale to "C", "",LC_C, LC_C_GERMANY, LC_C_FRANCE, 
  18681. LC_C_SPAIN, LC_C_ITALY, LC_C_JAPAN, LC_C_USA or LC_C_UK. A locale value of "C" 
  18682. indicates the default C environment.  A locale value of "" tells setlocale to 
  18683. use the default locale for the implementation. 
  18684.  
  18685. The setlocale function returns a pointer to the string associated with the 
  18686. specified category for the new locale.  The string can be used on a subsequent 
  18687. call to restore that part of the program's locale. 
  18688.  
  18689. Note:  Because the string to which a successful call to setlocale points may be 
  18690. overwritten by subsequent calls to the setlocale function, you should copy the 
  18691. string if you plan to use it later. 
  18692.  
  18693. On error, the setlocale function returns NULL and the program's locale is not 
  18694. changed. 
  18695.  
  18696. To query the locale, give a NULL as the second parameter.  For example, to 
  18697. query all the categories of your locale, enter the following statement: 
  18698.  
  18699.     char *string = setlocale(LC_ALL, NULL);
  18700.  
  18701. Example of setlocale 
  18702.  
  18703.  
  18704. ΓòÉΓòÉΓòÉ <hidden> Example of setlocale ΓòÉΓòÉΓòÉ
  18705.  
  18706. /************************************************************************
  18707. *
  18708.  
  18709. This example sets the locale of the program to be LC_C_FRANCE and prints the 
  18710. string that is associated with the locale. 
  18711.  
  18712.                                                                         *
  18713. ************************************************************************/
  18714.  
  18715. #include <stdio.h>
  18716. #include <locale.h>
  18717.  
  18718. char *string;
  18719.  
  18720. int main(void)
  18721. {
  18722.    string = setlocale(LC_ALL, LC_C_FRANCE);
  18723.    if (string != NULL)
  18724.       printf(" %s \n",string);
  18725. }
  18726.  
  18727.  
  18728. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18729.  
  18730. o getenv  - Search for Environment Variables 
  18731. o localeconv  - Query Locale Conventions 
  18732. o _putenv - Modify Environment Variables 
  18733. o locale.h 
  18734.  
  18735.  
  18736. ΓòÉΓòÉΓòÉ 6.197. _setmode - Set File Translation Mode ΓòÉΓòÉΓòÉ
  18737.  
  18738.  
  18739. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18740.  
  18741. #include <fcntl.h>
  18742. #include <io.h>
  18743.  
  18744. int _setmode(int handle, int mode);
  18745.  
  18746.  
  18747. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18748.  
  18749. Language Level: Extension 
  18750.  
  18751. The _setmode function sets the translation mode of the file given by handle to 
  18752. mode. The mode must be one of the values in the following table: 
  18753.  
  18754. Value          Meaning 
  18755. O_TEXT         Sets the translated text mode.  Carriage-return line-feed 
  18756.                combinations are translated into a single line feed on input. 
  18757.                Line-feed characters are translated into carriage-return 
  18758.                line-feed combinations on output. 
  18759. O_BINARY       Sets the binary (untranslated) mode.  The above translations are 
  18760.                suppressed. 
  18761.  
  18762. Use the _setmode function to change the translation mode of a file handle. The 
  18763. translation mode only affects the _read and _write functions. This function 
  18764. does not affect the translation mode of streams. 
  18765.  
  18766. If a file handle is acquired other than by a call to _open, _creat, _sopen or 
  18767. _fileno, The _setmode function should be called for that file handle before 
  18768. using it within the _read or _write functions. 
  18769.  
  18770. The _setmode function returns the previous translation mode if successful. A 
  18771. return value of -1 indicates an error, and errno is set to one of the following 
  18772. values: 
  18773.  
  18774. Value          Meaning 
  18775. EBADF          The file handle is not a handle for an open file. 
  18776. EINVAL         Incorrect mode (neither O_TEXT nor O_BINARY) 
  18777.  
  18778. Example of _setmode 
  18779.  
  18780.  
  18781. ΓòÉΓòÉΓòÉ <hidden> Example of _setmode ΓòÉΓòÉΓòÉ
  18782.  
  18783. /************************************************************************
  18784. *
  18785.  
  18786. This example uses _open to create the file SETMODE.DAT and writes to it. The 
  18787. program then uses _setmode to change the translation mode of SETMODE.DAT from 
  18788. binary to text. 
  18789.  
  18790.                                                                         *
  18791. ************************************************************************/
  18792.  
  18793. #include <stdio.h>
  18794. #include <stdlib.h>
  18795. #include <fcntl.h>
  18796. #include <io.h>
  18797. #include <sys\stat.h>
  18798.  
  18799. #define FILENAME "SETMODE.DAT"
  18800.  
  18801. /* routine to validate return codes */
  18802. void ckrc(rc) {
  18803.    if ((rc) == -1)
  18804.    {
  18805.       printf("Unexpected return code = -1\n");
  18806.       _exit(1);
  18807.    }
  18808. }
  18809.  
  18810. int main(void)
  18811. {
  18812.    int h;
  18813.    int xfer;
  18814.    int mode;
  18815.    char rbuf[256];
  18816.    char wbuf[] = "123\n456\n";
  18817.  
  18818.    ckrc(h =  _open(FILENAME,
  18819.     O_CREAT | O_RDWR |
  18820.     O_TRUNC | O_TEXT,
  18821.     S_IREAD | S_IWRITE));
  18822.  
  18823.    ckrc(_write(h,wbuf,sizeof(wbuf)));   /* write the file (text) */
  18824.  
  18825.    ckrc(_lseek(h,0,SEEK_SET)); /* seek back to the start of the file */
  18826.  
  18827.    ckrc(xfer = _read(h,rbuf,5));        /* read the file text */
  18828.    printf("Read in %d characters (4 expected)\n",xfer);
  18829.  
  18830.    ckrc(mode = _setmode(h,O_BINARY));
  18831.    if (mode == O_TEXT) printf("Mode changed from binary to text\n");
  18832.    else printf("Previous mode was not text (unexpected)\n");
  18833.  
  18834.    ckrc(xfer = _read(h,rbuf,5));        /* read the file (binary) */
  18835.    printf("Read in %d characters (5 expected)\n",xfer);
  18836.  
  18837.    ckrc(_close(h));
  18838.  
  18839.    remove (FILENAME);
  18840.  
  18841.    return 0;
  18842.  
  18843. /****************  The expected output is:  *****************************
  18844.  
  18845.       Read in 4 characters (4 expected)
  18846.       Mode changed from binary to text
  18847.       Read in 5 characters (5 expected)
  18848. */
  18849. }
  18850.  
  18851.  
  18852. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18853.  
  18854. o _creat - Create New File 
  18855. o _open - Open File 
  18856. o _sopen - Open Shared File 
  18857. o _read - Read Into Buffer 
  18858. o _write - Writes from Buffer to File 
  18859. o fcntl.h 
  18860. o io.h 
  18861. o share.h 
  18862. o sys\stat.h 
  18863.  
  18864.  
  18865. ΓòÉΓòÉΓòÉ 6.198. setvbuf  - Control Buffering ΓòÉΓòÉΓòÉ
  18866.  
  18867.  
  18868. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18869.  
  18870. #include <stdio.h>
  18871.  
  18872. int setvbuf(FILE *stream, char *buf, int type, size_t size);
  18873.  
  18874.  
  18875. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18876.  
  18877. Language Level: ANSI, SAA 
  18878.  
  18879. The setvbuf function allows control over the buffering strategy and buffer size 
  18880. for a specified stream. The stream must refer to a file that has been opened, 
  18881. but not read or written to. 
  18882.  
  18883. The array pointed to by buf designates an area that you provide that the C 
  18884. library may choose to use as a buffer for the stream.  A buf value of NULL 
  18885. indicates that no such area is supplied and that the C library is to assume 
  18886. responsibility for managing its own buffers for the stream.  If you supply a 
  18887. buffer, it must exist until the stream is closed. 
  18888.  
  18889. If type is _IOFBF or _IOLBF, size is the size of the supplied buffer.  If buf 
  18890. is NULL, the C library will take size as the suggested size for its own buffer. 
  18891. If type is _IONBF, both buf and size are ignored. 
  18892.  
  18893. Value         Meaning 
  18894. _IONBF        No buffer is used. 
  18895. _IOFBF        Full buffering is used for input and output. Use buf as the 
  18896.               buffer and size as the size of the buffer. 
  18897. _IOLBF        Line buffering is used.  The buffer is flushed when a new-line 
  18898.               character is written, when the buffer is full, or when input is 
  18899.               requested. 
  18900.  
  18901. The value for size must be greater than 0. 
  18902.  
  18903. The setvbuf function returns a 0 if successful and nonzero if an invalid value 
  18904. was specified in the parameter list, or if the request cannot be performed. 
  18905.  
  18906. Warning: The array used as the buffer must still exist when the specified 
  18907. stream is closed. For example, if the buffer is declared within the scope of a 
  18908. function block, the stream must be closed before the function is terminated and 
  18909. frees the storage allocated to the buffer. 
  18910.  
  18911. Example of setvbuf 
  18912.  
  18913.  
  18914. ΓòÉΓòÉΓòÉ <hidden> Example of setvbuf ΓòÉΓòÉΓòÉ
  18915.  
  18916. /************************************************************************
  18917. *
  18918.  
  18919. This example sets up a buffer of buf for stream1 and specifies that input to 
  18920. stream2 is to be unbuffered. 
  18921.  
  18922.                                                                         *
  18923. ************************************************************************/
  18924.  
  18925. #include <stdio.h>
  18926.  
  18927. #define  BUF_SIZE  1024
  18928.  
  18929. char buf[BUF_SIZE];
  18930. FILE *stream1, *stream2;
  18931.  
  18932. int main(void)
  18933. {
  18934.    stream1 = fopen("myfile1.dat", "r");
  18935.    stream2 = fopen("myfile2.dat", "r");
  18936.  
  18937.    /* stream1 uses a user-assigned buffer of BUF_SIZE bytes */
  18938.    if (setvbuf(stream1, buf, _IOFBF, sizeof(buf)) != 0)
  18939.       printf("Incorrect type or size of buffer\n");
  18940.  
  18941.    /* stream2 is unbuffered                                  */
  18942.    if (setvbuf(stream2, NULL, _IONBF, 0) != 0)
  18943.       printf("Incorrect type or size of buffer\n");
  18944.    .
  18945.    .
  18946.    .
  18947. }
  18948.  
  18949.  
  18950. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  18951.  
  18952. o fclose  - Close Stream 
  18953. o fflush  - Write Buffer to File 
  18954. o _flushall - Write Buffers to Files 
  18955. o fopen  - Open Files 
  18956. o setbuf  - Control Buffering 
  18957. o stdio.h 
  18958.  
  18959.  
  18960. ΓòÉΓòÉΓòÉ 6.199. signal Install Interrupt Handlers ΓòÉΓòÉΓòÉ
  18961.  
  18962.  
  18963. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  18964.  
  18965. #include <signal.h>
  18966.  
  18967. void (*signal(int sig, void (*sig_handler)(int)))(int);
  18968.  
  18969.  
  18970. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  18971.  
  18972. Language Level: ANSI, SAA, Extension 
  18973.  
  18974. The signal function assigns the interrupt signal sig to the signal handler 
  18975. sig_handler. The sig argument must be one of the signal constants defined in 
  18976. <signal.h>. 
  18977.  
  18978. The meanings of the values of sig are as follows: 
  18979.  
  18980. Value             Meaning 
  18981. SIGABRT           Abnormal termination signal sent by the abort function. 
  18982.                   Default action is to end the program with exit code 3. 
  18983. SIGBREAK          Ctrl-Break signal. Default action is to end the program with 
  18984.                   exit code 99. 
  18985. SIGFPE            Floating-point exceptions that are not masked, such as 
  18986.                   overflow, division by zero, and invalid operation.  Default 
  18987.                   action is to end the program with exit code 99 and provide a 
  18988.                   machine-state dump. 
  18989. SIGILL            Instruction not allowed.  Default action is to end the 
  18990.                   program with exit code 99 and provide a machine-state dump. 
  18991. SIGINT            Ctrl-C signal. Default action is to end the program with exit 
  18992.                   code 99. 
  18993. SIGSEGV           Access to memory not valid. Default action is to end the 
  18994.                   program with exit code 99 and provide a machine-state dump. 
  18995. SIGTERM           Program termination signal sent by the user.  Default action 
  18996.                   is to end the program with exit code 99. 
  18997. SIGUSR1           Defined by the user. Default action is to ignore the signal. 
  18998. SIGUSR2           Defined by the user. Default action is to ignore the signal. 
  18999. SIGUSR3           Defined by the user. Default action is to ignore the signal. 
  19000.  
  19001. Signals can be reported as a result of a machine interrupt (for example, 
  19002. division by zero) or by an explicit request to report a signal by using the 
  19003. raise function. 
  19004.  
  19005. The sig_handler argument must be either the SIG_DFL or SIG_IGN constant, also 
  19006. defined in <signal.h>, or the address of a function that takes an integer 
  19007. argument (the signal). 
  19008.  
  19009. The action taken when the interrupt signal is received depends on the value of 
  19010. sig_handler: 
  19011.  
  19012. Value           Meaning 
  19013. SIG_DFL         This is the initial setting for all signals. For most signals, 
  19014.                 the system default is to end the program. All files controlled 
  19015.                 by the process are closed, but buffers are not flushed.  A 
  19016.                 machine-state dump is provided for SIGFPE, SIGILL, and SIGSEGV. 
  19017.                 The default response for the user-defined signals (SIGUSR1, 
  19018.                 SIGUSR2, and SIGUSR3) is to ignore them. 
  19019. SIG_IGN         The interrupt signal is ignored. 
  19020. SIG_HANDLER     Installs the specified function as the signal handler for the 
  19021.                 given signal. 
  19022.  
  19023. For all signals, the function is passed two arguments. The first argument is 
  19024. the signal number and the second is 0, unless the signal is SIG_FPE. For 
  19025. SIG_FPE signals, the second argument passed is a floating-point error signal as 
  19026. defined in <float.h>. If the signal handling function returns, the calling 
  19027. process resumes running immediately following the point at which it received 
  19028. the interrupt signal. 
  19029.  
  19030. When a signal is reported and the sig_handler called, signal handling for that 
  19031. signal is reset to the default. Depending on the purpose of the signal handler, 
  19032. it can be desirable to reestablish the signal handling from within the 
  19033. sig_handler function. You can also reset the default handling with an explicit 
  19034. call to signal. 
  19035.  
  19036. Signals and signal handlers are not shared between threads. If you do not 
  19037. establish a signal handler within a thread, the default signal handling will be 
  19038. used regardless of what handlers you may have established in other concurrent 
  19039. threads. 
  19040.  
  19041. Note:  If an exception occurs in a math or critical library function, it is 
  19042. handled by the C/C++ Tools exception handler.  Your sig_handler will not be 
  19043. called. 
  19044.  
  19045. All calls to the signal function return the address of the previous handler for 
  19046. the re-assigned signal. 
  19047.  
  19048. A return value of SIG_ERR, defined in <signal.h>, indicates an error, and errno 
  19049. is set to EINVAL. The possible causes of the error are an incorrect sig value 
  19050. or an undefined value for func. 
  19051.  
  19052. Example of signal 
  19053.  
  19054.  
  19055. ΓòÉΓòÉΓòÉ <hidden> Example of signal ΓòÉΓòÉΓòÉ
  19056.  
  19057. /************************************************************************
  19058. *
  19059. In the following example, the call to signal in main establishes the function 
  19060. handler to process the interrupt signal raised by abort.  An error value 
  19061. returned from this call to signal causes the program to end with a printed 
  19062. error message. 
  19063.  
  19064.                                                                         *
  19065. ************************************************************************/
  19066.  
  19067. #include <stdio.h>
  19068. #include <signal.h>
  19069. #include <stdlib.h>
  19070.  
  19071. void handler(int sig)
  19072. {
  19073.     printf("Registered signal type for abort = %d\n", sig);
  19074.     printf("Abort should not flush this line");
  19075. }
  19076.  
  19077. int main(void)
  19078. {
  19079.     if (signal(SIGABRT, handler) == SIG_ERR)
  19080.     {
  19081.         perror("Could not set SIGABRT");
  19082.         exit(-1);
  19083.     }
  19084.  
  19085.     abort();   /* signal raised by abort */
  19086.  
  19087.     /* The expected output is:
  19088.  
  19089.        Registered signal type for abort = 5   */
  19090.  
  19091. }
  19092.  
  19093.  
  19094. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19095.  
  19096. o abort  - Stop a Program 
  19097. o atexit  - Record Program Termination Function 
  19098. o exit  - End Program 
  19099. o _exit - End Process 
  19100. o _fpreset - Reset Floating-Point Unit 
  19101. o raise  - Send Signal 
  19102. o _spawnl -_spawnvpe -Start and Run Child Processes 
  19103. o signal.h 
  19104.  
  19105.  
  19106. ΓòÉΓòÉΓòÉ 6.200. sin  - Calculate Sine ΓòÉΓòÉΓòÉ
  19107.  
  19108.  
  19109. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19110.  
  19111. #include <math.h>
  19112.  
  19113. double sin(double x);     /* Calculate sine of x */
  19114.  
  19115.  
  19116. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19117.  
  19118. Language Level: ANSI, SAA 
  19119.  
  19120. The sin function calculates the sine of x, with x expressed in radians. 
  19121.  
  19122. Example of sin 
  19123.  
  19124.  
  19125. ΓòÉΓòÉΓòÉ <hidden> Example of sin ΓòÉΓòÉΓòÉ
  19126.  
  19127. /************************************************************************
  19128. *
  19129.  
  19130. This example computes y as the sine of ╤â/2. 
  19131.  
  19132.                                                                         *
  19133. ************************************************************************/
  19134.  
  19135. #include <math.h>
  19136. #include <stdio.h>
  19137.  
  19138. int main(void)
  19139. {
  19140.    double pi, x, y;
  19141.  
  19142.    pi = 3.1415926535;
  19143.    x = pi/2;
  19144.    y = sin(x);
  19145.  
  19146.    printf("sin( %lf ) = %lf\n", x, y);
  19147. }
  19148.  
  19149. /*********************  Output should be similar to:  *************
  19150.  
  19151. sin( 1.570796 ) = 1.000000
  19152. */
  19153.  
  19154.  
  19155. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19156.  
  19157. o asin  - Calculate Arcsine 
  19158. o _fasin - Calculate Arcsine 
  19159. o _fcossin - Calculate Cosine and Sine 
  19160. o _fsin - Calculate Sine 
  19161. o _fsincos - Calculate Sine and Cosine 
  19162. o sinh  - Calculate Hyperbolic Sine 
  19163. o math.h 
  19164.  
  19165.  
  19166. ΓòÉΓòÉΓòÉ 6.201. sinh  - Calculate Hyperbolic Sine ΓòÉΓòÉΓòÉ
  19167.  
  19168.  
  19169. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19170.  
  19171. #include <math.h>
  19172.  
  19173. double sinh(double x);     /* Calculate hyperbolic sine of x */
  19174.  
  19175.  
  19176. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19177.  
  19178. Language Level: ANSI, SAA 
  19179.  
  19180. The sinh function calculates the hyperbolic sine of x, with x expressed in 
  19181. radians. If the result is too large, sinh sets errno to ERANGE and returns the 
  19182. value HUGE_VAL (positive or negative, depending on the value of x). 
  19183.  
  19184. Example of sinh 
  19185.  
  19186.  
  19187. ΓòÉΓòÉΓòÉ <hidden> Example of sinh ΓòÉΓòÉΓòÉ
  19188.  
  19189. /************************************************************************
  19190. *
  19191.  
  19192. This example computes y as the hyperbolic sine of ╤â/2. 
  19193.  
  19194.                                                                         *
  19195. ************************************************************************/
  19196.  
  19197. #include <math.h>
  19198. #include <stdio.h>
  19199.  
  19200. int main(void)
  19201. {
  19202.    double pi, x, y;
  19203.  
  19204.    pi = 3.1415926535;
  19205.    x = pi/2;
  19206.    y = sinh(x);
  19207.  
  19208.    printf("sinh( %lf ) = %lf\n", x, y);
  19209. }
  19210.  
  19211. /*********************  Output should be similar to:  *************
  19212.  
  19213. sinh( 1.570796 ) = 2.301299
  19214. */
  19215.  
  19216.  
  19217. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19218.  
  19219. o asin  - Calculate Arcsine 
  19220. o cosh  - Calculate Hyperbolic Cosine 
  19221. o _fasin - Calculate Arcsine 
  19222. o _fcossin - Calculate Cosine and Sine 
  19223. o _fsin - Calculate Sine 
  19224. o _fsincos - Calculate Sine and Cosine 
  19225. o sin  - Calculate Sine 
  19226. o tanh  - Calculate Hyperbolic Tangent 
  19227. o math.h 
  19228.  
  19229.  
  19230. ΓòÉΓòÉΓòÉ 6.202. _sopen - Open Shared File ΓòÉΓòÉΓòÉ
  19231.  
  19232.  
  19233. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19234.  
  19235. #include <fcntl.h>
  19236. #include <sys\stat.h>
  19237. #include <share.h>
  19238. #include <io.h>
  19239.  
  19240. int _sopen(char *pathname, int oflag, int shflag , int pmode);
  19241.  
  19242.  
  19243. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19244.  
  19245. Language Level: Extension 
  19246.  
  19247. The _sopen function opens the file specified by pathname and prepares the file 
  19248. for subsequent shared reading or writing as defined by oflag and shflag. The 
  19249. oflag is an integer expression formed by combining one or more of the constants 
  19250. defined in <fcntl.h>. When more than one constant is given, the constants are 
  19251. joined with the OR operator (|). 
  19252.  
  19253. Oflag          Meaning 
  19254. O_APPEND       Reposition the file pointer to the end of the file before every 
  19255.                write operation. 
  19256. O_CREAT        Create and open a new file.  This flag has no effect if the file 
  19257.                specified by pathname exists. 
  19258. O_EXCL         Return an error value if the file specified by pathname exists. 
  19259.                This flag applies only when used with O_CREAT. 
  19260. O_RDONLY       Open the file for reading only.  If this flag is given, neither 
  19261.                O_RDWR nor O_WRONLY can be given. 
  19262. O_RDWR         Open the file for both reading and writing.  If this flag is 
  19263.                given, neither O_RDONLY nor O_WRONLY can be given. 
  19264. O_TRUNC        Open and truncate an existing file to 0 length. The file must 
  19265.                have write permission. The contents of the file are destroyed. 
  19266.                On the OS/2 operating system, do not specify O_TRUNC with 
  19267.                O_RDONLY. 
  19268. O_WRONLY       Open the file for writing only.  If this flag is given, neither 
  19269.                O_RDONLY nor O_RDWR can be given. 
  19270. O_BINARY       Open the file in binary (untranslated) mode. (See fopen. for a 
  19271.                description of binary mode.) 
  19272. O_TEXT         Open the file in text (translated) mode. (See fopen. for a 
  19273.                description of text mode.) 
  19274.  
  19275. The shflag argument is one of the following constants, defined in <share.h>. 
  19276.  
  19277. Shflag          Meaning 
  19278. SH_DENYRW       Deny read and write access to file 
  19279. SH_DENYWR       Deny write access to file 
  19280. SH_DENYRD       Deny read access to file 
  19281. SH_DENYNO       Permit read and write access. 
  19282.  
  19283. There is no default value for the shflag. 
  19284.  
  19285. The pmode argument is an integer expression containing one or both of the 
  19286. constants S_IWRITE and S_IREAD, defined in <sys\stat.h>. The pmode argument is 
  19287. required only when O_CREAT is specified. If the file does not exist, pmode 
  19288. specifies the permission settings of the file, which are set when the new file 
  19289. is closed for the first time. If the file exists, the pmode argument is 
  19290. ignored. The pmode argument is an integer expression containing one or both of 
  19291. the constants S_IWRITE and S_IREAD. The meanings of the pmode argument are in 
  19292. the following table. 
  19293.  
  19294. Value                   Meaning 
  19295. S_IWRITE                Writing permitted 
  19296. S_IREAD                 Reading permitted 
  19297. S_IREAD | S_IWRITE      Reading and writing permitted. 
  19298.  
  19299. If write permission is not given, the file is read only.  On the OS/2 operating 
  19300. system, all files are readable; you cannot give write-only permission.  Thus, 
  19301. the modes S_IWRITE and S_IREAD | S_IWRITE are equivalent. 
  19302.  
  19303. Specifying a pmode of S_IREAD is similar to making a file read-only with the 
  19304. ATTRIB system command. 
  19305.  
  19306. The _sopen function applies the current file permission mask to pmode before 
  19307. setting the permissions. (See _umask - Sets File Mask of Current Process for 
  19308. information on file permission masks.) 
  19309.  
  19310. The _sopen function returns a file handle for the opened file. A return value 
  19311. of -1 indicates an error, and errno is set to one of the following values: 
  19312.  
  19313. Value          Meaning 
  19314. EACCESS        The given path name is a directory, but the file is read-only 
  19315.                and an open for writing was attempted, or a sharing violation 
  19316.                occurred. 
  19317. EEXIST         The O_CREAT and O_EXCL flags are specified, but the named file 
  19318.                already exists. 
  19319. EMFILE         No more file handles are available. 
  19320. ENOENT         The file or path name was not found. 
  19321. EINVAL         An incorrect argument was passed. 
  19322. EOS2ERR        The call to the operating system was not successful. 
  19323.  
  19324. Example of _sopen 
  19325.  
  19326.  
  19327. ΓòÉΓòÉΓòÉ <hidden> Example of _sopen ΓòÉΓòÉΓòÉ
  19328.  
  19329. /************************************************************************
  19330. *
  19331.  
  19332. This example opens the file sample.dat for shared reading and writing using 
  19333. _sopen. It then opens the file for shared reading. 
  19334.  
  19335.                                                                         *
  19336. ************************************************************************/
  19337.  
  19338. #include <io.h>
  19339. #include <stdio.h>
  19340. #include <stdlib.h>
  19341. #include <fcntl.h>
  19342. #include <share.h>
  19343.  
  19344. int main(void)
  19345. {
  19346.    int  fh1, fh2;
  19347.  
  19348.    printf("\nCreating sample.dat.\n");
  19349.    system("echo Sample Program > sample.dat");
  19350.  
  19351.    /* share open the file for reading and writing */
  19352.  
  19353.    if (-1 == (fh1 = _sopen("sample.dat",O_RDWR,SH_DENYNO) ))
  19354.    {
  19355.       perror("_sopen failed");
  19356.       return 1;
  19357.    }
  19358.  
  19359.    /* share open the file for reading only */
  19360.  
  19361.    if (-1 == (fh2 = _sopen("sample.dat",O_RDONLY,SH_DENYNO) ))
  19362.    {
  19363.       perror("_sopen failed");
  19364.       _close(fh1);
  19365.       return 1;
  19366.    }
  19367.  
  19368.    printf("File sample.dat successfully opened for sharing.\n");
  19369.    _close(fh1);
  19370.    _close(fh2);
  19371.    return 0;
  19372. /*****************  The expected output is:  ****************************
  19373.  
  19374.       Creating sample.dat.
  19375.       File sample.dat successfully opened for sharing.
  19376. */
  19377. }
  19378.  
  19379.  
  19380. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19381.  
  19382. o _close - Closes File Associated with Handle 
  19383. o _creat - Create New File 
  19384. o _open - Open File 
  19385. o _fdopen - Associates Input Or Output With File 
  19386. o fopen  - Open Files 
  19387. o _sopen - Open Shared File 
  19388. o _umask - Sets File Mask of Current Process 
  19389. o fcntl.h 
  19390. o io.h 
  19391. o share.h 
  19392. o sys\stat.h 
  19393.  
  19394.  
  19395. ΓòÉΓòÉΓòÉ 6.203. _spawnl -_spawnvpe -Start and Run Child Processes ΓòÉΓòÉΓòÉ
  19396.  
  19397.  
  19398. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19399.  
  19400. #include <process.h>
  19401.  
  19402. int _spawnl(int modeflag, char *pathname, char *arg0, char *arg1, ...,
  19403.                 char *argn, NULL);
  19404.  
  19405. int _spawnlp(int modeflag, char *pathname, char *arg0, char *arg1, ...,
  19406.                  char *argn, NULL);
  19407.  
  19408. int _spawnle(int modeflag, char *pathname, char *arg0, char *arg1, ...,
  19409.                  char *argn, NULL, char *envp[ ]);
  19410.  
  19411. int _spawnlpe(int modeflag, char *pathname, char *arg0, char *arg1, ...,
  19412.                   char *argn, NULL, char *envp[ ]);
  19413.  
  19414. int _spawnv(int modeflag, char *pathname, char *argv[ ]);
  19415.  
  19416. int _spawnvp(int modeflag, char *pathname, char *argv[ ]);
  19417.  
  19418. int _spawnve(int modeflag, char *pathname, char *argv[ ], char *envp[ ]);
  19419.  
  19420. int _spawnvpe(int modeflag, char *pathname, char *argv[ ], char *envp[ ])
  19421.  
  19422.  
  19423. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19424.  
  19425. Language Level: Extension 
  19426.  
  19427. Each of the _spawn functions creates and runs a new child process. Enough 
  19428. storage must be available for loading and running the child process. All of the 
  19429. _spawn functions are versions of the same routine; the letters at the end 
  19430. determine the specific variation: 
  19431.  
  19432. Letter   Variation 
  19433.  p       Uses PATH environment variable to find the file to be run 
  19434.  l       Lists command-line arguments separately 
  19435.  v       Passes to the child process an array of pointers to command-line 
  19436.          arguments 
  19437.  e       Passes to the child process an array of pointers to environment 
  19438.          strings. 
  19439.  
  19440. The modeflag argument determines the action taken by the parent process before 
  19441. and during the _spawn. The following values for modeflag are defined in 
  19442. <process.h>. 
  19443.  
  19444. Value          Meaning 
  19445. P_WAIT         Suspend the parent process until the child process is complete. 
  19446. P_NOWAIT       Continue to run the parent process concurrently. 
  19447. P_OVERLAY      Start the child process, and then if successful, end the parent 
  19448.                process.  (This has the same effect as _exec calls.) 
  19449.  
  19450. The pathname argument specifies the file to run as the child process.  The 
  19451. pathname can specify a full path (from the root), a partial path (from the 
  19452. current working directory), or just a file name.  If pathname does not have a 
  19453. file name extension or end with a period, the _spawn functions add the 
  19454. extension .EXE and search for the file. If pathname has an extension, only that 
  19455. extension is used.  If pathname ends with a period, the _spawn functions search 
  19456. for pathname with no extension. The _spawnlp, _spawnlpe, _spawnvp, and 
  19457. _spawnvpe functions search for pathname (using the same procedures) in the 
  19458. directories specified by the PATH environment variable. 
  19459.  
  19460. You pass arguments to the child process by giving one or more pointers to 
  19461. character strings as arguments in the _spawn routine.  These character strings 
  19462. form the argument list for the child process. 
  19463.  
  19464. The argument pointers can be passed as separate arguments (_spawnl, _spawnle, 
  19465. _spawnlp, and _spawnlpe) or as an array of pointers (_spawnv, _spawnve, 
  19466. _spawnvp, and _spawnvpe).  At least one argument, either arg0 or argv[0], must 
  19467. be passed to the child process.  By convention, this argument is a copy of the 
  19468. pathname argument.  However, a different value will not produce an error. 
  19469.  
  19470. Use the _spawnl, _spawnle, _spawnlp, and _spawnlpe routines in cases where you 
  19471. know the number of arguments.  The arg0 is usually a pointer to pathname. The 
  19472. arg1 through argn arguments are pointers to the character strings forming the 
  19473. new argument list.  Following argn, there must be a NULL pointer to mark the 
  19474. end of the argument list. 
  19475.  
  19476. The _spawnv, _spawnve, _spawnvp, and _spawnvpe functions are useful when the 
  19477. number of arguments to the child process is variable.  Pointers to the 
  19478. arguments are passed as an array, argv.  The argv[0] argument is usually a 
  19479. pointer to the pathname. The argv[1] through argv[n] arguments are pointers to 
  19480. the character strings forming the new argument list.  The argv[n+1] argument 
  19481. must be a NULL pointer to mark the end of the argument list. 
  19482.  
  19483. Files that are open when a _spawn call is made remain open in the child 
  19484. process.  In the _spawnl, _spawnlp, _spawnv, and _spawnvp calls, the child 
  19485. process inherits the environment of the parent. The _spawnle, _spawnlpe, 
  19486. _spawnve, and _spawnvpe functions let you alter the environment for the child 
  19487. process by passing a list of environment settings through the envp argument. 
  19488. The envp argument is an array of character pointers, each element of which 
  19489. points to a null-terminated string, that defines an environment variable.  Such 
  19490. a string has the form: 
  19491.  
  19492.    NAME=value
  19493.  
  19494. where NAME is the name of an environment variable, and value is the string 
  19495. value to which that variable is set.  (Notice that value is not enclosed in 
  19496. double quotation marks.) The final element of the envp array should be NULL. 
  19497. When envp itself is NULL, the child process inherits the environment settings 
  19498. of the parent process. 
  19499.  
  19500. Note:  Signal settings are not preserved in child processes created by calls to 
  19501.        _spawn functions. The signal settings are reset to the default in the 
  19502.        child process. 
  19503.  
  19504. The return from a spawn has one of two different meanings.  The return value of 
  19505. a synchronous spawn is the exit status of the child process.  The return value 
  19506. of an asynchronous spawn is the process identification of the child process. 
  19507. You can use the _wait or _cwait functions to get the child process exit code if 
  19508. an asynchronous spawn was done. 
  19509.  
  19510. A return value of -1 indicates an error (the child process is not started), and 
  19511. errno is set to one of the following values: 
  19512.  
  19513. Value       Meaning 
  19514. EAGAIN      The limit of the number of processes that the OS/2 operating system 
  19515.             permits has been reached. 
  19516. EINVAL      The modeflag argument is incorrect. 
  19517. ENOENT      The file or path name was not found or was not specified correctly. 
  19518. ENOEXEC     The specified file is not executable or has an incorrect executable 
  19519.             file format. 
  19520. ENOMEM      Not enough storage is available to run the child process. 
  19521.  
  19522. Example of _spawnl - _spawnvpe 
  19523.  
  19524.  
  19525. ΓòÉΓòÉΓòÉ <hidden> Example of _spawnl - _spawnvpe ΓòÉΓòÉΓòÉ
  19526.  
  19527. /************************************************************************
  19528. *
  19529. This example shows calls to four of the eight _spawn routines.  When called 
  19530. without arguments from the command line, the program first runs the code for 
  19531. case PARENT.  It spawns a copy of itself, waits for its child to run, then 
  19532. spawns a second child.  The instructions for the child are blocked to run only 
  19533. if argv[0] and one parameter were passed (case CHILD).  In its turn, each child 
  19534. spawns a grandchild as a copy of the same program.  The grandchild instructions 
  19535. are blocked by the existence of two passed parameters. The grandchild is 
  19536. permitted to overlay the child.  Each of the processes prints a message 
  19537. identifying itself. 
  19538.  
  19539.                                                                         *
  19540. ************************************************************************/
  19541.  
  19542. #include  <stdio.h>
  19543. #include  <process.h>
  19544. #define   PARENT        1
  19545. #define   CHILD         2
  19546. #define   GRANDCHILD    3
  19547.  
  19548. int main(int argc, char **argv, char **envp)
  19549. {
  19550.    int    result;
  19551.    char   *args[4];
  19552.  
  19553.    switch(argc)
  19554.    {
  19555.       case PARENT:
  19556.       /* no argument was passed:  spawn child and wait */
  19557.          result = _spawnle(P_WAIT, argv[0],
  19558.                                argv[0], "one", NULL, envp);
  19559.          if (result)
  19560.              abort();
  19561.          args[0] = argv[0];
  19562.          args[1] = "two";
  19563.          args[2] = NULL;
  19564.  
  19565.          /* spawn another child, and wait for it */
  19566.          result = _spawnve(P_WAIT, argv[0],
  19567.                       args, envp);
  19568.          if (result)
  19569.              abort();
  19570.          printf("Parent process ended\n");
  19571.          _exit(0);
  19572.  
  19573.       case CHILD:
  19574.       /* one argument passed:  allow grandchild to overlay */
  19575.          printf("child process %s began\n", argv[1]);
  19576.          if (*argv[1] == 'o')            /* child one? */
  19577.          {
  19578.             _spawnl(P_OVERLAY, argv[0],
  19579.                         argv[0], "one", "two", NULL);
  19580.             abort();
  19581.             /* not executed because child was overlaid */
  19582.          }
  19583.          if (*argv[1] == 't')            /* child two? */
  19584.          {
  19585.              args[0] = argv[0];
  19586.              args[1] = "two";
  19587.              args[2] = "one";
  19588.              args[3] = NULL;
  19589.              _spawnv(P_OVERLAY, argv[0], args);
  19590.              abort();
  19591.              /* not executed because child was overlaid */
  19592.          }
  19593.          abort();       /* argument not valid */
  19594.  
  19595.      case GRANDCHILD:   /* two arguments passed */
  19596.         printf("grandchild %s ran\n", argv[1]);
  19597.         _exit(0);
  19598.    }
  19599.  
  19600. /******  The output should be similar to:  *************
  19601.  
  19602.     child process one began
  19603.     grandchild one ran
  19604.     child process two began
  19605.     Parent process ended
  19606.     grandchild two ran
  19607. */
  19608. }
  19609.  
  19610.  
  19611. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19612.  
  19613. o abort  - Stop a Program 
  19614. o _cwait - Wait for Child Process 
  19615. o _execl - _execvp - Load and Run Child Process 
  19616. o exit  - End Program 
  19617. o _exit - End Process 
  19618. o _wait - Wait for Child Process 
  19619. o process.h 
  19620.  
  19621.  
  19622. ΓòÉΓòÉΓòÉ 6.204. _splitpath - Decompose Path Name ΓòÉΓòÉΓòÉ
  19623.  
  19624.  
  19625. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19626.  
  19627. #include <stdlib.h>
  19628.  
  19629. void _splitpath(char *path, char *drive, char *dir,
  19630.                     char *fname, char *ext);
  19631.  
  19632.  
  19633. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19634.  
  19635. Language Level: Extension 
  19636.  
  19637. The _splitpath function decomposes an existing path name path into its four 
  19638. components. The path should point to a buffer containing the complete path 
  19639. name. 
  19640.  
  19641. The maximum size necessary for each buffer is specified by the _MAX_DRIVE, 
  19642. _MAX_DIR, _MAX_FNAME, and _MAX_EXT constants defined in <stdlib.h>.  The other 
  19643. arguments point to the following buffers used to store the path name elements: 
  19644.  
  19645. Buffer      Description 
  19646. drive       Contains the drive letter followed by a colon (:) if a drive is 
  19647.             specified in path. 
  19648. dir         Contains the path of subdirectories, if any, including the trailing 
  19649.             slash.  Slashes (/), backslashes (\), or both may be present in 
  19650.             path. 
  19651. fname       Contains the base file name without any extensions. 
  19652. ext         Contains the file name extension, if any, including the leading 
  19653.             period (.). 
  19654.  
  19655. The return parameters contain empty strings for any path name components not 
  19656. found in path. 
  19657.  
  19658. There is no return value. 
  19659.  
  19660. Example of _splitpath 
  19661.  
  19662.  
  19663. ΓòÉΓòÉΓòÉ <hidden> Example of _splitpath ΓòÉΓòÉΓòÉ
  19664.  
  19665. /************************************************************************
  19666. *
  19667.  
  19668. This example builds a file name path from the specified components, and then 
  19669. extracts the individual components. 
  19670.  
  19671.                                                                         *
  19672. ************************************************************************/
  19673.  
  19674. #include <stdio.h>
  19675. #include <stdlib.h>
  19676.  
  19677. int main(void)
  19678. {
  19679.    char path_buffer [_MAX_PATH];
  19680.    char drive [_MAX_DRIVE];
  19681.    char dir [_MAX_DIR];
  19682.    char fname [_MAX_FNAME];
  19683.    char ext [_MAX_EXT];
  19684.  
  19685.    _makepath (path_buffer, "c",
  19686.         "qc\\bob\\eclibref\\e", "makepath", "c");
  19687.    printf ("Path created with _makepath: %s\n\n",
  19688.         path_buffer);
  19689.  
  19690.    _splitpath (path_buffer, drive, dir, fname, ext);
  19691.    printf ("Path extracted with _splitpath:\n");
  19692.    printf ("drive: %s\n", drive);
  19693.    printf ("directory: %s\n", dir);
  19694.    printf ("file name: %s\n", fname);
  19695.    printf ("extension: %s\n", ext);
  19696.  
  19697.    return 0;
  19698.  
  19699. /************  The output should be similar to:  ********
  19700.  
  19701.    Path created with _makepath:
  19702.          c:qc\bob\eclibref\e\makepath.c
  19703.  
  19704.    Path extracted with _splitpath:
  19705.    drive: c:
  19706.    directory: qc\bob\eclibref\e\
  19707.    file name: makepath
  19708.    extension: .c
  19709. */
  19710.  
  19711. }
  19712.  
  19713.  
  19714. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19715.  
  19716. o _fullpath - Get Full Path Name of Partial Path 
  19717. o _getcwd - Get Path Name of Current Directory 
  19718. o _getdcwd - Get Full Path Name of Current Directory 
  19719. o _makepath - Create Path 
  19720. o stdlib.h 
  19721.  
  19722.  
  19723. ΓòÉΓòÉΓòÉ 6.205. sprintf  - Formatted Print to Buffer ΓòÉΓòÉΓòÉ
  19724.  
  19725.  
  19726. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19727.  
  19728. #include <stdio.h>
  19729.  
  19730. int sprintf(char *buffer, const char *format-string, argument-list);
  19731.  
  19732.  
  19733. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19734.  
  19735. Language Level: ANSI, SAA, Extension 
  19736.  
  19737. The sprintf function formats and stores a series of characters and values in 
  19738. the array buffer. Any argument-list is converted and put out according to the 
  19739. corresponding format specification in the format-string. 
  19740.  
  19741. The format-string consists of ordinary characters and has the same form and 
  19742. function as the format-string argument for the printf function.  See printf for 
  19743. a description of the format-string and arguments. 
  19744.  
  19745. In extended mode, sprintf also converts floating-point values of NaN and 
  19746. infinity to the strings "NAN" or "nan" and "INFINITY" or "infinity". The case 
  19747. and sign of the string is determined by the format specifiers.  See Infinity 
  19748. and NaN Support for more information on infinity and NaN values. 
  19749.  
  19750. The sprintf function returns the number of characters written in the array, not 
  19751. counting the ending null character. 
  19752.  
  19753. Example of sprintf 
  19754.  
  19755.  
  19756. ΓòÉΓòÉΓòÉ <hidden> Example of sprintf ΓòÉΓòÉΓòÉ
  19757.  
  19758. /************************************************************************
  19759. *
  19760.  
  19761. The following example uses sprintf to format and print various data. 
  19762.  
  19763.                                                                         *
  19764. ************************************************************************/
  19765.  
  19766. #include <stdio.h>
  19767.  
  19768. char buffer[200];
  19769. int i, j;
  19770. double fp;
  19771. char *s = "baltimore";
  19772. char c;
  19773.  
  19774. int main(void)
  19775. {
  19776.    c = 'l';
  19777.    i = 35;
  19778.    fp = 1.7320508;
  19779.  
  19780.    /* Format and print various data */
  19781.    j = sprintf(buffer, "%s\n", s);
  19782.    j += sprintf(buffer+j, "%c\n", c);
  19783.    j += sprintf(buffer+j, "%d\n", i);
  19784.    j += sprintf(buffer+j, "%f\n", fp);
  19785.    printf("string:\n%s\ncharacter count = %d\n", buffer, j);
  19786. }
  19787.  
  19788. /*********************  Output should be similar to:  *************
  19789.  
  19790. string:
  19791. baltimore
  19792. l
  19793. 35
  19794. 1.732051
  19795.  
  19796. character count = 24
  19797. */
  19798.  
  19799.  
  19800. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19801.  
  19802. o _cprintf - Print Characters to Screen 
  19803. o fprintf  - Write Formatted Data 
  19804. o printf  - Formatted Print 
  19805. o sscanf  - Read Data 
  19806. o Infinity and NaN Support 
  19807. o vfprintf  - Print Argument Data 
  19808. o vprintf  - Print Argument Data 
  19809. o vsprintf  - Print Argument Data 
  19810. o stdio.h 
  19811.  
  19812.  
  19813. ΓòÉΓòÉΓòÉ 6.206. sqrt  - Calculate Square Root ΓòÉΓòÉΓòÉ
  19814.  
  19815.  
  19816. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19817.  
  19818. #include <math.h>
  19819.  
  19820. double sqrt(double x);
  19821.  
  19822.  
  19823. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19824.  
  19825. Language Level: ANSI, SAA 
  19826.  
  19827. The sqrt function calculates the nonnegative value of the square root of x. 
  19828.  
  19829. The sqrt function returns the square root result.  If x is negative, the 
  19830. function sets errno to EDOM, and returns 0. 
  19831.  
  19832. Example of sqrt 
  19833.  
  19834.  
  19835. ΓòÉΓòÉΓòÉ <hidden> Example of sqrt ΓòÉΓòÉΓòÉ
  19836.  
  19837. /************************************************************************
  19838. *
  19839.  
  19840. This example computes the square root of the quantity passed as the first 
  19841. argument to main. It prints an error message if you pass a negative value. 
  19842.  
  19843.                                                                         *
  19844. ************************************************************************/
  19845.  
  19846. #include <stdio.h>
  19847. #include <stdlib.h>
  19848. #include <math.h>
  19849.  
  19850. int main(int argc, char ** argv)
  19851. {
  19852.   char * rest;
  19853.   double value;
  19854.  
  19855.   if ( argc != 2 )
  19856.     printf( "Usage: %s value\n", argv[0] );
  19857.   else
  19858.   {
  19859.     value = strtod( argv[1], &rest );
  19860.     if ( value < 0.0 )
  19861.        perror( "sqrt of a negative number" );
  19862.     else
  19863.        printf("sqrt( %lf ) = %lf\n", value, sqrt( value ));
  19864.   }
  19865. }
  19866.  
  19867. /********************  If the input is 45,  *****************************
  19868. ****************  then the output should be similar to:  **********
  19869.  
  19870. sqrt( 45.000000 ) = 6.708204
  19871. */
  19872.  
  19873.  
  19874. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19875.  
  19876. o exp  - Exponential Function 
  19877. o _fsqrt -  Calculate Square Root 
  19878. o hypot  - Calculate Hypotenuse 
  19879. o log  - Calculate Natural Logarithm 
  19880. o log10  - Calculate Base 10 Logarithm 
  19881. o pow  - Compute Power 
  19882. o math.h 
  19883.  
  19884.  
  19885. ΓòÉΓòÉΓòÉ 6.207. srand  - Set Seed for rand Function ΓòÉΓòÉΓòÉ
  19886.  
  19887.  
  19888. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19889.  
  19890. #include <stdlib.h>
  19891.  
  19892. void srand(unsigned int seed);
  19893.  
  19894.  
  19895. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19896.  
  19897. Language Level: ANSI, SAA 
  19898.  
  19899. The srand function sets the starting point for producing a series of 
  19900. pseudo-random integers.  If srand is not called, the rand seed is set as if 
  19901. srand(1) was called at program start.  Any other value for seed sets the 
  19902. generator to a different starting point. 
  19903.  
  19904. The rand function generates the pseudo-random numbers. 
  19905.  
  19906. There is no return value. 
  19907.  
  19908. Example of srand 
  19909.  
  19910.  
  19911. ΓòÉΓòÉΓòÉ <hidden> Example of srand ΓòÉΓòÉΓòÉ
  19912.  
  19913. /************************************************************************
  19914. *
  19915.  
  19916. This example first calls srand with a value other than 1 to initiate the random 
  19917. value sequence.  Then the program computes 5 random values for the array of 
  19918. integers called ranvals. 
  19919.  
  19920.                                                                         *
  19921. ************************************************************************/
  19922.  
  19923. #include <stdlib.h>
  19924. #include <stdio.h>
  19925.  
  19926. int main(void)
  19927. {
  19928.    int i, ranvals[5];
  19929.  
  19930.    srand(17);
  19931.    for (i = 0; i < 5; i++)
  19932.    {
  19933.       ranvals[i] = rand();
  19934.       printf("Iteration %d ranvals [%d] = %d\n", i+1, i, ranvals[i]);
  19935.    }
  19936. }
  19937.  
  19938. /******************  Output should be similar to:  ****************
  19939.  
  19940. Iteration 1 ranvals [0] = 24107
  19941. Iteration 2 ranvals [1] = 16552
  19942. Iteration 3 ranvals [2] = 12125
  19943. Iteration 4 ranvals [3] = 9427
  19944. Iteration 5 ranvals [4] = 13152
  19945. */
  19946.  
  19947.  
  19948. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  19949.  
  19950. o rand  - Generate Random Number 
  19951. o stdlib.h 
  19952.  
  19953.  
  19954. ΓòÉΓòÉΓòÉ 6.208. sscanf  - Read Data ΓòÉΓòÉΓòÉ
  19955.  
  19956.  
  19957. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  19958.  
  19959. #include <stdio.h>
  19960.  
  19961. int sscanf(const char *buffer, const char *format, argument-list);
  19962.  
  19963.  
  19964. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  19965.  
  19966. Language Level: ANSI, SAA, Extension 
  19967.  
  19968. The sscanf function reads data from buffer into the locations given by 
  19969. argument-list.  Each argument must be a pointer to a variable with a type that 
  19970. corresponds to a type specifier in the format-string. See scanf for a 
  19971. description of the format-string. 
  19972.  
  19973. The sscanf function returns the number of fields that were successfully 
  19974. converted and assigned.  The return value does not include fields that were 
  19975. read but not assigned. 
  19976.  
  19977. In extended mode, sscanf also reads in the strings the strings "INFINITY", 
  19978. "INF", and "NAN" (in upper or lowercase) and converts them to the corresponding 
  19979. floating-point value.  The sign of the value is determined by the format 
  19980. specification. See Infinity and NaN Support for more information on infinity 
  19981. and NaN values. 
  19982.  
  19983. The return value is EOF when the end of the string is encountered before 
  19984. anything is converted. 
  19985.  
  19986. Example of sscanf 
  19987.  
  19988.  
  19989. ΓòÉΓòÉΓòÉ <hidden> Example of sscanf ΓòÉΓòÉΓòÉ
  19990.  
  19991. /************************************************************************
  19992. *
  19993.  
  19994. This example uses sscanf to read various data from the string tokenstring, and 
  19995. then displays the data. 
  19996.  
  19997.                                                                         *
  19998. ************************************************************************/
  19999.  
  20000. #include <stdio.h>
  20001.  
  20002. #define  SIZE  81
  20003.  
  20004. char *tokenstring = "15 12 14";
  20005. int i;
  20006. float fp;
  20007. char s[SIZE];
  20008. char c;
  20009.  
  20010. int main(void)
  20011. {
  20012.    /* Input various data                              */
  20013.    sscanf(tokenstring, "%s %c%d%f", s, &c, &i, &fp);
  20014.  
  20015.    /* If there were no space between %s and %c,       */
  20016.    /* sscanf would read the first character following */
  20017.    /* the string, which is a blank space.             */
  20018.  
  20019.    /* Display the data */
  20020.    printf("string = %s\n",s);
  20021.    printf("character = %c\n",c);
  20022.    printf("integer = %d\n",i);
  20023.    printf("floating-point number = %f\n",fp);
  20024. }
  20025.  
  20026. /*****************  Output should be similar to:  *****************
  20027.  
  20028. string = 15
  20029. character = 1
  20030. integer = 2
  20031. floating-point number = 14.000000
  20032. */
  20033.  
  20034.  
  20035. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20036.  
  20037. o _cscanf - Read Data from Keyboard 
  20038. o fscanf  - Read Formatted Data 
  20039. o scanf  - Read Data 
  20040. o sprintf  - Formatted Print to Buffer 
  20041. o Infinity and NaN Support 
  20042. o stdio.h 
  20043.  
  20044.  
  20045. ΓòÉΓòÉΓòÉ 6.209. _stat - Get Information about File or Directory ΓòÉΓòÉΓòÉ
  20046.  
  20047.  
  20048. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20049.  
  20050. #include <sys\types.h>
  20051. #include <sys\stat.h>
  20052.  
  20053. int _stat(const char *pathname, struct stat *buffer);
  20054.  
  20055.  
  20056. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20057.  
  20058. Language Level: Extension 
  20059.  
  20060. The _stat function stores information about the file or directory specified by 
  20061. pathname in the structure to which buffer points.  The _stat structure, defined 
  20062. in <sys\stat.h>, contains the following fields: 
  20063.  
  20064. Field          Value 
  20065. st_mode        Bit mask for file-mode information. The _stat function sets the 
  20066.                S_IFCHR bit if handle refers to a device. The S_IFDIR bit is set 
  20067.                if pathname specifies a directory. The S_IFREG bit is set if 
  20068.                pathname specifies an ordinary file.  User read/write bits are 
  20069.                set according to the permission mode of the file. The S_IEXEC 
  20070.                bit is set using the file name extension. The other bits are 
  20071.                undefined. 
  20072.  
  20073.                                         F E D C B A 9 8 7 6 5 4 3 2 1 0
  20074.                                         Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé Γöé
  20075.                                         ΓööΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓö┤ΓöÇΓöÿ
  20076.                                                  
  20077.                                   S_IFREGΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ Γöé Γöé     Γöé Γöé ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇexecute/search permission,
  20078.                               (regular file)     Γöé Γöé     Γöé Γöé     owner (S_IEXEC)
  20079.                                   S_IFDIRΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ Γöé     Γöé ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇwrite permission, owner
  20080.                                   S_IFCHRΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ     ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇread permission, owner
  20081.  
  20082. st_dev         Drive number of the disk containing the file. 
  20083. st_rdev        Drive number of the disk containing the file (same as st_dev). 
  20084. st_nlink       Always 1. 
  20085. st_size        Size of the file in bytes. 
  20086. st_atime       Time of last modification of file. 
  20087. st_mtime       Same as st_atime if not provided by the file system. 
  20088. st_ctime       Same as st_atime if not provided by the file system. 
  20089.  
  20090. Note:  If the given pathname specifies only a device (for example C:\), _stat 
  20091. returns an error, and fields in the _stat structure are not meaningful. 
  20092.  
  20093. The _stat function returns the value 0 if the file status information is 
  20094. obtained.  A return value of -1 indicates an error, and errno is set to ENOENT, 
  20095. indicating that the file name or path name could not be found. 
  20096.  
  20097. Example of _stat 
  20098.  
  20099.  
  20100. ΓòÉΓòÉΓòÉ <hidden> Example of _stat ΓòÉΓòÉΓòÉ
  20101.  
  20102. /************************************************************************
  20103. *
  20104.  
  20105. This example requests that the status information for the file test.exe be 
  20106. placed into the structure buf.  If the request is successful and the file is 
  20107. executable, the example runs test.exe. 
  20108.  
  20109.                                                                         *
  20110. ************************************************************************/
  20111.  
  20112. #include <sys\types.h>
  20113. #include <sys\stat.h>
  20114. #include <process.h>
  20115. #include <stdio.h>
  20116.  
  20117. int main(void)
  20118. {
  20119.     struct stat buf;
  20120.  
  20121.     if (_stat("test.exe", &buf) == 0)
  20122.     {
  20123.         if ( (buf.st_mode & S_IFREG) &&
  20124.                        (buf.st_mode & S_IEXEC) )
  20125.                               _execl("test.exe", "test", NULL);
  20126.             /* file is executable */
  20127.     }
  20128.     else
  20129.         printf("File could not be found\n");
  20130.  
  20131.     return 0;
  20132.  
  20133.     /* The source for test.exe
  20134.  
  20135.         #include <stdio.h>
  20136.  
  20137.         int main(void)
  20138.         {                                                                      */
  20139.             puts("test.exe is an executable file");
  20140.         }                                                                      */
  20141.                                          */
  20142.  
  20143. /**********  The output should be similar to:  ***********
  20144.  
  20145.    test.exe is an executable file
  20146. */
  20147. }
  20148.  
  20149.  
  20150. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20151.  
  20152. o _fstat - Information about Open File 
  20153. o sys\stat.h 
  20154. o sys\types.h 
  20155.  
  20156.  
  20157. ΓòÉΓòÉΓòÉ 6.210. _status87 - Get Floating-Point Status Word ΓòÉΓòÉΓòÉ
  20158.  
  20159.  
  20160. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20161.  
  20162. #include <float.h>  /* also defined in <builtin.h> */
  20163.  
  20164. unsigned int _status87(void);
  20165.  
  20166.  
  20167. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20168.  
  20169. Language Level: Extension 
  20170.  
  20171. The _status87 function gets the current floating-point status word. The 
  20172. floating-point status word is a combination of the numeric coprocessor status 
  20173. word and other conditions detected by the numeric exception handler, such as 
  20174. floating-point stack underflow and overflow. 
  20175.  
  20176. The bits in the value returned reflect the floating-point status for the 
  20177. current thread only before the call was made. The _status87 function does not 
  20178. affect any other threads that may be processing. 
  20179.  
  20180. Example of _status87 
  20181.  
  20182.  
  20183. ΓòÉΓòÉΓòÉ <hidden> Example of _status87 ΓòÉΓòÉΓòÉ
  20184.  
  20185. /************************************************************************
  20186. *
  20187.  
  20188. This example uses _status87 to get the value of the floating-point status word. 
  20189.  
  20190.                                                                         *
  20191. ************************************************************************/
  20192.  
  20193. #include <stdio.h>
  20194. #include <float.h>
  20195.  
  20196. double a = 1e-40, b;
  20197. float x, y;
  20198.  
  20199. int main(void)
  20200. {
  20201.     printf("status = 0x%.4x - clear\n", _status87( ));
  20202.  
  20203.    /* change control word to mask all exceptions */
  20204.     _control87(0x037f,0xffff);
  20205.  
  20206.     y = a;         /* store into y is inexact and causes underflow */
  20207.     printf("status = 0x%.4X - inexact, underflow\n", _status87( ));
  20208.  
  20209.    /* reinitialize the floating point unit */
  20210.     _fpreset();
  20211.  
  20212.    /* change control word to mask all exceptions */
  20213.     _control87(0x037f,0xffff);
  20214.  
  20215.     b = y;         /* y is denormal */
  20216.     printf("status = 0x%.4X - denormal\n", _status87());
  20217.  
  20218.    /* reinitialize the floating point unit */
  20219.     _fpreset();
  20220.  
  20221.    return 0;
  20222.  
  20223.    /* The expected output is:
  20224.  
  20225.       status = 0x0000 - clear
  20226.       status = 0x0030 - inexact, underflow
  20227.       status = 0x0002 - denormal                */
  20228.  
  20229. }
  20230.  
  20231.  
  20232. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20233.  
  20234. o _clear87 - Clear Floating-Point Status Word 
  20235. o _control87 - Set Floating-Point Status Word 
  20236. o _fpreset - Reset Floating-Point Unit 
  20237. o float.h 
  20238.  
  20239.  
  20240. ΓòÉΓòÉΓòÉ 6.211. strcat  - Concatenate Strings ΓòÉΓòÉΓòÉ
  20241.  
  20242.  
  20243. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20244.  
  20245. #include <string.h>
  20246.  
  20247. char *strcat(char *string1, const char *string2);
  20248.  
  20249.  
  20250. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20251.  
  20252. Language Level: ANSI, SAA 
  20253.  
  20254. The strcat function concatenates string2 to string1 and ends the resulting 
  20255. string with the null character. 
  20256.  
  20257. The strcat function operates on null-terminated strings. The string arguments 
  20258. to the function should contain a null character (\0) marking the end of the 
  20259. string. No length checking is performed. Do not use a literal string for a 
  20260. string1 value, although string2 may be a literal string. 
  20261.  
  20262. If the storage of string1 overlaps the storage of string2, the behavior is 
  20263. undefined. The strcat function returns a pointer to the concatenated string 
  20264. (string1). 
  20265.  
  20266. Example of strcat 
  20267.  
  20268.  
  20269. ΓòÉΓòÉΓòÉ <hidden> Example of strcat ΓòÉΓòÉΓòÉ
  20270.  
  20271. /************************************************************************
  20272. *
  20273.  
  20274. This example creates the string "computer program" using strcat. 
  20275.  
  20276.                                                                         *
  20277. ************************************************************************/
  20278.  
  20279. #include <stdio.h>
  20280. #include <string.h>
  20281.  
  20282. #define SIZE 40
  20283.  
  20284.  
  20285. int main(void)
  20286. {
  20287.   char buffer1[SIZE] = "computer";
  20288.   char * ptr;
  20289.  
  20290.   ptr = strcat( buffer1, " program" );
  20291.   printf( "buffer1 = %s\n", buffer1 );
  20292.  
  20293. }
  20294.  
  20295. /*****************  Output should be similar to:  *****************
  20296.  
  20297. computer program
  20298. */
  20299.  
  20300.  
  20301. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20302.  
  20303. o strchr  - Search for Character 
  20304. o strcmp  - Compare Strings 
  20305. o strcpy  - Copy Strings 
  20306. o strcspn  - Compare Strings 
  20307. o strncat  - Concatenate Strings 
  20308. o wcscat  - Append wchar_t Strings 
  20309. o wcsncat  - Concatenate wchar_t Strings 
  20310. o string.h 
  20311.  
  20312.  
  20313. ΓòÉΓòÉΓòÉ 6.212. strchr  - Search for Character ΓòÉΓòÉΓòÉ
  20314.  
  20315.  
  20316. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20317.  
  20318. #include <string.h>
  20319.  
  20320. char *strchr(const char *string, int c);
  20321.  
  20322.  
  20323. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20324.  
  20325. Language Level: ANSI, SAA 
  20326.  
  20327. The strchr function finds the first occurrence of a character in a string. The 
  20328. character c can be the null character (\0); the ending null character of string 
  20329. is included in the search. 
  20330.  
  20331. The strchr function operates on null-terminated strings. The string arguments 
  20332. to the function should contain a null character (\0) marking the end of the 
  20333. string. 
  20334.  
  20335. The strchr function returns a pointer to the first occurrence of c converted to 
  20336. a character in string. The function returns NULL if the ending null character 
  20337. is not found. 
  20338.  
  20339. Example of strchr 
  20340.  
  20341.  
  20342. ΓòÉΓòÉΓòÉ <hidden> Example of strchr ΓòÉΓòÉΓòÉ
  20343.  
  20344. /************************************************************************
  20345. *
  20346.  
  20347. This example finds the first occurrence of the character p in "computer 
  20348. program". 
  20349.  
  20350.                                                                         *
  20351. ************************************************************************/
  20352.  
  20353. #include <stdio.h>
  20354. #include <string.h>
  20355.  
  20356. #define SIZE 40
  20357.  
  20358. int main(void)
  20359. {
  20360.   char buffer1[SIZE] = "computer program";
  20361.   char * ptr;
  20362.   int    ch = 'p';
  20363.  
  20364.   ptr = strchr( buffer1, ch );
  20365.   printf( "The first occurrence of %c in '%s' is '%s'\n",
  20366.             ch, buffer1, ptr );
  20367.  
  20368. }
  20369.  
  20370. /*****************  Output should be similar to:  *****************
  20371.  
  20372. The first occurrence of p in 'computer program' is 'puter program'
  20373. */
  20374.  
  20375.  
  20376. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20377.  
  20378. o strcmp  - Compare Strings 
  20379. o strcspn  - Compare Strings 
  20380. o strncmp  - Compare Strings 
  20381. o strpbrk  - Find Characters in String 
  20382. o strrchr  - Find Last Occurrence of Character in String 
  20383. o strspn  - Search Strings 
  20384. o wcschr  - Search wchar_t String for Given wchar_t 
  20385. o wcsspn  - Search wchar_t Characters in String 
  20386. o string.h 
  20387.  
  20388.  
  20389. ΓòÉΓòÉΓòÉ 6.213. strcmp  - Compare Strings ΓòÉΓòÉΓòÉ
  20390.  
  20391.  
  20392. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20393.  
  20394. #include <string.h>
  20395.  
  20396. int strcmp(const char *string1, const char *string2);
  20397.  
  20398.  
  20399. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20400.  
  20401. Language Level: ANSI, SAA 
  20402.  
  20403. The strcmp function compares string1 and string2. 
  20404.  
  20405. The function operates on null-terminated strings. The string arguments to the 
  20406. function should contain a null character (\0) marking the end of the string. 
  20407. The strcmp function returns a value indicating the relationship between the two 
  20408. strings, as follows: 
  20409.  
  20410. Value               Meaning 
  20411. Less than 0         string1 less than string2 
  20412. 0                   string1 identical to string2 
  20413. Greater than 0      string1 greater than string2. 
  20414.  
  20415. Example of strcmp 
  20416.  
  20417.  
  20418. ΓòÉΓòÉΓòÉ <hidden> Example of strcmp ΓòÉΓòÉΓòÉ
  20419.  
  20420. /************************************************************************
  20421. *
  20422.  
  20423. This example compares the two strings passed to main using strcmp. 
  20424.  
  20425.                                                                         *
  20426. ************************************************************************/
  20427.  
  20428. #include <stdio.h>
  20429. #include <string.h>
  20430.  
  20431. int main(int argc, char ** argv)
  20432. {
  20433.   int  result;
  20434.  
  20435.   if ( argc != 3 )
  20436.   {
  20437.     printf( "Usage: %s string1 string2\n", argv[0] );
  20438.   }
  20439.   else
  20440.   {
  20441.  
  20442.     result = strcmp( argv[1], argv[2] );
  20443.  
  20444.     if ( result == 0 )
  20445.       printf( "\"%s\" is identical to \"%s\"\n", argv[1], argv[2] );
  20446.     else if ( result < 0 )
  20447.       printf( "\"%s\" is less than \"%s\"\n", argv[1], argv[2] );
  20448.     else
  20449.       printf( "\"%s\" is greater than \"%s\"\n", argv[1], argv[2] );
  20450.   }
  20451. }
  20452.  
  20453. /****************  If the input is the strings  *************************
  20454. ***********  "is this first?" and "is this before that one?",  **********
  20455. ******************  then the expected output is:  *****************
  20456.  
  20457. "is this first?" is greater than "is this before that one?"
  20458. */
  20459.  
  20460.  
  20461. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20462.  
  20463. o strcmpi - Compare Strings 
  20464. o strcoll  - Compare Strings 
  20465. o strcspn  - Compare Strings 
  20466. o stricmp - Compare Strings 
  20467. o strncmp  - Compare Strings 
  20468. o strnicmp - Compare Strings 
  20469. o wcscmp  - Compare wchar_t Strings 
  20470. o wcsncmp  - Compare wchar_t Strings 
  20471. o string.h 
  20472.  
  20473.  
  20474. ΓòÉΓòÉΓòÉ 6.214. strcmpi - Compare Strings ΓòÉΓòÉΓòÉ
  20475.  
  20476.  
  20477. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20478.  
  20479. #include <string.h>
  20480.  
  20481. int strcmpi(const char *string1, const char *string2);
  20482.  
  20483.  
  20484. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20485.  
  20486. Language Level: Extension 
  20487.  
  20488. The strcmpi function compares string1 and string2 without sensitivity to case. 
  20489. All alphabetic characters in the two arguments string1 and string2 are 
  20490. converted to lowercase before the comparison. 
  20491.  
  20492. The function operates on null-ended strings. The string arguments to the 
  20493. function are expected to contain a null character (\0) marking the end of the 
  20494. string. 
  20495.  
  20496. The strcmpi function returns a value indicating the relationship between the 
  20497. two strings, as follows: 
  20498.  
  20499. Value             Meaning 
  20500. Less than 0       string1 less than string2 
  20501. 0                 string1 equivalent to string2 
  20502. Greater than 0    string1 greater than string2. 
  20503.  
  20504. Example of strcmpi 
  20505.  
  20506.  
  20507. ΓòÉΓòÉΓòÉ <hidden> Example of strcmpi ΓòÉΓòÉΓòÉ
  20508.  
  20509. /************************************************************************
  20510. *
  20511.  
  20512. This example uses strcmpi to compare two strings: 
  20513.  
  20514.                                                                         *
  20515. ************************************************************************/
  20516.  
  20517. #include <stdio.h>
  20518. #include <string.h>
  20519.  
  20520. int main(void)
  20521. {
  20522.     /* Compare two strings without regard to case */
  20523.  
  20524.     if (0 == strcmpi("hello","HELLO"))
  20525.        printf("The strings are equivalent.\n");
  20526.     else
  20527.        printf("The strings are not equivalent.\n");
  20528.  
  20529.     return 0;
  20530.  
  20531. /***************  The output should be similar to:  *********************
  20532.  
  20533.      The strings are equivalent.
  20534. */
  20535. }
  20536.  
  20537.  
  20538. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20539.  
  20540.  
  20541. o strcoll  - Compare Strings 
  20542. o strcspn  - Compare Strings 
  20543. o strdup - Duplicate String 
  20544. o stricmp - Compare Strings 
  20545. o strncmp  - Compare Strings 
  20546. o strnicmp - Compare Strings 
  20547. o wcscmp  - Compare wchar_t Strings 
  20548. o wcsncmp  - Compare wchar_t Strings 
  20549. o string.h 
  20550.  
  20551.  
  20552. ΓòÉΓòÉΓòÉ 6.215. strcoll  - Compare Strings ΓòÉΓòÉΓòÉ
  20553.  
  20554.  
  20555. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20556.  
  20557. #include <string.h>
  20558.  
  20559. int strcoll(const char *string1, const char *string2);
  20560.  
  20561.  
  20562. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20563.  
  20564. Language Level: ANSI, SAA 
  20565.  
  20566. The strcoll function compares two strings using the collating sequence 
  20567. specified by the program's locale. 
  20568.  
  20569. The strcoll function returns a value indicating the relationship between the 
  20570. strings, as listed below. 
  20571.  
  20572. Value               Meaning 
  20573. Less than 0         string1 less than string2 
  20574. 0                   string1 equivalent to string2 
  20575. Greater than 0      string1 greater than string2 
  20576.  
  20577. Example of strcoll 
  20578.  
  20579.  
  20580. ΓòÉΓòÉΓòÉ <hidden> Example of strcoll ΓòÉΓòÉΓòÉ
  20581.  
  20582. /************************************************************************
  20583. *
  20584.  
  20585. This example compares the two strings passed to main. 
  20586.  
  20587.                                                                         *
  20588. ************************************************************************/
  20589.  
  20590. #include <stdio.h>
  20591. #include <string.h>
  20592.  
  20593. int main(int argc, char ** argv)
  20594. {
  20595.   int  result;
  20596.  
  20597.   if ( argc != 3 )
  20598.   {
  20599.     printf( "Usage: %s string1 string2\n", argv[0] );
  20600.   }
  20601.   else
  20602.   {
  20603.  
  20604.     result = strcoll( argv[1], argv[2] );
  20605.  
  20606.     if ( result == 0 )
  20607.       printf( "\"%s\" is identical to \"%s\"\n", argv[1], argv[2] );
  20608.     else if ( result < 0 )
  20609.       printf( "\"%s\" is less than \"%s\"\n", argv[1], argv[2] );
  20610.     else
  20611.       printf( "\"%s\" is greater than \"%s\"\n", argv[1], argv[2] );
  20612.   }
  20613. }
  20614.  
  20615. /******************  If the input is the strings  ***********************
  20616. ****************  "firststring" and "secondstring",  ********************
  20617. ******************  then the expected output is:  *****************
  20618.  
  20619. "firststring" is less than "secondstring"
  20620. */
  20621.  
  20622.  
  20623. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20624.  
  20625. o setlocale  - Set Locale 
  20626. o strcmp  - Compare Strings 
  20627. o strcmpi - Compare Strings 
  20628. o stricmp - Compare Strings 
  20629. o strncmp  - Compare Strings 
  20630. o strnicmp - Compare Strings 
  20631. o strcspn  - Compare Strings 
  20632. o wcscmp  - Compare wchar_t Strings 
  20633. o wcsncmp  - Compare wchar_t Strings 
  20634. o string.h 
  20635.  
  20636.  
  20637. ΓòÉΓòÉΓòÉ 6.216. strcpy  - Copy Strings ΓòÉΓòÉΓòÉ
  20638.  
  20639.  
  20640. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20641.  
  20642. #include <string.h>
  20643.  
  20644. char *strcpy(char *string1, const char *string2);
  20645.  
  20646.  
  20647. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20648.  
  20649. Language Level: ANSI, SAA 
  20650.  
  20651. The strcpy function copies string2, including the ending null character, to the 
  20652. location specified by string1 
  20653.  
  20654. The strcpy function operates on null-terminated strings. The string arguments 
  20655. to the function should contain a null character (\0) marking the end of the 
  20656. string. No length checking is performed. You should not use a literal string 
  20657. for a string1 value, although string2 may be a literal string. 
  20658.  
  20659. The strcpy function returns string1. 
  20660.  
  20661. Example of strcpy 
  20662.  
  20663.  
  20664. ΓòÉΓòÉΓòÉ <hidden> Example of strcpy ΓòÉΓòÉΓòÉ
  20665.  
  20666. /************************************************************************
  20667. *
  20668.  
  20669. This example copies the contents of source to destination. 
  20670.  
  20671.                                                                         *
  20672. ************************************************************************/
  20673.  
  20674. #include <stdio.h>
  20675. #include <string.h>
  20676.  
  20677. #define SIZE    40
  20678.  
  20679. int main(void)
  20680. {
  20681.   char source[ SIZE ] = "This is the source string";
  20682.   char destination[ SIZE ] = "And this is the destination string";
  20683.   char * return_string;
  20684.  
  20685.   printf( "destination is originally = \"%s\"\n", destination );
  20686.   return_string = strcpy( destination, source );
  20687.   printf( "After strcpy, destination becomes \"%s\"\n", destination );
  20688. }
  20689.  
  20690. /*****************  Output should be similar to:  *****************
  20691.  
  20692. destination is originally = "And this is the destination string"
  20693. After strcpy, destination becomes "This is the source string"
  20694. */
  20695.  
  20696.  
  20697. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20698.  
  20699. o strcat  - Concatenate Strings 
  20700. o strdup - Duplicate String 
  20701. o strncpy  - Copy Strings 
  20702. o wcscpy  - Copy wchar_t Strings 
  20703. o wcsncpy  - Copy wchar_t Strings 
  20704. o string.h 
  20705.  
  20706.  
  20707. ΓòÉΓòÉΓòÉ 6.217. strcspn  - Compare Strings ΓòÉΓòÉΓòÉ
  20708.  
  20709.  
  20710. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20711.  
  20712. #include <string.h>
  20713.  
  20714. size_t strcspn(const char *string1, const char *string2);
  20715.  
  20716.  
  20717. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20718.  
  20719. Language Level: ANSI, SAA 
  20720.  
  20721. The strcspn function finds the first occurrence of a character in string1 that 
  20722. belongs to the set of characters specified by string2. Ending null characters 
  20723. are not considered in the search. 
  20724.  
  20725. The strcspn function operates on null-terminated strings. The string arguments 
  20726. to the function should contain a null character (\0) marking the end of the 
  20727. string. 
  20728.  
  20729. The strcspn function returns the index of the first character found. This value 
  20730. is equivalent to the length of the initial substring of string1 that consists 
  20731. entirely of characters not in string2. 
  20732.  
  20733. Example of strcspn 
  20734.  
  20735.  
  20736. ΓòÉΓòÉΓòÉ <hidden> Example of strcspn ΓòÉΓòÉΓòÉ
  20737.  
  20738. /************************************************************************
  20739. *
  20740.  
  20741. This example uses strcspn to find the first occurrence of any of the characters 
  20742. a, x, l or e in string. 
  20743.  
  20744.                                                                         *
  20745. ************************************************************************/
  20746.  
  20747. #include <stdio.h>
  20748. #include <string.h>
  20749.  
  20750. #define SIZE    40
  20751.  
  20752. int main(void)
  20753. {
  20754.   char string[ SIZE ] = "This is the source string";
  20755.   char * substring = "axle";
  20756.  
  20757.   printf( "The first %i characters in the string \"%s\" "
  20758.           "are not in the string \"%s\" \n",
  20759.             strcspn(string, substring), string, substring);
  20760.  
  20761. }
  20762.  
  20763. /**********  Output should be similar to:  **************
  20764.  
  20765. The first 10 characters in the string "This is the source string"
  20766. are not in the string "axle"
  20767. */
  20768.  
  20769.  
  20770. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20771.  
  20772. o strchr  - Search for Character 
  20773. o strcmp  - Compare Strings 
  20774. o strcmpi - Compare Strings 
  20775. o stricmp - Compare Strings 
  20776. o strncmp  - Compare Strings 
  20777. o strnicmp - Compare Strings 
  20778. o strpbrk  - Find Characters in String 
  20779. o strspn  - Search Strings 
  20780. o wcscmp  - Compare wchar_t Strings 
  20781. o wcsncmp  - Compare wchar_t Strings 
  20782. o string.h 
  20783.  
  20784.  
  20785. ΓòÉΓòÉΓòÉ 6.218. _strdate - Copy Current Date ΓòÉΓòÉΓòÉ
  20786.  
  20787.  
  20788. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20789.  
  20790. #include <time.h>
  20791.  
  20792. char *_strdate(char *date);
  20793.  
  20794.  
  20795. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20796.  
  20797. Language Level: Extension 
  20798.  
  20799. The _strdate function stores the current date as a string in the buffer pointed 
  20800. to by date in the following format: 
  20801.  
  20802.    mm/dd/yy
  20803.  
  20804. The two digits mm represent the month, the digits dd represent the day of the 
  20805. month, and the digits yy represent the year.  For example, the string 10/08/91 
  20806. represents October 8, 1991. The buffer must be at least 9 bytes. 
  20807.  
  20808. Note:  The time and date functions begin at 00:00 Coordinated Universal Time, 
  20809. January 1, 1970. 
  20810.  
  20811. The _strdate function returns a pointer to the buffer containing the date 
  20812. string.  There is no error return. 
  20813.  
  20814. Example of _strdate 
  20815.  
  20816.  
  20817. ΓòÉΓòÉΓòÉ <hidden> Example of _strdate ΓòÉΓòÉΓòÉ
  20818.  
  20819. /************************************************************************
  20820. *
  20821. This example prints the current date: 
  20822.  
  20823.                                                                         *
  20824. ************************************************************************/
  20825.  
  20826. #include <stdio.h>
  20827. #include <time.h>
  20828.  
  20829. int main(void)
  20830. {
  20831.     char buffer [9];
  20832.  
  20833.     printf("The current date is %s \n", _strdate(buffer));
  20834.  
  20835.     return 0;
  20836.  
  20837. /**************  The output should be similar to:  **********************
  20838.  
  20839.      The current date is 03/21/93
  20840. */
  20841. }
  20842.  
  20843.  
  20844. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20845.  
  20846. o asctime  - Convert Time 
  20847. o ctime  - Convert Time 
  20848. o gmtime  - Convert Time 
  20849. o localtime  - Convert Time 
  20850. o mktime  - Convert Local Time 
  20851. o time  - Determine Current Time 
  20852. o _tzset - Assign Values to Locale Information 
  20853. o time.h 
  20854.  
  20855.  
  20856. ΓòÉΓòÉΓòÉ 6.219. strdup - Duplicate String ΓòÉΓòÉΓòÉ
  20857.  
  20858.  
  20859. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20860.  
  20861. #include <string.h>
  20862.  
  20863. char *strdup(const char *string);
  20864.  
  20865.  
  20866. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20867.  
  20868. Language Level: Extension &ipfisyn. root=copy.copy copying duplicate 
  20869. duplicating 
  20870.  
  20871. The strdup function reserves storage space for a copy of string by calling 
  20872. malloc. The string argument to this function is expected to contain a null 
  20873. character (\0) marking the end of the string. 
  20874.  
  20875. The strdup function returns a pointer to the storage space containing the 
  20876. copied string. If it cannot reserve storage strdup returns NULL. 
  20877.  
  20878. Example of strdup 
  20879.  
  20880.  
  20881. ΓòÉΓòÉΓòÉ <hidden> Example of strdup ΓòÉΓòÉΓòÉ
  20882.  
  20883. /************************************************************************
  20884. *
  20885.  
  20886. This example uses strdup to duplicate a string and print the copy. 
  20887.  
  20888.                                                                         *
  20889. ************************************************************************/
  20890.  
  20891. #include <stdio.h>
  20892. #include <string.h>
  20893.  
  20894. int main(void)
  20895. {
  20896.     char *string = "this is a copy";
  20897.     char *newstr;
  20898.  
  20899.     /* Make newstr point to a duplicate of str3 */
  20900.     if ( (newstr = strdup(string)) != NULL )
  20901.         printf("The new string is: %s\n", newstr);
  20902.  
  20903.     return 0;
  20904.  
  20905.     /* The expected ouput:
  20906.  
  20907.        The new string is: this is a copy  */
  20908.  
  20909. }
  20910.  
  20911.  
  20912. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20913.  
  20914. o strcpy  - Copy Strings 
  20915. o strncpy  - Copy Strings 
  20916. o wcscpy  - Copy wchar_t Strings 
  20917. o wcsncpy  - Copy wchar_t Strings 
  20918. o string.h 
  20919.  
  20920.  
  20921. ΓòÉΓòÉΓòÉ 6.220. strerror  - Set Pointer to Runtime Error Message ΓòÉΓòÉΓòÉ
  20922.  
  20923.  
  20924. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20925.  
  20926. #include <string.h>
  20927.  
  20928. char *strerror(int errnum);
  20929.  
  20930.  
  20931. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20932.  
  20933. Language Level: ANSI, SAA 
  20934.  
  20935. The strerror function maps the error number in errnum to an error message 
  20936. string. The strerror function returns a pointer to the string. It does not use 
  20937. the program locale in any way. 
  20938.  
  20939. Example of strerror 
  20940.  
  20941.  
  20942. ΓòÉΓòÉΓòÉ <hidden> Example of strerror ΓòÉΓòÉΓòÉ
  20943.  
  20944. /************************************************************************
  20945. *
  20946.  
  20947. This example opens a file and prints a runtime error message if an error 
  20948. occurs. 
  20949.  
  20950.                                                                         *
  20951. ************************************************************************/
  20952.  
  20953. #include <stdio.h>
  20954. #include <string.h>
  20955. #include <errno.h>
  20956.  
  20957. int main(void)
  20958. {
  20959.    FILE *stream;
  20960.    .
  20961.    .
  20962.    .
  20963.    if ((stream = fopen("myfile.dat", "r")) == NULL)
  20964.       printf(" %s \n", strerror(errno));
  20965. }
  20966.  
  20967.  
  20968. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  20969.  
  20970. o clearerr  - Reset Error Indicators 
  20971. o ferror  - Test for Read/Write Errors 
  20972. o perror  - Print Error Message 
  20973. o _strerror - Set Pointer to System Error String 
  20974. o string.h 
  20975.  
  20976.  
  20977. ΓòÉΓòÉΓòÉ 6.221. _strerror - Set Pointer to System Error String ΓòÉΓòÉΓòÉ
  20978.  
  20979.  
  20980. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  20981.  
  20982. #include <string.h>
  20983.  
  20984. char *_strerror(char *string);
  20985.  
  20986.  
  20987. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  20988.  
  20989. Language Level: Extension 
  20990.  
  20991. The _strerror function tests for system error. It gets the system error message 
  20992. for the last library call that produced an error and prefaces it with your 
  20993. string message. 
  20994.  
  20995. Your string message can be a maximum of 94 bytes. 
  20996.  
  20997. Unlike perror, _strerror by itself does not print a message.  To print the 
  20998. message returned by _strerror to stdout, use a printf statement similar to the 
  20999. following: 
  21000.  
  21001.    if ((access("datafile",2)) == -1)
  21002.       printf(stderr,_strerror(NULL));
  21003.  
  21004. You could also print the message to stderr with an fprintf statement. 
  21005.  
  21006. To produce accurate results, call _strerror immediately after a library 
  21007. function returns with an error.  Otherwise, subsequent calls might write over 
  21008. the errno value. 
  21009.  
  21010. If string is equal to NULL, _strerror returns a pointer to a string containing 
  21011. the system error message for the last library call that produced an error, 
  21012. ended by a new-line character (\n). 
  21013.  
  21014. If string is not equal to NULL, _strerror returns a pointer to a string 
  21015. containing: 
  21016.  
  21017. o Your string message 
  21018. o A colon 
  21019. o A space 
  21020. o The system error message for the last library call producing an error 
  21021. o A new-line character (\n). 
  21022.  
  21023. Example of _strerror 
  21024.  
  21025.  
  21026. ΓòÉΓòÉΓòÉ <hidden> Example of _strerror ΓòÉΓòÉΓòÉ
  21027.  
  21028. /************************************************************************
  21029. *
  21030.  
  21031. This example shows how _strerror can be used with the fopen function. 
  21032.  
  21033.                                                                         *
  21034. ************************************************************************/
  21035.  
  21036. #include <string.h>
  21037. #include <stdio.h>
  21038.  
  21039. int main(void)
  21040. {
  21041.     FILE *fh1, *fh2;
  21042.  
  21043.     fh1 = fopen("data1","r");
  21044.     if (fh1 == NULL)
  21045.     /*  the error message goes through stdout not stderr  */
  21046.         printf(_strerror("Open failed on input file"));
  21047.  
  21048.     fh2 = fopen("data2","w+");
  21049.     if (fh2 == NULL)
  21050.        printf(_strerror("Open failed on output file"));
  21051.     else
  21052.        printf("Open on output file was successful.\n");
  21053.  
  21054.     if (fh1 != NULL)
  21055.        fclose(fh1);
  21056.     if (fh2 != NULL)
  21057.        fclose(fh2);
  21058.  
  21059.     return 0;
  21060.  
  21061.  
  21062. /***************  The output should be similar to:  *********************
  21063.  
  21064.    Open failed on input file: The file cannot be found.
  21065.    Open on output file was successful.
  21066. */
  21067. }
  21068.  
  21069.  
  21070. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21071.  
  21072. o clearerr  - Reset Error Indicators 
  21073. o ferror  - Test for Read/Write Errors 
  21074. o perror  - Print Error Message 
  21075. o strerror  - Set Pointer to Runtime Error Message 
  21076. o string.h 
  21077.  
  21078.  
  21079. ΓòÉΓòÉΓòÉ 6.222. strftime  - Convert to Formatted Time ΓòÉΓòÉΓòÉ
  21080.  
  21081.  
  21082. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21083.  
  21084. #include <time.h>
  21085.  
  21086. size_t strftime(char *dest, size_t maxsize, const char *format,
  21087.                    const struct tm *timeptr);
  21088.  
  21089.  
  21090. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21091.  
  21092. Language Level: ANSI, SAA 
  21093.  
  21094. The strftime function places characters into the array pointed to by dest 
  21095. according to the string pointed to by format.  The format string is a multibyte 
  21096. character string. This function uses the current locale. 
  21097.  
  21098. The format string contains: 
  21099.  
  21100. o Conversion specification characters 
  21101. o Multibyte characters that are placed unchanged into the array. 
  21102.  
  21103. The characters that are converted are determined by the locale and by the 
  21104. values in the time structure pointed to by timeptr.  The conversion specifiers 
  21105. and their meanings are listed below: 
  21106.  
  21107. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  21108. Γöé SPECIFIERΓöé MEANING                              Γöé
  21109. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21110. Γöé "%a"   Γöé Insert abbreviated weekday name of locale.             Γöé
  21111. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21112. Γöé "%A"   Γöé Insert full weekday name of locale.                Γöé
  21113. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21114. Γöé "%b"   Γöé Insert abbreviated month name of locale.              Γöé
  21115. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21116. Γöé "%B"   Γöé Insert full month name of locale.                 Γöé
  21117. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21118. Γöé "%c"   Γöé Insert date and time of locale.                  Γöé
  21119. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21120. Γöé "%d"   Γöé Insert day of the month (01-31).                  Γöé
  21121. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21122. Γöé "%H"   Γöé Insert hour (24-hour clock) as a decimal number (00-23).      Γöé
  21123. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21124. Γöé "%I"   Γöé Insert hour (12-hour clock) as a decimal number (01-12).      Γöé
  21125. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21126. Γöé "%j"   Γöé Insert day of the year (001-366).                 Γöé
  21127. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21128. Γöé "%m"   Γöé Insert month (01-12).                       Γöé
  21129. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21130. Γöé "%M"   Γöé Insert minute (00-59).                       Γöé
  21131. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21132. Γöé "%p"   Γöé Insert equivalent of either AM or PM of locale.          Γöé
  21133. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21134. Γöé "%S"   Γöé Insert second (00-61).                       Γöé
  21135. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21136. Γöé "%U"   Γöé Insert week number of the year (00-53) where Sunday is the first  Γöé
  21137. Γöé      Γöé day of the week.                          Γöé
  21138. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21139. Γöé "%w"   Γöé Insert weekday (0-6) where Sunday is 0.              Γöé
  21140. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21141. Γöé "%W"   Γöé Insert week number of the year (00-53) where Monday is the first  Γöé
  21142. Γöé      Γöé day of the week.                          Γöé
  21143. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21144. Γöé "%x"   Γöé Insert date representation of locale.               Γöé
  21145. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21146. Γöé "%X"   Γöé Insert time representation of locale.               Γöé
  21147. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21148. Γöé "%y"   Γöé Insert year without the century (00-99).              Γöé
  21149. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21150. Γöé "%Y"   Γöé Insert year.                            Γöé
  21151. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21152. Γöé "%Z"   Γöé Insert name of time zone, or no characters if time zone is not   Γöé
  21153. Γöé      Γöé available.                             Γöé
  21154. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21155. Γöé "%%"   Γöé Insert %.                             Γöé
  21156. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  21157.  
  21158. The behavior is undefined when objects being copied overlap. maxsize specifies 
  21159. the maximum number of characters that can be copied into the array. 
  21160.  
  21161. The strftime function returns the number of characters (bytes) placed into the 
  21162. array, not including the terminating null character.  On error, 0 is returned. 
  21163.  
  21164. Note:  The time and date functions begin at 00:00 Universal Time, January 1, 
  21165. 1970. 
  21166.  
  21167. Example of strftime 
  21168.  
  21169.  
  21170. ΓòÉΓòÉΓòÉ <hidden> Example of strftime ΓòÉΓòÉΓòÉ
  21171.  
  21172. /************************************************************************
  21173. *
  21174.  
  21175. This example places characters into the array dest and prints the resulting 
  21176. string. 
  21177.  
  21178.                                                                         *
  21179. ************************************************************************/
  21180.  
  21181. #include <stdio.h>
  21182. #include <time.h>
  21183.  
  21184. int main(void)
  21185. {
  21186.   char dest[70];
  21187.   int ch;
  21188.   time_t temp;
  21189.   struct tm *timeptr;
  21190.  
  21191.   temp = time(NULL);
  21192.   timeptr = localtime(&temp);
  21193.   ch = strftime(dest,sizeof(dest)-1,"Today is %A,"
  21194.               " %b %d. \n Time: %I:%M %p", timeptr);
  21195.   printf("%d characters placed in string to make: \n \n %s", ch, dest);
  21196. }
  21197.  
  21198. /*****************  Output should be similar to:  *****************
  21199.  
  21200. 44 characters placed in string to make:
  21201.  
  21202.  Today is Wednesday, Oct 23.
  21203.  Time: 03:07 PM
  21204. */
  21205.  
  21206.  
  21207. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21208.  
  21209. o asctime  - Convert Time 
  21210. o ctime  - Convert Time 
  21211. o gmtime  - Convert Time 
  21212. o localtime  - Convert Time 
  21213. o setlocale  - Set Locale 
  21214. o time  - Determine Current Time 
  21215. o time.h 
  21216.  
  21217.  
  21218. ΓòÉΓòÉΓòÉ 6.223. stricmp - Compare Strings ΓòÉΓòÉΓòÉ
  21219.  
  21220.  
  21221. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21222.  
  21223. #include <string.h>
  21224.  
  21225. int stricmp(const char *string1, const char *string2);
  21226.  
  21227.  
  21228. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21229.  
  21230. Language Level: Extension 
  21231.  
  21232. The stricmp function compares string1 and string2 without sensitivity for case. 
  21233. All alphabetic characters in the arguments string1 and string2 are converted to 
  21234. lowercase before the comparison. The stricmp function operates on 
  21235. null-terminated strings. 
  21236.  
  21237. The function returns a value that indicates the following relationship between 
  21238. the two strings : 
  21239.  
  21240. Value             Meaning 
  21241. Less than 0       string1 less than string2 
  21242. 0                 string1 identical to string2 
  21243. Greater than 0    string1 greater than string2. 
  21244.  
  21245. Example of stricmp 
  21246.  
  21247.  
  21248. ΓòÉΓòÉΓòÉ <hidden> Example of stricmp ΓòÉΓòÉΓòÉ
  21249.  
  21250. /************************************************************************
  21251. *
  21252. This example uses stricmp to compare two strings. 
  21253.  
  21254.                                                                         *
  21255. ************************************************************************/
  21256.  
  21257. #include <stdio.h>
  21258. #include <string.h>
  21259.  
  21260. int main(void)
  21261. {
  21262.     char *str1 = "this is a string";
  21263.     char *str2 = "THIS IS A STRING";
  21264.  
  21265.     /* Compare two strings without regard to case */
  21266.     if ( stricmp( str1,str2 ) )
  21267.        printf("str1 is not the same as str2\n");
  21268.     else
  21269.        printf("str1 is the same as str2\n");
  21270.  
  21271.     return 0;
  21272.  
  21273.     /* The expected output is:
  21274.  
  21275.        str 1 is the same as str 2   */
  21276.  
  21277. }
  21278.  
  21279.  
  21280. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21281.  
  21282. o strcmp  - Compare Strings 
  21283. o strcmpi - Compare Strings 
  21284. o strcspn  - Compare Strings 
  21285. o strncmp  - Compare Strings 
  21286. o strnicmp - Compare Strings 
  21287. o wcscmp  - Compare wchar_t Strings 
  21288. o wcsncmp  - Compare wchar_t Strings 
  21289. o string.h 
  21290. o strnicmp - Compare Strings 
  21291.  
  21292.  
  21293. ΓòÉΓòÉΓòÉ 6.224. strlen  - Determine String Length ΓòÉΓòÉΓòÉ
  21294.  
  21295.  
  21296. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21297.  
  21298. #include <string.h>
  21299.  
  21300. size_t strlen(const char *string);
  21301.  
  21302.  
  21303. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21304.  
  21305. Language Level: ANSI, SAA 
  21306.  
  21307. The strlen function determines the length of string excluding the terminating 
  21308. null character. 
  21309.  
  21310. The strlen function returns the length of string. 
  21311.  
  21312. Example of strlen 
  21313.  
  21314.  
  21315. ΓòÉΓòÉΓòÉ <hidden> Example of strlen ΓòÉΓòÉΓòÉ
  21316.  
  21317. /************************************************************************
  21318. *
  21319.  
  21320. This example determines the length of the string that is passed to main. 
  21321.  
  21322.                                                                         *
  21323. ************************************************************************/
  21324.  
  21325. #include <stdio.h>
  21326. #include <string.h>
  21327.  
  21328. int main(int argc, char ** argv)
  21329. {
  21330.  
  21331.   if ( argc != 2 )
  21332.     printf( "Usage: %s string\n", argv[0] );
  21333.   else
  21334.     printf( "Input string has a length of %i\n", strlen( argv[1] ));
  21335. }
  21336.  
  21337. /******************  If the input is the string  ***********************
  21338. *****************"How long is this string?", ******************
  21339. ******************  then the expected output is:  *****************
  21340.  
  21341. Input string has a length of 24
  21342. */
  21343.  
  21344.  
  21345. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21346.  
  21347. o mblen  - Multibyte String Length 
  21348. o strrev - Reverse String 
  21349. o wcslen  - Calculate Length of wchar_t String 
  21350. o string.h 
  21351.  
  21352.  
  21353. ΓòÉΓòÉΓòÉ 6.225. strlwr - Convert Uppercase to Lowercase ΓòÉΓòÉΓòÉ
  21354.  
  21355.  
  21356. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21357.  
  21358. #include <string.h>
  21359.  
  21360. char *strlwr(char *string);
  21361.  
  21362.  
  21363. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21364.  
  21365. Language Level: Extension 
  21366.  
  21367. The strlwr function converts any uppercase letters in the given null-terminated 
  21368. string to lowercase.  Other characters are not affected. 
  21369.  
  21370. The strlwr function returns a pointer to the converted string. There is no 
  21371. error return. 
  21372.  
  21373. Example of strlwr 
  21374.  
  21375.  
  21376. ΓòÉΓòÉΓòÉ <hidden> Example of strlwr ΓòÉΓòÉΓòÉ
  21377.  
  21378. /************************************************************************
  21379. *
  21380.  
  21381. This example makes a copy in all lowercase of the string "General Assembly", 
  21382. and then prints the copy. 
  21383.  
  21384.                                                                         *
  21385. ************************************************************************/
  21386.  
  21387. #include <string.h>
  21388. #include <stdio.h>
  21389.  
  21390. int main(void)
  21391. {
  21392.     char *string="General Assembly";
  21393.     char *copy;
  21394.  
  21395.     copy = strlwr(strdup(string));
  21396.  
  21397.     printf("Expected result: general assembly\n");
  21398.     printf("strlwr returned: %s\n", copy);
  21399.  
  21400.     return 0;
  21401.  
  21402.     /* The expected output is:
  21403.  
  21404.        Expected result: general assembly
  21405.        strlwr returned: general assembly  */
  21406.  
  21407. }
  21408.  
  21409.  
  21410. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21411.  
  21412. o strupr - Convert Lowercase to Uppercase 
  21413. o _toascii - _tolower - _toupper - Convert Character 
  21414. o tolower - toupper  - Convert Character Case 
  21415. o string.h 
  21416.  
  21417.  
  21418. ΓòÉΓòÉΓòÉ 6.226. strncat  - Concatenate Strings ΓòÉΓòÉΓòÉ
  21419.  
  21420.  
  21421. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21422.  
  21423. #include <string.h>
  21424.  
  21425. char *strncat(char *string1, const char *string2, size_t count);
  21426.  
  21427.  
  21428. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21429.  
  21430. Language Level: ANSI, SAA 
  21431.  
  21432. The strncat function appends the first count characters of string2 to string1 
  21433. and ends the resulting string with a null character (\0). If count is greater 
  21434. than the length of string2, the length of string2 is used in place of count. 
  21435.  
  21436. The strncat function operates on null-terminated strings. The string argument 
  21437. to the function should contain a null character (\0) marking the end of the 
  21438. string. 
  21439.  
  21440. The strncat function returns a pointer to the joined string (string1). 
  21441.  
  21442. Example of strncat 
  21443.  
  21444.  
  21445. ΓòÉΓòÉΓòÉ <hidden> Example of strncat ΓòÉΓòÉΓòÉ
  21446.  
  21447. /************************************************************************
  21448. *
  21449.  
  21450. This example demonstrates the difference between strcat and strncat.  strcat 
  21451. appends the entire second string to the first, whereas strncat appends only the 
  21452. specified number of characters in the second string to the first. 
  21453.  
  21454.                                                                         *
  21455. ************************************************************************/
  21456.  
  21457. #include <stdio.h>
  21458. #include <string.h>
  21459.  
  21460. #define SIZE 40
  21461.  
  21462.  
  21463. int main(void)
  21464. {
  21465.   char buffer1[SIZE] = "computer";
  21466.   char * ptr;
  21467.  
  21468.   /* Call strcat with buffer1 and " program" */
  21469.  
  21470.   ptr = strcat( buffer1, " program" );
  21471.   printf( "strcat : buffer1 = \"%s\"\n", buffer1 );
  21472.  
  21473.   /* Reset buffer1 to contain just the string "computer" again */
  21474.  
  21475.   memset( buffer1, '\0', sizeof( buffer1 ));
  21476.   ptr = strcpy( buffer1, "computer" );
  21477.  
  21478.   /* Call strncat with buffer1 and " program" */
  21479.   ptr = strncat( buffer1, " program", 3 );
  21480.   printf( "strncat: buffer1 = \"%s\"\n", buffer1 );
  21481. }
  21482.  
  21483. /*****************  Output should be similar to:  *****************
  21484.  
  21485. strcat : buffer1 = "computer program"
  21486. strncat: buffer1 = "computer pr"
  21487. */
  21488.  
  21489.  
  21490. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21491.  
  21492. o strcat  - Concatenate Strings 
  21493. o strnicmp - Compare Strings 
  21494. o wcscat  - Append wchar_t Strings 
  21495. o wcsncat  - Concatenate wchar_t Strings 
  21496. o string.h 
  21497.  
  21498.  
  21499. ΓòÉΓòÉΓòÉ 6.227. strncmp  - Compare Strings ΓòÉΓòÉΓòÉ
  21500.  
  21501.  
  21502. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21503.  
  21504. #include <string.h>
  21505.  
  21506. int strncmp(const char *string1, const char *string2, size_t count);
  21507.  
  21508.  
  21509. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21510.  
  21511. Language Level: ANSI, SAA 
  21512.  
  21513. The strncmp function compares the first count characters of string1 and 
  21514. string2. 
  21515.  
  21516. The strncmp function returns a value indicating the relationship between the 
  21517. substrings, as follows: 
  21518.  
  21519. Value               Meaning 
  21520. Less than 0         substring1 less than substring2 
  21521. 0                   substring1 equivalent to substring2 
  21522. Greater than 0      substring1 greater than substring2 
  21523.  
  21524. Example of strncmp 
  21525.  
  21526.  
  21527. ΓòÉΓòÉΓòÉ <hidden> Example of strncmp ΓòÉΓòÉΓòÉ
  21528.  
  21529. /************************************************************************
  21530. *
  21531.  
  21532. This example demonstrates the difference between strcmp and strncmp. 
  21533.  
  21534.                                                                         *
  21535. ************************************************************************/
  21536.  
  21537. #include <stdio.h>
  21538. #include <string.h>
  21539.  
  21540. #define SIZE 10
  21541.  
  21542. int main(void)
  21543. {
  21544.   int  result;
  21545.   int  index = 3;
  21546.   char buffer1[SIZE] = "abcdefg";
  21547.   char buffer2[SIZE] = "abcfg";
  21548.   void print_result( int, char *, char * );
  21549.  
  21550.   result = strcmp( buffer1, buffer2 );
  21551.   printf( "Comparison of each character\n" );
  21552.   printf( "  strcmp: " );
  21553.   print_result( result, buffer1, buffer2 );
  21554.  
  21555.   result = strncmp( buffer1, buffer2, index);
  21556.   printf( "\nComparison of only the first %i characters\n", index );
  21557.   printf( "  strncmp: " );
  21558.   print_result( result, buffer1, buffer2 );
  21559. }
  21560.  
  21561. void print_result( int res, char * p_buffer1, char * p_buffer2 )
  21562. {
  21563.   if ( res == 0 )
  21564.     printf( "\"%s\" is identical to \"%s\"\n", p_buffer1, p_buffer2);
  21565.   else if ( res < 0 )
  21566.     printf( "\"%s\" is less than \"%s\"\n", p_buffer1, p_buffer2 );
  21567.   else
  21568.     printf( "\"%s\" is greater than \"%s\"\n", p_buffer1, p_buffer2 );
  21569. }
  21570.  
  21571. /*****************  Output should be similar to:  *****************
  21572.  
  21573. Comparison of each character
  21574.   strcmp: "abcdefg" is less than "abcfg"
  21575.  
  21576. Comparison of only the first 3 characters
  21577.   strncmp: "abcdefg" is identical to "abcfg"
  21578. */
  21579.  
  21580.  
  21581. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21582.  
  21583. o strcmp  - Compare Strings 
  21584. o strcmpi - Compare Strings 
  21585. o strcoll  - Compare Strings 
  21586. o strcspn  - Compare Strings 
  21587. o stricmp - Compare Strings 
  21588. o strnicmp - Compare Strings 
  21589. o wcscmp  - Compare wchar_t Strings 
  21590. o wcsncmp  - Compare wchar_t Strings 
  21591. o string.h 
  21592.  
  21593.  
  21594. ΓòÉΓòÉΓòÉ 6.228. strncpy  - Copy Strings ΓòÉΓòÉΓòÉ
  21595.  
  21596.  
  21597. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21598.  
  21599. #include <string.h>
  21600.  
  21601. char *strncpy(char *string1, const char *string2, size_t count);
  21602.  
  21603.  
  21604. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21605.  
  21606. Language Level: ANSI, SAA 
  21607.  
  21608. The strncpy function copies count characters of string2 to string1. If count is 
  21609. less than or equal to the length of string2, a null character (\0) is not 
  21610. appended to the copied string. If count is greater than the length of string2, 
  21611. the string1 result is padded with null characters (\0) up to length count. 
  21612.  
  21613. The strncpy function returns string1. 
  21614.  
  21615. Example of strncpy 
  21616.  
  21617.  
  21618. ΓòÉΓòÉΓòÉ <hidden> Example of strncpy ΓòÉΓòÉΓòÉ
  21619.  
  21620. /************************************************************************
  21621. *
  21622.  
  21623. This example demonstrates the difference between strcpy and strncpy. 
  21624.  
  21625.                                                                         *
  21626. ************************************************************************/
  21627.  
  21628. #include <stdio.h>
  21629. #include <string.h>
  21630.  
  21631. #define SIZE    40
  21632.  
  21633. int main(void)
  21634. {
  21635.   char source[ SIZE ] = "123456789";
  21636.   char source1[ SIZE ] = "123456789";
  21637.   char destination[ SIZE ] = "abcdefg";
  21638.   char destination1[ SIZE ] = "abcdefg";
  21639.   char * return_string;
  21640.   int    index = 5;
  21641.  
  21642.   /* This is how strcpy works */
  21643.   printf( "destination is originally = '%s'\n", destination );
  21644.   return_string = strcpy( destination, source );
  21645.   printf( "After strcpy, destination becomes '%s'\n\n", destination );
  21646.  
  21647.  
  21648.   /* This is how strncpy works */
  21649.   printf( "destination1 is originally = '%s'\n", destination1 );
  21650.   return_string = strncpy( destination1, source1, index );
  21651.   printf( "After strncpy, destination1 becomes '%s'\n", destination1 );
  21652. }
  21653.  
  21654. /*****************  Output should be similar to:  *****************
  21655.  
  21656. destination is originally = 'abcdefg'
  21657. After strcpy, destination becomes '123456789'
  21658.  
  21659. destination1 is originally = 'abcdefg'
  21660. After strncpy, destination1 becomes '12345fg'
  21661. */
  21662.  
  21663.  
  21664. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21665.  
  21666. o strcpy  - Copy Strings 
  21667. o strdup - Duplicate String 
  21668. o strnicmp - Compare Strings 
  21669. o string.h 
  21670.  
  21671.  
  21672. ΓòÉΓòÉΓòÉ 6.229. strnicmp - Compare Strings ΓòÉΓòÉΓòÉ
  21673.  
  21674.  
  21675. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21676.  
  21677. #include <string.h>
  21678.  
  21679. int strnicmp(const char *string1, const char *string2, int n);
  21680.  
  21681.  
  21682. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21683.  
  21684. Language Level: Extension 
  21685.  
  21686. The strnicmp function operates on, at most, the first n characters of 
  21687. null-terminated strings. This function compares, at most, the first n 
  21688. characters of string1 and string2. 
  21689.  
  21690. The strnicmp function is case insensitive; the uppercase and lowercase forms of 
  21691. a letter are considered equivalent. 
  21692.  
  21693. The strnicmp returns a value indicating the relationship between the 
  21694. substrings, as listed below. 
  21695.  
  21696. Value             Meaning 
  21697. Less than 0       substring1 less than substring2 
  21698. 0                 substring1 equivalent to substring2 
  21699. Greater than 0    substring1 greater than substring2. 
  21700.  
  21701. Example of strnicmp 
  21702.  
  21703.  
  21704. ΓòÉΓòÉΓòÉ <hidden> Example of strnicmp ΓòÉΓòÉΓòÉ
  21705.  
  21706. /************************************************************************
  21707. *
  21708. This example uses strnicmp to compare two strings. 
  21709.  
  21710.                                                                         *
  21711. ************************************************************************/
  21712.  
  21713. #include <string.h>
  21714. #include <stdio.h>
  21715.  
  21716. int main(void)
  21717. {
  21718.     char *str1 = "THIS IS THE FIRST STRING";
  21719.     char *str2 = "This is the second string";
  21720.     int numresult;
  21721.  
  21722.     /* Compare the first 11 characters of
  21723.        str1 and str2 without regard to case */
  21724.     numresult = strnicmp(str1, str2, 11);
  21725.  
  21726.     if (numresult < 0)
  21727.        printf("String 1 is less than string2.\n");
  21728.     else
  21729.        if (numresult > 0)
  21730.           printf("String 1 is greater than string2.\n");
  21731.        else
  21732.           printf("The two strings are equivalent.\n");
  21733.  
  21734.     return 0;
  21735.  
  21736.     /* The expected output is:
  21737.  
  21738.        The two strings are equivalent. */
  21739.  
  21740. }
  21741.  
  21742.  
  21743. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21744.  
  21745. o strcmp  - Compare Strings 
  21746. o strcmpi - Compare Strings 
  21747. o stricmp - Compare Strings 
  21748. o strncmp  - Compare Strings 
  21749. o wcscmp  - Compare wchar_t Strings 
  21750. o wcsncmp  - Compare wchar_t Strings 
  21751. o string.h 
  21752.  
  21753.  
  21754. ΓòÉΓòÉΓòÉ 6.230. strnset - strset - Set Characters in String ΓòÉΓòÉΓòÉ
  21755.  
  21756.  
  21757. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21758.  
  21759. #include <string.h>
  21760.  
  21761. char *strnset(char *string, int c, size_t n);
  21762.  
  21763. char *strset(char *string, int c);
  21764.  
  21765.  
  21766. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21767.  
  21768. Language Level: Extension 
  21769.  
  21770. The strnset function sets at most the first n characters of string to c 
  21771. (converted to a char). If n is greater than the length of string, the length of 
  21772. string is used in place of n. The strset function sets all characters of string 
  21773. except the ending null character (\0) to c (converted to a char). 
  21774.  
  21775. For both functions, the string must be initialized and must end with a null 
  21776. character (\0). 
  21777.  
  21778. Both strset and strnset return a pointer to the altered string. There is no 
  21779. error return value. 
  21780.  
  21781. Example of strnset and strset 
  21782.  
  21783.  
  21784. ΓòÉΓòÉΓòÉ <hidden> Example of strnset and strset ΓòÉΓòÉΓòÉ
  21785.  
  21786. /************************************************************************
  21787. *
  21788. In this example, the strnset function sets not more than 4 characters of a 
  21789. string to the character 'x' Then the strset function changes any non-null 
  21790. characters of a string to the character 'k'. 
  21791.  
  21792.                                                                         *
  21793. ************************************************************************/
  21794.  
  21795. #include <stdio.h>
  21796. #include <string.h>
  21797.  
  21798. int main(void)
  21799. {
  21800.     char *str = "abcdefghi";
  21801.     printf("This is the string: %s\n",str);
  21802.  
  21803.     printf("This is the string after strnset: %s\n", strnset(str, 'x', 4));
  21804.  
  21805.     printf("This is the string after strset: %s\n", strset(str, 'k'));
  21806.  
  21807.     return 0;
  21808.  
  21809. /****************  The output should be similar to:  ********************
  21810.  
  21811.    This is the string: abcdefghi
  21812.    This is the string after strnset: xxxxefghi
  21813.    This is the string after strset: kkkkkkkkk
  21814. */
  21815. }
  21816.  
  21817.  
  21818. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21819.  
  21820. o strchr  - Search for Character 
  21821. o strpbrk  - Find Characters in String 
  21822. o wcschr  - Search wchar_t String for Given wchar_t 
  21823. o wcspbrk  - Locate wchar_t Characters in String 
  21824. o string.h 
  21825.  
  21826.  
  21827. ΓòÉΓòÉΓòÉ 6.231. strpbrk  - Find Characters in String ΓòÉΓòÉΓòÉ
  21828.  
  21829.  
  21830. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21831.  
  21832. #include <string.h>
  21833.  
  21834. char *strpbrk(const char *string1, const char *string2);
  21835.  
  21836.  
  21837. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21838.  
  21839. Language Level: ANSI, SAA 
  21840.  
  21841. The strpbrk function locates the first occurrence in the string pointed to by 
  21842. string1 of any character from the string pointed to by string2. 
  21843.  
  21844. The strpbrk function returns a pointer to the character. If string1 and string2 
  21845. have no characters in common, a NULL pointer is returned. 
  21846.  
  21847. Example of strpbrk 
  21848.  
  21849.  
  21850. ΓòÉΓòÉΓòÉ <hidden> Example of strpbrk ΓòÉΓòÉΓòÉ
  21851.  
  21852. /************************************************************************
  21853. *
  21854.  
  21855. This example returns a pointer to the first occurrence in the array string of 
  21856. either a or b. 
  21857.  
  21858.                                                                         *
  21859. ************************************************************************/
  21860.  
  21861. #include <stdio.h>
  21862. #include <string.h>
  21863.  
  21864. int main(void)
  21865. {
  21866.    char *result, *string = "A Blue Danube";
  21867.    char *chars = "ab";
  21868.  
  21869.    result = strpbrk(string, chars);
  21870.    printf("The first occurrence of any of the characters \"%s\" in "
  21871.           "\"%s\" is \"%s\"\n", chars, string, result);
  21872. }
  21873.  
  21874. /*****************  Output should be similar to:  *****************
  21875.  
  21876. The first occurrence of any of the characters "ab" in "The Blue Danube"
  21877. is "anube"
  21878. */
  21879.  
  21880.  
  21881. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21882.  
  21883. o strchr  - Search for Character 
  21884. o strcspn  - Compare Strings 
  21885. o strrchr  - Find Last Occurrence of Character in String 
  21886. o strspn  - Search Strings 
  21887. o wcschr  - Search wchar_t String for Given wchar_t 
  21888. o wcscspn  - Find Offset of First wchar_t Match 
  21889. o wcspbrk  - Locate wchar_t Characters in String 
  21890. o wcsrchr  - Locate wchar_t Character in String 
  21891. o wcswcs  - Locate wchar_t Substring in wchar_t String 
  21892. o string.h 
  21893.  
  21894.  
  21895. ΓòÉΓòÉΓòÉ 6.232. strrchr  - Find Last Occurrence of Character in String ΓòÉΓòÉΓòÉ
  21896.  
  21897.  
  21898. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21899.  
  21900. #include <string.h>
  21901.  
  21902. char *strrchr(const char *string, int c);
  21903.  
  21904.  
  21905. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21906.  
  21907. Language Level: ANSI, SAA 
  21908.  
  21909. The strrchr function finds the last occurrence of c (converted to a character) 
  21910. in string.  The ending null character is considered part of the string. 
  21911.  
  21912. The strrchr function returns a pointer to the last occurrence of c in string. 
  21913. If the given character is not found, a NULL pointer is returned. 
  21914.  
  21915. Example of strrchr 
  21916.  
  21917.  
  21918. ΓòÉΓòÉΓòÉ <hidden> Example of strrchr ΓòÉΓòÉΓòÉ
  21919.  
  21920. /************************************************************************
  21921. *
  21922.  
  21923. This example compares the use of strchr and strrchr.  It searches the string 
  21924. for the first and last occurrence of p in the string. 
  21925.  
  21926.                                                                         *
  21927. ************************************************************************/
  21928.  
  21929. #include <stdio.h>
  21930. #include <string.h>
  21931.  
  21932. #define SIZE 40
  21933.  
  21934. int main(void)
  21935. {
  21936.   char buf[SIZE] = "computer program";
  21937.   char * ptr;
  21938.   int    ch = 'p';
  21939.  
  21940.   /* This illustrates strchr */
  21941.   ptr = strchr( buf, ch );
  21942.   printf( "The first occurrence of %c in '%s' is '%s'\n", ch, buf, ptr );
  21943.  
  21944.   /* This illustrates strrchr */
  21945.   ptr = strrchr( buf, ch );
  21946.   printf( "The last occurrence of %c in '%s' is '%s'\n", ch, buf, ptr );
  21947. }
  21948.  
  21949. /*****************  Output should be similar to:  *****************
  21950.  
  21951. The first occurrence of p in 'computer program' is 'puter program'
  21952. The last occurrence of p in 'computer program' is 'program'
  21953. */
  21954.  
  21955.  
  21956. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  21957.  
  21958. o strchr  - Search for Character 
  21959. o strcspn  - Compare Strings 
  21960. o strpbrk  - Find Characters in String 
  21961. o strspn  - Search Strings 
  21962. o wcschr  - Search wchar_t String for Given wchar_t 
  21963. o wcspbrk  - Locate wchar_t Characters in String 
  21964. o wcsrchr  - Locate wchar_t Character in String 
  21965. o wcswcs  - Locate wchar_t Substring in wchar_t String 
  21966. o string.h 
  21967.  
  21968.  
  21969. ΓòÉΓòÉΓòÉ 6.233. strrev - Reverse String ΓòÉΓòÉΓòÉ
  21970.  
  21971.  
  21972. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  21973.  
  21974. #include <string.h>
  21975.  
  21976. char *strrev(char *string);
  21977.  
  21978.  
  21979. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  21980.  
  21981. Language Level: Extension 
  21982.  
  21983. The strrev function reverses the order of the characters in the given string. 
  21984. The ending null character (\0) remains in place. 
  21985.  
  21986. The strrev function returns a pointer to the altered string.  There is no error 
  21987. return value. 
  21988.  
  21989. Example of strrev 
  21990.  
  21991.  
  21992. ΓòÉΓòÉΓòÉ <hidden> Example of strrev ΓòÉΓòÉΓòÉ
  21993.  
  21994. /************************************************************************
  21995. *
  21996. This example determines if a string is a palindrome.  A palindrome is a string 
  21997. that reads the same forward and backward. 
  21998.  
  21999.                                                                         *
  22000. ************************************************************************/
  22001.  
  22002. #include <stdio.h>
  22003. #include <string.h>
  22004.  
  22005. int palindrome(char *string);
  22006. {
  22007.     char *string2;
  22008.     /* Duplicate string for comparison */
  22009.     if (( string2 = strdup(string) ) == NULL)  {
  22010.         printf ("Storage could not be reserved for string\n");
  22011.         _exit(-1);
  22012.     }
  22013.  
  22014.     /* If result equals 0, the string is a palindrome */
  22015.     return (strcmp(string, strrev(string2)));
  22016. }
  22017.  
  22018. int main(void)
  22019. {
  22020.     char string[81];
  22021.     printf("Please enter a string.\n");
  22022.     scanf("%80s", string);
  22023.     if (palindrome(string))
  22024.        printf("The string is not a palindrome.\n");
  22025.     else
  22026.        printf("The string is a palindrome.\n");
  22027.  
  22028.     return 0;
  22029.  
  22030.  
  22031. /**************  The output should be similar to:  **********************
  22032.  
  22033.    Please enter a string.
  22034.    level
  22035.    The string is a palindrome.
  22036.  
  22037.  
  22038. ** ... or ... **
  22039.  
  22040.  
  22041.    Please enter a string.
  22042.    bolton
  22043.    The string is not a palindrome.
  22044. */
  22045. }
  22046.  
  22047.  
  22048. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22049.  
  22050. o strcat  - Concatenate Strings 
  22051. o strcmp  - Compare Strings 
  22052. o strcpy  - Copy Strings 
  22053. o strdup - Duplicate String 
  22054. o strnset - strset - Set Characters in String 
  22055. o string.h 
  22056.  
  22057.  
  22058. ΓòÉΓòÉΓòÉ 6.234. strspn  - Search Strings ΓòÉΓòÉΓòÉ
  22059.  
  22060.  
  22061. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22062.  
  22063. #include <string.h>
  22064.  
  22065. size_t strspn(const char *string1, const char *string2);
  22066.  
  22067.  
  22068. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22069.  
  22070. Language Level: ANSI, SAA 
  22071.  
  22072. The strspn function finds the first occurrence of a character in string1 that 
  22073. is not contained in the set of characters specified by string2. The null 
  22074. character (\0) that ends string2 is not considered in the matching process. 
  22075.  
  22076. The strspn function returns the index of the first character found. This value 
  22077. is equal to the length of the initial substring of string1 that consists 
  22078. entirely of characters from string2. If string1 begins with a character not in 
  22079. string2, strspn returns 0. If all the characters in string1 are found in 
  22080. string2, the length of string1 is returned. 
  22081.  
  22082. Example of strspn 
  22083.  
  22084.  
  22085. ΓòÉΓòÉΓòÉ <hidden> Example of strspn ΓòÉΓòÉΓòÉ
  22086.  
  22087. /************************************************************************
  22088. *
  22089.  
  22090. This example finds the first occurrence in the array string of a character that 
  22091. is neither an a, b, nor c.  Because the string in this example is cabbage, 
  22092. strspn returns 5, the length of the segment of cabbage before a character that 
  22093. is not an a, b or c. 
  22094.  
  22095.                                                                         *
  22096. ************************************************************************/
  22097.  
  22098. #include <stdio.h>
  22099. #include <string.h>
  22100.  
  22101. int main(void)
  22102. {
  22103.   char * string = "cabbage";
  22104.   char * source = "abc";
  22105.   int index;
  22106.  
  22107.   index = strspn( string, "abc" );
  22108.   printf( "The first %d characters of \"%s\" are found in \"%s\"\n",
  22109.           index, string, source );
  22110. }
  22111.  
  22112. /*****************  Output should be similar to:  *****************
  22113.  
  22114. The first 5 characters of "cabbage" are found in "abc"
  22115. */
  22116.  
  22117.  
  22118. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22119.  
  22120. o strchr  - Search for Character 
  22121. o strcspn  - Compare Strings 
  22122. o strpbrk  - Find Characters in String 
  22123. o strrchr  - Find Last Occurrence of Character in String 
  22124. o wcschr  - Search wchar_t String for Given wchar_t 
  22125. o wcscspn  - Find Offset of First wchar_t Match 
  22126. o wcspbrk  - Locate wchar_t Characters in String 
  22127. o wcsrchr  - Locate wchar_t Character in String 
  22128. o wcsspn  - Search wchar_t Characters in String 
  22129. o wcswcs  - Locate wchar_t Substring in wchar_t String 
  22130. o string.h 
  22131.  
  22132.  
  22133. ΓòÉΓòÉΓòÉ 6.235. strstr  - Locate Substring ΓòÉΓòÉΓòÉ
  22134.  
  22135.  
  22136. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22137.  
  22138. #include <string.h>
  22139.  
  22140. char *strstr(const char *string1, const char *string2);
  22141.  
  22142.  
  22143. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22144.  
  22145. Language Level: ANSI, SAA 
  22146.  
  22147. The strstr function finds the first occurrence of string2 in string1. The 
  22148. function ignores the null character (\0) that ends string2 in the matching 
  22149. process. 
  22150.  
  22151. The strstr function returns a pointer to the beginning of the first occurrence 
  22152. of string2 in string1. If string2 does not appear in string1, strstr returns 
  22153. NULL. If string2 points to a string with zero length, the function returns 
  22154. string1. 
  22155.  
  22156. Example of strstr 
  22157.  
  22158.  
  22159. ΓòÉΓòÉΓòÉ <hidden> Example of strstr ΓòÉΓòÉΓòÉ
  22160.  
  22161. /************************************************************************
  22162. *
  22163.  
  22164. This example locates the string haystack in the string "needle in a haystack". 
  22165.  
  22166.                                                                         *
  22167. ************************************************************************/
  22168.  
  22169. #include <string.h>
  22170. #include <stdio.h>
  22171.  
  22172. int main(void)
  22173. {
  22174.    char *string1 = "needle in a haystack";
  22175.    char *string2 = "haystack";
  22176.    char *result;
  22177.  
  22178.   result = strstr(string1,string2);
  22179.      /* Result = a pointer to "haystack" */
  22180.   printf("%s\n", result);
  22181. }
  22182.  
  22183. /*****************  Output should be similar to:  *****************
  22184.  
  22185. haystack
  22186. */
  22187.  
  22188.  
  22189. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22190.  
  22191. o strchr  - Search for Character 
  22192. o strcspn  - Compare Strings 
  22193. o strpbrk  - Find Characters in String 
  22194. o strrchr  - Find Last Occurrence of Character in String 
  22195. o strspn  - Search Strings 
  22196. o wcschr  - Search wchar_t String for Given wchar_t 
  22197. o wcscspn  - Find Offset of First wchar_t Match 
  22198. o wcspbrk  - Locate wchar_t Characters in String 
  22199. o wcsrchr  - Locate wchar_t Character in String 
  22200. o wcsspn  - Search wchar_t Characters in String 
  22201. o wcswcs  - Locate wchar_t Substring in wchar_t String 
  22202. o string.h 
  22203.  
  22204.  
  22205. ΓòÉΓòÉΓòÉ 6.236. _strtime - Copy Time ΓòÉΓòÉΓòÉ
  22206.  
  22207.  
  22208. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22209.  
  22210. #include <time.h>
  22211.  
  22212. char *_strtime(char *time);
  22213.  
  22214.  
  22215. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22216.  
  22217. Language Level: Extension 
  22218.  
  22219. The _strtime function copies the current time into the buffer to which time 
  22220. points.  The format is: 
  22221.  
  22222.    hh:mm:ss
  22223.  
  22224. where 
  22225.  
  22226. hh represents the hour in 24-hour notation, 
  22227.  
  22228. mm represents the minutes past the hour, 
  22229.  
  22230. ss represents the number of seconds. 
  22231.  
  22232. For example, the string 18:23:44 represents 23 minutes and 44 seconds past 6 
  22233. p.m. 
  22234.  
  22235. The buffer must be at least 9 bytes. 
  22236.  
  22237. Note:  The time and date functions begin at 00:00 Coordinated Universal Time, 
  22238. January 1, 1970. 
  22239.  
  22240. The value returned is a pointer to the buffer.  There is no error return. 
  22241.  
  22242. Example of _strtime 
  22243.  
  22244.  
  22245. ΓòÉΓòÉΓòÉ <hidden> Example of _strtime ΓòÉΓòÉΓòÉ
  22246.  
  22247. /************************************************************************
  22248. *
  22249. This example prints the current time: 
  22250.  
  22251.                                                                         *
  22252. ************************************************************************/
  22253.  
  22254. #include <stdio.h>
  22255. #include <time.h>
  22256.  
  22257. int main(void)
  22258. {
  22259.     char buffer[9];
  22260.  
  22261.     printf("The current time is %s \n",
  22262.              _strtime(buffer));
  22263.  
  22264.     return 0;
  22265.  
  22266. /*********  The output should be similar to:  *******
  22267.  
  22268.    The current time is 16:09:22
  22269. */
  22270. }
  22271.  
  22272.  
  22273. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22274.  
  22275. o asctime  - Convert Time 
  22276. o ctime  - Convert Time 
  22277. o gmtime  - Convert Time 
  22278. o localtime  - Convert Time 
  22279. o mktime  - Convert Local Time 
  22280. o time  - Determine Current Time 
  22281. o _tzset - Assign Values to Locale Information 
  22282. o time.h 
  22283.  
  22284.  
  22285. ΓòÉΓòÉΓòÉ 6.237. strtod  - Convert Character String to Numeric ΓòÉΓòÉΓòÉ
  22286.  
  22287.  
  22288. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22289.  
  22290. #include <stdlib.h>
  22291.  
  22292. double strtod(const char *nptr, char **endptr);
  22293.  
  22294.  
  22295. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22296.  
  22297. Language Level: ANSI, SAA 
  22298.  
  22299. The strtod function converts a character string to a double-precision value. 
  22300. The parameter nptr points to a sequence of characters that can be interpreted 
  22301. as a numerical value of the type double.  This function stops reading the 
  22302. string at the first character that it cannot recognize as part of a number. 
  22303. This character can be the null character at the end of the string. 
  22304.  
  22305. The strtod function expects nptr to point to a string with the following form: 
  22306.  
  22307.  ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ
  22308.   Γöé        Γöé  Γöé    Γöé  Γöé                 Γöé
  22309.   ΓööΓöÇΓöÇwhitespaceΓöÇΓöÇΓöÿ  Γö£ΓöÇΓöÇ + ΓöÇΓöÇΓöñ  Γö£ΓöÇdigitsΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöñ
  22310.            Γöé    Γöé  Γöé      Γöé    Γöé  Γöé     Γöé  Γöé
  22311.            ΓööΓöÇΓöÇ - ΓöÇΓöÇΓöÿ  Γöé      ΓööΓöÇΓöÇ . ΓöÇΓöÿ  ΓööΓöÇdigitsΓöÇΓöÿ  Γöé
  22312.                  Γöé                 Γöé
  22313.                  ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ . ΓöÇΓöÇdigitsΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  22314.  
  22315.  ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ
  22316.   Γöé              Γöé
  22317.   Γö£ΓöÇΓöÇeΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇdigitsΓöÇΓöÇΓöÿ
  22318.   Γöé   Γöé  Γöé   Γöé
  22319.   ΓööΓöÇΓöÇEΓöÇΓöÇΓöÿ  Γö£ΓöÇ + ΓöÇΓöñ
  22320.        Γöé   Γöé
  22321.        ΓööΓöÇ - ΓöÇΓöÿ
  22322.  
  22323. The first character that does not fit this form stops the scan. 
  22324.  
  22325. The strtod function returns the value of the floating-point number, except when 
  22326. the representation causes an underflow or overflow.  In the case of an 
  22327. overflow, it returns -HUGE_VAL or +HUGE_VAL;  in the case of an underflow, it 
  22328. returns 0. 
  22329.  
  22330. In both cases, errno is set to ERANGE, depending on the base of the value. If 
  22331. the string pointed to by nptr does not have the expected form, no conversion is 
  22332. performed and the value of nptr is stored in the object pointed to by endptr, 
  22333. provided that endptr is not a NULL pointer. 
  22334.  
  22335. Example of strtod 
  22336.  
  22337.  
  22338. ΓòÉΓòÉΓòÉ <hidden> Example of strtod ΓòÉΓòÉΓòÉ
  22339.  
  22340. /************************************************************************
  22341. *
  22342.  
  22343. This example converts the strings to a double value.  It prints out the 
  22344. converted value and the substring that stopped the conversion. 
  22345.  
  22346.                                                                         *
  22347. ************************************************************************/
  22348.  
  22349. #include <stdlib.h>
  22350. #include <stdio.h>
  22351.  
  22352. int main(void)
  22353. {
  22354.    char *string, *stopstring;
  22355.    double x;
  22356.  
  22357.    string = "3.1415926This stopped it";
  22358.    x = strtod(string, &stopstring);
  22359.    printf("string = %s\n", string);
  22360.    printf("   strtod = %lf\n", x);
  22361.    printf("   Stopped scan at %s\n\n", stopstring);
  22362.  
  22363.    string = "100ergs";
  22364.    x = strtod(string, &stopstring);
  22365.    printf("string = \"%s\"\n", string);
  22366.    printf("   strtod = %lf\n", x);
  22367.    printf("   Stopped scan at \"%s\"\n\n", stopstring);
  22368. }
  22369.  
  22370. /*****************  Output should be similar to:  *****************
  22371.  
  22372. string = 3.1415926This stopped it
  22373.    strtod = 3.141593
  22374.    Stopped scan at This stopped it
  22375.  
  22376. string = 100ergs
  22377.    strtod = 100.000000
  22378.    Stopped scan at ergs
  22379. */
  22380.  
  22381.  
  22382. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22383.  
  22384. o atof  - Convert Character Strings 
  22385. o atoi  - Convert Character Strings 
  22386. o atol  - Convert Character Strings 
  22387. o _atold - Convert ASCII String to Long Double 
  22388. o strtol  - Convert Character String to Numeric 
  22389. o strtold - Convert String to Long Double 
  22390. o strtoul  - Convert String Segment to Unsigned Integer 
  22391. o stdlib.h 
  22392.  
  22393.  
  22394. ΓòÉΓòÉΓòÉ 6.238. strtok  - Tokenize String ΓòÉΓòÉΓòÉ
  22395.  
  22396.  
  22397. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22398.  
  22399. #include <string.h>
  22400.  
  22401. char *strtok(char *string1, const char *string2);
  22402.  
  22403.  
  22404. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22405.  
  22406. Language Level: ANSI, SAA 
  22407.  
  22408. The strtok function reads string1 as a series of zero or more tokens and 
  22409. string2 as the set of characters serving as delimiters of the tokens in 
  22410. string1. The tokens in string1 can be separated by one or more of the 
  22411. delimiters from string2. The tokens in string1 can be located by a series of 
  22412. calls to strtok. 
  22413.  
  22414. In the first call to strtok for a given string1, strtok searches for the first 
  22415. token in string1, skipping over leading delimiters.  A pointer to the first 
  22416. token is returned. 
  22417.  
  22418. To read the next token from string1, call strtok with a NULL string1 argument. 
  22419. A NULL string1 argument causes strtok to search for the next token in the 
  22420. previous token string. Each delimiter is replaced by a null character.  The set 
  22421. of delimiters can vary from call to call, so string2 can take any value. 
  22422.  
  22423. The first time strtok is called, it returns a pointer to the first token in 
  22424. string1.  In later calls with the same token string, strtok returns a pointer 
  22425. to the next token in the string.  A NULL pointer is returned when there are no 
  22426. more tokens.  All tokens are null-terminated. 
  22427.  
  22428. Example of strtok 
  22429.  
  22430.  
  22431. ΓòÉΓòÉΓòÉ <hidden> Example of strtok ΓòÉΓòÉΓòÉ
  22432.  
  22433. /************************************************************************
  22434. *
  22435.  
  22436. Using a loop, this example gathers tokens, separated by blanks or commas, from 
  22437. a string until no tokens are left.  After processing the tokens (not shown), 
  22438. the example returns the pointers to the tokens a, string, of, and tokens.  The 
  22439. next call to strtok returns NULL and the loop ends. 
  22440.  
  22441.                                                                         *
  22442. ************************************************************************/
  22443.  
  22444. #include <stdio.h>
  22445. #include <string.h>
  22446.  
  22447. int main(void)
  22448. {
  22449.    char *token, *string = "a string, of, ,tokens\0,after null terminator";
  22450.  
  22451.    /* the string pointed to by string is broken up into the tokens
  22452.       "a string", " of", " ", and "tokens" ; the null terminator (\0)
  22453.       is encountered and execution stops after the token "tokens"     */
  22454.    token = strtok(string, ",");
  22455.    do
  22456.    {
  22457.       printf("token: %s\n", token);
  22458.    }
  22459.    while (token = strtok(NULL, ","));
  22460. }
  22461.  
  22462. /*****************  Output should be similar to:  *****************
  22463.  
  22464. token: a string
  22465. token:  of
  22466. token:
  22467. token: tokens
  22468. */
  22469.  
  22470.  
  22471. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22472.  
  22473. o strcat  - Concatenate Strings 
  22474. o strchr  - Search for Character 
  22475. o strcmp  - Compare Strings 
  22476. o strcpy  - Copy Strings 
  22477. o strcspn  - Compare Strings 
  22478. o strspn  - Search Strings 
  22479. o string.h 
  22480.  
  22481.  
  22482. ΓòÉΓòÉΓòÉ 6.239. strtol  - Convert Character String to Numeric ΓòÉΓòÉΓòÉ
  22483.  
  22484.  
  22485. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22486.  
  22487. #include <stdlib.h>
  22488.  
  22489. long int strtol(const char *nptr, char **endptr, int base);
  22490.  
  22491.  
  22492. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22493.  
  22494. Language Level: ANSI, SAA 
  22495.  
  22496. The strtol function converts a character string to a long-integer value. The 
  22497. parameter nptr points to a sequence of characters that can be interpreted as a 
  22498. numerical value of type long int. This function stops reading the string at the 
  22499. first character that it cannot recognize as part of a number. This character 
  22500. can be the null character (\0) at the end of the string. The ending character 
  22501. can also be the first numeric character greater than or equal to the base. 
  22502.  
  22503. When you use the strtol function, nptr should point to a string with the 
  22504. following form: 
  22505.  
  22506. ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ
  22507.   Γöé        Γöé  Γöé    Γöé  Γöé    Γöé  Γöé      Γöé
  22508.   ΓööΓöÇΓöÇwhitespaceΓöÇΓöÇΓöÿ  Γö£ΓöÇΓöÇ + ΓöÇΓöÇΓöñ  Γö£ΓöÇΓöÇ0ΓöÇΓöÇΓöÇΓöñ  ΓööΓöÇΓöÇdigitsΓöÇΓöÇΓöÿ
  22509.            Γöé    Γöé  Γöé    Γöé
  22510.            ΓööΓöÇΓöÇ - ΓöÇΓöÇΓöÿ  Γö£ΓöÇΓöÇ0xΓöÇΓöÇΓöñ
  22511.                  Γöé    Γöé
  22512.                  ΓööΓöÇΓöÇ0XΓöÇΓöÇΓöÿ
  22513.  
  22514. If base is in the range of 2 through 36, it becomes the base of the number. If 
  22515. base is 0, the prefix determines the base (8, 16, or 10):  the prefix 0 means 
  22516. base 8;  the prefix 0x or 0X means base 16;  using any other digit without a 
  22517. prefix means decimal. 
  22518.  
  22519. The strtol function returns the value represented in the string, except when 
  22520. the representation causes an overflow.  In the case of an overflow, it returns 
  22521. LONG_MAX or LONG_MIN, according to the sign of the value and errno is set to 
  22522. ERANGE. If base is not a valid number, strtol sets errno to EDOM. 
  22523.  
  22524. errno is set to ERANGE for the exceptional cases, depending on the base of the 
  22525. value.  If the string pointed to by nptr does not have the expected form, no 
  22526. conversion is performed and the value of nptr is stored in the object pointed 
  22527. to by endptr, provided that endptr is not a NULL pointer. 
  22528.  
  22529. Example of strtol 
  22530.  
  22531.  
  22532. ΓòÉΓòÉΓòÉ <hidden> Example of strtol ΓòÉΓòÉΓòÉ
  22533.  
  22534. /************************************************************************
  22535. *
  22536.  
  22537. This example converts the strings to a long value.  It prints out the converted 
  22538. value and the substring that stopped the conversion. 
  22539.  
  22540.                                                                         *
  22541. ************************************************************************/
  22542.  
  22543. #include <stdlib.h>
  22544. #include <stdio.h>
  22545.  
  22546. int main(void)
  22547. {
  22548.    char *string, *stopstring;
  22549.    long l;
  22550.    int bs;
  22551.  
  22552.    string = "10110134932";
  22553.    printf("string = %s\n", string);
  22554.    for (bs = 2; bs <= 8; bs *= 2)
  22555.    {
  22556.       l = strtol(string, &stopstring, bs);
  22557.       printf("   strtol = %ld (base %d)\n", l, bs);
  22558.       printf("   Stopped scan at %s\n\n", stopstring);
  22559.       }
  22560. }
  22561.  
  22562. /*****************  Output should be similar to:  *****************
  22563.  
  22564. string = 10110134932
  22565.    strtol = 45 (base 2)
  22566.    Stopped scan at 34932
  22567.  
  22568.    strtol = 4423 (base 4)
  22569.    Stopped scan at 4932
  22570.  
  22571.    strtol = 2134108 (base 8)
  22572.    Stopped scan at 932
  22573. */
  22574.  
  22575.  
  22576. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22577.  
  22578. o atof  - Convert Character Strings 
  22579. o atoi  - Convert Character Strings 
  22580. o atol  - Convert Character Strings 
  22581. o _atold - Convert ASCII String to Long Double 
  22582. o _ltoa - Convert Long Integer to String 
  22583. o strtod  - Convert Character String to Numeric 
  22584. o strtold - Convert String to Long Double 
  22585. o strtoul  - Convert String Segment to Unsigned Integer 
  22586. o stdlib.h 
  22587.  
  22588.  
  22589. ΓòÉΓòÉΓòÉ 6.240. strtold - Convert String to Long Double ΓòÉΓòÉΓòÉ
  22590.  
  22591.  
  22592. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22593.  
  22594. #include <stdlib.h>
  22595.  
  22596. long double strtold(const char *nptr, char **endptr);
  22597.  
  22598.  
  22599. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22600.  
  22601. Language Level: Extension 
  22602.  
  22603. The strtold function converts a character string pointed to by nptr to a long 
  22604. double value.  When it reads a character it does not recognize as part of a 
  22605. number, strtold stops conversion and endptr points to the remainder of nptr. 
  22606. This character may be the ending null character. 
  22607.  
  22608. The string pointed to by nptr must have the following format: 
  22609.  
  22610.  ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ
  22611.   ΓööΓöÇΓöÇwhitespaceΓöÇΓöÇΓöÿ  ΓööΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γöÿ
  22612.             Γö£ΓöÇΓöÇΓöÇ+ΓöÇΓöÇΓöÇΓöñ  Γö£ΓöÇΓöÇdigitsΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöñ
  22613.             ΓööΓöÇΓöÇΓöÇ-ΓöÇΓöÇΓöÇΓöÿ  Γöé      ΓööΓöÇΓöÇ.ΓöÇΓöÇΓöÿ ΓööΓöÇdigitsΓöÇΓöÿ Γöé
  22614.                   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇ.ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇdigitsΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  22615.  
  22616.  ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇ
  22617.   Γö£ΓöÇΓöÇeΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇdigitsΓöÇΓöÇΓöÿ
  22618.   ΓööΓöÇΓöÇEΓöÇΓöÇΓöÿ  Γö£ΓöÇΓöÇ+ΓöÇΓöÇΓöñ
  22619.        ΓööΓöÇΓöÇ-ΓöÇΓöÇΓöÿ
  22620.  
  22621. The digits are one or more decimal digits.  If no digits appear before the 
  22622. decimal point, at least one digit must follow the decimal point.  An exponent 
  22623. expressed as a decimal integer may follow the digits.  The exponent may be 
  22624. signed. 
  22625.  
  22626. The value of nptr can also be one of the strings infinity, inf, or nan.  These 
  22627. strings are case insensitive, and can be preceded by a unary minus (-). They 
  22628. are converted to infinity and NaN values. See Infinity and NaN Support for more 
  22629. information about using infinity and NaN values. 
  22630.  
  22631. If the string pointed to by nptr does not have the expected form, no conversion 
  22632. is performed and endptr points to the value of nptr. 
  22633.  
  22634. The strtold function ignores any white-space characters, as defined by the 
  22635. isspace function. 
  22636.  
  22637. If successful, strtold returns the value of the long double number.  If it 
  22638. fails, strtold returns 0.  In the case of an underflow or overflow, it returns 
  22639. the following: 
  22640.  
  22641. Condition           Return Value 
  22642. Underflow           0 with errno set to ERANGE 
  22643. Positive overflow   +_LHUGE_VAL 
  22644. Negative overflow   -_LHUGE_VAL. 
  22645.  
  22646. Example of strtold 
  22647.  
  22648.  
  22649. ΓòÉΓòÉΓòÉ <hidden> Example of strtold ΓòÉΓòÉΓòÉ
  22650.  
  22651. /************************************************************************
  22652. *
  22653.  
  22654. This example uses strtold to convert two strings, "  -001234.5678e10end of 
  22655. string" and "NaNQthis cannot be converted" to their corresponding long double 
  22656. values.  It also prints out the part of the string that cannot be converted. 
  22657.  
  22658.                                                                         *
  22659. ************************************************************************/
  22660.  
  22661. #include <stdlib.h>
  22662. #include <stdio.h>
  22663.  
  22664. int main(void)
  22665. {
  22666.    char *nptr;
  22667.    char *endptr;
  22668.  
  22669.    nptr = "  -001234.5678e10end of string";
  22670.  
  22671.    printf("strtold = %.10Le\n", strtold(nptr, &endptr) );
  22672.    printf("end pointer at = %s\n\n", endptr);
  22673.  
  22674.    nptr = "NaNthis cannot be converted";
  22675.  
  22676.    printf("strtold = %.10Le\n", strtold(nptr, &endptr) );
  22677.    printf("end pointer at = %s\n\n", endptr);
  22678.  
  22679.    return 0;
  22680.  
  22681.    /* The expected output is:
  22682.  
  22683.       strtold = -1.2345678000e+13
  22684.       end pointer at = end of string
  22685.  
  22686.       strtold = nan
  22687.       end pointer at = this cannot be converted */
  22688.  
  22689. }
  22690.  
  22691.  
  22692. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22693.  
  22694. o atof  - Convert Character Strings 
  22695. o atoi  - Convert Character Strings 
  22696. o atol  - Convert Character Strings 
  22697. o _atold - Convert ASCII String to Long Double 
  22698. o strtod  - Convert Character String to Numeric 
  22699. o strtol  - Convert Character String to Numeric 
  22700. o strtoul  - Convert String Segment to Unsigned Integer 
  22701. o Infinity and NaN Support 
  22702. o stdlib.h 
  22703.  
  22704.  
  22705. ΓòÉΓòÉΓòÉ 6.241. strtoul  - Convert String Segment to Unsigned Integer ΓòÉΓòÉΓòÉ
  22706.  
  22707.  
  22708. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22709.  
  22710. #include <stdlib.h>
  22711.  
  22712. unsigned long int strtoul(const char *string1, char **string2, int base);
  22713.  
  22714.  
  22715. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22716.  
  22717. Language Level: ANSI, SAA 
  22718.  
  22719. The strtoul function converts a character string to an unsigned long-integer 
  22720. value. The input string1 is a sequence of characters that can be interpreted as 
  22721. a numerical value of the type unsigned long int.  The function stops reading 
  22722. the string at the first character that it cannot recognize as part of a number. 
  22723. This character can be the first numeric character greater than or equal to the 
  22724. base. The strtoul function sets string2 to point to the resulting output string 
  22725. if a conversion is performed and provided that string2 is not a NULL pointer. 
  22726.  
  22727. When you are using the strtoul function, string1 should point to a string with 
  22728. the following form: 
  22729.  
  22730. ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ
  22731.   Γöé        Γöé  Γöé    Γöé  Γöé    Γöé  Γöé      Γöé
  22732.   ΓööΓöÇΓöÇwhitespaceΓöÇΓöÇΓöÿ  Γö£ΓöÇΓöÇ + ΓöÇΓöÇΓöñ  Γö£ΓöÇΓöÇ0ΓöÇΓöÇΓöÇΓöñ  ΓööΓöÇΓöÇdigitsΓöÇΓöÇΓöÿ
  22733.            Γöé    Γöé  Γöé    Γöé
  22734.            ΓööΓöÇΓöÇ - ΓöÇΓöÇΓöÿ  Γö£ΓöÇΓöÇ0xΓöÇΓöÇΓöñ
  22735.                  Γöé    Γöé
  22736.                  ΓööΓöÇΓöÇ0XΓöÇΓöÇΓöÿ
  22737.  
  22738. If base is in the range of 2 through 36, it becomes the base of the number.  If 
  22739. base is 0, the prefix determines the base (8, 16, or 10):  the prefix 0 means 
  22740. base 8;  the prefix 0x or 0X means base 16;  using any other digit without a 
  22741. prefix means decimal. 
  22742.  
  22743. The strtoul function returns the value represented in the string or returns 0 
  22744. if no conversion could be performed. For an overflow, strtoul returns ULONG_MAX 
  22745. and sets errno to ERANGE.  If base is not a valid number, strtoul sets errno to 
  22746. EDOM. 
  22747.  
  22748. Example of strtoul 
  22749.  
  22750.  
  22751. ΓòÉΓòÉΓòÉ <hidden> Example of strtoul ΓòÉΓòÉΓòÉ
  22752.  
  22753. /************************************************************************
  22754. *
  22755.  
  22756. This example converts the string to an unsigned long value.  It prints out the 
  22757. converted value and the substring that stopped the conversion. 
  22758.  
  22759.                                                                         *
  22760. ************************************************************************/
  22761.  
  22762. #include <stdio.h>
  22763. #include <stdlib.h>
  22764.  
  22765. #define BASE 2
  22766.  
  22767. int main(void)
  22768. {
  22769.    char *string, *stopstring;
  22770.    unsigned long ul;
  22771.  
  22772.    string = "1000e13 e";
  22773.    printf("string = %s\n", string);
  22774.    ul = strtoul(string, &stopstring, BASE);
  22775.    printf("   strtoul = %ld (base %d)\n", ul, BASE);
  22776.    printf("   Stopped scan at %s\n\n", stopstring);
  22777. }
  22778.  
  22779. /*****************  Output should be similar to:  *****************
  22780.  
  22781. string = 1000e13 e
  22782.    strtoul = 8 (base 2)
  22783.    Stopped scan at e13 e
  22784. */
  22785.  
  22786.  
  22787. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22788.  
  22789. o atof  - Convert Character Strings 
  22790. o atoi  - Convert Character Strings 
  22791. o atol  - Convert Character Strings 
  22792. o _atold - Convert ASCII String to Long Double 
  22793. o strtod  - Convert Character String to Numeric 
  22794. o strtol  - Convert Character String to Numeric 
  22795. o strtold - Convert String to Long Double 
  22796. o _ultoa - Convert Unsigned Long Integer to String 
  22797. o stdlib.h 
  22798.  
  22799.  
  22800. ΓòÉΓòÉΓòÉ 6.242. strupr - Convert Lowercase to Uppercase ΓòÉΓòÉΓòÉ
  22801.  
  22802.  
  22803. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22804.  
  22805. #include <string.h>
  22806.  
  22807. char *strupr(char *string);
  22808.  
  22809.  
  22810. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22811.  
  22812. Language Level: Extension 
  22813.  
  22814. The strupr function converts any lowercase letters in string to uppercase. 
  22815. Other characters are not affected. 
  22816.  
  22817. The strupr function returns a pointer to the converted string. There is no 
  22818. error return. 
  22819.  
  22820. Example of strupr 
  22821.  
  22822.  
  22823. ΓòÉΓòÉΓòÉ <hidden> Example of strupr ΓòÉΓòÉΓòÉ
  22824.  
  22825. /************************************************************************
  22826. *
  22827. This example makes a copy in all-uppercase of the string "DosWrite", and then 
  22828. prints the copy. 
  22829.  
  22830.                                                                         *
  22831. ************************************************************************/
  22832.  
  22833. #include <string.h>
  22834. #include <stdio.h>
  22835.  
  22836. int main(void)
  22837. {
  22838.     char *string = "DosWrite";
  22839.     char *copy;
  22840.  
  22841.     copy=strupr(strdup(string));
  22842.     printf("This is a copy of the string\n");
  22843.     printf("with all letters capitalized: %s\n",copy);
  22844.  
  22845.     return 0;
  22846.  
  22847.     /* The expected output is:
  22848.  
  22849.        This is a copy of the string
  22850.        with all letters capitalized: DOSWRITE */
  22851.  
  22852. }
  22853.  
  22854.  
  22855. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22856.  
  22857. o strlwr - Convert Uppercase to Lowercase 
  22858. o _toascii - _tolower - _toupper - Convert Character 
  22859. o tolower - toupper  - Convert Character Case 
  22860. o string.h 
  22861.  
  22862.  
  22863. ΓòÉΓòÉΓòÉ 6.243. strxfrm  - Transform Strings ΓòÉΓòÉΓòÉ
  22864.  
  22865.  
  22866. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22867.  
  22868. #include <string.h>
  22869.  
  22870. size_t strxfrm(char *string1, const char *string2, size_t count);
  22871.  
  22872.  
  22873. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22874.  
  22875. Language Level: ANSI, SAA 
  22876.  
  22877. The strxfrm function transforms the string pointed to by string2 and places the 
  22878. result into the string pointed to by string1.  The transformation is determined 
  22879. by the program's current locale.  The transformed string is not necessarily 
  22880. readable, but can be used with the strcmp or strncmp functions. 
  22881.  
  22882. The strxfrm function returns the length of the transformed string, excluding 
  22883. the terminating null character.  If the value returned is greater than or equal 
  22884. to count, the contents of the transformed string are indeterminate. 
  22885.  
  22886. Example of strxfrm 
  22887.  
  22888.  
  22889. ΓòÉΓòÉΓòÉ <hidden> Example of strxfrm ΓòÉΓòÉΓòÉ
  22890.  
  22891. /************************************************************************
  22892. *
  22893.  
  22894. This example prompts the user to input a string of characters, then uses 
  22895. strxfrm to transform the string and return its length. 
  22896.  
  22897.                                                                         *
  22898. ************************************************************************/
  22899.  
  22900. #include <stdio.h>
  22901. #include <string.h>
  22902.  
  22903. int main(void)
  22904. {
  22905.    char *string1, buffer[80];
  22906.    int length;
  22907.  
  22908.    printf("Type in a string of characters.\n ");
  22909.    string1 = gets(buffer);
  22910.    length = strxfrm(NULL, string1, 0);
  22911.    printf("You would need a %d element array to hold the string\n",length);
  22912.    printf("\n\n%s\n\n transformed according",string1);
  22913.    printf(" to this program's locale. \n");
  22914. }
  22915.  
  22916.  
  22917. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22918.  
  22919. o localeconv  - Query Locale Conventions 
  22920. o setlocale  - Set Locale 
  22921. o strcmp  - Compare Strings 
  22922. o strcmpi - Compare Strings 
  22923. o strcoll  - Compare Strings 
  22924. o stricmp - Compare Strings 
  22925. o strncmp  - Compare Strings 
  22926. o strnicmp - Compare Strings 
  22927. o string.h 
  22928.  
  22929.  
  22930. ΓòÉΓòÉΓòÉ 6.244. _swab - Swap Adjacent Bytes ΓòÉΓòÉΓòÉ
  22931.  
  22932.  
  22933. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  22934.  
  22935. #include <stdlib.h>
  22936.  
  22937. void _swab(char *source, char *destination, int n);
  22938.  
  22939.  
  22940. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  22941.  
  22942. Language Level: Extension 
  22943.  
  22944. The _swab function copies n bytes from source, swaps each pair of adjacent 
  22945. bytes, and stores the result at destination.  The integer n should be an even 
  22946. number to allow for swapping. If n is an odd number, a null character (\0) is 
  22947. added after the last byte. 
  22948.  
  22949. The _swab function is typically used to prepare binary data for transfer to a 
  22950. machine that uses a different byte order. 
  22951.  
  22952. There is no return value. 
  22953.  
  22954. Example of _swab 
  22955.  
  22956.  
  22957. ΓòÉΓòÉΓòÉ <hidden> Example of _swab ΓòÉΓòÉΓòÉ
  22958.  
  22959. /************************************************************************
  22960. *
  22961. This example copies n bytes from one location to another, swapping each pair of 
  22962. adjacent bytes: 
  22963.  
  22964.                                                                         *
  22965. ************************************************************************/
  22966.  
  22967. #include <stdlib.h>
  22968. #include <stdio.h>
  22969.  
  22970. /* This array is not a string because it does not end
  22971.              with a null character */
  22972. char from[20] = "hTsii  s atsirgn..x ";
  22973. char to[20];
  22974.  
  22975. int main(void)
  22976. {
  22977.     _swab(from, to, 19);
  22978.  
  22979.     printf("%s\n", to);
  22980.                       /* Because swab appends a null character, */
  22981.                       /* the array is now a string              */
  22982.  
  22983.     return 0;
  22984.  
  22985. /***************  The output should be similar to:  *********************
  22986.  
  22987.    This is a string..
  22988. */
  22989. }
  22990.  
  22991.  
  22992. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  22993.  
  22994. o fgetc  - Read a Character 
  22995. o fputc  - Write a Character 
  22996. o stdlib.h 
  22997.  
  22998.  
  22999. ΓòÉΓòÉΓòÉ 6.245. system - Invoke the Command Processor ΓòÉΓòÉΓòÉ
  23000.  
  23001.  
  23002. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23003.  
  23004. #include <stdlib.h>
  23005.  
  23006. int system(char *string);
  23007.  
  23008.  
  23009. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23010.  
  23011. Language Level: ANSI, SAA, Extension 
  23012.  
  23013. The system function passes the command string to a command processor to be run. 
  23014. The command processor specified in the COMSPEC environment variable is searched 
  23015. for first. If it does not exist or is not a valid executable file, the default 
  23016. command processor, CMD.EXE, is searched for in the current directory and in all 
  23017. the directories specified in the PATH environment variable. 
  23018.  
  23019. If the specified command is the name of an executable file created from a C 
  23020. program, full initialization and termination is performed, including automatic 
  23021. flushing of buffers and closing of files.  To pass information across a system 
  23022. function, use a method of interprocess communication like pipes or shared 
  23023. memory. 
  23024.  
  23025. You can also use system to redirect standard streams using the redirection 
  23026. operators (the angle brackets), for example: 
  23027.  
  23028.    rc = system("cprogram < in.file");
  23029.  
  23030. The defaults for the standard streams will be whatever the standard streams are 
  23031. at the point of the system call;  for example, if the root program redirects 
  23032. stdout to file.txt, a printf call in a C module invoked by a system call will 
  23033. append to file.txt. 
  23034.  
  23035. If the argument is a null pointer, the system function returns nonzero if a 
  23036. command processor exists and 0 if it does not exist. The return value will be 
  23037. the return value from the command processor if it is successfully called. If 
  23038. system cannot call the command processor successfully, the return value is -1 
  23039. and errno is set to one of the following values: 
  23040.  
  23041. Value         Meaning 
  23042. ENOCMD        No valid command processor found. 
  23043. ENOMEM        Insufficient memory to complete the function. 
  23044. EOS2ERR       A system error occurred.  Check _doserrno for the specific OS/2 
  23045.               error code. 
  23046.  
  23047. Example of system 
  23048.  
  23049.  
  23050. ΓòÉΓòÉΓòÉ <hidden> Example of system ΓòÉΓòÉΓòÉ
  23051.  
  23052. /************************************************************************
  23053. *
  23054. This example shows how to use system to execute the OS/2 command dir c:\ : 
  23055.  
  23056.                                                                         *
  23057. ************************************************************************/
  23058.  
  23059. #include <stdlib.h>
  23060.  
  23061. int main(void)
  23062. {
  23063.     int rc;
  23064.  
  23065.     rc = system("dir c:\\");
  23066.     exit(rc);
  23067.  
  23068.     /* The expected output is a listing of files
  23069.          on the root directory of the c: drive   */
  23070. }
  23071.  
  23072.  
  23073. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23074.  
  23075. o exit  - End Program 
  23076. o _exit - End Process 
  23077. o process.h 
  23078. o stdlib.h 
  23079.  
  23080.  
  23081. ΓòÉΓòÉΓòÉ 6.246. tan  - Calculate Tangent ΓòÉΓòÉΓòÉ
  23082.  
  23083.  
  23084. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23085.  
  23086. #include <math.h>
  23087.  
  23088. double tan(double x);
  23089.  
  23090.  
  23091. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23092.  
  23093. Language Level: ANSI, SAA 
  23094.  
  23095. The tan function calculates the tangent of x, where x is expressed in radians. 
  23096. If x is too large, a partial loss of significance in the result can occur. 
  23097.  
  23098. Example of tan 
  23099.  
  23100.  
  23101. ΓòÉΓòÉΓòÉ <hidden> Example of tan ΓòÉΓòÉΓòÉ
  23102.  
  23103. /************************************************************************
  23104. *
  23105.  
  23106. This example computes x as the tangent of ╤â/4. 
  23107.  
  23108.                                                                         *
  23109. ************************************************************************/
  23110.  
  23111. #include <math.h>
  23112. #include <stdio.h>
  23113.  
  23114. int main(void)
  23115. {
  23116.    double pi, x;
  23117.  
  23118.    pi = 3.1415926;
  23119.    x = tan(pi/4.0);
  23120.  
  23121.    printf("tan( %lf ) is %lf\n", pi/4, x);
  23122. }
  23123.  
  23124. /******************  Output should be similar to:  ****************
  23125.  
  23126. tan( 0.785398 ) is 1.000000
  23127. */
  23128.  
  23129.  
  23130. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23131.  
  23132. o atan - atan2  - Calculate Arctangent 
  23133. o cos  - Calculate Cosine 
  23134. o _fpatan - Calculate Arctangent 
  23135. o _fptan - Calculate Tangent 
  23136. o sin  - Calculate Sine 
  23137. o tanh  - Calculate Hyperbolic Tangent 
  23138. o math.h 
  23139.  
  23140.  
  23141. ΓòÉΓòÉΓòÉ 6.247. tanh  - Calculate Hyperbolic Tangent ΓòÉΓòÉΓòÉ
  23142.  
  23143.  
  23144. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23145.  
  23146. #include <math.h>
  23147.  
  23148. double tanh(double x);
  23149.  
  23150.  
  23151. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23152.  
  23153. Language Level: ANSI, SAA 
  23154.  
  23155. The tanh function calculates the hyperbolic tangent of x, where x is expressed 
  23156. in radians. The result of the tanh function cannot have a range error. 
  23157.  
  23158.  
  23159. ΓòÉΓòÉΓòÉ <hidden> Example of tanh ΓòÉΓòÉΓòÉ
  23160.  
  23161. /************************************************************************
  23162. *
  23163.  
  23164. This example computes x as the hyperbolic tangent of ╤â/4. 
  23165.  
  23166.                                                                         *
  23167. ************************************************************************/
  23168.  
  23169. #include <math.h>
  23170. #include <stdio.h>
  23171.  
  23172. int main(void)
  23173. {
  23174.    double pi, x;
  23175.  
  23176.    pi = 3.1415926;
  23177.    x = tanh(pi/4);
  23178.  
  23179.    printf("tanh( %lf ) = %lf\n", pi/4, x);
  23180. }
  23181.  
  23182. /******************  Output should be similar to:  ****************
  23183.  
  23184. tanh( 0.785398 ) = 0.655794
  23185. */
  23186.  
  23187.  
  23188. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23189.  
  23190. o atan - atan2  - Calculate Arctangent 
  23191. o cosh  - Calculate Hyperbolic Cosine 
  23192. o _fpatan - Calculate Arctangent 
  23193. o _fptan - Calculate Tangent 
  23194. o sinh  - Calculate Hyperbolic Sine 
  23195. o tan  - Calculate Tangent 
  23196. o math.h 
  23197.  
  23198.  
  23199. ΓòÉΓòÉΓòÉ 6.248. _tcalloc - Reserve Tiled Storage Block ΓòÉΓòÉΓòÉ
  23200.  
  23201.  
  23202. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23203.  
  23204. #define __TILED__
  23205. #include <stdlib.h>  /* also defined in <malloc.h> */
  23206.  
  23207. void *_tcalloc(size_t number, size_t size)
  23208.  
  23209.  
  23210. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23211.  
  23212. Language Level: Extension 
  23213.  
  23214. The _tcalloc function allocates tiled memory for an array of number elements, 
  23215. each of length size bytes, and initializes all bits of each element to 0. The 
  23216. allocated memory is guaranteed not to cross a 64K boundary if the size is not 
  23217. greater than 64K. Otherwise, the memory is aligned on a 64K boundary. 
  23218.  
  23219. Note:  Memory allocated by _tcalloc must be freed using the _tfree function, 
  23220. and not any other version of free. 
  23221.  
  23222. The _tcalloc function returns a pointer to the allocated tiled memory. If not 
  23223. enough storage is available, or if num or size is 0, _tcalloc returns NULL. 
  23224.  
  23225. Example of _tcalloc 
  23226.  
  23227.  
  23228. ΓòÉΓòÉΓòÉ <hidden> Example of _tcalloc ΓòÉΓòÉΓòÉ
  23229.  
  23230. /************************************************************************
  23231. *
  23232.  
  23233. This program allocates tiled memory for an array of 100 elements of size char. 
  23234.  
  23235.                                                                         *
  23236. ************************************************************************/
  23237.  
  23238.  
  23239. #ifndef __TILED__
  23240.    #define __TILED__
  23241. #endif
  23242. #include <stdlib.h>
  23243.  
  23244. int main()
  23245.     {
  23246.     char *memoryPtr;
  23247.  
  23248.     if ((memoryPtr = _tcalloc( 100, sizeof(char)) != NULL)
  23249.        {
  23250.        printf("Successfully allocated 100 char of tiled memory.\n");
  23251.        _tfree(memoryPtr);
  23252.        }
  23253.     else
  23254.        printf("Unable to allocate tiled object.\n");
  23255.  
  23256. /********  If the program is successful, the output should be:  ******
  23257.  
  23258.           Successfully allocated 100 char of tiled memory.
  23259.  
  23260. *********************************************************************/
  23261.     }
  23262.  
  23263.  
  23264. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23265.  
  23266. o calloc  - Reserve and Initialize Storage 
  23267. o _debug_calloc - Reserve and Initialize Storage 
  23268. o _msize - Return Number of Bytes Allocated 
  23269. o _tmalloc - Reserve Tiled Storage Block 
  23270. o _trealloc - Reallocate Tiled Storage Block 
  23271. o _tfree - Free Tiled Storage Block 
  23272.  
  23273.  
  23274. ΓòÉΓòÉΓòÉ 6.249. _tell - Get Pointer Position ΓòÉΓòÉΓòÉ
  23275.  
  23276.  
  23277. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23278.  
  23279. #include <io.h>
  23280.  
  23281. long _tell(int handle);
  23282.  
  23283.  
  23284. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23285.  
  23286. Language Level: Extension 
  23287.  
  23288. The _tell function gets the current position of the file pointer associated 
  23289. with handle. The position is the number of bytes from the beginning of the 
  23290. file. 
  23291.  
  23292. The _tell function returns the current position. A return value of -1L 
  23293. indicates an error, and errno is set to one of the following values: 
  23294.  
  23295. Value          Meaning 
  23296. EBADF          The file handle is not valid. 
  23297. EOS2ERR        The call to the operating system was not successful. 
  23298.  
  23299. On devices incapable of seeking (such as screens and printers), the return 
  23300. value is -1L. 
  23301.  
  23302. Example of _tell 
  23303.  
  23304.  
  23305. ΓòÉΓòÉΓòÉ <hidden> Example of _tell ΓòÉΓòÉΓòÉ
  23306.  
  23307. /************************************************************************
  23308. *
  23309.  
  23310. This example opens the file sample.dat. It then uses tell to get the current 
  23311. position of the file pointer and report if it is successful or unsuccessful. 
  23312. The program then closes sample.dat. 
  23313.  
  23314.                                                                         *
  23315. ************************************************************************/
  23316.  
  23317. #include <io.h>
  23318. #include <stdio.h>
  23319. #include <stdlib.h>
  23320. #include <fcntl.h>
  23321.  
  23322. int main(void)
  23323. {
  23324.    long filePtrPos;
  23325.    int  fh;
  23326.  
  23327.    printf("\nCreating sample.dat.\n");
  23328.    system("echo Sample Program > sample.dat");
  23329.  
  23330.    if (-1 == (fh = _open("sample.dat",O_RDWR | O_APPEND)))
  23331.    {
  23332.       perror("Unable to open sample.dat");
  23333.       return 1;
  23334.    }
  23335.  
  23336.    /* Get the current file pointer position. */
  23337.  
  23338.    if ( -1 == (filePtrPos = _tell(fh)))
  23339.    {
  23340.       perror("Unable to _tell");
  23341.       _close(fh);
  23342.       return 1;
  23343.    }
  23344.  
  23345.    printf("File pointer is at position %d.\n",filePtrPos);
  23346.  
  23347.    _close(fh);
  23348.    return 0;
  23349.  
  23350. /*******************  The expected output is:  **************************
  23351.  
  23352.       Creating sample.dat.
  23353.       File pointer is at position 0.
  23354. */
  23355. }
  23356.  
  23357.  
  23358. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23359.  
  23360. o fseek  - Reposition File Position 
  23361. o ftell  - Get Current Position 
  23362. o _lseek - Move File Pointer 
  23363. o io.h 
  23364.  
  23365.  
  23366. ΓòÉΓòÉΓòÉ 6.250. _tempnam - Produce Temporary File Name ΓòÉΓòÉΓòÉ
  23367.  
  23368.  
  23369. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23370.  
  23371. #include <stdio.h>
  23372.  
  23373. char *_tempnam(char *dir, char *prefix);
  23374.  
  23375.  
  23376. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23377.  
  23378. Language Level: Extension 
  23379.  
  23380. The _tempnam function creates a temporary file name in another directory.  The 
  23381. prefix is the prefix to the file name. The _tempnam function tests for the 
  23382. existence of the file with the given name in the following directories, listed 
  23383. in order of precedence: 
  23384.  
  23385. o If the TMP environment variable is set and the directory specified by TMP 
  23386.   exists, the directory is specified by TMP. 
  23387.  
  23388. o If the TMP environment variable is not set or the directory specified by TMP 
  23389.   does not exist, the directory is specified by the dir argument to _tempnam 
  23390.  
  23391. o If the dir argument is NULL, or dir is the name of nonexistent directory, the 
  23392.   directory is pointed to by P_tmpdir in <stdio.h>. 
  23393.  
  23394. o If P_tmpdir does not exist, the directory is the current working directory. 
  23395.  
  23396. Note:  Because _tempnam uses malloc to reserve space for the created file name, 
  23397. you must free this space when you no longer need it. 
  23398.  
  23399. The _tempnam function returns a pointer to the temporary name, if successful. 
  23400. If the name cannot be created or it already exists, _tempnam returns the value 
  23401. NULL. 
  23402.  
  23403. Example of _tempnam 
  23404.  
  23405.  
  23406. ΓòÉΓòÉΓòÉ <hidden> Example of _tempnam ΓòÉΓòÉΓòÉ
  23407.  
  23408. /***************************************************************************
  23409. *                                                                          *
  23410. This example creates a temporary file name using the directory a:\tmp: 
  23411.  
  23412.                                                                         *
  23413. ************************************************************************/
  23414.  
  23415. #include <stdio.h>
  23416.  
  23417. int main(void)
  23418. {
  23419.     char *name1;
  23420.  
  23421.     if((name1 = _tempnam("a:\\tmp","stq")) != NULL)
  23422.         printf("%s is safe to use as a temporary file.\n", name1);
  23423.     else
  23424.  
  23425.         printf("Cannot create unique filename\n");
  23426.  
  23427.     return 0;
  23428.  
  23429. /*****************  The output should be similar to:  *******************
  23430.  
  23431.    D:\stqU3CP2.C2T is safe to use as a temporary file.
  23432. */
  23433. }
  23434.  
  23435.  
  23436. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23437.  
  23438. o malloc  - Reserve Storage Block 
  23439. o _rmtmp - Remove Temporary Files 
  23440. o tmpfile  - Create Temporary File 
  23441. o tmpnam  - Produce Temporary File Name 
  23442. o stdio.h 
  23443.  
  23444.  
  23445. ΓòÉΓòÉΓòÉ 6.251. _tfree - Free Tiled Storage Block ΓòÉΓòÉΓòÉ
  23446.  
  23447.  
  23448. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23449.  
  23450. #define __TILED__
  23451. #include <stdlib.h>  /* also defined in <malloc.h> */
  23452.  
  23453. void _tfree(void *ptr);
  23454.  
  23455.  
  23456. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23457.  
  23458. Language Level: Extension 
  23459.  
  23460. The _tfree function frees the tiled memory pointed to by ptr that has been 
  23461. allocated by one of the memory management functions. If ptr is NULL, then no 
  23462. action occurs. 
  23463.  
  23464. Note:  The _tfree function can only be used to free memory allocated by the 
  23465. tiled memory management functions. 
  23466.  
  23467. The _tfree function has no return value. 
  23468.  
  23469. Example of _tfree 
  23470.  
  23471.  
  23472. ΓòÉΓòÉΓòÉ <hidden> Example of _tfree ΓòÉΓòÉΓòÉ
  23473.  
  23474. /************************************************************************
  23475. *
  23476.  
  23477. This example uses the _tfree function to free a block of tiled memory that was 
  23478. previously allocated by the _tmalloc function. 
  23479.  
  23480.                                                                         *
  23481. ************************************************************************/
  23482.  
  23483.  
  23484. #ifndef __TILED__
  23485.    #define __TILED__
  23486. #endif
  23487. #include <stdlib.h>
  23488.  
  23489. int main()
  23490.     {
  23491.     char *memoryPtr;
  23492.  
  23493.     if ((memoryPtr = _tmalloc(100)) != NULL)
  23494.        {
  23495.        printf("Successfully allocated 100 bytes of tiled memory.\n");
  23496.        _tfree(memoryPtr);
  23497.        }
  23498.     else
  23499.        printf("Unable to allocate tiled object.\n");
  23500.  
  23501. /********  If the program is successful, the output should be:  *****
  23502.  
  23503.           Successfully allocated 100 bytes of tiled memory.
  23504.  
  23505. ********************************************************************/
  23506.     }
  23507.  
  23508.  
  23509. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23510.  
  23511. o free  - Release Storage Blocks 
  23512. o _debug_free - Release Storage Blocks 
  23513. o _tcalloc - Reserve Tiled Storage Block 
  23514. o _trealloc - Reallocate Tiled Storage Block 
  23515. o _tmalloc - Reserve Tiled Storage Block 
  23516.  
  23517.  
  23518. ΓòÉΓòÉΓòÉ 6.252. _threadstore - Access Thread-Specific Storage ΓòÉΓòÉΓòÉ
  23519.  
  23520.  
  23521. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23522.  
  23523. #include <stdlib.h>
  23524.  
  23525. void *_threadstore(void);
  23526.  
  23527.  
  23528. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23529.  
  23530. Language Level: Extension 
  23531.  
  23532. The _threadstore function gives you access to a private thread pointer that is 
  23533. initialized to NULL. You can assign any thread-specific data structure to this 
  23534. pointer. 
  23535.  
  23536. The _threadstore function returns the address of the pointer to the defined 
  23537. thread storage space. 
  23538.  
  23539. Example of _threadstore 
  23540.  
  23541.  
  23542. ΓòÉΓòÉΓòÉ <hidden> Example of _threadstore ΓòÉΓòÉΓòÉ
  23543.  
  23544. /************************************************************************
  23545. *
  23546.  
  23547. This example uses the _threadstore function to point to storage that is local 
  23548. to the thread. It prints the address pointed to by _threadstore. 
  23549.  
  23550.                                                                         *
  23551. ************************************************************************/
  23552.  
  23553.  
  23554. #include <stdlib.h>
  23555. #include <stddef.h>
  23556. #include <stdio.h>
  23557.  
  23558. #define  privateStore   (*_threadstore())
  23559.  
  23560.  
  23561. void thread(void *dummy)
  23562.     {
  23563.     privateStore = malloc(100);
  23564.  
  23565.     printf("The starting address of the storaged space is %p\n",
  23566.              privateStore);
  23567.  
  23568.     /* user must free storage before exiting thread */
  23569.  
  23570.     free (privateStore);
  23571.     _endthread();
  23572.     }
  23573.  
  23574. int main(void)
  23575.    {
  23576.    int i;
  23577.  
  23578.    for (i=0;i < 10; i++)
  23579.       {
  23580.       _beginthread(thread,NULL,(unsigned) 32096, NULL) ;
  23581.       }
  23582.  
  23583.    DosSleep(5000L);
  23584.    }
  23585.  
  23586.  
  23587. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23588.  
  23589. o _beginthread - Create New Thread 
  23590. o _endthread - Terminate Current Thread 
  23591. o stdlib.h 
  23592.  
  23593.  
  23594. ΓòÉΓòÉΓòÉ 6.253. time  - Determine Current Time ΓòÉΓòÉΓòÉ
  23595.  
  23596.  
  23597. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23598.  
  23599. #include <time.h>
  23600.  
  23601. time_t time(time_t *timeptr);
  23602.  
  23603.  
  23604. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23605.  
  23606. Language Level: ANSI, SAA 
  23607.  
  23608. The time function determines the current calendar time, which is not 
  23609. necessarily the local time localtime. 
  23610.  
  23611. The time function returns the current calendar time. The return value is also 
  23612. stored in the location given by timeptr. If timeptr is NULL, the return value 
  23613. is not stored. If the calendar time is not available, the value (time_t)(-1) is 
  23614. returned. 
  23615.  
  23616. Note:  The time and date functions begin at 00:00 Universal Time, January 1, 
  23617. 1970. 
  23618.  
  23619. Example of time 
  23620.  
  23621.  
  23622. ΓòÉΓòÉΓòÉ <hidden> Example of time ΓòÉΓòÉΓòÉ
  23623.  
  23624. /************************************************************************
  23625. *
  23626.  
  23627. This example gets the time and assigns it to ltime.  It then uses the ctime 
  23628. function to convert the number of seconds to the current date and time. This 
  23629. example then prints a message giving the current time. 
  23630.  
  23631.                                                                         *
  23632. ************************************************************************/
  23633.  
  23634. #include <time.h>
  23635. #include <stdio.h>
  23636.  
  23637. int main(void)
  23638. {
  23639.    time_t ltime;
  23640.  
  23641.    time(<ime);
  23642.    printf("The time is %s\n", ctime(<ime));
  23643. }
  23644.  
  23645. /******************  Output should be similar to:  ****************
  23646.  
  23647. The time is Mon Mar 22 19:01:41 1993
  23648. */
  23649.  
  23650.  
  23651. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23652.  
  23653. o asctime  - Convert Time 
  23654. o ctime  - Convert Time 
  23655. o gmtime  - Convert Time 
  23656. o localtime  - Convert Time 
  23657. o mktime  - Convert Local Time 
  23658. o _strtime - Copy Time 
  23659. o time.h 
  23660.  
  23661.  
  23662. ΓòÉΓòÉΓòÉ 6.254. _tmalloc - Reserve Tiled Storage Block ΓòÉΓòÉΓòÉ
  23663.  
  23664.  
  23665. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23666.  
  23667. #define __TILED__
  23668. #include <stdlib.h>  /* also defined in <malloc.h> */
  23669.  
  23670. void _tmalloc(size_t size);
  23671.  
  23672.  
  23673. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23674.  
  23675. Language Level: Extension 
  23676.  
  23677. The _tmalloc function allocates tiled memory for an object of size size, the 
  23678. value of which is indeterminate. If the size is less than 64K, then the memory 
  23679. block is guaranteed not to cross a 64K boundary. Otherwise, the block will 
  23680. begin on a 64K boundary. 
  23681.  
  23682. Note:  Memory allocated by the _tmalloc function may only be freed using the 
  23683. _tfree function. 
  23684.  
  23685. The _tmalloc function returns a pointer to the allocated tiled memory. If not 
  23686. enough storage is available, or if size is 0, then _tmalloc returns NULL. 
  23687.  
  23688. Example of _tmalloc 
  23689.  
  23690.  
  23691. ΓòÉΓòÉΓòÉ <hidden> Example of _tmalloc ΓòÉΓòÉΓòÉ
  23692.  
  23693. /************************************************************************
  23694. *
  23695.  
  23696. This example used the _tmalloc function to allocate 100 bytes of tiled memory. 
  23697.  
  23698.                                                                         *
  23699. ************************************************************************/
  23700.  
  23701.  
  23702. #ifndef __TILED__
  23703.    #define __TILED__
  23704. #endif
  23705. #include <stdlib.h>
  23706.  
  23707. int main()
  23708.     {
  23709.     char *memoryPtr;
  23710.  
  23711.     if ((memoryPtr = _tmalloc(100)) != NULL)
  23712.        {
  23713.        printf("Successfully allocated 100 bytes of tiled memory.\n");
  23714.        _tfree(memoryPtr);
  23715.        }
  23716.     else
  23717.        printf("Unable to allocate tiled object.\n");
  23718.  
  23719. /********  If the program is successful, the output should be:  ******
  23720.  
  23721.           Successfully allocated 100 bytes of tiled memory.
  23722.  
  23723. *********************************************************************/
  23724.     }
  23725.  
  23726.  
  23727. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23728.  
  23729. o _debug_malloc - Reserve Storage Blocks 
  23730. o malloc  - Reserve Storage Block 
  23731. o _msize - Return Number of Bytes Allocated 
  23732. o _tcalloc - Reserve Tiled Storage Block 
  23733. o _trealloc - Reallocate Tiled Storage Block 
  23734. o _tfree - Free Tiled Storage Block 
  23735. o stdlib.h 
  23736.  
  23737.  
  23738. ΓòÉΓòÉΓòÉ 6.255. tmpfile  - Create Temporary File ΓòÉΓòÉΓòÉ
  23739.  
  23740.  
  23741. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23742.  
  23743. #include <stdio.h>
  23744.  
  23745. FILE *tmpfile(void);
  23746.  
  23747.  
  23748. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23749.  
  23750. Language Level: ANSI, SAA 
  23751.  
  23752. The tmpfile function creates a temporary binary file.  The file is 
  23753. automatically removed when it is closed or when the program is terminated. 
  23754.  
  23755. The tmpfile function opens the temporary file in wb+ mode. 
  23756.  
  23757. The tmpfile function returns a stream pointer, if successful. If it cannot open 
  23758. the file, it returns a NULL pointer. On normal termination (exit), these 
  23759. temporary files are removed. 
  23760.  
  23761. Example of tmpfile 
  23762.  
  23763.  
  23764. ΓòÉΓòÉΓòÉ <hidden> Example of tmpfile ΓòÉΓòÉΓòÉ
  23765.  
  23766. /************************************************************************
  23767. *
  23768.  
  23769. This example creates a temporary file and if successful, writes tmpstring to 
  23770. it.  At program termination, the file is removed. 
  23771.  
  23772.                                                                         *
  23773. ************************************************************************/
  23774.  
  23775. #include <stdio.h>
  23776.  
  23777. FILE *stream;
  23778. char tmpstring[ ] = "This is the string to be temporarily written";
  23779.  
  23780. int main(void)
  23781.  
  23782. {
  23783.    if((stream = tmpfile( )) == NULL)
  23784.       perror("Cannot make a temporary file");
  23785.    else
  23786.       fprintf(stream, "%s", tmpstring);
  23787. }
  23788.  
  23789.  
  23790. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23791.  
  23792. o fopen  - Open Files 
  23793. o tmpnam  - Produce Temporary File Name 
  23794. o _tempnam - Produce Temporary File Name 
  23795. o _rmtmp - Remove Temporary Files 
  23796. o stdio.h 
  23797.  
  23798.  
  23799. ΓòÉΓòÉΓòÉ 6.256. tmpnam  - Produce Temporary File Name ΓòÉΓòÉΓòÉ
  23800.  
  23801.  
  23802. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23803.  
  23804. #include <stdio.h>
  23805.  
  23806. char *tmpnam(char *string);
  23807.  
  23808.  
  23809. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23810.  
  23811. Language Level: ANSI, SAA 
  23812.  
  23813. The tmpnam function produces a valid file name that is not the same as the name 
  23814. of any existing file. It stores this name in string.  If string is NULL, tmpnam 
  23815. leaves the result in an internal static buffer.  Any subsequent calls destroy 
  23816. this value.  If string is not NULL, it must point to an array of at least 
  23817. L_tmpnam bytes.  The value of L_tmpnam is defined in <stdio.h>. 
  23818.  
  23819. The tmpnam function returns a pointer to the name, unless it cannot create a 
  23820. unique name; in which case, it returns NULL. 
  23821.  
  23822. The tmpnam function produces a different name each time it is called within a 
  23823. module up to at least TMP_MAX (a value of at least 25) names.  Note that files 
  23824. created using names returned by tmpnam are not automatically discarded at the 
  23825. end of the program. Files can be removed by the remove function. 
  23826.  
  23827. Example of tmpnam 
  23828.  
  23829.  
  23830. ΓòÉΓòÉΓòÉ <hidden> Example of tmpnam ΓòÉΓòÉΓòÉ
  23831.  
  23832. /************************************************************************
  23833. *
  23834.  
  23835. This example calls tmpnam to produce a valid file name. 
  23836.  
  23837.                                                                         *
  23838. ************************************************************************/
  23839.  
  23840. #include <stdio.h>
  23841.  
  23842. int main(void)
  23843. {
  23844.    char *name1;
  23845.    if ((name1 = tmpnam(NULL)) !=NULL)
  23846.       printf("%s can be used as a file name.\n", name1);
  23847.    else printf("Cannot create a unique file name\n");
  23848.  
  23849. }
  23850.  
  23851.  
  23852. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23853.  
  23854. o fopen  - Open Files 
  23855. o remove  - Delete File 
  23856. o _tempnam - Produce Temporary File Name 
  23857. o stdio.h 
  23858.  
  23859.  
  23860. ΓòÉΓòÉΓòÉ 6.257. _toascii - _tolower - _toupper - Convert Character ΓòÉΓòÉΓòÉ
  23861.  
  23862.  
  23863. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23864.  
  23865. #include <ctype.h>
  23866. int _toascii(int c);
  23867.  
  23868. int _tolower(int c);
  23869.  
  23870. int _toupper(int c);
  23871.  
  23872.  
  23873. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23874.  
  23875. Language Level: Extension 
  23876.  
  23877. The _toascii, _tolower, and _toupper macros convert a single character as 
  23878. described below. 
  23879.  
  23880. The _toascii macro sets all but the low-order 7 bits of c to 0 so that the 
  23881. converted value represents a character in the ASCII character set.  If c 
  23882. already represents an ASCII character, c is unchanged. 
  23883.  
  23884. Important  Only use the _tolower macro when you know that c is uppercase. The 
  23885.            result of _tolower is undefined if c is not an uppercase letter. 
  23886.  
  23887. Only use the _toupper macro when you know that c is lowercase. The result of 
  23888. _toupper is undefined if c is not a lowercase letter. 
  23889.  
  23890. Note:  These are all macros, but _tolower and _toupper also have function 
  23891. versions because the macro versions do not correctly handle arguments with side 
  23892. effects.  Function declarations of _tolower and _toupper are given in 
  23893. <stdlib.h>. The function versions are part of the standard library, and are 
  23894. defined in the SAA standard. For portability, use the functions instead of the 
  23895. macros. 
  23896.  
  23897. The _toascii, _tolower, and _toupper macros return the possibly converted 
  23898. character c.  There is no error return. 
  23899.  
  23900. Example of _toascii - _tolower - _toupper 
  23901.  
  23902.  
  23903. ΓòÉΓòÉΓòÉ <hidden> Example of _toascii &ndask. _tolower - _toupper ΓòÉΓòÉΓòÉ
  23904.  
  23905. /************************************************************************
  23906. *
  23907. This example prints four sets of characters.  The first set is the ASCII 
  23908. characters having graphic images, which range from 0x21 through 0x7e. The 
  23909. second set takes integers 0x7f21 through 0x7f7e and applies the _toascii macro 
  23910. to them, yielding the same set of printable characters. The third set is the 
  23911. characters with all lowercase letters converted to uppercase.  The fourth set 
  23912. is the characters with all uppercase letters converted to lowercase. 
  23913.  
  23914.                                                                         *
  23915. ************************************************************************/
  23916.  
  23917. #include <stdio.h>
  23918. #include <ctype.h>
  23919.  
  23920. int main(void)
  23921. {
  23922.    int ch;
  23923.  
  23924.    printf("Characters 0x01 to 0x03,
  23925.                    and integers 0x7f01 to 0x7f03 mapped to\n");
  23926.    printf("ASCII by _toascii() both yield
  23927.             the same graphic characters.\n\n");
  23928.  
  23929.    for (ch = 0x01; ch <= 0x03; ch++)
  23930.    {
  23931.       printf("char 0x%.4X: %c    ", ch, ch);
  23932.       printf("char _toascii(0x%.4X): %c\n",
  23933.                ch+0x7f00, ch+0x7f00);
  23934.    }
  23935.  
  23936.    printf("\nCharacters A, B and C converted
  23937.                  to lower case and\n");
  23938.    printf("Characters a, b and c converted
  23939.            to upper case.\n\n");
  23940.  
  23941.    for (ch = 0x41; ch <= 0x43; ch++)  {
  23942.       printf("_tolower(%c) = %c   ", ch, _tolower(ch) );
  23943.       printf("_toupper(%c) = %c\n",
  23944.                   ch+0x20, _toupper(ch+0x20) );
  23945.    }
  23946.  
  23947.     return 0;
  23948.  
  23949. /**********  The output should be similar to:  **************
  23950.  
  23951.    Characters 0x01 to 0x03, and integers 0x7f01 to 0x7f03
  23952.    mapped to ASCII by _/toascii() both yield the same
  23953.    graphic characters.
  23954.  
  23955.    char 0x0001:     char _toascii(0x7F01): 
  23956.    char 0x0002:     char _toascii(0x7F02): 
  23957.    char 0x0003:     char _toascii(0x7F03): 
  23958.  
  23959.    Characters A, B and C converted to lower case and
  23960.    Characters a, b and c converted to upper case.
  23961.  
  23962.    _tolower(A) = a   _toupper(a) = A
  23963.    _tolower(B) = b   _toupper(b) = B
  23964.    _tolower(C) = c   _toupper(c) = C
  23965. */
  23966. }
  23967.  
  23968.  
  23969. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  23970.  
  23971. o isalnum to isxdigit  - Test Integer Value 
  23972. o _isascii - Test Integer Values 
  23973. o _iscsym - _iscsymf - Test Integer 
  23974. o tolower - toupper  - Convert Character Case 
  23975. o ctype.h 
  23976.  
  23977.  
  23978. ΓòÉΓòÉΓòÉ 6.258. tolower - toupper  - Convert Character Case ΓòÉΓòÉΓòÉ
  23979.  
  23980.  
  23981. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  23982.  
  23983. #include <ctype.h>
  23984.  
  23985. int tolower(int c);   /* Convert c to lowercase if appropriate */
  23986.  
  23987. int toupper(int c);   /* Convert c to uppercase if appropriate */
  23988.  
  23989.  
  23990. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  23991.  
  23992. Language Level: ANSI, SAA 
  23993.  
  23994. The tolower function returns a lowercase c if c represents an uppercase letter; 
  23995. otherwise, c is returned.  c is unchanged. 
  23996.  
  23997. The toupper function returns an uppercase c if c represents a lowercase letter; 
  23998. otherwise, c is returned. c is unchanged. 
  23999.  
  24000. Example of tolower - toupper 
  24001.  
  24002.  
  24003. ΓòÉΓòÉΓòÉ <hidden> Example of tolower - toupper ΓòÉΓòÉΓòÉ
  24004.  
  24005. /************************************************************************
  24006. *
  24007.  
  24008. This example uses the toupper and tolower functions to modify characters 
  24009. between code 0 and code 7f. 
  24010.  
  24011.                                                                         *
  24012. ************************************************************************/
  24013.  
  24014. #include <stdio.h>
  24015. #include <ctype.h>
  24016.  
  24017. int main(void)
  24018. {
  24019.    int ch;
  24020.  
  24021.    for (ch = 0; ch <= 0x7f; ch++)
  24022.    {
  24023.       printf("toupper=%#04x\n", toupper(ch));
  24024.       printf("tolower=%#04x\n", tolower(ch));
  24025.       putchar('\n');
  24026.       }
  24027. }
  24028.  
  24029.  
  24030. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24031.  
  24032. o isalnum to isxdigit  - Test Integer Value 
  24033. o _isascii - Test Integer Values 
  24034. o _iscsym - _iscsymf - Test Integer 
  24035. o _toascii - _tolower - _toupper - Convert Character 
  24036. o ctype.h 
  24037.  
  24038.  
  24039. ΓòÉΓòÉΓòÉ 6.259. _trealloc - Reallocate Tiled Storage Block ΓòÉΓòÉΓòÉ
  24040.  
  24041.  
  24042. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24043.  
  24044. #define __TILED__
  24045. #include <stdlib.h>  /* also defined in <malloc.h> */
  24046.  
  24047. void _trealloc(void *ptr, size_t size);
  24048.  
  24049.  
  24050. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24051.  
  24052. Language Level: Extension 
  24053.  
  24054. The _trealloc function changes the size of the tiled memory pointed to ptr to 
  24055. the specified size, in bytes. The contents of the tiled memory are unchanged up 
  24056. to the smaller of the new and old sizes. Any new tiled memory that is allocated 
  24057. is uninitialized. 
  24058.  
  24059. Note:  The _trealloc function reallocates tiled memory that has been allocated 
  24060. by the _tmalloc, _tcalloc or _trealloc functions. If the memory was not 
  24061. allocated by one of these functions or was previously freed, a message appears 
  24062. and the program ends. 
  24063.  
  24064. The _trealloc function returns a pointer to the reallocated tiled memory. If 
  24065. not enough storage is available or size is 0, then _trealloc returns NULL and 
  24066. the original block does not change. 
  24067.  
  24068. Example of _trealloc 
  24069.  
  24070.  
  24071. ΓòÉΓòÉΓòÉ <hidden> Example of _trealloc ΓòÉΓòÉΓòÉ
  24072.  
  24073. /************************************************************************
  24074. *
  24075.  
  24076. This example uses _trealloc to reallocate a block of tiled memory that was 
  24077. previously allocated by _tmalloc. 
  24078.  
  24079.                                                                         *
  24080. ************************************************************************/
  24081.  
  24082.  
  24083. #ifndef __TILED__
  24084.    #define __TILED__
  24085. #endif
  24086. #include <stdlib.h>
  24087.  
  24088. int main()
  24089.     {
  24090.     char *memoryPtr;
  24091.  
  24092.     if ((memoryPtr = _tmalloc(100)) != NULL)
  24093.        {
  24094.        printf("Successfully allocated 100 bytes of tiled memory.\n");
  24095.        }
  24096.     else
  24097.        {
  24098.        printf("Unable to allocate tiled object.\n");
  24099.        return 1;
  24100.        }
  24101.  
  24102.     if ((memoryPtr = _trealloc(memoryPtr,1000)) != NULL)
  24103.        {
  24104.        printf("Successfully reallocated 1000 bytes of tiled memory.\n");
  24105.        _tfree(memoryPtr);
  24106.        }
  24107.     else
  24108.        {
  24109.        printf("Unable to allocate tiled object.\n");
  24110.        return 1;
  24111.        }
  24112.  
  24113.     if ((memoryPtr = _tmalloc(100)) != NULL)
  24114.  
  24115. /********  If the program is successful, the output should be:  *****
  24116.  
  24117.           Successfully reallocated 100 bytes of tiled memory.
  24118.  
  24119. ********************************************************************/
  24120.  
  24121.     }
  24122.  
  24123.  
  24124. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24125.  
  24126. o _debug_calloc - Reserve and Initialize Storage 
  24127. o _msize - Return Number of Bytes Allocated 
  24128. o realloc  - Change Reserved Storage Block Size 
  24129. o _tcalloc - Reserve Tiled Storage Block 
  24130. o _tmalloc - Reserve Tiled Storage Block 
  24131. o _tfree - Free Tiled Storage Block 
  24132. o stdlib.h 
  24133.  
  24134.  
  24135. ΓòÉΓòÉΓòÉ 6.260. _tzset - Assign Values to Locale Information ΓòÉΓòÉΓòÉ
  24136.  
  24137.  
  24138. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24139.  
  24140. #include <time.h>
  24141.  
  24142. void _tzset(void);
  24143.  
  24144.  
  24145. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24146.  
  24147. Language Level: Extension 
  24148.  
  24149. The _tzset function uses the environment variable TZ to change the time zone 
  24150. and daylight saving time (DST) zone values of your current locale. These values 
  24151. are used by the gmtime and localtime functions to make corrections from 
  24152. Coordinated Universal Time (formerly GMT) to local time. 
  24153.  
  24154. To use _tzset, set the TZ variable to the appropriate values. (For the possible 
  24155. values for TZ, see the chapter on runtime environment variables in the 
  24156. Programming Guide) Then call _tzset to incorporate the changes in the time zone 
  24157. information into your current locale. 
  24158.  
  24159. To set TZ from within a program, use the _putenv function before calling 
  24160. _tzset. 
  24161.  
  24162. Note:  The time and date functions begin at 00:00 Coordinated Universal Time, 
  24163. January 1, 1970. :enote. 
  24164.  
  24165. There is no return value. 
  24166.  
  24167. Example of _tzset 
  24168.  
  24169.  
  24170. ΓòÉΓòÉΓòÉ <hidden> Example of _tzset ΓòÉΓòÉΓòÉ
  24171.  
  24172. /************************************************************************
  24173. *
  24174. This example uses the _putenv and _tzset functions to set the time zone to 
  24175. Central Time. 
  24176.  
  24177.                                                                         *
  24178. ************************************************************************/
  24179.  
  24180. #include <time.h>
  24181. #include <stdio.h>
  24182.  
  24183. int main(void)
  24184. {
  24185.    time_t currentTime;
  24186.    struct tm  * ts;
  24187.  
  24188.    /* Get the current time */
  24189.    (void)time(¤tTime);
  24190.  
  24191.    printf( "The GMT time is %s\n", asctime(gmtime(¤tTime)) );
  24192.  
  24193.    ts = localtime(¤tTime);
  24194.  
  24195.    if (ts->tm_isdst > 0)   /* check if Daylight Saving Time is in effect */
  24196.    {
  24197.       printf("The local time is %s", asctime(ts));
  24198.       printf("Daylight Saving Time is in effect.\n");
  24199.    }
  24200.    else
  24201.    {
  24202.       printf("The local time is %s",asctime(ts));
  24203.       printf("Daylight Saving Time is not in effect.\n\n");
  24204.    }
  24205.  
  24206.    printf("**** Changing to Central Time **** \n\n");
  24207.    _putenv("TZ=CST6CDT");
  24208.    _tzset();
  24209.  
  24210.    ts = localtime(¤tTime);
  24211.  
  24212.    if (ts->tm_isdst > 0)   /* check if Daylight Saving Time is in effect */
  24213.    {
  24214.       printf("The local time is %s",asctime(ts));
  24215.       printf("Daylight Saving Time is in effect.\n");
  24216.    }
  24217.    else
  24218.    {
  24219.       printf("The local time is %s",asctime(ts));
  24220.       printf("Daylight Saving Time is not in effect.\n");
  24221.    }
  24222.  
  24223.    /*  Possible output could be:
  24224.  
  24225.        The GMT time is Thu Sep  3 11:55:04 1991
  24226.  
  24227.        The local time is Thu Sep  3 07:55:04 1991
  24228.        Daylight Saving Time is in effect.
  24229.  
  24230.        **** Changing to Central Time ****
  24231.  
  24232.        The local time is Thu Sep  3 06:55:04 1991
  24233.        Daylight Saving Time is in effect.      */
  24234.  
  24235. }
  24236.  
  24237.  
  24238. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24239.  
  24240. o asctime  - Convert Time 
  24241. o _ftime - Store Current Time 
  24242. o gmtime  - Convert Time 
  24243. o localtime  - Convert Time 
  24244. o mktime  - Convert Local Time 
  24245. o _putenv - Modify Environment Variables 
  24246. o time  - Determine Current Time 
  24247. o time.h 
  24248.  
  24249.  
  24250. ΓòÉΓòÉΓòÉ 6.261. _ultoa - Convert Unsigned Long Integer to String ΓòÉΓòÉΓòÉ
  24251.  
  24252.  
  24253. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24254.  
  24255. #include <stdlib.h>
  24256.  
  24257. char *_ultoa(unsigned long value, char *string, int radix);
  24258.  
  24259.  
  24260. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24261.  
  24262. Language Level: Extension 
  24263.  
  24264. The _ultoa function converts the digits of the given unsigned long value to a 
  24265. null-terminated character string and stores the result in string. No overflow 
  24266. checking is performed. The radix argument specifies the base of value; it must 
  24267. be in the range of 2 through 36. 
  24268.  
  24269. Note:  The space allocated for string must be large enough to hold the returned 
  24270. string. The function can return up to 33 bytes, including the null character 
  24271. (\0). 
  24272.  
  24273. The _ultoa function returns a pointer to string. There is no error return 
  24274. value. 
  24275.  
  24276. Example of _ultoa 
  24277.  
  24278.  
  24279. ΓòÉΓòÉΓòÉ <hidden> Example of _ultoa ΓòÉΓòÉΓòÉ
  24280.  
  24281. /************************************************************************
  24282. *
  24283. This example converts the digits of the value 255 to decimal, binary and 
  24284. hexadecimal representations: 
  24285.  
  24286.                                                                         *
  24287. ************************************************************************/
  24288.  
  24289. #include <stdio.h>
  24290. #include <stdlib.h>
  24291.  
  24292. int main(void)
  24293. {
  24294.     char buffer[10];
  24295.     char *p;
  24296.  
  24297.     p = _ultoa(255UL, buffer, 10);
  24298.     printf("The result of _ultoa(255) with radix of 10 is %s\n", p);
  24299.  
  24300.     p = _ultoa(255UL, buffer, 2);
  24301.     printf("The result of _ultoa(255) with radix of 2 is %s\n", p);
  24302.  
  24303.     p = _ultoa(255UL, buffer, 16);
  24304.     printf("The result of _ultoa(255) with radix of 16 is %s\n", p);
  24305.  
  24306.     return 0;
  24307.  
  24308.     /* The expected output is:
  24309.  
  24310.        The result of _ultoa(255) with radix of 10 is 255
  24311.        The result of _ultoa(255) with radix of 2 is 11111111
  24312.        The result of _ultoa(255) with radix of 16 is ff      */
  24313.  
  24314. }
  24315.  
  24316.  
  24317. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24318.  
  24319. o _ecvt - Convert Floating-Point to Character 
  24320. o _fcvt - Convert Floating-Point to String 
  24321. o _gcvt - Convert Floating-Point to String 
  24322. o _itoa - Convert Integer to String 
  24323. o _ltoa - Convert Long Integer to String 
  24324. o stdlib.h 
  24325.  
  24326.  
  24327. ΓòÉΓòÉΓòÉ 6.262. _umask - Sets File Mask of Current Process ΓòÉΓòÉΓòÉ
  24328.  
  24329.  
  24330. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24331.  
  24332. #include <io.h>
  24333. #include <sys\stat.h>
  24334.  
  24335. int _umask(int pmode);
  24336.  
  24337.  
  24338. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24339.  
  24340. Language Level: Extension 
  24341.  
  24342. The _umask function sets the file permission mask of the executing process 
  24343. environment to the mode specified by pmode. The file permission mask modifies 
  24344. the permission setting of new files created by _creat, _open, or _sopen. 
  24345.  
  24346. If a bit in the mask is 1, the corresponding bit in the requested permission 
  24347. value of the file is set to 0 (disallowed).  If a bit in the mask is 0, the 
  24348. corresponding bit is left unchanged.  The permission setting for a new file is 
  24349. not set until the file is closed for the first time. 
  24350.  
  24351. The _umask function returns the previous value of pmode.  A return value of -1 
  24352. indicates that the value used for pmode was not valid, and errno is set to 
  24353. EINVAL. 
  24354.  
  24355. The variable pmode contains one or both of the constants S_WRITE and S_IREAD, 
  24356. defined in <sys\stat.h>. The possible values for pmode are: 
  24357.  
  24358. Value                   Meaning 
  24359. S_IREAD                 No effect 
  24360. S_IWRITE                Writing not permitted 
  24361. S_IREAD | S_IWRITE      Writing not permitted. 
  24362.  
  24363. If the write bit is set in the mask, any new files will be read-only. You 
  24364. cannot give write-only permission, meaning that setting the read bit has no 
  24365. effect. 
  24366.  
  24367. Example of _umask 
  24368.  
  24369.  
  24370. ΓòÉΓòÉΓòÉ <hidden> Example of _umask ΓòÉΓòÉΓòÉ
  24371.  
  24372. /************************************************************************
  24373. *
  24374.  
  24375. This example sets the permission mask to create a write-only file. 
  24376.  
  24377.                                                                         *
  24378. ************************************************************************/
  24379.  
  24380. #include <sys\stat.h>
  24381. #include <io.h>
  24382. #include <stdio.h>
  24383.  
  24384. int main(void)
  24385. {
  24386.    int oldMask;
  24387.  
  24388.    oldMask = _umask(S_IWRITE);
  24389.    printf("\nDefault system startup mask is %d.\n",oldMask);
  24390.    return 0;
  24391.  
  24392. /******************  The expected output is:  ***************************
  24393.  
  24394.       Default system startup mask is 0.
  24395. */
  24396.  
  24397. }
  24398.  
  24399.  
  24400. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24401.  
  24402. o _chmod - Change File Permission Setting 
  24403. o _creat - Create New File 
  24404. o _open - Open File 
  24405. o _sopen - Open Shared File 
  24406. o io.h 
  24407. o sys\stat.h 
  24408. o sys\types.h 
  24409.  
  24410.  
  24411. ΓòÉΓòÉΓòÉ 6.263. ungetc  - Push Character onto Input Stream ΓòÉΓòÉΓòÉ
  24412.  
  24413.  
  24414. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24415.  
  24416. #include <stdio.h>
  24417.  
  24418. int ungetc(int c, FILE *stream);
  24419.  
  24420.  
  24421. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24422.  
  24423. Language Level: ANSI, SAA 
  24424.  
  24425. The ungetc function pushes the unsigned character c back onto the given input 
  24426. stream.  However, only one sequential ungetc is guaranteed to be pushed back 
  24427. onto the input stream if you call ungetc consecutively. The stream must be open 
  24428. for reading.  A subsequent read operation on the stream starts with c.  You 
  24429. cannot push EOF back on the stream using ungetc. 
  24430.  
  24431. Characters placed on the stream by ungetc will be erased if a fseek, fsetpos, 
  24432. rewind, or fflush function is called before the character is read from the 
  24433. stream. 
  24434.  
  24435. The ungetc function returns the integer argument c converted to an unsigned 
  24436. char or EOF if c cannot be pushed back. 
  24437.  
  24438. Example of ungetc 
  24439.  
  24440.  
  24441. ΓòÉΓòÉΓòÉ <hidden> Example of ungetc ΓòÉΓòÉΓòÉ
  24442.  
  24443. /************************************************************************
  24444. *
  24445. In this example, the while statement reads decimal digits from an input data 
  24446. stream by using arithmetic statements to compose the numeric values of the 
  24447. numbers as it reads them.  When a nondigit character appears before the end of 
  24448. the file, ungetc replaces it in the input stream so that later input functions 
  24449. can process it. 
  24450.  
  24451.                                                                         *
  24452. ************************************************************************/
  24453.  
  24454. #include <stdio.h>
  24455. #include <ctype.h>
  24456.  
  24457. int main(void)
  24458. {
  24459.    FILE *stream;
  24460.    int ch;
  24461.    unsigned int result = 0;
  24462.    .
  24463.    .
  24464.    .
  24465.    while ((ch = getc(stream)) != EOF && isdigit(ch))
  24466.       result = result * 10 + ch - '0';
  24467.    if (ch != EOF)
  24468.       ungetc(ch,stream);
  24469.          /* Put the nondigit character back */
  24470. }
  24471.  
  24472.  
  24473. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24474.  
  24475. o getc  - Read a Character 
  24476. o fflush  - Write Buffer to File 
  24477. o fseek  - Reposition File Position 
  24478. o fsetpos  - Set File Position 
  24479. o putc - putchar  - Write a Character 
  24480. o rewind  - Adjust Current File Position 
  24481. o _ungetch - Push Character Back to Keyboard 
  24482. o stdio.h 
  24483.  
  24484.  
  24485. ΓòÉΓòÉΓòÉ 6.264. _ungetch - Push Character Back to Keyboard ΓòÉΓòÉΓòÉ
  24486.  
  24487.  
  24488. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24489.  
  24490. #include <conio.h>
  24491.  
  24492. int _ungetch(int c);
  24493.  
  24494.  
  24495. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24496.  
  24497. Language Level: Extension 
  24498.  
  24499. The _ungetch function pushes the character c back to the keyboard, causing c to 
  24500. be the next character read. The _ungetch function fails if called more than 
  24501. once before the next read operation. The character c cannot be the EOF 
  24502. character. 
  24503.  
  24504. If successful, the _ungetch function returns the character c. A return value of 
  24505. EOF indicates an error. 
  24506.  
  24507. Example of _ungetch 
  24508.  
  24509.  
  24510. ΓòÉΓòÉΓòÉ <hidden> Example of _ungetch ΓòÉΓòÉΓòÉ
  24511.  
  24512. /************************************************************************
  24513. *
  24514.  
  24515. This example uses _getch to read a string delimited by the character 'x'.  It 
  24516. then calls _ungetch to return the delimiter to the keyboard buffer. Other input 
  24517. routines can then process the delimiter. 
  24518.  
  24519.                                                                         *
  24520. ************************************************************************/
  24521.  
  24522. #include <conio.h>
  24523. #include <stdio.h>
  24524.  
  24525. int main(void)
  24526. {
  24527.    int ch;
  24528.  
  24529.    _cprintf("\nType in some letters.");
  24530.    printf("\n");
  24531.    _cprintf("If you type in an 'x', the program ends.\n");
  24532.    printf("\n");
  24533.  
  24534.    for(;;)
  24535.    {
  24536.       ch = _getch();
  24537.  
  24538.       if (ch == 'x')
  24539.       {
  24540.          _ungetch(ch);
  24541.          break;
  24542.       }
  24543.       _putch(ch);
  24544.    }
  24545.  
  24546.    ch=_getch();
  24547.  
  24548.    printf("\n");
  24549.    _cprintf("\nThe last character was '%c'.", ch);
  24550.  
  24551.    return 0;
  24552.  
  24553. /**************  The output should be similar to:  **********************
  24554.  
  24555.    Type in some letters.
  24556.    If you type in an 'x', the program ends.
  24557.  
  24558.    One Two Three Four Five Si
  24559.  
  24560.    The last character was 'x'.
  24561. */
  24562. }
  24563.  
  24564.  
  24565. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24566.  
  24567. o _cscanf - Read Data from Keyboard 
  24568. o _getch - _getche - Read Character from Keyboard 
  24569. o ungetc  - Push Character onto Input Stream 
  24570. o conio.h 
  24571.  
  24572.  
  24573. ΓòÉΓòÉΓòÉ 6.265. _unlink - Delete File ΓòÉΓòÉΓòÉ
  24574.  
  24575.  
  24576. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24577.  
  24578. #include <stdio.h>  /* also defined in <io.h> */
  24579.  
  24580. int _unlink(const char *pathname);
  24581.  
  24582.  
  24583. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24584.  
  24585. Language Level: Extension 
  24586.  
  24587. The _unlink function deletes the file specified by pathname. 
  24588.  
  24589. For portability, you can use the SAA remove function. 
  24590.  
  24591. The _unlink function returns the value 0 if the file is successfully deleted. A 
  24592. return value of -1 indicates an error, and errno is set to one of the following 
  24593. values: 
  24594.  
  24595. Value          Meaning 
  24596. EACCESS        The path name specifies a read-only file or a directory. 
  24597. EISOPEN        The file is open. 
  24598. ENOENT         An incorrect path name was specified, or the file or path name 
  24599.                was not found. 
  24600.  
  24601. Example of _unlink 
  24602.  
  24603.  
  24604. ΓòÉΓòÉΓòÉ <hidden> Example of _unlink ΓòÉΓòÉΓòÉ
  24605.  
  24606. /************************************************************************
  24607. *
  24608. This example deletes the file tmpfile from the system or prints an error 
  24609. message if unable to delete it. 
  24610.  
  24611.                                                                         *
  24612. ************************************************************************/
  24613.  
  24614. #include <stdio.h>
  24615.  
  24616. int main(void)
  24617. {
  24618.     if (_unlink("tmpfile") == -1)
  24619.         perror("Cannot delete tmpfile");
  24620.     else
  24621.         printf("tmpfile has been successfully deleted\n");
  24622.  
  24623.     return 0;
  24624.  
  24625. /*****************  The output should be similar to:  *******************
  24626.  
  24627.    tmpfile has been successfully deleted
  24628. */
  24629. }
  24630.  
  24631.  
  24632. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24633.  
  24634. o remove  - Delete File 
  24635. o _rmtmp - Remove Temporary Files 
  24636. o stdio.h 
  24637.  
  24638.  
  24639. ΓòÉΓòÉΓòÉ 6.266. _utime - Set Modification Time ΓòÉΓòÉΓòÉ
  24640.  
  24641.  
  24642. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24643.  
  24644. #include <sys\utime.h>
  24645. #include <sys\types.h>
  24646.  
  24647. int _utime(char *pathname, struct utimbuf *times);
  24648.  
  24649.  
  24650. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24651.  
  24652. Language Level: Extension 
  24653.  
  24654. The _utime function sets the modification time for the file specified by 
  24655. pathname.  The process must have write access to the file;  otherwise, the time 
  24656. cannot be changed. 
  24657.  
  24658. Although the utimbuf structure contains a field for access time, only the 
  24659. modification time is set in the OS/2 operating system. If times is a NULL 
  24660. pointer, the modification time is set to the current time.  Otherwise, times 
  24661. must point to a structure of type utimbuf, defined in <sys\utime.h>.  The 
  24662. modification time is set from the modtime field in this structure. 
  24663.  
  24664. Note:  The _utime function accepts only even numbers of seconds. If you enter 
  24665.        an odd number of seconds, the function rounds it down. 
  24666.  
  24667. The _utime function returns the value 0 if the file modification time was 
  24668. changed.  A return value of -1 indicates an error, and errno is set to one of 
  24669. the following values: 
  24670.  
  24671. Value          Meaning 
  24672. EACCESS        The path name specifies a directory or read-only file. 
  24673. EMFILE         There are too many open files.  The file must be opened to 
  24674.                change its modification time. 
  24675. ENOENT         The file path name was not found, or the file name was 
  24676.                incorrectly specified. 
  24677.  
  24678. Example of _utime 
  24679.  
  24680.  
  24681. ΓòÉΓòÉΓòÉ <hidden> Example of _utime ΓòÉΓòÉΓòÉ
  24682.  
  24683. /************************************************************************
  24684. *
  24685. This example sets the last modification time of file \TMP\DATA to the current 
  24686. time.  It prints an error message if it cannot. 
  24687.  
  24688.                                                                         *
  24689. ************************************************************************/
  24690.  
  24691. #include <sys\types.h>
  24692. #include <sys\utime.h>
  24693. #include <sys\stat.h>
  24694. #include <stdio.h>
  24695.  
  24696. int main(void)
  24697. {
  24698.     struct utimbuf ubuf;
  24699.     struct stat statbuf;
  24700.     /* seconds to current date from 1970 Jan 1 */
  24701.     ubuf.modtime = 946702799;
  24702.     /*  Sat Dec 31 23:59:59 1999  */
  24703.  
  24704.     /* changing file modification time  */
  24705.     if (_utime("\\tmp\\data", &ubuf ) == -1)
  24706.     {
  24707.        perror("_utime failed");
  24708.        _exit(-1);
  24709.     }
  24710.  
  24711.     /* display the modification time  */
  24712.     if (_stat("\\tmp\\data", &statbuf) == 0)
  24713.         printf("The file modification time is %s\n",
  24714.                  ctime(&statbuf.st_mtime));
  24715.     else
  24716.         printf("File could not be found\n");
  24717.  
  24718.     return 0;
  24719.  
  24720. /***********  The output should be similar to:  ************
  24721.  
  24722.    The file modification time is
  24723.    Fri Dec 31 23:59:58 1999
  24724. */
  24725. }
  24726.  
  24727.  
  24728. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24729.  
  24730. o _fstat - Information about Open File 
  24731. o _stat - Get Information about File or Directory 
  24732. o sys\utime.h 
  24733. o sys\types.h 
  24734.  
  24735.  
  24736. ΓòÉΓòÉΓòÉ 6.267. va_arg - va_end - va_start - Access Function Arguments ΓòÉΓòÉΓòÉ
  24737.  
  24738.  
  24739. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24740.  
  24741. #include <stdarg.h>
  24742.  
  24743. var_type va_arg(va_list arg_ptr, var_type);
  24744.  
  24745. void va_end(va_list arg_ptr);
  24746.  
  24747. void va_start(va_list arg_ptr, variable_name);
  24748.  
  24749.  
  24750. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24751.  
  24752. Language Level: ANSI, SAA 
  24753.  
  24754. The va_arg, va_end, and va_start macros access the arguments to a function when 
  24755. it takes a fixed number of required arguments and a variable number of optional 
  24756. arguments.  You declare required arguments as ordinary parameters to the 
  24757. function and access the arguments through the parameter names. 
  24758.  
  24759. The va_start macro initializes the arg_ptr pointer for subsequent calls to 
  24760. va_arg and va_end. 
  24761.  
  24762. The argument variable_name is the identifier of the rightmost named parameter 
  24763. in the parameter list (preceding , ...).  Use the va_start macro before the 
  24764. va_arg macro. Corresponding va_start and va_end macros must be in the same 
  24765. function. 
  24766.  
  24767. The va_arg macro retrieves a value of the given var_type from the location 
  24768. given by arg_ptr and increases arg_ptr to point to the next argument in the 
  24769. list.  The va_arg macro can retrieve arguments from the list any number of 
  24770. times within the function. The var_type argument must be one of int, long, 
  24771. double, struct, union, or pointer, or a typedef of one of these types. 
  24772.  
  24773. The va_end macro is needed to indicate the end of parameter scanning. 
  24774.  
  24775. The va_arg macro returns the current argument. The va_end and va_start macros 
  24776. do not return a value. 
  24777.  
  24778. Example of va_arg - va_end - va_start 
  24779.  
  24780.  
  24781. ΓòÉΓòÉΓòÉ <hidden> Example of va_arg - va_end - va_start ΓòÉΓòÉΓòÉ
  24782.  
  24783. /************************************************************************
  24784. *
  24785.  
  24786. This example passes a variable number of arguments to a function, stores each 
  24787. argument in an array, and prints each argument. 
  24788.  
  24789.                                                                         *
  24790. ************************************************************************/
  24791.  
  24792. #include <stdio.h>
  24793. #include <stdarg.h>
  24794.  
  24795. int vout(int max, ...);
  24796.  
  24797. int main(void)
  24798. {
  24799.    vout(3, "Sat", "Sun", "Mon");
  24800.    printf("\n");
  24801.    vout(5, "Mon", "Tues", "Wed", "Thurs", "Fri");
  24802. }
  24803.  
  24804. int vout(int max, ...)
  24805. {
  24806.    va_list arg_ptr;
  24807.    int args = 0;
  24808.    char *days[7];
  24809.  
  24810.    va_start(arg_ptr, max);
  24811.    while(args < max)
  24812.    {
  24813.       days[args] = va_arg(arg_ptr, char *);
  24814.       printf("Day:  %s  \n", days[args++]);
  24815.       }
  24816.    va_end(arg_ptr);
  24817. }
  24818.  
  24819. /******************  Output should be similar to:  ****************
  24820.  
  24821. Day:  Sat
  24822. Day:  Sun
  24823. Day:  Mon
  24824.  
  24825. Day:  Mon
  24826. Day:  Tues
  24827. Day:  Wed
  24828. Day:  Thurs
  24829. Day:  Fri
  24830. */
  24831.  
  24832.  
  24833. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24834.  
  24835. o vfprintf  - Print Argument Data 
  24836. o vprintf  - Print Argument Data 
  24837. o vsprintf  - Print Argument Data 
  24838. o stdarg.h 
  24839.  
  24840.  
  24841. ΓòÉΓòÉΓòÉ 6.268. vfprintf  - Print Argument Data ΓòÉΓòÉΓòÉ
  24842.  
  24843.  
  24844. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24845.  
  24846. #include <stdarg.h>
  24847. #include <stdio.h>
  24848.  
  24849. int vfprintf(FILE *stream, const char *format, va_list arg_ptr);
  24850.  
  24851.  
  24852. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24853.  
  24854. Language Level: ANSI, SAA, Extension 
  24855.  
  24856. The vfprintf function is similar to fprintf, except that arg_ptr points to a 
  24857. list of arguments whose number can vary from call to call in the program. These 
  24858. arguments should be initialized by va_start for each call. In contrast, fprintf 
  24859. can have a list of arguments, but the number of arguments in that list is fixed 
  24860. when you compile the program. For a specification of the format string, see 
  24861. printf. 
  24862.  
  24863. In extended mode, vfprintf also converts floating-point values of NaN and 
  24864. infinity to the strings "NAN" or "nan" and "INFINITY" or "infinity". The case 
  24865. and sign of the string is determined by the format specifiers.  See Infinity 
  24866. and NaN Support for more information on infinity and NaN values. 
  24867.  
  24868. If there is no error, vfprintf returns the number of characters written to 
  24869. stream. If an error occurs, the function returns a negative value. 
  24870.  
  24871. Example of vfprintf 
  24872.  
  24873.  
  24874. ΓòÉΓòÉΓòÉ <hidden> Example of vfprintf ΓòÉΓòÉΓòÉ
  24875.  
  24876. /************************************************************************
  24877. *
  24878.  
  24879. This example prints out a variable number of strings to the file myfile. 
  24880.  
  24881.                                                                         *
  24882. ************************************************************************/
  24883.  
  24884. #include <stdarg.h>
  24885. #include <stdio.h>
  24886.  
  24887. void vout(FILE *stream, char *fmt, ...);
  24888. char fmt1 [] = "%s  %s  %s\n";
  24889.  
  24890. int main(void)
  24891. {
  24892.    FILE *stream;
  24893.    stream = fopen("myfile.dat", "w");
  24894.  
  24895.    vout(stream, fmt1, "Sat", "Sun", "Mon");
  24896. }
  24897.  
  24898. void vout(FILE *stream, char *fmt, ...)
  24899.  
  24900. {
  24901.    va_list arg_ptr;
  24902.  
  24903.    va_start(arg_ptr, fmt);
  24904.    vfprintf(stream, fmt, arg_ptr);
  24905.    va_end(arg_ptr);
  24906. }
  24907.  
  24908. /******************  Output should be similar to:  ****************
  24909.  
  24910. Sat  Sun  Mon
  24911. */
  24912.  
  24913.  
  24914. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  24915.  
  24916. o fprintf  - Write Formatted Data 
  24917. o printf  - Formatted Print 
  24918. o sprintf  - Formatted Print to Buffer 
  24919. o va_arg - va_end - va_start - Access Function Arguments 
  24920. o vprintf  - Print Argument Data 
  24921. o vsprintf  - Print Argument Data 
  24922. o Infinity and NaN Support 
  24923. o stdarg.h 
  24924. o stdio.h 
  24925.  
  24926.  
  24927. ΓòÉΓòÉΓòÉ 6.269. vprintf  - Print Argument Data ΓòÉΓòÉΓòÉ
  24928.  
  24929.  
  24930. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  24931.  
  24932. #include <stdarg.h>
  24933. #include <stdio.h>
  24934.  
  24935. int vprintf(const char *format, va_list arg_ptr);
  24936.  
  24937.  
  24938. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  24939.  
  24940. Language Level: ANSI, SAA, Extension 
  24941.  
  24942. The vprintf function is similar to printf, except that arg_ptr points to a list 
  24943. of arguments whose number can vary from call to call in the program. These 
  24944. arguments should be initialized by va_start for each call. In contrast, printf 
  24945. can have a list of arguments, but the number of arguments in that list is fixed 
  24946. when you compile the program. For a specification of the format string, see 
  24947. printf. 
  24948.  
  24949. In extended mode, vprintf also converts floating-point values of NaN and 
  24950. infinity to the strings "NAN" or "nan" and "INFINITY" or "infinity". The case 
  24951. and sign of the string is determined by the format specifiers.  See Infinity 
  24952. and NaN Support for more information on infinity and NaN values. 
  24953.  
  24954. If there is no error, vprintf returns the number of characters written to 
  24955. stdout.  If an error occurs, this function returns a negative value. 
  24956.  
  24957. Example of vprintf 
  24958.  
  24959.  
  24960. ΓòÉΓòÉΓòÉ <hidden> Example of vprintf ΓòÉΓòÉΓòÉ
  24961.  
  24962. /************************************************************************
  24963. *
  24964.  
  24965. This example prints out a variable number of strings to stdout. 
  24966.  
  24967.                                                                         *
  24968. ************************************************************************/
  24969.  
  24970. #include <stdarg.h>
  24971. #include <stdio.h>
  24972.  
  24973. void vout(char *fmt, ...);
  24974. char fmt1 [] = "%s  %s  %s   %s   %s \n";
  24975.  
  24976. int main(void)
  24977. {
  24978.    FILE *stream;
  24979.    stream = fopen("myfile.dat", "w");
  24980.  
  24981.    vout(fmt1, "Mon", "Tues", "Wed", "Thurs", "Fri");
  24982. }
  24983.  
  24984. void vout(char *fmt, ...)
  24985. {
  24986.    va_list arg_ptr;
  24987.  
  24988.    va_start(arg_ptr, fmt);
  24989.    vprintf(fmt, arg_ptr);
  24990.    va_end(arg_ptr);
  24991. }
  24992.  
  24993. /******************  Output should be similar to:  ****************
  24994.  
  24995. Mon  Tues  Wed   Thurs   Fri
  24996. */
  24997.  
  24998.  
  24999. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25000.  
  25001. o fprintf  - Write Formatted Data 
  25002. o printf  - Formatted Print 
  25003. o sprintf  - Formatted Print to Buffer 
  25004. o va_arg - va_end - va_start - Access Function Arguments 
  25005. o vfprintf  - Print Argument Data 
  25006. o vsprintf  - Print Argument Data 
  25007. o Infinity and NaN Support 
  25008. o stdarg.h 
  25009. o stdio.h 
  25010.  
  25011.  
  25012. ΓòÉΓòÉΓòÉ 6.270. vsprintf  - Print Argument Data ΓòÉΓòÉΓòÉ
  25013.  
  25014.  
  25015. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25016.  
  25017. #include <stdarg.h>
  25018. #include <stdio.h>
  25019.  
  25020. int vsprintf(char *target-string, const char *format, va_list arg_ptr);
  25021.  
  25022.  
  25023. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25024.  
  25025. Language Level: ANSI, SAA, Extension 
  25026.  
  25027. The vsprintf function is similar to sprintf except that arg_ptr points to a 
  25028. list of arguments whose number can vary from call to call in the program.  In 
  25029. contrast, sprintf can have a list of arguments, but the number of arguments in 
  25030. that list is fixed when you compile the program. For a specification of the 
  25031. format string, see printf. 
  25032.  
  25033. In extended mode, vsprintf also converts floating-point values of NaN and 
  25034. infinity to the strings "NAN" or "nan" and "INFINITY" or "infinity". The case 
  25035. and sign of the string is determined by the format specifiers.  See Infinity 
  25036. and NaN Support for more information on infinity and NaN values. 
  25037.  
  25038. If there is no error, vsprintf returns the number of characters written to 
  25039. target-string. If an error occurs, this function returns a negative value. 
  25040.  
  25041. Example of vsprintf 
  25042.  
  25043.  
  25044. ΓòÉΓòÉΓòÉ <hidden> Example of vsprintf ΓòÉΓòÉΓòÉ
  25045.  
  25046. /************************************************************************
  25047. *
  25048.  
  25049. This example assigns a variable number of strings to string and prints the 
  25050. resultant string. 
  25051.  
  25052.                                                                         *
  25053. ************************************************************************/
  25054.  
  25055. #include <stdarg.h>
  25056. #include <stdio.h>
  25057.  
  25058. void vout(char *string, char *fmt, ...);
  25059. char fmt1 [] = "%s  %s  %s\n";
  25060.  
  25061. int main(void)
  25062. {
  25063.    char string[100];
  25064.  
  25065.    vout(string, fmt1, "Sat", "Sun", "Mon");
  25066.    printf("The string is:  %s\n", string);
  25067. }
  25068.  
  25069. void vout(char *string, char *fmt, ...)
  25070. {
  25071.    va_list arg_ptr;
  25072.  
  25073.    va_start(arg_ptr, fmt);
  25074.    vsprintf(string, fmt, arg_ptr);
  25075.    va_end(arg_ptr);
  25076. }
  25077.  
  25078. /******************  Output should be similar to:  ****************
  25079.  
  25080. The string is:  Sat  Sun  Mon
  25081. */
  25082.  
  25083.  
  25084. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25085.  
  25086. o fprintf  - Write Formatted Data 
  25087. o printf  - Formatted Print 
  25088. o sprintf  - Formatted Print to Buffer 
  25089. o va_arg - va_end - va_start - Access Function Arguments 
  25090. o vfprintf  - Print Argument Data 
  25091. o vprintf  - Print Argument Data 
  25092. o Infinity and NaN Support 
  25093. o stdarg.h 
  25094. o stdio.h 
  25095.  
  25096.  
  25097. ΓòÉΓòÉΓòÉ 6.271. _wait - Wait for Child Process ΓòÉΓòÉΓòÉ
  25098.  
  25099.  
  25100. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25101.  
  25102. #include <process.h>
  25103.  
  25104. int _wait (int *stat_loc);
  25105.  
  25106.  
  25107. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25108.  
  25109. Language Level: Extension 
  25110.  
  25111. The _wait function delays a parent process until one of the immediate child 
  25112. processes stops.  If all the child processes stop before _wait is called, 
  25113. control returns immediately to the parent function. 
  25114.  
  25115. If stat_loc is NULL, the _wait function does not use it.  If it is not NULL, 
  25116. _wait places information about the return status and the return code ot the 
  25117. child process that ended in the location to which stat_loc points. 
  25118.  
  25119. If the child process ended normally, with a call to the OS/2 DosExit function, 
  25120. the lowest-order byte of stat_loc is 0, and the next higher-order byte contains 
  25121. the lowest-order byte of the argument passed to DosExit by the child process. 
  25122. The value of this byte depends on how the child process caused the system to 
  25123. call DosExit. 
  25124.  
  25125. If the child process called exit, _exit, or return from main, the byte contains 
  25126. the lowest-order byte of the argument the child process passed to exit, _exit, 
  25127. or return.  The value of the byte is undefined if the child process caused a 
  25128. DosExit call simply by reaching the end of main. 
  25129.  
  25130. If the child process ended abnormally, the lowest-order byte of stat_loc 
  25131. contains the return status code from the OS/2 DosWaitChild function, and the 
  25132. next higher-order byte is 0. See the Toolkit online Programming Reference for 
  25133. details about the DosWaitChild return status codes. 
  25134.  
  25135. If _wait returns after a normal end of a child process, it returns the process 
  25136. identifier of the child process to the parent process. A return value of -1 
  25137. indicates an error, and errno is set to one of the following values: 
  25138.  
  25139. Value          Meaning 
  25140. ECHILD         There were no child processes or they all ended before the call 
  25141.                to _wait. This value indicates that no child processes exist for 
  25142.                the particular process. 
  25143. EINTR          Unexpected end of a child process. 
  25144.  
  25145. Example of _wait 
  25146.  
  25147.  
  25148. ΓòÉΓòÉΓòÉ <hidden> Example of _wait ΓòÉΓòÉΓòÉ
  25149.  
  25150. /************************************************************************
  25151. *
  25152. This example creates a new process called CHILD.EXE, specifying P_NOWAIT when 
  25153. the child process is called. The parent process calls _wait and waits for the 
  25154. child process to stop running. The parent process then displays the return 
  25155. information of the child process in hexadecimal. 
  25156.  
  25157.                                                                         *
  25158. ************************************************************************/
  25159.  
  25160. #include <stdio.h>
  25161. #include <process.h>
  25162.  
  25163. int stat_child;
  25164.  
  25165. int main(void)
  25166. {
  25167.     int pid;
  25168.  
  25169.     _spawnl(P_NOWAIT,"child2.exe", "child2.exe", NULL);
  25170.  
  25171.     if ( (pid=_wait(&stat_child)) == -1 )
  25172.         perror(NULL);       /* Display error status message, if any */
  25173.     else
  25174.         printf("child process %d just ran.\n",pid);
  25175.  
  25176.     /* Display the word returned when child ended. */
  25177.     printf("return information was 0x%X\n",stat_child);
  25178.  
  25179.     return 0;
  25180.  
  25181.  
  25182. /* If the source for child2.exe is:                                    */
  25183. /*                                                                     */
  25184. /*  #include <stdio.h>                                                 */
  25185.  
  25186. /*  int main(void)                                                     */
  25187. /*  {                                                                  */
  25188. /*      puts("child2.exe is an executable file");                      */
  25189. /*  }                                                                  */
  25190. /*                                                                     */
  25191. /*  Then the ouput should be similar to:              */
  25192.  
  25193. /* child process 24 just ran.                         */
  25194. /* return information was 0x0                         */
  25195.  
  25196. }
  25197.  
  25198.  
  25199. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25200.  
  25201. o _cwait - Wait for Child Process 
  25202. o _execl - _execvp - Load and Run Child Process 
  25203. o exit  - End Program 
  25204. o _exit - End Process 
  25205. o _spawnl -_spawnvpe -Start and Run Child Processes 
  25206. o process.h 
  25207.  
  25208.  
  25209. ΓòÉΓòÉΓòÉ 6.272. wcscat  - Append wchar_t Strings ΓòÉΓòÉΓòÉ
  25210.  
  25211.  
  25212. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25213.  
  25214. #include <wcstr.h>
  25215.  
  25216. wchar_t *wcscat(wchar_t *string1, const wchar_t *string2);
  25217.  
  25218.  
  25219. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25220.  
  25221. Language Level: SAA 
  25222.  
  25223. The wcscat function appends a copy of the string pointed to by string2 to the 
  25224. end of the string pointed to by string1. 
  25225.  
  25226. The wcscat function operates on null-terminated wchar_t strings. The string 
  25227. arguments to this function should contain a wchar_t null character marking the 
  25228. end of the string. Boundary checking is not performed. 
  25229.  
  25230. The wcscat function returns the value of string1. 
  25231.  
  25232. Example of wcscat 
  25233.  
  25234.  
  25235. ΓòÉΓòÉΓòÉ <hidden> Example of wcscat ΓòÉΓòÉΓòÉ
  25236.  
  25237. /*************************************************************************
  25238. *
  25239. This example creates the wide character string "computer program" using wcscat. 
  25240.  
  25241.                                                                         *
  25242. ************************************************************************/
  25243.  
  25244. #include <stdio.h>
  25245. #include <wcstr.h>
  25246.  
  25247. #define SIZE 40
  25248.  
  25249.  
  25250. int main(void)
  25251. {
  25252.   wchar_t buffer1[SIZE] = L"computer";
  25253.   wchar_t * string      = L" program";
  25254.   wchar_t * ptr;
  25255.  
  25256.   ptr = wcscat( buffer1, string );
  25257.   printf( "buffer1 = %ls\n", buffer1 );
  25258.  
  25259. }
  25260.  
  25261. /************************************************************************
  25262. *
  25263.  
  25264. /****************  Output should be similar to:  ******************
  25265.  
  25266. buffer1 = computer program
  25267. */
  25268.  
  25269.                                                                         *
  25270. ************************************************************************/
  25271.  
  25272.  
  25273. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25274.  
  25275. o strcat  - Concatenate Strings 
  25276. o strncat  - Concatenate Strings 
  25277. o wcsncat  - Concatenate wchar_t Strings 
  25278. o wcstr.h 
  25279.  
  25280.  
  25281. ΓòÉΓòÉΓòÉ 6.273. wcschr  - Search wchar_t String for Given wchar_t ΓòÉΓòÉΓòÉ
  25282.  
  25283.  
  25284. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25285.  
  25286. #include <wcstr.h>
  25287.  
  25288. wchar_t  *wcschr(const wchar_t *string1, wchar_t character);
  25289.  
  25290.  
  25291. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25292.  
  25293. Language Level: SAA 
  25294.  
  25295. The wcschr function searches string for the occurrence of character. The 
  25296. character may be a wchar_t null character (\0);  the wchar_t null character at 
  25297. the end of string is included in the search. 
  25298.  
  25299. The wcschr function operates on null-terminated wchar_t strings. The string 
  25300. argument to this function should contain a wchar_t null character marking the 
  25301. end of the string. 
  25302.  
  25303. The wcschr function returns a pointer to the first occurrence of character in 
  25304. string. If the character is not found, a NULL pointer is returned. 
  25305.  
  25306. Example of wcschr 
  25307.  
  25308.  
  25309. ΓòÉΓòÉΓòÉ <hidden> Example of wcschr ΓòÉΓòÉΓòÉ
  25310.  
  25311. /*************************************************************************
  25312. *
  25313. This example finds the first occurrence of the character p in the wide 
  25314. character string "computer program". 
  25315.  
  25316.                                                                         *
  25317. ************************************************************************/
  25318.  
  25319. #include <stdio.h>
  25320. #include <wcstr.h>
  25321.  
  25322. #define SIZE 40
  25323.  
  25324. int main(void)
  25325. {
  25326.   wchar_t buffer1[SIZE] = L"computer program";
  25327.   wchar_t * ptr;
  25328.   wchar_t ch = L'p';
  25329.  
  25330.   ptr = wcschr( buffer1, ch );
  25331.   printf( "The first occurrence of %lc in '%ls' is '%ls'\n",
  25332.                           ch, buffer1, ptr );
  25333.  
  25334. }
  25335.  
  25336. /************************************************************************
  25337. *
  25338.  
  25339. /****************  Output should be similar to:  ******************
  25340.  
  25341. The first occurrence of p in 'computer program' is 'puter program'
  25342. */
  25343.  
  25344.                                                                         *
  25345. ************************************************************************/
  25346.  
  25347.  
  25348. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25349.  
  25350. o strchr  - Search for Character 
  25351. o strcspn  - Compare Strings 
  25352. o strpbrk  - Find Characters in String 
  25353. o strrchr  - Find Last Occurrence of Character in String 
  25354. o strspn  - Search Strings 
  25355. o wcscspn  - Find Offset of First wchar_t Match 
  25356. o wcspbrk  - Locate wchar_t Characters in String 
  25357. o wcsrchr  - Locate wchar_t Character in String 
  25358. o wcsspn  - Search wchar_t Characters in String 
  25359. o wcswcs  - Locate wchar_t Substring in wchar_t String 
  25360. o wcstr.h 
  25361.  
  25362.  
  25363. ΓòÉΓòÉΓòÉ 6.274. wcscmp  - Compare wchar_t Strings ΓòÉΓòÉΓòÉ
  25364.  
  25365.  
  25366. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25367.  
  25368. #include <wcstr.h>
  25369.  
  25370. int wcscmp(const wchar_t *string1, const wchar_t *string2);
  25371.  
  25372.  
  25373. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25374.  
  25375. Language Level: SAA 
  25376.  
  25377. The wcscmp function compares two wchar_t strings. 
  25378.  
  25379. The wcscmp function operates on null-terminated wchar_t strings. The string 
  25380. arguments to this function should contain a wchar_t null character marking the 
  25381. end of the string. Boundary checking is not performed when a string is added to 
  25382. or copied. 
  25383.  
  25384. The wcscmp function returns a value indicating the relationship between the two 
  25385. strings, as follows: 
  25386.  
  25387. Value               Meaning 
  25388. Less than 0         string1 less than string2 
  25389. 0                   string1 identical to string2 
  25390. Greater than 0      string1 greater than string2. 
  25391.  
  25392. Example of wcscmp 
  25393.  
  25394.  
  25395. ΓòÉΓòÉΓòÉ <hidden> Example of wcscmp ΓòÉΓòÉΓòÉ
  25396.  
  25397. /*************************************************************************
  25398. *
  25399.  
  25400. This example compares the wide character string string1 to string2 using 
  25401. wcscmp. 
  25402.  
  25403.                                                                         *
  25404. ************************************************************************/
  25405.  
  25406. #include <stdio.h>
  25407. #include <wcstr.h>
  25408.  
  25409. int main(void)
  25410. {
  25411.   int  result;
  25412.   wchar_t string1[] = L"abcdef";
  25413.   wchar_t string2[] = L"abcdefg";
  25414.  
  25415.   result = wcscmp( string1, string2 );
  25416.  
  25417.   if ( result == 0 )
  25418.     printf( "\"%ls\" is identical to \"%ls\"\n", string1, string2);
  25419.   else if ( result < 0 )
  25420.     printf( "\"%ls\" is less than \"%ls\"\n", string1, string2 );
  25421.   else
  25422.     printf( "\"%ls\" is greater than \"%ls\"\n", string1, string2);
  25423. }
  25424.  
  25425. /************************************************************************
  25426. *
  25427.  
  25428. /****************  Output should be similar to:  ******************
  25429.  
  25430. "abcdef" is less than "abcdefg"
  25431. */
  25432.  
  25433.                                                                         *
  25434. ************************************************************************/
  25435.  
  25436.  
  25437. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25438.  
  25439. o strcmp  - Compare Strings 
  25440. o strcmpi - Compare Strings 
  25441. o stricmp - Compare Strings 
  25442. o strnicmp - Compare Strings 
  25443. o wcsncmp  - Compare wchar_t Strings 
  25444. o wcstr.h 
  25445.  
  25446.  
  25447. ΓòÉΓòÉΓòÉ 6.275. wcscpy  - Copy wchar_t Strings ΓòÉΓòÉΓòÉ
  25448.  
  25449.  
  25450. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25451.  
  25452. #include <wcstr.h>
  25453.  
  25454. wchar_t *wcscpy(wchar_t *string1, const wchar_t *string2);
  25455.  
  25456.  
  25457. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25458.  
  25459. Language Level: SAA 
  25460.  
  25461. The wcscpy function copies the contents of string2 (including the ending 
  25462. wchar_t null character) into string1. 
  25463.  
  25464. The wcscpy function operates on null-terminated wchar_t strings. The string 
  25465. arguments to this function should contain a wchar_t null character marking the 
  25466. end of the string. Boundary checking is not performed. 
  25467.  
  25468. The wcscpy function returns the value of string1. 
  25469.  
  25470. Example of wcscpy 
  25471.  
  25472.  
  25473. ΓòÉΓòÉΓòÉ <hidden> Example of wcscpy ΓòÉΓòÉΓòÉ
  25474.  
  25475. /*************************************************************************
  25476. *
  25477. This example copies the contents of source to destination. 
  25478.  
  25479.                                                                         *
  25480. ************************************************************************/
  25481.  
  25482. #include <stdio.h>
  25483. #include <wcstr.h>
  25484.  
  25485. #define SIZE    40
  25486.  
  25487. int main(void)
  25488. {
  25489.   wchar_t source[ SIZE ] = L"This is the source string";
  25490.   wchar_t destination[ SIZE ] = L"And this is the destination string";
  25491.   wchar_t * return_string;
  25492.  
  25493.   printf( "destination is originally = \"%ls\"\n", destination );
  25494.   return_string = wcscpy( destination, source );
  25495.   printf( "After wcscpy, destination becomes \"%ls\"\n", destination );
  25496. }
  25497.  
  25498. /************************************************************************
  25499. *
  25500.  
  25501. /****************  Output should be similar to:  ******************
  25502.  
  25503. destination is originally = "And this is the destination string"
  25504. After wcscpy, destination becomes "This is the source string"
  25505. */
  25506.  
  25507.                                                                         *
  25508. ************************************************************************/
  25509.  
  25510.  
  25511. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25512.  
  25513. o strcpy  - Copy Strings 
  25514. o strdup - Duplicate String 
  25515. o strncpy  - Copy Strings 
  25516. o wcsncpy  - Copy wchar_t Strings 
  25517. o wcstr.h 
  25518.  
  25519.  
  25520. ΓòÉΓòÉΓòÉ 6.276. wcscspn  - Find Offset of First wchar_t Match ΓòÉΓòÉΓòÉ
  25521.  
  25522.  
  25523. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25524.  
  25525. #include <wcstr.h> /* SAA extension to ANSI */
  25526.  
  25527. size_t wcscspn(const wchar_t *string1, const wchar_t *string2);
  25528.  
  25529.  
  25530. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25531.  
  25532. Language Level: SAA 
  25533.  
  25534. The wcscspn function determines the number of wchar_t characters in the initial 
  25535. segment of the string pointed to by string1 that do not appear in the string 
  25536. pointed to by string2. 
  25537.  
  25538. The wcscspn function operates on null-terminated wchar_t strings.  The string 
  25539. arguments to this function should contain a wchar_t null character marking the 
  25540. end of the string. 
  25541.  
  25542. The wcscspn function returns the number of wchar_t characters in the segment. 
  25543.  
  25544. Example of wcscspn 
  25545.  
  25546.  
  25547. ΓòÉΓòÉΓòÉ <hidden> Example of wcscspn ΓòÉΓòÉΓòÉ
  25548.  
  25549. /*************************************************************************
  25550. *
  25551. This example uses wcscspn to find the first occurrence of any of the characters 
  25552. a, x, l, or e in string. 
  25553.  
  25554.                                                                         *
  25555. ************************************************************************/
  25556.  
  25557. #include <stdio.h>
  25558. #include <wcstr.h>
  25559.  
  25560. #define SIZE    40
  25561.  
  25562. int main(void)
  25563. {
  25564.   wchar_t string[ SIZE ] = L"This is the source string";
  25565.   wchar_t * substring = L"axle";
  25566.  
  25567.   printf( "The first %i characters in the string \"%ls\" are not in the "
  25568.           "string \"%ls\" \n", wcscspn( string, substring),
  25569.           string, substring );
  25570. }
  25571.  
  25572. /************************************************************************
  25573. *
  25574.  
  25575. /****************  Output should be similar to:  ******************
  25576.  
  25577. The first 10 characters in the string "This is the source string" are not
  25578. in the string "axle"
  25579. */
  25580.  
  25581.                                                                         *
  25582. ************************************************************************/
  25583.  
  25584.  
  25585. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25586.  
  25587. o strcspn  - Compare Strings 
  25588. o strspn  - Search Strings 
  25589. o wcsspn  - Search wchar_t Characters in String 
  25590. o wcswcs  - Locate wchar_t Substring in wchar_t String 
  25591. o wcstr.h 
  25592.  
  25593.  
  25594. ΓòÉΓòÉΓòÉ 6.277. wcslen  - Calculate Length of wchar_t String ΓòÉΓòÉΓòÉ
  25595.  
  25596.  
  25597. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25598.  
  25599. #include <wcstr.h>
  25600.  
  25601. size_t wcslen(const wchar_t *string);
  25602.  
  25603.  
  25604. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25605.  
  25606. Language Level: SAA 
  25607.  
  25608. The wcslen function computes the number of wchar_t characters in the string 
  25609. pointed to by string. 
  25610.  
  25611. The wcslen function returns the number of wchar_t characters that precede the 
  25612. terminating wchar_t null character. 
  25613.  
  25614. Example of wcslen 
  25615.  
  25616.  
  25617. ΓòÉΓòÉΓòÉ <hidden> Example of wcslen ΓòÉΓòÉΓòÉ
  25618.  
  25619. /*************************************************************************
  25620. *
  25621. This example computes the length of a wchar_t string. 
  25622.  
  25623.                                                                         *
  25624. ************************************************************************/
  25625.  
  25626. #include <stdio.h>
  25627. #include <wcstr.h>
  25628.  
  25629. int main(void)
  25630. {
  25631.   wchar_t * string = L"abcdef";
  25632.  
  25633.   printf( "Length of \"%ls\" is %i\n", string, wcslen( string ));
  25634. }
  25635.  
  25636. /************************************************************************
  25637. *
  25638.  
  25639. /****************  Output should be similar to:  ******************
  25640.  
  25641. Length of "abcdef" is 6
  25642. */
  25643.  
  25644.                                                                         *
  25645. ************************************************************************/
  25646.  
  25647.  
  25648. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25649.  
  25650. o mblen  - Multibyte String Length 
  25651. o strlen  - Determine String Length 
  25652. o wcstr.h 
  25653.  
  25654.  
  25655. ΓòÉΓòÉΓòÉ 6.278. wcsncat  - Concatenate wchar_t Strings ΓòÉΓòÉΓòÉ
  25656.  
  25657.  
  25658. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25659.  
  25660. #include <wcstr.h>
  25661.  
  25662. wchar_t *wcsncat(wchar_t *string1, const wchar_t *string2, size_t count);
  25663.  
  25664.  
  25665. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25666.  
  25667. Language Level: SAA 
  25668.  
  25669. The wcsncat function appends up to count wide characters from string2 to the 
  25670. end of string1 and appends a wchar_t null character to the result. 
  25671.  
  25672. The wcsncat function operates on null-terminated wchar_t strings. The string 
  25673. arguments to this function should contain a wchar_t null character marking the 
  25674. end of the string. 
  25675.  
  25676. The wcsncat function returns string1. 
  25677.  
  25678. Example of wcsncat 
  25679.  
  25680.  
  25681. ΓòÉΓòÉΓòÉ <hidden> Example of wcsncat ΓòÉΓòÉΓòÉ
  25682.  
  25683. /*************************************************************************
  25684. *
  25685. This example demonstrates the difference between wcscat and wcsncat.  wcscat 
  25686. appends the entire second string to the first whereas wcsncat appends only the 
  25687. specified number of characters in the second string to the first. 
  25688.  
  25689.                                                                         *
  25690. ************************************************************************/
  25691.  
  25692. #include <stdio.h>
  25693. #include <wcstr.h>
  25694.  
  25695. #define SIZE 40
  25696.  
  25697. int main(void)
  25698. {
  25699.   wchar_t buffer1[SIZE] = L"computer";
  25700.   wchar_t * ptr;
  25701.  
  25702.   /* Call wcscat with buffer1 and " program" */
  25703.  
  25704.   ptr = wcscat( buffer1, L" program" );
  25705.   printf( "wcscat : buffer1 = \"%ls\"\n", buffer1 );
  25706.  
  25707.   /* Reset buffer1 to contain just the string "computer" again */
  25708.  
  25709.   memset( buffer1, L'\0', sizeof( buffer1 ));
  25710.   ptr = wcscpy( buffer1, L"computer" );
  25711.  
  25712.   /* Call wcsncat with buffer1 and " program" */
  25713.   ptr = wcsncat( buffer1, L" program", 3 );
  25714.   printf( "wcsncat: buffer1 = \"%ls\"\n", buffer1 );
  25715. }
  25716.  
  25717. /************************************************************************
  25718. *
  25719.  
  25720. /****************  Output should be similar to:  ******************
  25721.  
  25722. wcscat : buffer1 = "computer program"
  25723. wcsncat: buffer1 = "computer pr"
  25724. */
  25725.  
  25726.                                                                         *
  25727. ************************************************************************/
  25728.  
  25729.  
  25730. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25731.  
  25732. o strncat  - Concatenate Strings 
  25733. o strcat  - Concatenate Strings 
  25734. o wcscat  - Append wchar_t Strings 
  25735. o wcstr.h 
  25736.  
  25737.  
  25738. ΓòÉΓòÉΓòÉ 6.279. wcsncmp  - Compare wchar_t Strings ΓòÉΓòÉΓòÉ
  25739.  
  25740.  
  25741. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25742.  
  25743. #include <wcstr.h>
  25744.  
  25745. int wcsncmp(const wchar_t *string1, const wchar_t *string2, size_t count);
  25746.  
  25747.  
  25748. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25749.  
  25750. Language Level: SAA 
  25751.  
  25752. The wcsncmp function compares up to count wide characters in string1 to 
  25753. string2. 
  25754.  
  25755. The wcsncmp function operates on null-terminated wchar_t strings. The string 
  25756. arguments to this function should contain a wchar_t null character marking the 
  25757. end of the string. 
  25758.  
  25759. The wcsncmp function returns a value indicating the relationship between the 
  25760. two strings, as follows: 
  25761.  
  25762. Value               Meaning 
  25763. Less than 0         string1 less than string2 
  25764. 0                   string1 identical to string2 
  25765. Greater than 0      string1 greater than string2. 
  25766.  
  25767. Example of wcsmcmp 
  25768.  
  25769.  
  25770. ΓòÉΓòÉΓòÉ <hidden> Example of wcsncmp ΓòÉΓòÉΓòÉ
  25771.  
  25772. /*************************************************************************
  25773. *
  25774. This example demonstrates the difference between wcscmp and wcsncmp. 
  25775.  
  25776.                                                                         *
  25777. ************************************************************************/
  25778.  
  25779. #include <stdio.h>
  25780. #include <wcstr.h>
  25781.  
  25782. #define SIZE 10
  25783.  
  25784. int main(void)
  25785. {
  25786.   int  result;
  25787.   int  index = 3;
  25788.   wchar_t buffer1[SIZE] = L"abcdefg";
  25789.   wchar_t buffer2[SIZE] = L"abcfg";
  25790.   void print_result( int, wchar_t *, wchar_t * );
  25791.  
  25792.   result = wcscmp( buffer1, buffer2 );
  25793.   printf( "Comparison of each character\n" );
  25794.   printf( "  wcscmp: " );
  25795.   print_result( result, buffer1, buffer2 );
  25796.  
  25797.   result = wcsncmp( buffer1, buffer2, index);
  25798.   printf( "\nComparison of only the first %i characters\n", index );
  25799.   printf( "  wcsncmp: " );
  25800.   print_result( result, buffer1, buffer2 );
  25801. }
  25802.  
  25803. void print_result( int res, wchar_t * p_buffer1, wchar_t * p_buffer2 )
  25804. {
  25805.   if ( res == 0 )
  25806.     printf( "\"%ls\" is identical to \"%ls\"\n", p_buffer1, p_buffer2);
  25807.   else if ( res < 0 )
  25808.     printf( "\"%ls\" is less than \"%ls\"\n", p_buffer1, p_buffer2 );
  25809.   else
  25810.     printf( "\"%ls\" is greater than \"%ls\"\n", p_buffer1, p_buffer2 );
  25811. }
  25812.  
  25813. /************************************************************************
  25814. *
  25815.  
  25816. /****************  Output should be similar to:  ******************
  25817.  
  25818. Comparison of each character
  25819.   wcscmp: "abcdefg" is less than "abcfg"
  25820.  
  25821. Comparison of only the first 3 characters
  25822.   wcsncmp: "abcdefg" is identical to "abcfg"
  25823. */
  25824.  
  25825.                                                                         *
  25826. ************************************************************************/
  25827.  
  25828.  
  25829. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25830.  
  25831. o strncmp  - Compare Strings 
  25832. o strcmp  - Compare Strings 
  25833. o strcoll  - Compare Strings 
  25834. o strcmpi - Compare Strings 
  25835. o stricmp - Compare Strings 
  25836. o strnicmp - Compare Strings 
  25837. o wcscmp  - Compare wchar_t Strings 
  25838. o wcstr.h 
  25839.  
  25840.  
  25841. ΓòÉΓòÉΓòÉ 6.280. wcsncpy  - Copy wchar_t Strings ΓòÉΓòÉΓòÉ
  25842.  
  25843.  
  25844. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25845.  
  25846. #include <wcstr.h>
  25847.  
  25848. wchar_t *wcsncpy(wchar_t *string1, const wchar_t *string2, size_t count);
  25849.  
  25850.  
  25851. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25852.  
  25853. Language Level: SAA 
  25854.  
  25855. The wcsncpy function copies up to count wide characters from string2 to 
  25856. string1. If string2 is shorter than count characters, string1 is padded out to 
  25857. count characters with wchar_t null characters. 
  25858.  
  25859. The wcsncpy function operates on null-terminated wchar_t strings. The string 
  25860. arguments to this function should contain a wchar_t null character marking the 
  25861. end of the string. 
  25862.  
  25863. The wcsncpy function returns string1. 
  25864.  
  25865. Example of wcsncpy 
  25866.  
  25867.  
  25868. ΓòÉΓòÉΓòÉ <hidden> Example of wcsncpy ΓòÉΓòÉΓòÉ
  25869.  
  25870. /*************************************************************************
  25871. *
  25872. This example demonstrates the difference between wcscpy and wcsncpy. 
  25873.  
  25874.                                                                         *
  25875. ************************************************************************/
  25876.  
  25877. #include <stdio.h>
  25878. #include <wcstr.h>
  25879.  
  25880. #define SIZE    40
  25881.  
  25882. int main(void)
  25883. {
  25884.   wchar_t source[ SIZE ] = L"123456789";
  25885.   wchar_t source1[ SIZE ] = L"123456789";
  25886.   wchar_t destination[ SIZE ] = L"abcdefg";
  25887.   wchar_t destination1[ SIZE ] = L"abcdefg";
  25888.   wchar_t * return_string;
  25889.   int    index = 5;
  25890.  
  25891.   /* This is how wcscpy works */
  25892.   printf( "destination is originally = '%ls'\n", destination );
  25893.   return_string = wcscpy( destination, source );
  25894.   printf( "After wcscpy, destination becomes '%ls'\n\n", destination );
  25895.  
  25896.   /* This is how wcsncpy works */
  25897.   printf( "destination1 is originally = '%ls'\n", destination1 );
  25898.   return_string = wcsncpy( destination1, source1, index );
  25899.   printf( "After wcsncpy, destination1 becomes '%ls'\n", destination1 );
  25900. }
  25901.  
  25902. /************************************************************************
  25903. *
  25904.  
  25905. /****************  Output should be similar to:  ******************
  25906.  
  25907. destination is originally = 'abcdefg'
  25908. After wcscpy, destination becomes '123456789'
  25909.  
  25910. destination1 is originally = 'abcdefg'
  25911. After wcsncpy, destination1 becomes '12345fg'
  25912. */
  25913.  
  25914.                                                                         *
  25915. ************************************************************************/
  25916.  
  25917.  
  25918. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25919.  
  25920. o strcpy  - Copy Strings 
  25921. o strncpy  - Copy Strings 
  25922. o wcscpy  - Copy wchar_t Strings 
  25923. o wcstr.h 
  25924.  
  25925.  
  25926.  
  25927. ΓòÉΓòÉΓòÉ 6.281. wcspbrk  - Locate wchar_t Characters in String ΓòÉΓòÉΓòÉ
  25928.  
  25929.  
  25930. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  25931.  
  25932. #include <wcstr.h>
  25933.  
  25934. wchar_t *wcspbrk(const wchar_t *string1, const wchar_t *string2);
  25935.  
  25936.  
  25937. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  25938.  
  25939. Language Level: SAA 
  25940.  
  25941. The wcspbrk function locates the first occurrence in the string pointed to by 
  25942. string1 of any character from the string pointed to by string2. 
  25943.  
  25944. The wcspbrk function returns a pointer to the character, or NULL if no wchar_t 
  25945. from string2 occurs in string1. 
  25946.  
  25947. Example of wcscpbrk 
  25948.  
  25949.  
  25950. ΓòÉΓòÉΓòÉ <hidden> Example of wcspbrk ΓòÉΓòÉΓòÉ
  25951.  
  25952. /************************************************************************
  25953. *
  25954. This example returns a pointer to the first occurrence in the array string of 
  25955. either a or b. 
  25956.  
  25957.                                                                         *
  25958. ************************************************************************/
  25959.  
  25960. #include <stdio.h>
  25961. #include <wcstr.h>
  25962.  
  25963. int main(void)
  25964. {
  25965.   wchar_t * result;
  25966.   wchar_t * string = L"The Blue Danube";
  25967.   wchar_t *chars = L"ab";
  25968.  
  25969.   result = wcspbrk( string, chars);
  25970.    printf("The first occurrence of any of the characters \"%ls\" in "
  25971.           "\"%ls\" is \"%ls\"\n", chars, string, result);
  25972.  
  25973. }
  25974.  
  25975. /************************************************************************
  25976. *
  25977.  
  25978. /****************  Output should be similar to:  ******************
  25979.  
  25980. The first occurrence of any of the characters "ab" in "The Blue Danube"
  25981. is "anube"
  25982. */
  25983.  
  25984.                                                                         *
  25985. ************************************************************************/
  25986.  
  25987.  
  25988. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  25989.  
  25990. o strchr  - Search for Character 
  25991. o strcspn  - Compare Strings 
  25992. o strpbrk  - Find Characters in String 
  25993. o strrchr  - Find Last Occurrence of Character in String 
  25994. o strspn  - Search Strings 
  25995. o wcschr  - Search wchar_t String for Given wchar_t 
  25996. o wcscspn  - Find Offset of First wchar_t Match 
  25997. o wcsncmp  - Compare wchar_t Strings 
  25998. o wcsrchr  - Locate wchar_t Character in String 
  25999. o wcsspn  - Search wchar_t Characters in String 
  26000. o wcswcs  - Locate wchar_t Substring in wchar_t String 
  26001. o wcstr.h 
  26002.  
  26003.  
  26004. ΓòÉΓòÉΓòÉ 6.282. wcsrchr  - Locate wchar_t Character in String ΓòÉΓòÉΓòÉ
  26005.  
  26006.  
  26007. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26008.  
  26009. #include <wcstr.h>
  26010.  
  26011. wchar_t *wcsrchr(const wchar_t *string, wchar_t character);
  26012.  
  26013.  
  26014. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26015.  
  26016. Language Level: SAA 
  26017.  
  26018. The wcsrchr function locates the last occurrence of character in the string 
  26019. pointed to by string.  The terminating wchar_t null character is considered to 
  26020. be part of the string. 
  26021.  
  26022. The wcsrchr function returns a pointer to the character, or a NULL pointer if 
  26023. character does not occur in the string. 
  26024.  
  26025. Example of wcsrchr 
  26026.  
  26027.  
  26028. ΓòÉΓòÉΓòÉ <hidden> Example of wcsrchr ΓòÉΓòÉΓòÉ
  26029.  
  26030. /************************************************************************
  26031. *
  26032. This example compares the use of wcschr and wcsrchr.  It searches the string 
  26033. for the first and last occurrence of p in the wide character string. 
  26034.  
  26035.                                                                         *
  26036. ************************************************************************/
  26037.  
  26038. #include <stdio.h>
  26039. #include <wcstr.h>
  26040.  
  26041. #define SIZE 40
  26042.  
  26043. int main(void)
  26044. {
  26045.   wchar_t buf[SIZE] = L"computer program";
  26046.   wchar_t * ptr;
  26047.   int    ch = 'p';
  26048.  
  26049.   /* This illustrates wcschr */
  26050.   ptr = wcschr( buf, ch );
  26051.   printf( "The first occurrence of %c in '%ls' is '%ls'\n", ch, buf, ptr );
  26052.  
  26053.   /* This illustrates wscrchr */
  26054.   ptr = wcsrchr( buf, ch );
  26055.   printf( "The last occurrence of %c in '%ls' is '%ls'\n",  ch, buf, ptr );
  26056. }
  26057.  
  26058. /************************************************************************
  26059. *
  26060.  
  26061. /****************  Output should be similar to:  ******************
  26062.  
  26063. The first occurrence of p in 'computer program' is 'puter program'
  26064. The last occurrence of p in 'computer program' is 'program'
  26065. */
  26066.  
  26067.                                                                         *
  26068. ************************************************************************/
  26069.  
  26070.  
  26071. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26072.  
  26073. o strchr  - Search for Character 
  26074. o strcspn  - Compare Strings 
  26075. o strpbrk  - Find Characters in String 
  26076. o strrchr  - Find Last Occurrence of Character in String 
  26077. o strspn  - Search Strings 
  26078. o wcschr  - Search wchar_t String for Given wchar_t 
  26079. o wcscspn  - Find Offset of First wchar_t Match 
  26080. o wcsspn  - Search wchar_t Characters in String 
  26081. o wcswcs  - Locate wchar_t Substring in wchar_t String 
  26082. o wcspbrk  - Locate wchar_t Characters in String 
  26083. o wcstr.h 
  26084.  
  26085.  
  26086. ΓòÉΓòÉΓòÉ 6.283. wcsspn  - Search wchar_t Characters in String ΓòÉΓòÉΓòÉ
  26087.  
  26088.  
  26089. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26090.  
  26091. #include <wcstr.h>
  26092.  
  26093. size_t wcsspn(const wchar_t *string1, const wchar_t *string2);
  26094.  
  26095.  
  26096. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26097.  
  26098. Language Level: SAA 
  26099.  
  26100. The wcsspn function computes the number of wchar_t characters in the initial 
  26101. segment of the string pointed to by string1, which consists entirely of wchar_t 
  26102. characters from the string pointed to by string2. 
  26103.  
  26104. The wcsspn function returns the number of wchar_t characters in the segment. 
  26105.  
  26106. Example of wcsspn 
  26107.  
  26108.  
  26109. ΓòÉΓòÉΓòÉ <hidden> Example of wcsspn ΓòÉΓòÉΓòÉ
  26110.  
  26111. /************************************************************************
  26112. *
  26113. This example finds the first occurrence in the array string of a character that 
  26114. is neither an a, b, nor c.  Because the string in this example is cabbage, 
  26115. wcsspn returns 5, the index of the segment of cabbage before a character that 
  26116. is not an a, b, or c. 
  26117.  
  26118.                                                                         *
  26119. ************************************************************************/
  26120.  
  26121. #include <stdio.h>
  26122. #include <wcstr.h>
  26123.  
  26124. int main(void)
  26125. {
  26126.   wchar_t * string = L"cabbage";
  26127.   wchar_t * source = L"abc";
  26128.   int index;
  26129.  
  26130.   index = wcsspn( string, L"abc" );
  26131.   printf( "The first %d characters of \"%ls\" are found in \"%ls\"\n",
  26132.               index, string, source );
  26133. }
  26134.  
  26135. /************************************************************************
  26136. *
  26137.  
  26138. /****************  Output should be similar to:  ******************
  26139.  
  26140. The first 5 characters of "cabbage" are found in "abc"
  26141. */
  26142.  
  26143.                                                                         *
  26144. ************************************************************************/
  26145.  
  26146.  
  26147. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26148.  
  26149. o strchr  - Search for Character 
  26150. o strcspn  - Compare Strings 
  26151. o strpbrk  - Find Characters in String 
  26152. o strrchr  - Find Last Occurrence of Character in String 
  26153. o strspn  - Search Strings 
  26154. o wcschr  - Search wchar_t String for Given wchar_t 
  26155. o wcscspn  - Find Offset of First wchar_t Match 
  26156. o wcsrchr  - Locate wchar_t Character in String 
  26157. o wcsspn  - Search wchar_t Characters in String 
  26158. o wcswcs  - Locate wchar_t Substring in wchar_t String 
  26159. o wcspbrk  - Locate wchar_t Characters in String 
  26160. o wcstr.h 
  26161.  
  26162.  
  26163. ΓòÉΓòÉΓòÉ 6.284. wcstombs  - Convert wchar_t String to Multibyte Character String ΓòÉΓòÉΓòÉ
  26164.  
  26165.  
  26166. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26167.  
  26168. #include <stdlib.h>
  26169.  
  26170. size_t wcstombs(char *dest, const wchar_t *string, size_t count);
  26171.  
  26172.  
  26173. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26174.  
  26175. Language Level: ANSI, SAA 
  26176.  
  26177. The wcstombs function converts the wchar_t string pointed to by string into the 
  26178. multibyte array pointed to by dest.  The converted string begins in the initial 
  26179. shift state.  The conversion stops after count bytes in dest are filled up or a 
  26180. wchar_t null character is encountered. 
  26181.  
  26182. The wcstombs function returns the length in bytes of the multibyte character 
  26183. string, not including a terminating null character.  The value (size_t)-1 is 
  26184. returned if an invalid multibyte character is encountered. 
  26185.  
  26186. Example of wcstombs 
  26187.  
  26188.  
  26189. ΓòÉΓòÉΓòÉ <hidden> Example of wcstombs ΓòÉΓòÉΓòÉ
  26190.  
  26191. /*************************************************************************
  26192. *
  26193. In this example, a wchar_t string is converted to a char string twice.  The 
  26194. first call converts the entire string, while the second call only converts 
  26195. three characters. The results are printed each time. 
  26196.  
  26197.                                                                         *
  26198. ************************************************************************/
  26199.  
  26200. #include <stdio.h>
  26201. #include <stdlib.h>
  26202. #include <string.h>
  26203.  
  26204. #define SIZE 20
  26205.  
  26206. int main(void)
  26207. {
  26208.   char dest[SIZE];
  26209.   wchar_t * dptr = L"string";
  26210.   size_t count = SIZE;
  26211.   size_t length;
  26212.  
  26213.   length = wcstombs( dest, dptr, count );
  26214.   printf( "%d characters were converted.\n", length );
  26215.   printf( "The converted string is \"%s\"\n\n", dest );
  26216.  
  26217.   /* Reset the destination buffer */
  26218.   memset( dest, '\0', sizeof(dest));
  26219.  
  26220.   /* Now convert only 3 characters */
  26221.   length = wcstombs( dest, dptr, 3 );
  26222.   printf( "%d characters were converted.\n", length );
  26223.   printf( "The converted string is \"%s\"\n", dest );
  26224. }
  26225.  
  26226. /************************************************************************
  26227. *
  26228.  
  26229. /****************  Output should be similar to:  ******************
  26230.  
  26231. 6 characters were converted.
  26232. The converted string is "string"
  26233.  
  26234. 3 characters were converted.
  26235. The converted string is "str"
  26236. */
  26237.  
  26238.                                                                         *
  26239. ************************************************************************/
  26240.  
  26241.  
  26242. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26243.  
  26244. o mbstowcs  - Convert Multibyte Characters to wchar_t Characters 
  26245. o wcslen  - Calculate Length of wchar_t String 
  26246. o wctomb  - Convert wchar_t Character to Multibyte Character 
  26247. o stdlib.h 
  26248.  
  26249.  
  26250. ΓòÉΓòÉΓòÉ 6.285. wcswcs  - Locate wchar_t Substring in wchar_t String ΓòÉΓòÉΓòÉ
  26251.  
  26252.  
  26253. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26254.  
  26255. #include <wcstr.h>
  26256.  
  26257. wchar_t *wcswcs(const wchar_t *string1, const wchar_t *string2);
  26258.  
  26259.  
  26260. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26261.  
  26262. Language Level: SAA 
  26263.  
  26264. The wcswcs function locates the first occurrence in the string pointed to by 
  26265. string1 of the sequence of wchar_t characters (excluding the terminating 
  26266. wchar_t null character) in the string pointed to by string2. 
  26267.  
  26268. The wcswcs function returns a pointer to the located string or NULL if the 
  26269. string is not found.  If string2 points to a string with zero length, the 
  26270. function returns string1. 
  26271.  
  26272. Example of wcswcs 
  26273.  
  26274.  
  26275. ΓòÉΓòÉΓòÉ <hidden> Example of wcswcs ΓòÉΓòÉΓòÉ
  26276.  
  26277. /*************************************************************************
  26278. *
  26279. This example finds the first occurrence of the wide character string pr in 
  26280. buffer1. 
  26281.  
  26282.                                                                         *
  26283. ************************************************************************/
  26284.  
  26285. #include <stdio.h>
  26286. #include <wcstr.h>
  26287.  
  26288. #define SIZE 40
  26289.  
  26290. int main(void)
  26291. {
  26292.   wchar_t buffer1[SIZE] = L"computer program";
  26293.   wchar_t * ptr;
  26294.   wchar_t * wch = L"pr";
  26295.  
  26296.   ptr = wcswcs( buffer1, wch );
  26297.   printf( "The first occurrence of %ls in '%ls' is '%ls'\n",
  26298.                           wch, buffer1, ptr );
  26299. }
  26300.  
  26301. /************************************************************************
  26302. *
  26303.  
  26304. /****************  Output should be similar to:  ******************
  26305.  
  26306. The first occurrence of pr in 'computer program' is 'program'
  26307. */
  26308.  
  26309.                                                                         *
  26310. ************************************************************************/
  26311.  
  26312.  
  26313. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26314.  
  26315. o strchr  - Search for Character 
  26316. o strcspn  - Compare Strings 
  26317. o strpbrk  - Find Characters in String 
  26318. o strrchr  - Find Last Occurrence of Character in String 
  26319. o strspn  - Search Strings 
  26320. o wcschr  - Search wchar_t String for Given wchar_t 
  26321. o wcscspn  - Find Offset of First wchar_t Match 
  26322. o wcspbrk  - Locate wchar_t Characters in String 
  26323. o wcsrchr  - Locate wchar_t Character in String 
  26324. o wcsspn  - Search wchar_t Characters in String 
  26325. o wcstr.h 
  26326.  
  26327.  
  26328. ΓòÉΓòÉΓòÉ 6.286. wctomb  - Convert wchar_t Character to Multibyte Character ΓòÉΓòÉΓòÉ
  26329.  
  26330.  
  26331. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26332.  
  26333. #include <stdlib.h>
  26334.  
  26335. int wctomb(char *string, wchar_t character);
  26336.  
  26337.  
  26338. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26339.  
  26340. Language Level: ANSI, SAA 
  26341.  
  26342. The wctomb function converts the wchar_t value of character into a multibyte 
  26343. array pointed to by string.  If the value of character is 0, the function is 
  26344. left in the initial shift state.  At most, wctomb stores MB_CUR_MAX characters 
  26345. in string. 
  26346.  
  26347. The wctomb function returns the length in bytes of the multibyte character. 
  26348. The value -1 is returned if character is not a valid multibyte character.  If 
  26349. string is a NULL pointer, the wctomb function returns nonzero if 
  26350. shift-dependent encoding is used, or 0 otherwise. 
  26351.  
  26352. Example of wctomb 
  26353.  
  26354.  
  26355. ΓòÉΓòÉΓòÉ <hidden> Example of wctomb ΓòÉΓòÉΓòÉ
  26356.  
  26357. /*************************************************************************
  26358. *
  26359. This example converts the wide character c to a character. 
  26360.  
  26361.                                                                         *
  26362. ************************************************************************/
  26363.  
  26364. #include <stdio.h>
  26365. #include <stdlib.h>
  26366.  
  26367. #define SIZE 40
  26368.  
  26369. int main(void)
  26370. {
  26371.   static char  buffer[ SIZE ];
  26372.   wchar_t wch = L'c';
  26373.   int length;
  26374.  
  26375.   length = wctomb( buffer, wch );
  26376.   printf( "The number of bytes that comprise the multibyte "
  26377.              "character is %i\n", length );
  26378.   printf( "And the converted string is \"%s\"\n", buffer );
  26379. }
  26380.  
  26381. /************************************************************************
  26382. *
  26383.  
  26384. /****************  Output should be similar to:  ******************
  26385.  
  26386. The number of bytes that comprise the multibyte character is 1
  26387. And the converted string is "c"
  26388. */
  26389.  
  26390.                                                                         *
  26391. ************************************************************************/
  26392.  
  26393.  
  26394. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26395.  
  26396. o mbtowc  - Convert Multibyte Character to wchar_t 
  26397. o wcslen  - Calculate Length of wchar_t String 
  26398. o wcstombs  - Convert wchar_t String to Multibyte Character String 
  26399. o stdlib.h 
  26400.  
  26401.  
  26402. ΓòÉΓòÉΓòÉ 6.287. _write - Writes from Buffer to File ΓòÉΓòÉΓòÉ
  26403.  
  26404.  
  26405. ΓòÉΓòÉΓòÉ <hidden> Format ΓòÉΓòÉΓòÉ
  26406.  
  26407. #include <io.h>
  26408.  
  26409. int _write(int handle, const void *buffer, unsigned int count);
  26410.  
  26411.  
  26412. ΓòÉΓòÉΓòÉ <hidden> Description ΓòÉΓòÉΓòÉ
  26413.  
  26414. Language Level: Extension 
  26415.  
  26416. The _write function writes count bytes from buffer into the file associated 
  26417. with handle. The write operation begins at the current position of the file 
  26418. pointer associated with the given file. If the file is open for appending, the 
  26419. operation begins at the end of the file. After the write operation, the file 
  26420. pointer is increased by the number of bytes actually written. 
  26421.  
  26422. If the given file was opened in text mode, each line feed character is replaced 
  26423. with a carriage return/line feed pair in the output.  The replacement does not 
  26424. affect the return value. 
  26425.  
  26426. The _write function returns the number of bytes moved from the buffer to the 
  26427. file. The return value may be positive but less than count. A return value of 
  26428. -1 indicates an error, and errno is set to one of the following values: 
  26429.  
  26430. Value          Meaning 
  26431. EBADF          The file handle is not valid, or the file is not open for 
  26432.                writing. 
  26433. ENOSPC         No space is left on the device. 
  26434. EOS2ERR        The call to the operating system was not successful. 
  26435.  
  26436. Example of _write 
  26437.  
  26438.  
  26439. ΓòÉΓòÉΓòÉ <hidden> Example of _write ΓòÉΓòÉΓòÉ
  26440.  
  26441. /************************************************************************
  26442. *
  26443.  
  26444. This example writes the contents of the character array buffer to the output 
  26445. file whose handle is fh. 
  26446.  
  26447.                                                                         *
  26448. ************************************************************************/
  26449.  
  26450. #include <io.h>
  26451. #include <stdio.h>
  26452. #include <stdlib.h>
  26453. #include <fcntl.h>
  26454. #include <string.h>
  26455.  
  26456. int main(void)
  26457.    {
  26458.    int  fh;
  26459.    char buffer[20];
  26460.  
  26461.    memset(buffer,'a',20);  /* initialize storage  */
  26462.  
  26463.    printf("\nCreating sample.dat.\n");
  26464.    system("echo Sample Program > sample.dat");
  26465.  
  26466.    if (-1 == (fh = _open("sample.dat",O_RDWR | O_APPEND)))
  26467.       {
  26468.       perror("Unable to open sample.dat");
  26469.       return 1;
  26470.       }
  26471.  
  26472.    if (5 != _write(fh,buffer,5) )
  26473.       {
  26474.       perror("Unable to write to sample.dat");
  26475.       _close(fh);
  26476.       return 1;
  26477.       }
  26478.  
  26479.    printf("Successfully appended 5 characters.\n");
  26480.  
  26481.    _close(fh);
  26482.    return 0;
  26483.  
  26484. /******************  The expected output is:  ***************************
  26485.  
  26486.       Creating sample.dat.
  26487.       Successfully appended 5 characters.
  26488. */
  26489.    }
  26490.  
  26491.  
  26492. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26493.  
  26494. o _creat - Create New File 
  26495. o fread  - Read Items 
  26496. o fwrite  - Write Items 
  26497. o _lseek - Move File Pointer 
  26498. o _open - Open File 
  26499. o _read - Read Into Buffer 
  26500. o _sopen - Open Shared File 
  26501. o _tell - Get Pointer Position 
  26502. o io.h 
  26503.  
  26504.  
  26505. ΓòÉΓòÉΓòÉ 7. Include Files ΓòÉΓòÉΓòÉ
  26506.  
  26507. The include files provided with the runtime library contain macro and constant 
  26508. definitions, type definitions, and function declarations.  Some functions 
  26509. require definitions and declarations from include files to work properly. The 
  26510. inclusion of files is optional, as long as the necessary statements from the 
  26511. files are coded directly into the source. 
  26512.  
  26513. Note:  If the /Ms compiler option (use _System linkage) is specified, you must 
  26514. include the appropriate header files with the declarations of the library 
  26515. functions that you use. 
  26516.  
  26517. This section describes the following include files, explains their contents, 
  26518. and lists the functions that use the files. 
  26519.  
  26520. o assert.h 
  26521. o builtin.h 
  26522. o conio.h 
  26523. o ctype.h 
  26524. o direct.h 
  26525. o errno.h 
  26526. o fcntl.h 
  26527. o float.h 
  26528. o io.h 
  26529. o limits.h 
  26530. o locale.h 
  26531. o malloc.h 
  26532. o math.h 
  26533. o memory.h 
  26534. o process.h 
  26535. o search.h 
  26536. o setjmp.h 
  26537. o share.h 
  26538. o signal.h 
  26539. o stdarg.h 
  26540. o stddef.h 
  26541. o stdio.h 
  26542. o stdlib.h 
  26543. o string.h 
  26544. o sys\stat.h 
  26545. o sys\timeb.h 
  26546. o sys\types.h 
  26547. o sys\utime.h 
  26548. o time.h 
  26549. o wcstr.h 
  26550.  
  26551.  
  26552. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26553.  
  26554. o #include 
  26555.  
  26556.  
  26557. ΓòÉΓòÉΓòÉ 7.1. assert.h ΓòÉΓòÉΓòÉ
  26558.  
  26559. The assert.h include file defines the assert macro.  You must include assert.h 
  26560. when you use assert. 
  26561.  
  26562. The definition of assert is in an #ifndef preprocessor block.  If you have not 
  26563. defined the identifier NDEBUG through a #define directive or on the compiler 
  26564. command line, the assert macro tests a given expression (the assertion).  If 
  26565. the assertion is false, the system prints a message to stderr and an abort 
  26566. signal is raised for the program. 
  26567.  
  26568. If NDEBUG is defined, assert is defined to do nothing. You can suppress program 
  26569. assertions by defining NDEBUG. 
  26570.  
  26571.  
  26572. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26573.  
  26574. o #define 
  26575. o #ifndef 
  26576. o Include Files 
  26577. o #include 
  26578.  
  26579.  
  26580. ΓòÉΓòÉΓòÉ 7.2. builtin.h ΓòÉΓòÉΓòÉ
  26581.  
  26582. The builtin.h include file contains function declarations for the following 
  26583. built-in functions: 
  26584.  
  26585. _alloca             _disable 
  26586. _enable             _facos 
  26587. _fasin              _fcos 
  26588. _fcossin            _fpatan 
  26589. _fptan              _fsin 
  26590. _fsincos            _fyl2x 
  26591. _fyl2xp1            _f2xm1 
  26592. _getTIBvalue        _inp 
  26593. _inpd               _inpw 
  26594. _interrupt          _outp 
  26595. _outpd              _outpw 
  26596. __parmdwords 
  26597.  
  26598. The builtin.h file also includes declaration for the following intrinsic 
  26599. functions: 
  26600.  
  26601. _clear87            _control87 
  26602. _status87 
  26603.  
  26604. The functions _clear87, _control87, and _status87 are also defined in float.h. 
  26605. The function _alloca is also defined in stdlib.h and malloc.h. The functions 
  26606. _inp, _inpd, _inpw, _outp, _outpd, and _outpw are also defined in conio.h. 
  26607.  
  26608. The builtin.h file also includes a declaration for the type size_t, which is 
  26609. also defined in stddef.h. 
  26610.  
  26611.  
  26612. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26613.  
  26614. o Intrinsic Functions 
  26615. o Include Files 
  26616. o #include 
  26617.  
  26618.  
  26619. ΓòÉΓòÉΓòÉ 7.3. conio.h ΓòÉΓòÉΓòÉ
  26620.  
  26621. The conio.h include file contains definitions for the functions that involve 
  26622. screen and console input and output: 
  26623.  
  26624. _cgets              _cprintf 
  26625. _cputs              _cscanf 
  26626. _getch              _getche 
  26627. _inp                _inpd 
  26628. _inpw               _kbhit 
  26629. _outp               _outpd 
  26630. _outpw              _putch 
  26631. _ungetch 
  26632.  
  26633.  
  26634. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26635.  
  26636. o io.h 
  26637. o stdio.h 
  26638. o Include Files 
  26639. o #include 
  26640.  
  26641.  
  26642. ΓòÉΓòÉΓòÉ 7.4. ctype.h ΓòÉΓòÉΓòÉ
  26643.  
  26644. The ctype.h include file defines functions used in character classification. 
  26645. The functions defined in ctype.h are: 
  26646.  
  26647. isalnum             isalpha 
  26648. iscntrl             isdigit 
  26649. isgraph             islower 
  26650. isprint             ispunct 
  26651. isspace             isupper 
  26652. isxdigit            &tolower. 
  26653. &toupper. 
  26654.  
  26655. In extended mode, the ctype.h file also includes definitions for the following 
  26656. C/C++Tools extensions: 
  26657.  
  26658. _isascii            _iscsym 
  26659. _iscsymf            _toascii 
  26660. _tolower            _toupper 
  26661.  
  26662. In the C/C++ Tools compiler, the ctype.h functions are all implemented as 
  26663. macros. 
  26664.  
  26665.  
  26666. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26667.  
  26668. o Include Files 
  26669. o #include 
  26670.  
  26671.  
  26672. ΓòÉΓòÉΓòÉ 7.5. direct.h ΓòÉΓòÉΓòÉ
  26673.  
  26674. The direct.h include file contains definitions for functions that control 
  26675. directories and drives. The functions defined in direct.h are: 
  26676.  
  26677. _chdir              _chdrive 
  26678. _getcwd             _getdcwd 
  26679. _getdrive           _mkdir 
  26680. _rmdir 
  26681.  
  26682.  
  26683. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26684.  
  26685. o Include Files 
  26686. o #include 
  26687.  
  26688.  
  26689. ΓòÉΓòÉΓòÉ 7.6. errno.h ΓòÉΓòÉΓòÉ
  26690.  
  26691. The errno.h include file defines the macros EDOM and ERANGE, and a modifiable 
  26692. lvalue having type int called errno. It also defines the global variable 
  26693. _doserrno, which is determined by the OS/2 error code when an operating system 
  26694. error occurs. 
  26695.  
  26696. See Runtime Return Codes and Messages for a list of the runtime error messages 
  26697. and the errno values associated with each message. 
  26698.  
  26699. Note:  If you are going to test the value of errno after library function 
  26700. calls, first set it to 0, because its value may not be reset during the call. 
  26701.  
  26702. The definitions of errno and _doserrno are also provided in stdlib.h. 
  26703.  
  26704.  
  26705. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26706.  
  26707. o Runtime Return Codes and Messages 
  26708. o stdlib.h 
  26709. o Include Files 
  26710. o #include 
  26711.  
  26712.  
  26713. ΓòÉΓòÉΓòÉ 7.7. fcntl.h ΓòÉΓòÉΓòÉ
  26714.  
  26715. The fcntl.h contains definitions for constants used by the _open and _sopen 
  26716. functions. Definitions for these two functions are included in io.h. Additional 
  26717. definitions for _sopen are provided in share.h. 
  26718.  
  26719.  
  26720. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26721.  
  26722. o io.h 
  26723. o share.h 
  26724. o Include Files 
  26725. o #include 
  26726.  
  26727.  
  26728. ΓòÉΓòÉΓòÉ 7.8. float.h ΓòÉΓòÉΓòÉ
  26729.  
  26730. The float.h include file contains definitions of constants that specify the 
  26731. ranges of floating-point data types, for example, the maximum number of digits 
  26732. for objects of type double or the minimum exponent for objects of type float. 
  26733. In extended mode, float.h also defines the macros that represent infinity and 
  26734. NaN (not-a-number) values, and contains the definitions for the following 
  26735. functions that manipulate the floating-point control and status words, and for 
  26736. the constants that they use: 
  26737.  
  26738. _clear87            _control87 
  26739. _fpreset            _status87 
  26740.  
  26741.  
  26742. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26743.  
  26744. o Infinity and NaN Support 
  26745. o Floating-Point Variables 
  26746. o Include Files 
  26747. o #include 
  26748.  
  26749.  
  26750. ΓòÉΓòÉΓòÉ 7.9. io.h ΓòÉΓòÉΓòÉ
  26751.  
  26752. The io.h include file contains definitions for the following file handle and 
  26753. low-level input and output functions: 
  26754.  
  26755. _access             _chmod 
  26756. _chsize             _close 
  26757. _creat              _dup 
  26758. _dup2               __eof 
  26759. _filelength         _isatty 
  26760. _lseek              _open 
  26761. _read               remove 
  26762. rename              _setmode 
  26763. _sopen              _tell 
  26764. _umask              _unlink 
  26765. _write 
  26766.  
  26767. Two additional functions, _fstat and _stat, are defined in sys\stat. 
  26768.  
  26769. Constants required by the _open and _sopen functions are provided in fcntl.h. 
  26770. Additional constants used by _sopen are defined in share.h. 
  26771.  
  26772. The _unlink function is also defined in stdio.h. 
  26773.  
  26774.  
  26775. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26776.  
  26777. o fcntl.h 
  26778. o share.h 
  26779. o sys\stat.h 
  26780. o stdlib.h 
  26781. o conio.h 
  26782. o stdio.h 
  26783. o Include Files 
  26784. o #include 
  26785.  
  26786.  
  26787. ΓòÉΓòÉΓòÉ 7.10. limits.h ΓòÉΓòÉΓòÉ
  26788.  
  26789. The limits.h include file contains definitions of constants that specify the 
  26790. ranges of integer and character data types, such as the maximum value for an 
  26791. object of type char. 
  26792.  
  26793.  
  26794. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26795.  
  26796. o Characters 
  26797. o Integers 
  26798. o Include Files 
  26799. o #include 
  26800.  
  26801.  
  26802. ΓòÉΓòÉΓòÉ 7.11. locale.h ΓòÉΓòÉΓòÉ
  26803.  
  26804. The locale.h include file contains declarations for the setlocale and 
  26805. localeconv library functions. These functions are useful for changing the C 
  26806. locale when you are creating applications for international markets. 
  26807.  
  26808. locale.h also contains the declaration for the type struct lconv and the 
  26809. following macro definitions: 
  26810.  
  26811. NULL                LC_ALL 
  26812. LC_COLLATE          LC_CTYPE 
  26813. LC_MONETARY         LC_NUMERIC 
  26814. LC_TIME             LC_C_TOD 
  26815. LC_C                LC_C_FRANCE 
  26816. LC_C_GERMANY        LC_C_ITALY 
  26817. LC_C_JAPAN          LC_C_SPAIN 
  26818. LC_C_UK             LC_C_USA 
  26819.  
  26820. NULL is also defined in stddef.h on page stddef.h, stdio.h on page stdio.h, 
  26821. stdlib.h on page stdlib.h, string.h on page string.h, time.h on page time.h, 
  26822. and wcstr.h on page wcstr.h. 
  26823.  
  26824.  
  26825. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26826.  
  26827. o Include Files 
  26828. o #include 
  26829.  
  26830.  
  26831. ΓòÉΓòÉΓòÉ 7.12. malloc.h ΓòÉΓòÉΓòÉ
  26832.  
  26833. The malloc.h include file contains definitions for the following memory 
  26834. allocation functions: 
  26835.  
  26836. _alloca             calloc 
  26837. _debug_calloc       _debug_free 
  26838. _debug_malloc       _debug_heapmin 
  26839. _debug_realloc      _dump_allocated 
  26840. free                _heap_check 
  26841. malloc              &mszize. 
  26842. realloc 
  26843.  
  26844. It also includes a definition for the type size_t. 
  26845.  
  26846. The SAA definitions of calloc, free, malloc, and realloc are provided in 
  26847. stdlib.h, as are _alloca and _heapmin. 
  26848.  
  26849. The _debug_calloc, _debug_free, _debug_malloc, _debug_heapmin, _debug_realloc, 
  26850. _dump_allocated, and _heap_check functions are also defined as standard 
  26851. extensions in stdlib.h. 
  26852.  
  26853. Note:  To use these functions, you must also define the __DEBUG_ALLOC__ macro. 
  26854. See Debug Memory Management Functions for more information about these 
  26855. functions. 
  26856.  
  26857. The _tcalloc, _tfree, _tmalloc, _trealloc functions are also defined as 
  26858. standard extensions in stdlib.h. 
  26859.  
  26860. Note: 
  26861.  
  26862.  1. To use these functions, you must also define the __TILED__ macro. See Tiled 
  26863.     Memory Management Functions for more information about these functions. 
  26864.  
  26865.  2. If you define __DEBUG_ALLOC__ and __TILED__ at the same time, the tiled 
  26866.     memory functions are provided, and the debug memory features are disabled. 
  26867.  
  26868. The malloc.h include file also defines a number of far and near pointer macros 
  26869. to the corresponding SAA or standard library function. These macros are: 
  26870.  
  26871. _fcalloc            _ffree 
  26872. _fheapmin           _fmalloc 
  26873. _frealloc           _ncalloc 
  26874. _nfree              _nheapmin 
  26875. _nmalloc            _nrealloc 
  26876.  
  26877. These macros are also defined in stdlib.h. 
  26878.  
  26879.  
  26880. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26881.  
  26882. o stdlib.h 
  26883. o Include Files 
  26884. o #include 
  26885.  
  26886.  
  26887. ΓòÉΓòÉΓòÉ 7.13. math.h ΓòÉΓòÉΓòÉ
  26888.  
  26889. The math.h include file contains function declarations for all the 
  26890. floating-point math functions: 
  26891.  
  26892. acos                asin 
  26893. atan                atan2 
  26894. bessel              ceil 
  26895. cos                 cosh 
  26896. erf                 erfc 
  26897. exp                 fabs 
  26898. floor               fmod 
  26899. frexp               gamma 
  26900. hypot               ldexp 
  26901. log                 log10 
  26902. modf                pow 
  26903. sin                 sinh 
  26904. sqrt                tan 
  26905. tanh 
  26906.  
  26907. Note:  bessel does not correspond to a single function but to the functions 
  26908.        named _j0, _j1, _jn, _y0, _y1, and _yn. 
  26909.  
  26910. The math.h file also includes definitions for the following C/C++ Tools 
  26911. extensions: 
  26912.  
  26913. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  26914. Γöé _atold          Γöé _cabs           Γöé _matherr         Γöé
  26915. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  26916.  
  26917. The _atold function is also defined in stdlib.h. 
  26918.  
  26919. The math.h include file defines the macros HUGE, _LHUGE, HUGE_VAL, and 
  26920. _LHUGE_VAL, which expand to a positive double expression or to infinity. 
  26921.  
  26922. You can define a macro _FP_INLINE to inline the functions sin, cos, tan, atan, 
  26923. acos and asin. If you use _FP_INLINE to inline the functions, you cannot use 
  26924. the functions defined in complex.h, or an error message is generated. 
  26925.  
  26926. For all mathematical functions, a domain error occurs when an input argument is 
  26927. outside the range of values allowed for that function.  In the event of a 
  26928. domain error, errno is set to the value of EDOM. 
  26929.  
  26930. A range error occurs if the result of the function cannot be represented in a 
  26931. double value.  If the magnitude of the result is too large (overflow), the 
  26932. function returns the positive or negative value of the macro HUGE_VAL, and sets 
  26933. errno to ERANGE.  If the result is too small (underflow), the function returns 
  26934. zero. 
  26935.  
  26936.  
  26937. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26938.  
  26939. o stdlib.h 
  26940. o Include Files 
  26941. o #include 
  26942.  
  26943.  
  26944. ΓòÉΓòÉΓòÉ 7.14. memory.h ΓòÉΓòÉΓòÉ
  26945.  
  26946. The memory.h include file contains definitions for the following buffer 
  26947. manipulation functions: 
  26948.  
  26949. memccpy             memchr 
  26950. memcmp              memcpy 
  26951. memicmp             memmove 
  26952. memset 
  26953.  
  26954. The SAA definitions of these functions are provided in string.h. 
  26955.  
  26956. The memory.h include file also defines a number of far and near pointer macros 
  26957. to the corresponding SAA or standard library function.  These macros are: 
  26958.  
  26959. _fmemccpy           _fmemchr 
  26960. _fmemcmp            _fmemcpy 
  26961. _fmemicmp           _fmemset 
  26962.  
  26963. These macros are also defined in string.h. 
  26964.  
  26965.  
  26966. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26967.  
  26968. o string.h 
  26969. o Include Files 
  26970. o #include 
  26971.  
  26972.  
  26973. ΓòÉΓòÉΓòÉ 7.15. process.h ΓòÉΓòÉΓòÉ
  26974.  
  26975. The process.h include file contains definitions for the process control 
  26976. functions: 
  26977.  
  26978. abort               _beginthread 
  26979. _cwait              _endthread 
  26980. _execl              _execle 
  26981. _execlp             _execlpe 
  26982. _execv              _execve 
  26983. _execvp             _execvpe 
  26984. exit                _exit 
  26985. _getpid             _spawnl 
  26986. _spawnle            _spawnlp 
  26987. _spawnlpe           _spawnv 
  26988. _spawnve            _spawnvp 
  26989. _spawnvpe           system 
  26990. _wait 
  26991.  
  26992. The definitions of _beginthread and _endthread are also provided in stdlib.h, 
  26993. as are SAA definitions of abort, exit, and system. 
  26994.  
  26995.  
  26996. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  26997.  
  26998. o stdlib.h 
  26999. o Include Files 
  27000. o #include 
  27001.  
  27002.  
  27003. ΓòÉΓòÉΓòÉ 7.16. search.h ΓòÉΓòÉΓòÉ
  27004.  
  27005. The search.h include file contains the definitions for the following search 
  27006. functions: 
  27007.  
  27008. bsearch             _lfind 
  27009. _lsearch            qsort 
  27010.  
  27011. It also defines the type size_t. 
  27012.  
  27013. The SAA definitions for bsearch and qsort are provided in stdlib.h. 
  27014.  
  27015.  
  27016. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27017.  
  27018. o stdlib.h 
  27019. o Include Files 
  27020. o #include 
  27021.  
  27022.  
  27023. ΓòÉΓòÉΓòÉ 7.17. setjmp.h ΓòÉΓòÉΓòÉ
  27024.  
  27025. The setjmp.h include file contains function declarations for the setjmp macro 
  27026. and longjmp function.  It also defines a buffer type, jmp_buf, that the setjmp 
  27027. macro and longjmp function use to save and restore the program state. 
  27028.  
  27029.  
  27030. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27031.  
  27032. o Include Files 
  27033. o #include 
  27034.  
  27035.  
  27036. ΓòÉΓòÉΓòÉ 7.18. share.h ΓòÉΓòÉΓòÉ
  27037.  
  27038. The share.h include file defines constants used by the following functions: 
  27039.  
  27040. _creat              _fdopen 
  27041. _open               _sopen 
  27042.  
  27043. The definitions for the above functions are included in io.h. Additional 
  27044. constants for _open and _sopen are provided in fcntl.h. 
  27045.  
  27046.  
  27047. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27048.  
  27049. o fcntl.h 
  27050. o io.h 
  27051. o Include Files 
  27052. o #include 
  27053.  
  27054.  
  27055. ΓòÉΓòÉΓòÉ 7.19. signal.h ΓòÉΓòÉΓòÉ
  27056.  
  27057. The signal.h include file defines the values for signals.  The signal and raise 
  27058. functions are declared in signal.h. 
  27059.  
  27060. signal.h also defines the following macros: 
  27061.  
  27062. SIG_DFL             SIGILL 
  27063. SIG_ERR             SIGINT 
  27064. SIG_IGN             SIGSEGV 
  27065. SIGABRT             SIGTERM 
  27066. SIGFPE              SIGUSR1 
  27067. SIGUSR2             SIGUSR3 
  27068. signal.h also defines the type sig_atomic_t. 
  27069.  
  27070.  
  27071. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27072.  
  27073. o Include Files 
  27074. o #include 
  27075.  
  27076.  
  27077. ΓòÉΓòÉΓòÉ 7.20. stdarg.h ΓòÉΓòÉΓòÉ
  27078.  
  27079. The stdarg.h include file defines macros that allow you access to arguments in 
  27080. functions with variable-length argument lists.  The macros are: va_arg, 
  27081. va_start, and va_end. stdarg.h also defines the type va_list. 
  27082.  
  27083.  
  27084. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27085.  
  27086. o Include Files 
  27087. o #include 
  27088.  
  27089.  
  27090. ΓòÉΓòÉΓòÉ 7.21. stddef.h ΓòÉΓòÉΓòÉ
  27091.  
  27092. The stddef.h include file contains definitions of the commonly used pointers, 
  27093. variables, and types, from typedef statements, as listed below: 
  27094.  
  27095. ptrdiff_t        typedef for the type of the difference of two pointers 
  27096. size_t           typedef for the type of the value returned by sizeof 
  27097. wchar_t          typedef for a wide character constant. 
  27098.  
  27099. stddef.h also defines the macros NULL and offsetof. NULL is a pointer that is 
  27100. guaranteed not to point to a data object. NULL is also defined in locale.h. The 
  27101. offsetof macro expands to the number of bytes between a structure member and 
  27102. the start of the structure.  The offsetof macro has the form: 
  27103.  
  27104.    offsetof(structure_type, member)
  27105.  
  27106. stddef.h also contains definitions of the global variables errno and _threadid. 
  27107.  
  27108. The extended definition of errno is also included in stdlib.h, while the SAA 
  27109. version is in errno.h. 
  27110.  
  27111.  
  27112. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27113.  
  27114. o errno.h 
  27115. o stdlib.h 
  27116. o stdio.h 
  27117. o Include Files 
  27118. o #include 
  27119.  
  27120.  
  27121. ΓòÉΓòÉΓòÉ 7.22. stdio.h ΓòÉΓòÉΓòÉ
  27122.  
  27123. The stdio.h include file contains definitions of constants, macros, and types, 
  27124. along with function declarations for stream input and output functions. The 
  27125. stream I/O functions are: 
  27126.  
  27127. clearerr            fclose 
  27128. feof                ferror 
  27129. fflush              fgetc 
  27130. fgetpos             fgets 
  27131. fopen               fprintf 
  27132. fputc               fputs 
  27133. fread               freopen 
  27134. fscanf              fseek 
  27135. fsetpos             ftell 
  27136. fwrite              getc 
  27137. getchar             gets 
  27138. perror              printf 
  27139. putc                putchar 
  27140. puts                remove 
  27141. rename              rewind 
  27142. scanf               setbuf 
  27143. setvbuf             sprintf 
  27144. sscanf              tmpfile 
  27145. tmpnam              ungetc 
  27146. vfprintf            vprintf 
  27147. vsprintf 
  27148.  
  27149. In extended mode, stdio.h also contains definitions for the following 
  27150. extensions: 
  27151.  
  27152. _fcloseall          _fgetchar 
  27153. _fileno             _flushall 
  27154. _fputchar           _rmtmp 
  27155. _set_crt_msg_handle _tempnam 
  27156. _unlink 
  27157.  
  27158. The _unlink function is also defined in io.h. 
  27159.  
  27160. The stdio.h file also defines the macros listed below.  You can use these 
  27161. constants in your programs, but you should not alter their values. 
  27162.  
  27163. BUFSIZ 
  27164.   Specifies the buffer size to be used by the setbuf library function when you 
  27165.   are allocating buffers for stream I/O.  This value establishes the size of 
  27166.   system-allocated buffers and is used with setbuf. 
  27167. EOF 
  27168.   The value returned by an I/O function when the end of the file (or in some 
  27169.   cases, an error) is found. 
  27170. FOPEN_MAX 
  27171.   The number of files that can be opened simultaneously. 
  27172. FILENAME_MAX 
  27173.   The longest file name supported. If there is no reasonable limit, 
  27174.   FILENAME_MAX will be the recommended size. 
  27175. L_tmpnam 
  27176.   The size of the longest temporary name that can be generated by the tmpnam 
  27177.   function. 
  27178. P_tmpdir 
  27179.   Indicates the default directory to be used by the tempnam function. 
  27180. TMP_MAX 
  27181.   The minimum number of unique file names that can be generated by the tmpnam 
  27182.   function. 
  27183. NULL 
  27184.   A pointer guaranteed not to point to a data object. NULL is also defined in 
  27185.   locale.h. 
  27186.  
  27187. The FILE structure type is defined in stdio.h.  Stream I/O functions use a 
  27188. pointer to the FILE type to get access to a given stream.  The system uses the 
  27189. information in the FILE structure to maintain the stream.  The C standard 
  27190. streams stdin, stdout, and stderr are also defined in stdio.h. 
  27191.  
  27192. The macros SEEK_CUR, SEEK_END, and SEEK_SET expand to integral constant 
  27193. expressions and can be used as the third argument to fseek. 
  27194.  
  27195. The macros _IOFBF, _IOLBF, and _IONBF expand to integral constant expressions 
  27196. with distinct values suitable for use as the third argument to the setvbuf 
  27197. function. 
  27198.  
  27199. The type fpos_t is defined in stdio.h for use with fgetpos and fsetpos. 
  27200.  
  27201.  
  27202. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27203.  
  27204. o stddef.h 
  27205. o stdlib.h 
  27206. o conio.h 
  27207. o io.h 
  27208. o Include Files 
  27209. o #include 
  27210.  
  27211.  
  27212. ΓòÉΓòÉΓòÉ 7.23. stdlib.h ΓòÉΓòÉΓòÉ
  27213.  
  27214. The stdlib.h include file contains function declarations for the following 
  27215. functions: 
  27216.  
  27217. abort               abs 
  27218. atexit              atof 
  27219. atoi                atol 
  27220. bsearch             calloc 
  27221. div                 exit 
  27222. free                getenv 
  27223. labs                ldiv 
  27224. malloc              mblen 
  27225. mbstowcs            mbtowc 
  27226. qsort               rand 
  27227. realloc             srand 
  27228. strtod              strtol 
  27229. strtoul             system 
  27230. wctomb              wcstombs 
  27231.  
  27232. In extended mode, stdlib.h also contains definitions for the following standard 
  27233. extensions: 
  27234.  
  27235. _alloca             _atold 
  27236. _beginthread        _debug_calloc 
  27237. _debug_free         _debug_heapmin 
  27238. _debug_malloc       _debug_realloc 
  27239. _dump_allocated     _ecvt 
  27240. _endthread          _exit 
  27241. _fcvt               _freemod 
  27242. _fullpath           _gcvt 
  27243. _heapmin            _heap_check 
  27244. _itoa               _loadmod 
  27245. _lrotl              _lrotr 
  27246. _ltoa               _makepath 
  27247. max                 min 
  27248. _onexit             __parmdwords 
  27249. _putenv             _rotl 
  27250. _rotr               _searchenv 
  27251. _splitpath          strtold 
  27252. _swab               _threadstore 
  27253. _ultoa 
  27254.  
  27255. Note: 
  27256.  
  27257.  1. Note that you must also define the __DEBUG_ALLOC__ macro to use the 
  27258.     _debug_calloc, _debug_free, _debug_malloc, _debug_realloc, _dump_allocated, 
  27259.     _debug_heapmin, and _heap_check functions. For more information about these 
  27260.     functions, see Debug Memory Management Functions. 
  27261.  
  27262.  2. If you define __DEBUG_ALLOC__ and __TILED__ at the same time, the tiled 
  27263.     memory functions are provided, and the debug memory features are disabled. 
  27264.  
  27265. The stdlib.h file also contains definitions for the following macros: 
  27266.  
  27267. split=yes. 
  27268.  
  27269. NULL The NULL pointer value. The value of NULL is 0 when in extended mode; 
  27270.   otherwise, its value is ((void*)0). NULL is also defined in locale.h. 
  27271. EXIT_SUCCESS Expands to 0; used by the atexit function. 
  27272. EXIT_FAILURE Expands to 8; used by the atexit function. 
  27273. RAND_MAX Expands to an integer representing the largest number that the RAND 
  27274.   function can return. 
  27275. MB_CUR_MAX Expands to an integer representing the maximum number of bytes in a 
  27276.   multibyte character for the current locale. 
  27277.  
  27278. For more information on NULL and the types size_t and wchar_t, see stddef.h. 
  27279.  
  27280. In extended mode, stdlib.h also defines the following global variables: 
  27281.  
  27282. _doserrno           _environ 
  27283. errno               onexit_t 
  27284. _osmajor            _osminor 
  27285. _osmode 
  27286.  
  27287. The variable errno is also defined in stddef.h. The variable _doserrno and the 
  27288. SAA definition of errno are provided in errno.h. 
  27289.  
  27290. In addition, stdlib.h defines the following far and near pointer macros to the 
  27291. corresponding standard library function: 
  27292.  
  27293. _fcalloc            _ffree 
  27294. _fmalloc            _fheapmin 
  27295. _frealloc           _ncalloc 
  27296. _nfree              _nmalloc 
  27297. _nheapmin           _nrealloc 
  27298.  
  27299. These macros are also defined in malloc.h. 
  27300.  
  27301.  
  27302. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27303.  
  27304. o errno.h 
  27305. o malloc.h 
  27306. o stddef.h 
  27307. o stdio.h 
  27308. o Include Files 
  27309. o #include 
  27310.  
  27311.  
  27312. ΓòÉΓòÉΓòÉ 7.24. string.h ΓòÉΓòÉΓòÉ
  27313.  
  27314. The string.h include file declares the string manipulation functions: 
  27315.  
  27316. memchr              memcmp 
  27317. memcpy              memmove 
  27318. memset              strcat 
  27319. strchr              strcmp 
  27320. strcoll             strcpy 
  27321. strcspn             strerror 
  27322. strlen              strncat 
  27323. strncmp             strncpy 
  27324. strpbrk             strrchr 
  27325. strspn              strstr 
  27326. strtok              strxfrm 
  27327.  
  27328. In extended mode, string.h also contains definitions for the following standard 
  27329. extensions: 
  27330.  
  27331. memccpy             memicmp 
  27332. strcmpi             strdup 
  27333. _strerror           stricmp 
  27334. strlwr              strnicmp 
  27335. strnset             strrev 
  27336. strset              strupr 
  27337.  
  27338. The memxxxx functions are also included in memory.h. 
  27339.  
  27340. The string.h include file also defines the macro NULL and the type size_t. 
  27341. These definitions are also provided in stddef.h. NULL is also defined in 
  27342. locale.h. 
  27343.  
  27344. string.h also defines the following far  and near pointer macros to the 
  27345. corresponding standard library function: 
  27346.  
  27347. _fmemccpy           _fmemchr 
  27348. _fmemcmp            _fmemcpy 
  27349. _fmemicmp           _fmemmove 
  27350. _fmemset            _fstrcat 
  27351. _fstrchr            _fstrcmp 
  27352. _fstrcpy            _fstrcspn 
  27353. _fstrdup            _fstricmp 
  27354. _fstrlen            _fstrlwr 
  27355. _fstrncat           _fstrncmp 
  27356. _fstrncpy           _fstrnicmp 
  27357. _fstrnset           _fstrpbrk 
  27358. _fstrrchr           _fstrrev 
  27359. _fstrset            _fstrspn 
  27360. _fstrstr            _fstrtok 
  27361. _fstrupr            _nstrdup 
  27362.  
  27363. These macros are also defined in memory.h. 
  27364.  
  27365.  
  27366. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27367.  
  27368. o stddef.h 
  27369. o memory.h 
  27370. o stdlib.h 
  27371. o stdio.h 
  27372. o Include Files 
  27373. o #include 
  27374.  
  27375.  
  27376. ΓòÉΓòÉΓòÉ 7.25. sys\stat.h ΓòÉΓòÉΓòÉ
  27377.  
  27378. The sys\stat.h include file contains the definitions for the low-level 
  27379. input/output functions _fstat and _stat. It also defines the structure stat and 
  27380. the following types: 
  27381.  
  27382. dev_t               ino_t 
  27383. off_t               time_t 
  27384.  
  27385. These types are also defined in sys\types.h. 
  27386.  
  27387. Other low-level I/O functions are defined in io.h. 
  27388.  
  27389.  
  27390. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27391.  
  27392. o io.h 
  27393. o sys\types.h 
  27394. o Include Files 
  27395. o #include 
  27396.  
  27397.  
  27398. ΓòÉΓòÉΓòÉ 7.26. sys\timeb.h ΓòÉΓòÉΓòÉ
  27399.  
  27400. The sys\timeb.h include file contains the definition for the _ftime function 
  27401. and also defines the type time_t and the structure timeb. 
  27402.  
  27403.  
  27404. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27405.  
  27406. o Include Files 
  27407. o #include 
  27408.  
  27409.  
  27410. ΓòÉΓòÉΓòÉ 7.27. sys\types.h ΓòÉΓòÉΓòÉ
  27411.  
  27412. The sys\types.h include file contains the definitions for the following types: 
  27413.  
  27414. ino_t               time_t 
  27415. dev_t               off_t 
  27416.  
  27417. These types are also defined in sys\stat.h. 
  27418.  
  27419.  
  27420. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27421.  
  27422. o sys\stat.h 
  27423. o Include Files 
  27424. o #include 
  27425.  
  27426.  
  27427. ΓòÉΓòÉΓòÉ 7.28. sys\utime.h ΓòÉΓòÉΓòÉ
  27428.  
  27429. The sys\utime.h include file contains the definitions for the _utime function, 
  27430. the structure utimbuf, and the type time_t. 
  27431.  
  27432.  
  27433. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27434.  
  27435. o Include Files 
  27436. o #include 
  27437.  
  27438.  
  27439. ΓòÉΓòÉΓòÉ 7.29. time.h ΓòÉΓòÉΓòÉ
  27440.  
  27441. The time.h include file declares the time and date functions: 
  27442.  
  27443. asctime             clock 
  27444. ctime               difftime 
  27445. gmtime              localtime 
  27446. mktime              strftime 
  27447. time 
  27448.  
  27449. In extended mode, time.h also includes the definition for the standard 
  27450. extensions _strdate, _strtime, and _tzset. 
  27451.  
  27452. The time.h include file also provides: 
  27453.  
  27454. o A structure tm containing the components of a calendar time.  See gmtime  - 
  27455.   Convert Time for a list of the members of the tm structure. 
  27456.  
  27457. o A macro CLOCKS_PER_SEC equal to the number per second of the value returned 
  27458.   by the clock function. 
  27459.  
  27460. o Types clock_t, time_t, and size_t. 
  27461.  
  27462. o The NULL pointer value. 
  27463.  
  27464. For more information on NULL and the type size_t, see stddef.h. 
  27465.  
  27466. time.h also defines the global variables _daylight, _timezone, and _tzname. 
  27467.  
  27468.  
  27469. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27470.  
  27471. o stddef.h 
  27472. o Include Files 
  27473. o #include 
  27474.  
  27475.  
  27476. ΓòÉΓòÉΓòÉ 7.30. wcstr.h ΓòÉΓòÉΓòÉ
  27477.  
  27478. The wcstr.h include file declares the multibyte functions: 
  27479.  
  27480. wcscat              wcschr 
  27481. wcscmp              wcscpy 
  27482. wcscspn             wcslen 
  27483. wcsncat             wcsncmp 
  27484. wcsncpy             wcspbrk 
  27485. wcsspn              wcsrchr 
  27486. wcswcs 
  27487. wcstr.h also defines the types size_t, NULL, and wchar_t. 
  27488.  
  27489.  
  27490. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  27491.  
  27492. o Include Files 
  27493. o #include 
  27494.