79155799

Date: 2024-11-04 14:28:00
Score: 1
Natty:
Report link

Why? Where do these 1845,1846,821 come from?

%5c in scanf reads exactly 5 characters from the input and stores them as characters in a char array without adding a null terminator. But the code you provided currently is sing %5c with an int variable (int w) may causes scanf to interpret the w variable’s memory incorrectly. So it causes unpredictable results.

If you want to use %5c properly, you can declare w as a char array of sufficient size instead of int variable.

int y = 0;
char w[6] = {0};

scanf("%d %5c", &y, w);
printf("%d, %s\n", y, w);
Reasons:
  • Blacklisted phrase (0.5): Why?
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Why
  • Low reputation (0.5):
Posted by: Shelton Liu