Solved

Why sscanf compile warnings ?

Posted on 2014-02-11
5
736 Views
Last Modified: 2014-02-11
virtual const char * getDataAddress           (void)                         
    { 
      /* pointer to date format is  HH:MM::SS  */
      const char * iso8601_time_buf = getAddress();
      
      if ( (iso8601_time_buf != NULL) && ( (std::strlen(iso8601_time_buf)) == (ISO8601_TIME_BUF_LEN - 1) ) )
      {
				unsigned short hours;
				unsigned short minutes;
				unsigned short seconds;
				
				sscanf(iso8601_time_buf, "%d:%d:%d", &hours, &minutes, &seconds);
				
		    // minutes since midnight
        _rawValue = hours * 60 + seconds;
          
      }
      else
        _rawValue = 0;
        
      return ((const char *)&_rawValue);
    };

..\..\Version2\Parameters\ParameterTimeMP.h(65): warning:  #181-D: argument is incompatible with corresponding format string conversion
                                sscanf(iso8601_time_buf, "%d:%d:%d", &hours, &minutes, &seconds);
..\..\Version2\Parameters\ParameterTimeMP.h(65): warning:  #181-D: argument is incompatible with corresponding format string conversion
                                sscanf(iso8601_time_buf, "%d:%d:%d", &hours, &minutes, &seconds);
..\..\Version2\Parameters\ParameterTimeMP.h(65): warning:  #181-D: argument is incompatible with corresponding format string conversion
                                sscanf(iso8601_time_buf, "%d:%d:%d", &hours, &minutes, &seconds);

Open in new window


What is the reasons for warnings ?
0
Comment
Question by:naseeam
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 39850605
'sscanf()' seems to lack type specifiers for 'unsigned short' (and needs to be more picky about that than 'sprintf()' - try

virtual const char * getDataAddress           (void)                         
    { 
      /* pointer to date format is  HH:MM::SS  */
      const char * iso8601_time_buf = getAddress();
      
      if ( (iso8601_time_buf != NULL) && ( (std::strlen(iso8601_time_buf)) == (ISO8601_TIME_BUF_LEN - 1) ) )
      {
				unsigned int hours;
				unsigned int minutes;
				unsigned int seconds;
				
				sscanf(iso8601_time_buf, "%u:%u:%u", &hours, &minutes, &seconds);
				
		    // minutes since midnight
        _rawValue = hours * 60 + seconds;
          
      }
      else
        _rawValue = 0;
        
      return ((const char *)&_rawValue);
    };

Open in new window


instead.
0
 
LVL 1

Author Comment

by:naseeam
ID: 39850628
>> sscanf(iso8601_time_buf, "%u:%u:%u", &hours, &minutes, &seconds);

This produces exact same warnings as above.
0
 
LVL 86

Expert Comment

by:jkr
ID: 39850654
Have you also changed the value's declaration from 'unsigned short' to 'unsigned int'? The latter (short instead of int) seems to have been the main reason for the warnings. 'u' just denotes 'unsigned'.
0
 
LVL 1

Author Comment

by:naseeam
ID: 39850721
Now I changed the declaration and warnings aren't produced in this file.
0
 
LVL 1

Author Closing Comment

by:naseeam
ID: 39850726
Thank you very much!  Quick resolution to the problem.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question