Solved

Why sscanf compile warnings ?

Posted on 2014-02-11
5
700 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
Comment Utility
'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
 

Author Comment

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

This produces exact same warnings as above.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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
 

Author Comment

by:naseeam
Comment Utility
Now I changed the declaration and warnings aren't produced in this file.
0
 

Author Closing Comment

by:naseeam
Comment Utility
Thank you very much!  Quick resolution to the problem.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now