Thread: strptime Warning

  1. #1
    Not just a squid...
    Join Date
    Sep 2004
    Posts
    25

    strptime Warning

    I'm trying to use strptime to convert a string to a time structure, but I'm getting this warning from gcc:
    Code:
    main.c:198: warning: comparison between pointer and integer
    This is the line that is causing the problem:
    Code:
    if (strptime (timeString, "%Y-%m-%d", &dStart) == NULL)
    Which should work according to information that I've found online, and the strptime man page. Anyone have any idea what's wrong?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Are you including time.h?
    If so, can you show how timeString and dStart are declared?
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Does your program link? strptime is not a standard function, so you will need to (a) make sure it exists on your machine (b) with the signature you think it has (c) and with the prototype visible from the headers.

  4. #4
    Not just a squid...
    Join Date
    Sep 2004
    Posts
    25
    Quote Originally Posted by bithub View Post
    Are you including time.h?
    If so, can you show how timeString and dStart are declared?
    I am including time.h
    Here are my declarations:
    Code:
    struct tm dStart, dEnd, cDate;
    
    char *timeString;
    I have confirmed that timeString contains "2003-09-31"

  5. #5
    Not just a squid...
    Join Date
    Sep 2004
    Posts
    25
    Quote Originally Posted by tabstop View Post
    Does your program link? strptime is not a standard function, so you will need to (a) make sure it exists on your machine (b) with the signature you think it has (c) and with the prototype visible from the headers.
    It appears to be linking fine. I checked for strptime in time.h and it is in there with the same declaration.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    It should work if you put:
    #define __USE_XOPEN
    on the line right before you include time.h.
    bit∙hub [bit-huhb] n. A source and destination for information.

  7. #7
    Not just a squid...
    Join Date
    Sep 2004
    Posts
    25
    Quote Originally Posted by bithub View Post
    It should work if you put:
    #define __USE_XOPEN
    on the line right before you include time.h.
    So it does, thanks.

    As an aside, I had already tried this using "#define _XOPEN_SOURCE" which was specified in the man page on my system, but it didn't work like yours did. Can you explain this at all? I'm not familiar with requiring special defines before includes, or why it doesn't work if I try to define it on a different line (which I just checked).

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    It probably doesn't work if you define it on a different line because some other header clears it out before time.h is included.

    _XOPEN_SOURCE would probably work if time.h is the first header you included. For example, include time.h before you include stdio.h.

    Unfortunately, the preprocessor macros in glibc are a sloppy mess. When you attempt to use non-standard functions like this, it can be a real pain.
    bit∙hub [bit-huhb] n. A source and destination for information.

  9. #9
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    What OS and platform are you on?
    Post the code here if it ain't too big.

    If on Linux check out the "Notes" section of the strptime() manpage which explains why that directive is needed.
    Last edited by itCbitC; 10-05-2009 at 08:40 PM.

  10. #10
    Not just a squid...
    Join Date
    Sep 2004
    Posts
    25
    Quote Originally Posted by itCbitC View Post
    What OS and platform are you on?
    Post the code here if it ain't too big.

    If on Linux check out the "Notes" section of the strptime() manpage which explains why that directive is needed.
    I'm on Ubuntu 9.04. The code is pretty big, but the previous suggestion worked.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-16-2009, 06:00 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM