Solved

Why sscanf compile warnings ?

Posted on 2014-02-11
5
753 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

840 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