Please take a look at the following to see the difference between pre and post increment operators:
Code:
#include <stdio.h>
int main(void)
{
int x = 10;
int y = 0;
// Pre-increment
printf("%s\n", "Increment x before assigning the value to y");
printf("Original x == %d\n", x);
y = ++x;
printf("x == %d\n", x);
printf("y == %d\n\n", y);
x = 10;
// Post-increment
printf("%s\n", "Increment x after assigning the original value to y");
printf("Original x == %d\n", x);
y = x++;
printf("x == %d\n", x);
printf("y == %d\n", y);
return 0;
}
And the result:
Code:
$./foo
Increment x before assigning the value to y
Original x == 10
x == 11
y == 11
Increment x after assigning the original value to y
Original x == 10
x == 11
y == 10
Also, NEVER use gets()! gets() has been depreciated in C99 and removed completely from the C11 C Standard. Please use fgets() instead!