home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / srtsltn / data1.cab / Target / Samples / CSmpl / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-05  |  1.9 KB  |  77 lines

  1. /*
  2. * This sample applications demonstrates how to sort a file using the 
  3. * Sort Solution Library
  4. *
  5. * This source code is only intended as a supplement to the Sort Solution user 
  6. * documentation and related electronic documentation provided with the library.
  7. * See these sources for detailed information regarding the Sort Solution product.
  8. *
  9. *
  10. * Copyright ⌐ 1997,98 Mario M. Westphal
  11. * All Rights reserved
  12. */
  13.  
  14. // The standard stuff
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17.  
  18. // The Sort Solution headers
  19. #include "..\..\Include\sortsoli.h"
  20.  
  21.  
  22. // We sort a text file (each line delimited with a carriage return/linefeed pair)
  23. // using the key type String on the whole line...
  24. #define PROFILESTRING "INPUTFILE(input.txt)\r\n" \
  25.                       "OUTPUTFILE(output.txt)\r\n" \
  26.                       "FILETYPE(DELIMITED,\";\",\"0x0D,0x0A\")\r\n" \
  27.                       "KEY(String,ASC,1,0,0)\r\n"
  28.  
  29.  
  30. // Print an error message using SSIGetErrorMessage
  31. void PrintError(SORTSOL_ERROR Code)
  32. {
  33.     char msg[512];
  34.     unsigned len = sizeof(msg);
  35.     SSIGetErrorMessage(Code,msg,&len);
  36.     printf("\n%s\n",msg);
  37. }
  38.  
  39.  
  40. // M A I N
  41. int main(int argc, char *argv[])
  42. {
  43.     SSIH                    ssihandle;            // The Sort Solution handle
  44.     SORTSOL_ERROR            result;                // Stores results from the API calls
  45.     SORTSOL_CMDFILESTATUS    cmdstat;
  46.  
  47.     // (1) Create a sort instance from the command string
  48.     result = SSICreateFromCommandString(&ssihandle,PROFILESTRING,&cmdstat);
  49.     
  50.     // If there is an error at this stage, something is wrong with
  51.     // the profile string
  52.     if (result != SOSOERR_SUCCESS) {
  53.         PrintError(result);
  54.         if (cmdstat.LineNo > 0) {
  55.             printf("Error in line %d\n",cmdstat.LineNo);
  56.             printf("'%s'\n",cmdstat.ErrLine);
  57.         }
  58.         return -1;
  59.     }
  60.     else {
  61.         // Run the sort
  62.         result == SSISort(ssihandle);
  63.  
  64.         // Free the handle
  65.         SSIFree(ssihandle);
  66.     }
  67.     
  68.     if (result != SOSOERR_SUCCESS) {
  69.         PrintError(result);
  70.         return -1;
  71.     }
  72.     else {
  73.         printf("\nSort completed.\n");
  74.         return 0;
  75.     }
  76. }
  77.