Well on my lil project and I'm at the most complicated part, haven't been stuck long but I need help. This part of the code i suppose to get generate all possible combination of number and numbers and combination can't repeat. There 6 set of numbers the first 5 can't repeat, here is what I have so far. Its not efficient and is time consuming for my PC. probrably will take upto 10 minutes to complete.
Code:
void Gen2(int limit){
FILE *fPtr;
struct Ticket set;
struct Ticket nSet;
struct Ticket checkSet;
int pass;
int x;
int check;
int count = 0;
int loop;
if((fPtr = fopen("possCom.bin", "wb")) == NULL)
{
printf("Failed to get all possible combination.\n");
}
else
{
printf("Generation starting......\n");
for(pass = 1; pass <= limit; pass++)
{
numGen(&set);
printf("%d %d %d %d %d %d\n", set.num1, set.num2, set.num3, set.num4, set.num5, set.num6);
fwrite(&set, sizeof(struct Ticket), 1, fPtr);
if((pass % 10) == 0)
{
fseek(fPtr, 0 * sizeof(struct Ticket), SEEK_SET);
loop = pass;
for(x = count; x < loop; x++)
{
fread(&checkSet, sizeof(struct Ticket), 1, fPtr);
while(!feof(fPtr))
{
if(repeatCheck(&checkSet, &set) == 1)
{
printf("repetition was found\n");
nSet.num1 = set.num1;
nSet.num2 = set.num2;
nSet.num3 = set.num3;
nSet.num4 = set.num4;
nSet.num5 = set.num5;
nSet.num6 = set.num6;
while(repeatCheck(&checkSet, &nSet) == 1)
{
numGen(&gSet);
}
set.num1 = nSet.num1;
set.num2 = nSet.num2;
set.num3 = nSet.num3;
set.num4 = nSet.num4;
set.num5 = nSet.num5;
set.num6 = nSet.num6;
}
printf("repeatCheck complete\n");
getch();
fread(&checkSet, sizeof(struct Ticket), 1, fPtr);
}
count++;
}
}
printf("%d\n", pass);
}
}
fclose(fPtr);
menu();
}
The repeatCheck function returns the correct value but is just repeats constantly. If you need source code just ask.