Thread: someone help? strtol?

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

    someone help? strtol?

    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??

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Is there really a need for a double post???
    http://cboard.cprogramming.com/showthread.php?t=57454
    Woop?

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    5
    well i couldn't change the thread name or delete the thread so just created another one

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Lemme check with the judges.
    Wait, No, the judges are saying thats not a good reason for a double post. They are also giving the signal for the check the rule book http://cboard.cprogramming.com/annou...ouncementid=51
    Woop?

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    5
    ookaaay...i'm just a newbie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strtol() / malloc
    By sniperwire in forum C Programming
    Replies: 3
    Last Post: 11-02-2008, 09:01 PM
  2. strtol
    By kiz in forum C Programming
    Replies: 9
    Last Post: 10-21-2007, 11:42 AM
  3. Parse line using strtol
    By mike_g in forum C++ Programming
    Replies: 3
    Last Post: 10-05-2007, 09:47 AM
  4. strtol() is the only way?
    By Mario F. in forum C++ Programming
    Replies: 5
    Last Post: 06-07-2006, 02:32 PM
  5. strtol with floating point
    By Laserve in forum C Programming
    Replies: 3
    Last Post: 07-26-2004, 06:02 AM