home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / fish / code_examples / cmanual_456 / amigados / example5.c < prev    next >
C/C++ Source or Header  |  1991-01-12  |  2KB  |  67 lines

  1. /* Example5                                                           */
  2. /* This example demonstrates how to attach a short comment to a file. */
  3. /* A short file called "Letter.doc" will be created, and a short      */
  4. /* comment will be attached.                                          */
  5. /* To see the comment use the CLI command "List".                     */
  6.  
  7.  
  8. /* Declares BOOL: */
  9. #include <exec/types.h>
  10. /* Declares the FileHandle structure: */
  11. #include <libraries/dos.h>
  12.  
  13.  
  14. void main();
  15.  
  16. void main()
  17. {
  18.   struct FileHandle *file_handle;
  19.   char letter[ 8 ] = { 'D', 'e', 'a', 'r', ' ', 'S', 'i', 'r' };
  20.   long bytes_written;
  21.   BOOL ok;
  22.  
  23.  
  24.   /* Try to open file "Letter.doc" as a new file:     */
  25.   /* (If the file does not exist, it will be created. */
  26.   /* If it, on the the other hand, exist, it will be  */
  27.   /* overwritten.)                                    */
  28.   file_handle = (struct FileHandle *)
  29.     Open( "RAM:Letter.doc", MODE_NEWFILE );
  30.   
  31.   /* Have we opened the file successfully? */
  32.   if( file_handle == NULL )
  33.   {
  34.     printf( "Could not open the file!\n" );
  35.     exit();
  36.   }
  37.  
  38.  
  39.  
  40.   /* We have now opened a file, and are ready to start writing: */
  41.   bytes_written = Write( file_handle, letter, sizeof( letter ) );
  42.  
  43.   if( bytes_written != sizeof( letter ) )
  44.   {
  45.     printf( "Could not save the documment!\n" );
  46.     exit();
  47.   }
  48.   else
  49.     printf( "The documment was successfully saved!\n" );
  50.  
  51.  
  52.  
  53.   /* Attach a short comment: */
  54.   ok = SetComment( "RAM:Letter.doc", "A very short letter" );
  55.  
  56.   /* Check if the comment was successfully attached: */
  57.   if( !ok )
  58.     printf( "Could not attach the comment!\n" );
  59.   else
  60.     printf( "The comment was successfull attached to the file!\n" );
  61.  
  62.  
  63.  
  64.   /* Close the file: */
  65.   Close( file_handle );
  66. }
  67.