home *** CD-ROM | disk | FTP | other *** search
/ Rat's Nest 1 / ratsnest1.iso / prgmming / c / readuser.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-08  |  1.7 KB  |  73 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <io.h>
  5. #include <share.h>
  6. #include <fcntl.h>
  7.  
  8. #include "C:\IBMCPP\BBSDef.h"
  9.  
  10. void          LoadConfig(unsigned short NodeNum);
  11. void          ItoaPad(unsigned short Value, char *String, unsigned short Pad, char PadChar, unsigned char Radix);
  12. void          ToUpper(unsigned char *String);
  13. unsigned char GetFileNameStartPos(unsigned char *Path);
  14.  
  15. struct GConfigRecord  GConfig;
  16. struct NConfigRecord  NConfig;
  17.  
  18. #define  NODETECTCONFS
  19. #include "C:\IBMCPP\BBS\LOADCNF.C"
  20.  
  21. unsigned int main(void)
  22. {
  23.   unsigned char FileName[128];
  24.     signed int  Handle;
  25.  
  26.   struct UserRecord User;
  27.  
  28.   #ifdef __IBMC__
  29.   setvbuf(stdout, NULL, _IONBF, BUFSIZ);
  30.   #endif
  31.  
  32.   LoadConfig(1); /* Load config for node 1 */
  33.  
  34.   strcpy(FileName, NConfig.MainDir);
  35.   strcat(FileName, "USERS.BAK");        /* Importante! */
  36.  
  37.   if ((Handle=sopen(FileName, O_BINARY | O_RDONLY, SH_DENYNONE))==-1) {
  38.     puts("* Failed to open users.dat");
  39.     return EXIT_FILEERROR;
  40.   }
  41.  
  42.   while (read(Handle, &User, sizeof(User))==sizeof(User)) {
  43.  
  44.     /* All your own stuff goes here! */
  45.  
  46.     if (User.Killed) continue; /* Do not count killed users */
  47.     printf("User: %s\n", User.Name); /* Example */
  48.  
  49.  
  50.   } close(Handle);
  51.  
  52.   puts("* Done!");
  53.   return EXIT_NORMAL;
  54. }
  55.  
  56.  
  57. void ItoaPad(unsigned short Value, char *String, unsigned short Pad, char PadChar, unsigned char Radix)
  58. {
  59.   unsigned char  Temp[10];
  60.   unsigned short i;
  61.  
  62.   String[0]=0; /* Initialize String */
  63.  
  64.   itoa(Value,Temp,Radix);
  65.   if (strlen(Temp)<Pad) {
  66.     for(i=0;i!=(Pad-strlen(Temp));++i) {
  67.       String[i]=PadChar;
  68.     } String[i]=0;
  69.   }
  70.   strcat(String,Temp);
  71.   return;
  72. }
  73.