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

Read the sentence. The judge named the high school’s float most original. What kind of complement is the word in bold?
One of the geographical advantages of early rome
Can someone please help me to solve this: 1/2p+7=3/4p+9
How to the Israelis feel about the Hamas?
Read the sentence. The judge named the high school’s float most original. What kind of complement is the word in bold?
A bungee jumper feels weightless as she falls toward the earth.what accounts for her weightless feeling when she fall freely?1. the force of gravity disappears
May anyone answer this Math question please?
Which product is negative? −2 ⋅ (−7) ⋅ 12 ⋅ (4) 4 ⋅ (−9) ⋅ (−3) ⋅ (−1) −6 ⋅ (−7) ⋅ (−8) ⋅ 0 −3 ⋅ (−2) ⋅ (−4) ⋅ (−7)
Shawn took the bus from Seattle to Portland, a distance of 175miles. If the trip took 3.5 hours, what was the speed of the bus?
$15.60 to $11.70 percent of change