Thread: Help Meeeeee!!!!!!

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    5

    Question Help Anyone?

    HI,

    I need to tokenize the data from a file named books.dat to load into the system...anyone got any clues?! some help would be greatly appreciated

    Book data file format:
    <id>:<title>:<author>:<year>:<price>:<count>

    Example:
    1:A Book on C:A. Kelly:1997:89.95:7
    2:Java Software Solutions:J. Lewis:2000:79.95:2
    etc...

    n so far my code is looking like this...

    Code:
    #include "bookstore2.h"
    
    #define NUM_ARGUMENTS 3
    #define MAXSTRING 100
    #define ARRAYSTR 100
    
    int main(int argc, char **argv)
    {
       int tempID, tempYear, tempPrice, tempCount;
       char tempString[MAXSTRING], DELIMITER[] = ":";
       char* ptr;
       char* tempArray[ARRAYSTR];
       char* booksFile;
       char* salesFile;
       BookListType booklist;
       FILE* fp;
    
       /*when arguments are wrong*/
       if(argc != NUM_ARGUMENTS)
       {
          fprintf(stderr, "Argument error\n");
          return EXIT_FAILURE;
       }
       else
       {
          /*check what arguments were passed*/
          if((argv[1] == "books.dat") && (argv[2] == "sales.dat"))
          {
             loadData(&booklist, booksFile, salesFile);
             fp = fopen("books.dat", "r");
    
             /*read data from books.dat*/
             ptr = strtok(tempString, DELIMITER);
             tempID = strtol(ptr, &tempArray, 10);
             newBook->id = tempID;
          
             ptr = strtok(NULL, DELIMITER);
             strcpy(newBook->title, ptr);
    
             ptr = strtok(NULL, DELIMITER);
             strcpy(newBook->author, ptr);
    
             ptr = strtok(tempString, DELIMITER);
             tempYear = strtol(ptr, &tempArray, 10);
             newBook->year = tempYear;
    
             ptr = strtok(tempString, DELIMITER);
             tempPrice = strtol(ptr, &tempArray, 10);
             newBook->price = tempPrice;
    
             ptr = strtok(tempString, DELIMITER);
             tempCount = strtol(ptr, &tempArray, 10);
             newBook->count = tempCount;
    
             if(fp == NULL)
             {
                printf("Can't open file\n");
                exit(1);
             }
             fclose(fp);
          }
       }
    
       return EXIT_SUCCESS;
    }
    .....with these errors when compiled:

    bookstore2.c: In function `main':
    bookstore2.c:41: warning: passing arg 2 of `strtol' from incompatible pointer type
    bookstore2.c:42: error: `newBook' undeclared (first use in this function)
    bookstore2.c:42: error: (Each undeclared identifier is reported only once
    bookstore2.c:42: error: for each function it appears in.)
    bookstore2.c:51: warning: passing arg 2 of `strtol' from incompatible pointer type
    bookstore2.c:55: warning: passing arg 2 of `strtol' from incompatible pointer type
    bookstore2.c:59: warning: passing arg 2 of `strtol' from incompatible pointer type


    anyone know how to fix??
    Last edited by salsa; 10-03-2004 at 04:45 AM.

  2. #2

  3. #3
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > n so far my code is looking like this...
    You have a point; it's in sore need of some code tags.

    > anyone know how to fix??
    [code]stuff[/code]


    Note:
    Do not add code tags to what you have - instead, copy your code over from the code editing window again, overwriting what's currently in your post, then apply the code tags.

    Also, try a more descriptive subject line next time. Your subject line currently sounds like a 10 year old yelling to mommy.
    Last edited by Shadow; 10-03-2004 at 03:57 AM.
    The world is waiting. I must leave you now.

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    The strtol() issue is the least of your troubles. Is it possible you could attempt some simpler programs before tackling this one? Anyway, this is as good a place as any to start:
    Quote Originally Posted by salsa
    Code:
          if((argv[1] == "books.dat") && (argv[2] == "sales.dat"))
    http://computer.howstuffworks.com/c35.htm (The other chapters are also worth a read.)

Popular pages Recent additions subscribe to a feed