This
Code:
while(ptr[7] == ptr[2] || ptr[3] || ptr[6])
is equivalent to
Code:
while((ptr[7] == ptr[2]) || (ptr[3] != 0) || (ptr[6] != 0))
instead of what you probably meant, i.e.
Code:
while((ptr[7] == ptr[2]) || (ptr[7] == ptr[3]) || (ptr[7] == ptr[6]))
You have a lot of repeated code, and a lot of code that references constants, like that bit I quoted -- why are you saying ptr[7]? You should rarely mention array indices like that directly. A lot of it is unnecessary too. Like this.
Code:
if(ptr[3] == ptr[2])
{
while(ptr[3] == ptr[2])
{
ptr[3] = (rand() % 26) +'A';
break;
}
}
I'll assume you didn't really mean to have the break in since it renders the while loop irrelevant. In that case, here's some equivalent code.
Code:
do {
ptr[3] = rand() % 26 + 'A';
} while(ptr[3] == ptr[2]);
You should probably have a function for that. Maybe a function that takes in an array of letters you've already generated, so that it can iterate through the array and check for duplicates. That way you'd catch all repeats rather than just ptr[3] == ptr[2]. Example:
Code:
char random_letter_that_hasnt_been_generated_yet(char generated[], int generated_count) {
for(;;) {
char c = rand() % 26 + 'A';
int i, already_generated = 0;
for(i = 0; i < generated_count && !already_generated; i ++) {
if(c == generated[i]) already_generated = 1;
}
if(!already_generated) {
return c;
}
}
}
Of course it may be a good idea to not make that loop infinite, in case you try to generate 27 distinct letters (with only 26 different possibilities). The pigeonhole principle strikes again.