fredhead3968 fredhead3968
  • 21-12-2017
  • Computers and Technology
contestada

Write a program to test the difference between %d and %i conversion

Respuesta :

tonb
tonb tonb
  • 21-12-2017
void test(char *s)
{
  int i, d;
  sscanf(s, "%i", &i);
  printf("%s converts to %i using %%i\n", s, i);
  sscanf(s, "%d", &d);
  printf("%s converts to %d using %%d\n", s, d);
}

int main()
{
  test("123");
  test("0x123");
  return 0;
}

outputs:
123 converts to 123 using %i
123 converts to 123 using %d
0x123 converts to 291 using %i
0x123 converts to 0 using %d

As you can see, %i is capable of parsing hexadecimal, whereas %d is not. For printf they're the same.
Answer Link

Otras preguntas

Most people seem to have a preference for either cats or dogs. In my opinion, dogs are a lot more fun to own. Dogs are interested in what their owners do, ____
Rhonda breaks her arm while skateboarding. She tells her boss that she slipped and fell while working. What type of financial crime is she trying to commit? A.
What is the purpose of contraceptives?
Plz help me with this. Thank you!
The side lengths of a right triangle are 10, 26, and 24. Which is the hypotenuse?
hey! i’ll give brainliest please help.
Hey yall this question is for the edge students, my adhd is getting the best of me so I have to ask. when you do a cumulative exam and if you get a bad grade do
Write a 350 essay about Hiram Revels political life.
HELLPPPPPP PLEASE I'LL GIVE BRAINLEST
what is this poem aboutWhat impressions do you have from your reading about how Aztecs responded to childbirth, the importance of poetry for the Nahuatl (pre-Az