Using `scanf` for `unsigned long long int` with MinGW.

#include <stdio.h>
int main (void) {
int t;
int y, z, a, b;
scanf ("%i", &t);
for (t; t > 0 :wink: {
scanf ("%i", &y);
–t;
}
return 0;
}

The above code works fine and the program ends after I input t integers. But I want the program to allow me to enter larger positive integers, so I modified the code to this :

#include <stdio.h>
int main (void) {
   unsigned long long int t;
   int y, z, a, b;
   scanf ("%llu", &t);
   for (t; t > 0 ;) {
      scanf ("%i", &y);
      --t;
   } 
   return 0;
}

According to the code, if I enter 5, it should then allo me to enter 5 more integers, but instead I can enter as amny integers as I want. It seems that the for loop is not ending. Don’t know why.

Found the answer at Stackoverflow. For interested folks : link text
Checkout the first answer.

1 Like