sscanf error for unsign int type.

L

loudking

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!
 
S

santosh

loudking said:
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.
 
J

Joachim Schmitz

loudking said:
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
 
J

Joachim Schmitz

Joachim Schmitz said:
loudking said:
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
 
M

Martin Ambuhl

loudking said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top