Originally Posted by
Doriän
i don't get your point. My func returns 0 if is a prime, doesn't it? isn't 0 a success return value?
Not strictly, and most importantly, functions like "isdigit" or "isalpha" returns a "true/false" result, where true is considered any non-zero value, and false is zero. Your function uses this naming convention, but operates in the opposite way.
There are lots of functions where returning non-zero is an indication of success, fopen(), fread/fwrite are but a few examples where a non-zero result (or non-NULL - but as NULL and zero have the same value in most instances, I classify this as the same).
If you actually want to indicate SUCCESS/FAILURE, then you should return SUCCESS and compare with SUCCESS, not return 0 and compare with 0 - the fact that SUCCESS happens to be zero (in some systems) is besides the point.
But I still think functions that have similar names should operate in similar ways - so something called "isxxx" should return non-zero (e.g. 1) for "is" and 0 for "isn't".
yeah, I was skipping even numbers in the function, now I implemented a condition in the main for loop, so to pass to the function only odd numbers!
According to
this txt, my prime numbers (up to 997) are correct, so I believe are correct even after 997!
Sounds right then - I wasn't saying it was wrong, just that you should check it - obviously, if you are adding more numbers than you should, the number would grow larger than it should too!
You think so? So maybe is not my fault after all
?!
perhaps I could try to write it in a file? Would it change something?
Writing to a file using fprintf() wouldn't change anything. I don't know much abotu Eclipse CDT, so I don't know if it's printf supports 64-bit prints.
Perhaps you can use a manual conversion, like this:
Code:
char *lltostr(uintmax_t n, char *str, int maxlen) {
char *s = str[maxlen-1];
*s-- = 0; /* Start by marking the end */
do {
*s--- = (char)((n % 10) + '0');
n /= 10;
} while(n);
return s;
}
...
char ss[25];
printf("Sum = %s\n", lltostr(sum, ss, 25))
...
--
Mats