sscanf() question

This is a discussion on sscanf() question within the C Programming forums, part of the General Programming Boards category; I am using sscanf() to parse a line with the date contained within. The semantics of the line is as ...

  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,185
    %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,185
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,746
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    993
    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, 01: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, 09:19 PM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21