COMPILER IGNORING ++

HAY PROGRAMMERS,

I HAVE A PROBLEM WITH VISUAL STUDIO 2013 C++ CODE.

I HAVE THIS CODE:
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h>
__int8 a;
__int8 b=0;
void main(void)
{
	for (int i=0; i < 6; i++)
	{
		scanf("%ld", &a);
		printf("b is equal to: %ld", b);
		b++;
	}
}


THIS CODE COMPILES WITHOUT ERRORS.
WHAT THIS DOES IS THAT IT CREATES INTEGER VARIABLE WHICH IS 8 BITS LONG, ASKS USER TO ENTER A NUMBER IN THAT VARIABLE SIX TIMES. (NO POINT OF DOING THIS SIX TIMES, BUT IGNORE THIS FOR NOW).
ALSO, IT HAS A 8 BIT INTEGER VARIABLE WHICH COUNTS THE NUMBER OF TIMES USER ENTERED A NUMBER.
BUT THE PROBLEM IS THAT FOR SOME REASON COMPILER IGNORES b++; LINE.

OUTPUT FROM THIS CODE IS:
1
2
3
4
5
6
b is equal to: 0
b is equal to: 0
b is equal to: 0
b is equal to: 0
b is equal to: 0
b is equal to: 0


WHY?
I TYPED b++; AND IT SHOULD BE GRATER IN EVERY ITTERATION.

WHAT IS ODD IS THAT IF I REMOVE scanf FUNCTION OUTPUT IS:
1
2
3
4
5
6
b is equal to: 0
b is equal to: 1
b is equal to: 2
b is equal to: 3
b is equal to: 4
b is equal to: 5

ALSO, IF I DECLARE b AS __int16 AND NOT __int8 IT WORKS CORRECT WITH OR WITHOUT scanf.
1
2
3
4
5
6
b is equal to: 0
b is equal to: 1
b is equal to: 2
b is equal to: 3
b is equal to: 4
b is equal to: 5


WHY b CAN NOT BE DECLARED AS __int8 IN THIS LOOP?
OR WHY IS scanf CAUSEING COMPILER TO IGNORE b++ COMMAND?

THANX
Last edited on
You're lucky that's not blowing up.

In line 8, you're telling scanf that a is a long int (%ld) which is typically 32 bits. scanf will obligingly store 32 bits into a (an 8 bit number) and whatever follows it on the stack.
THANX MAN!
THIS WAS THE PROBLEM.
I THOUGHTH THAT l IS PREFIX FOR SHORTEST VARIABLES (l LIKE LOWEST (SIZE) OR SOMETHING LIKE THIS).


I USE %c NOW.
IT STILL DID NOT WORK CORRECT AT THE BEGGINING BECAUSE IT WAS SKIPPING SCANF IN EVERY SECOND ITERATION, BUT, I FOUND OUT THAT I NEED TO FLUSH BUFFER, AND NOW IT WORKS GREAT.

I WOULD NEWER FIGURE IT OUT WITHOUT YOU. I REALLY THOUGHT THAT ld STANDS FOR LOWEST INT, THAT IS INT WITH LOWEST (SMALLEST) SIZE.
THANX!
BYE
I'm deaf... Megaphone not needed...
NO, I AM JUST USING STANDARD COMMANDS, THERE IS NO COMMAND NAMED "MEGAPHONE" FOUND IN THE FILE.
Here, let me translate what chouhaizi said:
"Stop yelling!"
I AM NOT YELLING. ;)
I AM WERY CALM AND HAPPY RIGHT NOW. :P
I WOULD NEVER YELL ON YOU. ;) ☺☺
All Caps = Yelling on the Internet.
And why would you ever yell on somebody?

Good day...
Just speak normally or else your next thread that you will probably post in 60 seconds will not get any help.
Topic archived. No new replies allowed.