Here a piece of code:
long long someNumber;
...
do{
...
scanf("%d", &someNumber);
...
} while (...);
fprintf(someFile, "%d", someNumber);
I need to read a number which contains 11 chars. I've tried all scanf() and fprintf() modes like "%Ld", "%lld", etc. but the result always is not what I printed. But it is not even my problem. Then VS gives me an error when I'm typing ENTER: "Unhandled exception at 0x54A0F365 (msvcr120d.dll) in proj2.2.exe: 0xC0000005: Access violation reading location 0x0000000A." It opens "output.c" and refers to the line:
while ((ch = *format++) != _T('\0') && charsout >= 0) {
Actually, it prints a wrong number into file. But an error doesn't allow to continue the work of the program. What is happenening ? Where is my mistake ?
The format for reading a long long
is "%lld"
. Use
scanf("%lld", &someNumber);
Use the same format for writing it out too.
fprintf(someFile, "%lld", someNumber);
Per the docs, the correct data type specifier for type long long
is ll
. You need to use this both with scanf()
and with printf()
:
long long someNumber;
scanf("%lld", &someNumber);
printf("%lld", someNumber);
If fixing the field specifier as above does not resolve your issue, then you have an additional problem somewhere else in your code.
User contributions licensed under CC BY-SA 3.0