home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / RA-CDK03.ZIP / FILEDEMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-29  |  1.5 KB  |  51 lines

  1. /* File:    FILEDEMO.C  Example of accessing RA file
  2.     Version:        0.3    (23/04/96)
  3.     Author:        Damien Guard
  4.     Copyright:  Envy Technologies, 1996.
  5.     Notes:      This is an example of reading & using RemoteAccess data
  6.                     files using the RACDK.
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <share.h>
  12. #include "ra250c.h"
  13.  
  14. void main()
  15.     {
  16.         unsigned char sFileName[133];        /* Used to build us a filename */
  17.         FILE *fileptr;                            /* Standard file pointer */
  18.         struct CONFIGrecord CONFIGrec;    /* Variable to match CONFIG.RA */
  19.  
  20.         puts("RACDK - Example of accessing RemoteAccess file");
  21.  
  22.         /* Get RA variable */
  23.         strcpy(sFileName,getenv("RA"));
  24.         if (sFileName != NULL) printf("       'RA' environment variable = %s\n",sFileName);
  25.             else
  26.             {
  27.              puts("       'RA' variable not found");
  28.              exit(1);
  29.             };
  30.  
  31.         /* Build complete filename */
  32.         if (sFileName[strlen(sFileName)]=='\\') strcat(sFileName,"CONFIG.RA");
  33.             else strcat(sFileName,"\\CONFIG.RA");
  34.  
  35.         /* Actually open CONFIG.RA */
  36.         printf("       Opening %s\n",sFileName);
  37.         if ((fileptr=_fsopen(sFileName,"rb",SH_DENYNO)) == NULL) {
  38.             printf("       Unable to read %s\n",sFileName);
  39.             fclose(fileptr);
  40.             exit(1);
  41.         };
  42.  
  43.         /* Read in the record and close the file */
  44.         fread(&CONFIGrec,sizeof(CONFIGrec),1,fileptr);
  45.         fclose(fileptr);
  46.  
  47.         /* Convert the Pascal strings and display them */
  48.         Pas2C(CONFIGrec.Sysop);
  49.         Pas2C(CONFIGrec.SystemName);
  50.         printf("       Sysop of %s is %s\n",CONFIGrec.SystemName,CONFIGrec.Sysop);
  51. }