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

Why did workers want to engage in collective bargaining when Negroponte with an employer
What is the midpoint of PQ
You buy 2 concert tickets. Each ticket costs $45.50. The shipping cost for the whole order is $12.00. Which equation represents how to calculate the total cost
Tenderness of a tooth can best be determined by
What is the expected colorimetric result from the negative control in your assay?
could someone please help me
To be sure your priorities are straight before beginning team sports, you should evaluate your attitude towards______________? Question 1 options: Teamwork Winn
Which term refers to the level of local government directly below the state government?
The primary, natural habitat of a pathogen where it continues to exist is called the
True or false the us has always had two parties dating back to the federalists and anti federalists