Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > sscanf error for unsign int type.

Reply
Thread Tools

sscanf error for unsign int type.

 
 
loudking
Guest
Posts: n/a
 
      12-04-2007
Hi all,

I encountered a problem for sscanf from a string for unsigned int
type. The warning message is

main.c: In function `main':
main.c:171: warning: unsigned int format, different type arg (arg 3)

================================================== =======
if (begin_scn) {
u_short scn_major;
u_int scn_minor;

if (sscanf(begin_scn, "%4x%*1[.:,]%8x", &scn_major,
&scn_minor)
!= 2) {
fprintf(stderr, "Wrong SCN format: %s\n", begin_scn);
return 1;
}
}
================================================== =======

Would anybody tell me how to solve this problem?

Thanks in advance!
 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      12-04-2007
loudking wrote:

> Hi all,
>
> I encountered a problem for sscanf from a string for unsigned int
> type. The warning message is
>
> main.c: In function `main':
> main.c:171: warning: unsigned int format, different type arg (arg 3)
>
> ================================================== =======
> if (begin_scn) {
> u_short scn_major;
> u_int scn_minor;
>
> if (sscanf(begin_scn, "%4x%*1[.:,]%8x", &scn_major,
> &scn_minor)
> != 2) {
> fprintf(stderr, "Wrong SCN format: %s\n", begin_scn);
> return 1;
> }
> }
> ================================================== =======
>
> Would anybody tell me how to solve this problem?
>
> Thanks in advance!


Use the 'u' format specifier for unsigned int and 'hu' for unsigned
short.

 
Reply With Quote
 
 
 
 
Joachim Schmitz
Guest
Posts: n/a
 
      12-04-2007
"loudking" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> Hi all,
>
> I encountered a problem for sscanf from a string for unsigned int
> type. The warning message is
>
> main.c: In function `main':
> main.c:171: warning: unsigned int format, different type arg (arg 3)
>
> ================================================== =======
> if (begin_scn) {
> u_short scn_major;
> u_int scn_minor;
>
> if (sscanf(begin_scn, "%4x%*1[.:,]%8x", &scn_major,
> &scn_minor)
> != 2) {
> fprintf(stderr, "Wrong SCN format: %s\n", begin_scn);
> return 1;
> }
> }
> ================================================== =======
>
> Would anybody tell me how to solve this problem?
>
> Thanks in advance!

Apparently ip complains about scn_major not being an insigned int, while
scanf'c %X expects it to be just that. Try %hx for unsigned short.

Bye, Jojo


 
Reply With Quote
 
Joachim Schmitz
Guest
Posts: n/a
 
      12-04-2007
"Joachim Schmitz" <(E-Mail Removed)> schrieb im Newsbeitrag
news:fj3pkt$ab4$(E-Mail Removed)...
> "loudking" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:(E-Mail Removed)...
>> Hi all,
>>
>> I encountered a problem for sscanf from a string for unsigned int
>> type. The warning message is
>>
>> main.c: In function `main':
>> main.c:171: warning: unsigned int format, different type arg (arg 3)
>>
>> ================================================== =======
>> if (begin_scn) {
>> u_short scn_major;
>> u_int scn_minor;
>>
>> if (sscanf(begin_scn, "%4x%*1[.:,]%8x", &scn_major,
>> &scn_minor)
>> != 2) {
>> fprintf(stderr, "Wrong SCN format: %s\n", begin_scn);
>> return 1;
>> }
>> }
>> ================================================== =======
>>
>> Would anybody tell me how to solve this problem?
>>
>> Thanks in advance!

> Apparently ip complains about scn_major not being an insigned int, while
> scanf'c %X expects it to be just that. Try %hx for unsigned short.

Guess I'd better spellcheck _before_ sending...
"Apparently it complains about scn_major not being an unsigned int, while
scanf's %x expects it to be just that."

Bye, Jojo


 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      12-04-2007
loudking wrote:

> main.c: In function `main':
> main.c:171: warning: unsigned int format, different type arg (arg 3)


> if (begin_scn) {
> u_short scn_major;
> u_int scn_minor;
>
> if (sscanf(begin_scn, "%4x%*1[.:,]%8x", &scn_major,
> &scn_minor)
> != 2) {
> fprintf(stderr, "Wrong SCN format: %s\n", begin_scn);
> return 1;
> }
> }


> Would anybody tell me how to solve this problem?


Note the format specifier below:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
char begin_scn[] = "00ab.721a00ac";
unsigned short scn_major;
unsigned int scn_minor;

if (sscanf(begin_scn, "%4hx%*1[.:,]%8x", &scn_major, &scn_minor)
!= 2) {
fprintf(stderr, "Wrong SCN format: %s\n", begin_scn);
return EXIT_FAILURE;
}
printf("begin_scn is \"%s\"\n"
"scn_major = %#x\n"
"scn_minor = %#x\n", begin_scn, scn_major, scn_minor);
return 0;
}

[output]
begin_scn is "00ab.721a00ac"
scn_major = 0xab
scn_minor = 0x721a00ac

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling error key(int,int) in ATM2.ATMPanel cannot be applied to (int) powerhouse04 Java 1 12-16-2007 06:03 PM
Difference between int i, j; and int i; int j; arun C Programming 8 07-31-2006 05:11 AM
int a[10]; int* p=(int*)((&a)+1); But why p isn't equal to ((&a)+1)? aling C++ 8 10-20-2005 02:42 PM
int main(int argc, char *argv[] ) vs int main(int argc, char **argv ) Hal Styli C Programming 14 01-20-2004 10:00 PM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments