Token parsing
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Token parsing

  1. #1
    Join Date
    Oct 2004
    Posts
    32

    Token parsing

    Ok.

    This is what I have:

    Code:
    FILE* DB_handle = fopen (dbfile, "rb");
    
    if (DB_handle!=NULL) {
    char *read;
    char *id;
    struct _stat buf;
    char token[] = "";
      
    _fstat(_fileno(DB_handle), &buf);
    read = (CHAR*)malloc(buf.st_size);
    
    fread(read,sizeof(CHAR),1,DB_handle);
    
    id = strtok(read,token);
    
     while (id != NULL) {
     fputs("<td>",site_handle);
     fputs(id,site_handle);
     fputs("</td>",site_handle);
    
     id = strtok(NULL,token);
    
     }



    Ok, so what I'm trying to do is read a file into the memory as a CHAR, then scan that for my token, then every time it comes up, write it to an html table.(site_handle is the .html file)

    It all compiles, however it's only getting 1 token, and i think I may be loading it into the CHAR wrong.

  2. #2
    Join Date
    Mar 2002
    Posts
    350

    Re: Token parsing

    Code:
    fread(read,sizeof(CHAR),buf.st_size,DB_handle);

  3. #3
    Join Date
    Oct 2004
    Posts
    32

    Re: Token parsing

    Hmm.

    Ok now I have:


    Code:
    FILE* DB_handle = fopen (dbfile, "rb");
    
    if (DB_handle!=NULL) {
    char *read;
    char *id;
    struct _stat buf;
    char token[] = "";
      
    _fstat(_fileno(DB_handle), &buf);
    read = (CHAR*)malloc(buf.st_size);
    
    fread(read,sizeof(CHAR),buf.st_size,DB_handle);
    
    id = strtok(read,token);
    
     while (id != NULL) {
     fputs("<td>",site_handle);
     fputs(id,site_handle);
     fputs("</td>",site_handle);
    
     id = strtok(NULL,token);
    
     }
    And it just retrieves just the 1st line of data in the file, which doesnt have the token in/near it at all.

  4. #4
    Join Date
    Mar 2002
    Posts
    350

    Re: Token parsing

    check the return value of fread, it should be the same as buf.st_size

  5. #5
    Join Date
    Oct 2004
    Posts
    32

    Re: Token parsing

    it is the same

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center