Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Why sscanf compile warnings ?

Posted on 2014-02-11
5
Medium Priority
?
855 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

670 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