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

In an experiment, an unknown gas effuses at one-half the speed of oxygen gas, which has a molar mass of 32 g/mol. which might be the unknown gas?
Consider the equation 5x-2y=3. If possible, find a second linear equation to create a system of equations that has: Exactly one solution Exactly two solutions N
What kinds of figurative language does king use in his speech to describe inequality and the work of the civil rights movement?
Anybody have the answer?
What is the solution
what's the definition
Factor the expression. 24−18y Enter your answers in the boxes to complete the factored expression. ____(___ − 3y)
what properties of life sammy were mentioned
Why does Wiesel mention the story of the St. Louis in his speech "The Perils of Indifference"? A. To show how the United States failed to act on behalf of the
Que historia ocurrió primero la odisea o la iliada