Solved

Why sscanf compile warnings ?

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

728 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