Thread: sscanf() question

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    96

    sscanf() question

    I am using sscanf() to parse a line with the date contained within. The semantics of the line is as follows:

    Code:
    Date: Tues, February 24th 2009
    Now for my code I have:
    Code:
    sscanf(dummy, "Date: %s\n", date);
    But when I execute this instead of obtaining "Tues, February 24th 2009" I am only getting "Tues".
    How would I go about fixing this issue. Thanks!

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    %s stops at a space.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    96
    Thank you once again tabstop A little reading on the ole man page after you pointed that out and I found a solution to the problem. One more quick question is relating to an error I am getting when I compile with the -pedantic open enabled:

    Code:
          	if((pRet = popen("ps -el", "r")) == NULL) {
    	            fprintf(stderr, "ERROR:  File pointer returned a Null value\n");
    	            fprintf(stderr, "ERRNO = %s\n", strerror(errno));
    	            exit(1);
    	 }
    http.c:275: warning: implicit declaration of function ‘popen’
    http.c:275: warning: assignment makes pointer from integer without a cast

    But I have the pret declared as a FILE * to hold the return value from popen?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You need to include the header that contains popen.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    96
    I double checked the manpage and double checked to make sure <stdio.h> is included but I am still receiving the warning

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I am getting when I compile with the -pedantic open enabled:
    popen isn't an ANSI function, so it isn't prototyped when -pedantic is in effect.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    96
    Is there a way then to stop receiving this warning or do I just have to disabled -pedantic and/or ignore?

  8. #8
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    You're apparently targeting POSIX-like systems, so you can tell your implementation that by defining the _XOPEN_SOURCE macro to a suitable value. I'd recommend 600, which means SuSv3. You'd probably want to do this via the command-line, along the lines of:
    Code:
    gcc -Wall -std=c99 -pedantic -D_XOPEN_SOURCE=600
    For the older, but still-has-everything-you-need-probably SuSv2:
    Code:
    gcc -Wall -std=c89 -pedantic -D_XOPEN_SOURCE=500

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. Problem using sscanf fgets and overflow checking
    By jou00jou in forum C Programming
    Replies: 5
    Last Post: 02-18-2008, 06:42 AM
  3. sscanf question
    By Little_Dump in forum C Programming
    Replies: 5
    Last Post: 10-27-2003, 02:16 PM
  4. Dumb Question: What is sscanf?
    By KingZoolerius66 in forum C Programming
    Replies: 3
    Last Post: 10-04-2003, 08:19 PM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM