How do i get pythons range function in C?
I tried doing a while loop and incrementing but it gave weird results, it started counting at negative and ignored the varible i initialized.
Use a for loop, genius.
>>58601886
You're having problems counting from a to b in a loop?
>>58601886for i in range(100):
print("%d" % i)
Is just a glorified way of writingi = 0
while i < 100:
print("%d" % i)
i += 1
Which is directly transferable to C:int i = 0;
while (i < 100) {
printf("%d\n", i);
i += 1;
}
Which can be made convenient with a for loopint i;
for (i = 0; i < 100; i += 1) {
printf("%d\n", i);
}
>>58601977
Except what im trying to do is:for i in range(2240000000,2249999999)
And C can't seem to count from a specific number like python does.
>>58602027
>2240000000
Isn't that outside the range of a signed 32-bit int?
>>58602027
Dude. Just use i as the starting point, and loop until your ending point.
>>58602054
I guess i should just use a for loop then huh?
>>58602027
That's because of arithmetic overflow you retard.
Declare i a double instead or just loop from 0 to 9999999, because 2249999999-2240000000 is still 9999999 times
>>58602027
That number is too big for int, use long long or int64_t
>>58602027
use a long int instead of an int
>>58602092
AYYYYYYYYY
>>58602027
In C you have to care about the size of the variables you're using (Python does that for you automatically).
If you declare "int i" then i is required to hold at least from -32767 to 32767 (16-bit), although nowadays integers are normally 32-bit (from -2147483647 to 2147483647).
Your numbers are larger than what an int can hold. Therefore to guarantee that your code would work you would have to declare i as a long long instead:long long int i;
for (i = 2240000000; i < 2249999999; i++)
Long long signed integers are guaranteed to hold at least from -9223372036854775807 to 9223372036854775807 (64-bits), which is more than enough for your purposes.
>>58602080
Sure.int i;
for (i = 2240000000; i < 2249999999, i++) {
printf("ayy lmao"\n");
}
Although, you can't use an int like
>>58602112
and
>>58602108
said.
I typed this whole post on my phone, I hope you're happy.
>>58602225
Small mistake, integers commonly hold from -2147483648 to 2147483647 since most systems use a two's complement representation. That's not required by the standard, however.
>>58602225
So many data types so little time.
>>58602249
It's not even given that int is 32-bit wide, it must only be at least 16 bits. On 286, GCC would compile ints to 16 bits, but that's quite a while ago.
>>58602262
Yes, as I said. I was only correcting what I said that ints (((normally))) go from -2147483647 to 2147483647, when they actually normally go from -2147483648 instead.
>>58602346
> (((normally)))
Yo, I'm slow today, is this a lisp joke?
>>58603836
He's just being a /pol/tard, don't worry about it.