Hello.
I've been doing a small application that will go (using only unsigned integer values) from 0 to 4026531840 and print them out.
My code is next:

#include <stdio.h>
#include <inttypes.h>
int main(void){
uint64_t cnt;
for(cnt=0;cnt<=4026531840;cnt++){
printf("%d\n",cnt);
}
}

The only problem that i have is the last numbers are negative (the really last one is -268435456).
I also tried using:

#include <stdio.h>
int main(void){
unsigned long long int cnt;
for(cnt=0;cnt<=4026531840;cnt++){
printf("%d\n",cnt);
}
}

but the problem persists.
I'm using gcc:
Target: x86_64-linux-gnu
gcc version 4.6.1 (Debian 4.6.1-4)
on my linux machine:
Linux mysql 3.0.0-1-amd64 #1 SMP Sat Aug 27 16:21:11 UTC 2011 x86_64 GNU/Linux
Any ideas?

You're printing the value with %d, which is limited to signed int. The C99 specifier for unsigned long long is %llu:

#include <stdio.h>

int main(void)
{
    unsigned long long int cnt;
    
    for (cnt = 0; cnt <= 4026531840; cnt++)
        printf("%llu\n", cnt);
}
commented: Demonstrates an amazing ability to quickly solve problems not easily solved by others. Shows great depth of knowledge and a solid background based on in depth studies. +5

Thanks. Problem solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.