This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

sscanf() does not work correctly

When I use following statement in the code which runs on ARM9, it does not correctly parse the IP address.
I am using standard function for sscanf().

main()
{ unsigned char ip[16];
sscanf("255.1.1.1","%u.%u.%u.%u",&ip[0],&ip[1],&ip[2],&ip[3]);
}

thanks in advance,
-pjs

Parents
  • "When I try to run same program pc with intel processor, it works fine."

    Quite by accident because the PC is little-endian and tolerates unaligned integer accesses. scanf()-ing an unsigned integer into ip[0] overwrites ip[1] and quite likely ip[2] and ip[3] with zero. Try it on a big-endian architecture or one requires aligned accesses, but wear a bib when you do.

Reply
  • "When I try to run same program pc with intel processor, it works fine."

    Quite by accident because the PC is little-endian and tolerates unaligned integer accesses. scanf()-ing an unsigned integer into ip[0] overwrites ip[1] and quite likely ip[2] and ip[3] with zero. Try it on a big-endian architecture or one requires aligned accesses, but wear a bib when you do.

Children
No data