home *** CD-ROM | disk | FTP | other *** search
- ===========================================================================
- BBS: The Abacus * HST/DS * Potterville, MI
- Date: 06-06-93 (19:12) Number: 198
- From: DAVID JOHNSON Refer#: NONE
- To: ROLLIN WHITE Recvd: NO
- Subj: Parsing a text file Conf: (36) C Language
- ---------------------------------------------------------------------------
- RW> Does anyone have code(or even a reccommended approach) fo
- RW>reading in a text file that will serve as a program's
- RW>configuration file? Specifically, keywords like:
-
- RW>USER=John Doe
- /* Author: David W. Johnson
- * Code is placed in the Public Domain
- */
- #include <stdio.h>
- #include <string.h>
- #include <conio.h>
- #define MAXTOKENS 4
- main()
- {
- int counter,buffcount;
- char buffer[2][100]={{"SUBJECT=This is an example"},{";This is a comment"}}; cha
- r *p; char tokens[MAXTOKENS][80]={ {"USER"},{"ADDRESS"},{"SUBJECT"},{"STREET"}};
- clrscr(); for(buffcount=0;buffcount<2;buffcount++)
- {
- if(buffer[buffcount][0] ==';')
- {
- printf("Comment: %s",buffer[buffcount]);
- }
- else
- {
- p=strtok(buffer[buffcount],"=");
- for(counter=0;counter<MAXTOKENS;counter++)
- {
- if (strcmp(tokens[counter],p)==0)
- {
- p=strtok(NULL,"=");
- printf("%s:%s\n",tokens[counter],p);
- }
- }
- }
- }
- return 0;
- }
-
- ===
- * TLX v2.00 * Anyone with a clear conscience has a foggy memory.
-
- * DeLuxe2/386 1.25 #483 *
-
- --- DB 1.53/002503
- * Origin: Programmer's Guild BBS - Hamilton, Ont. (416)525-7616 (1:244/117)
- SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
- SEEN-BY: 153/752 154/40 77 157/110 159/100 125 430 575 950 203/23 209/209
- SEEN-BY: 261/1023 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20
-