I'm trying to make a simple prime number generator for bigger program. It needs two numbers (n and c) and needs to edit them. So I decided to put the numbers in pointers, and just give the adress two the pointers. After about a half-houre of fumbling with *'s and &'s my eye's need a break. Here's a copy of the code without the pointerstuff on it:
#include <stdio.h>
int nextprime(int n, int c);
int main() {
int n = 0, c = 0;
printf("%d, ", nextprime(n, c));
printf("%d, ", nextprime(n, c));
printf("%d, ", nextprime(n, c));
printf("%d, ", nextprime(n, c));
return 0;
}
int nextprime(int n, int c) {
/* This function will return the next prime number. Simple set n and c at 0 and
call the function whenever you need the next prime number. */
if(n == 0) {
n++;
return 2;
}
if(c == 0) {
c++;
return (6*n)-1;
}
if(c == 1) {
n++;
c--;
return (6*n)+1;
}
}
Good luck and thanks!:P