home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / vc / pro3 / parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-10  |  1.7 KB  |  57 lines

  1. ===========================================================================
  2.  BBS: The Abacus * HST/DS * Potterville, MI
  3. Date: 06-06-93 (19:12)             Number: 198
  4. From: DAVID JOHNSON                Refer#: NONE
  5.   To: ROLLIN WHITE                  Recvd: NO  
  6. Subj: Parsing a text file            Conf: (36) C Language
  7. ---------------------------------------------------------------------------
  8. RW>        Does anyone have code(or even a reccommended approach) fo
  9. RW>reading in a text file that will serve as a program's
  10. RW>configuration file?  Specifically, keywords like:
  11.  
  12. RW>USER=John Doe
  13. /* Author: David W. Johnson
  14.  * Code is placed in the Public Domain
  15.  */
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <conio.h>
  19. #define MAXTOKENS 4
  20. main()
  21. {
  22. int counter,buffcount;
  23. char buffer[2][100]={{"SUBJECT=This is an example"},{";This is a comment"}}; cha
  24. r *p; char tokens[MAXTOKENS][80]={ {"USER"},{"ADDRESS"},{"SUBJECT"},{"STREET"}};
  25.  clrscr(); for(buffcount=0;buffcount<2;buffcount++)
  26.  {
  27.  if(buffer[buffcount][0] ==';')
  28.    {
  29.    printf("Comment: %s",buffer[buffcount]);
  30.    }
  31.  else
  32.  {
  33.  p=strtok(buffer[buffcount],"=");
  34.  for(counter=0;counter<MAXTOKENS;counter++)
  35.    {
  36.    if (strcmp(tokens[counter],p)==0)
  37.        {
  38.        p=strtok(NULL,"=");
  39.        printf("%s:%s\n",tokens[counter],p);
  40.        }
  41.    }
  42.  }
  43.   }
  44. return 0;
  45. }
  46.  
  47. ===
  48.  * TLX v2.00 * Anyone with a clear conscience has a foggy memory.
  49.  
  50.  * DeLuxe2/386 1.25 #483 *
  51.  
  52. --- DB 1.53/002503
  53.  * Origin: Programmer's Guild BBS - Hamilton, Ont. (416)525-7616 (1:244/117)
  54. SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
  55. SEEN-BY: 153/752 154/40 77 157/110 159/100 125 430 575 950 203/23 209/209
  56. SEEN-BY: 261/1023 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20
  57.