home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / learn / assert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-25  |  1000 b   |  43 lines

  1. /* ASSERT.C illustrates function:
  2.  *      assert
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <conio.h>
  7. #include <string.h>
  8. #include <assert.h>
  9.  
  10. #define MAXSTR 120
  11.  
  12. void chkstr( char *string );    /* Prototype */
  13.  
  14. main()
  15. {
  16.     char string1[MAXSTR], string2[MAXSTR];
  17.  
  18.     /* Do various processes on strings and check the results. If
  19.      * none cause errors, force on error with empty string.
  20.      */
  21.     printf( "Enter a string: " );
  22.     gets( string1 );
  23.     chkstr( string1 );
  24.  
  25.     printf( "Enter another string: " );
  26.     gets( string2 );
  27.     chkstr( string2 );
  28.  
  29.     strcat( string1, string2 );
  30.     chkstr( string1 );
  31.     printf( "string1 + string2 = %s\n", string1 );
  32.  
  33.     chkstr( "" );
  34.     printf( "You'll never get here\n" );
  35. }
  36.  
  37. void chkstr( char *string )
  38. {
  39.     assert( string != NULL );               /* Cannot be NULL */
  40.     assert( *string != '\0' );              /* Cannot be empty */
  41.     assert( strlen( string ) < MAXSTR );    /* Length must be positive */
  42. }
  43.