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

Write the term or name from the word bank that best completes the sentence. word bank Anti-federalists, delegates, publius, articles of confederation federal,
find the product of -4x 3 y 2(7xy 4)
The argument "aldo says he saw a whooping crane in a wisconsin marsh; aldo is a highly reliable witness; so, aldo probably did see a whooping crane in a wiscons
0.5 kilograms (kg) is equal to how many ounces? Round your answer to the nearest tenth.
..............................
I need help plzzzzzzzzzz
Put the events of the Cuban Missile Crisis in the correct sequence. Start by marking the first event with 1. Kennedy ordered a blockade of Cuba. The Sovie
A 48.3 mL sample of gas in a cylinder is warmed from 22 C, 87 C to 0.0 C what is the final temperature
Can somebody please help with this (Will mark Brainliest) 30 Points! Algebra 1
how does a pedometer help people reach their fitness goals