how do i find an array of ints within a larger array of ints.

I have random ints:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void display::randomizer(void){//picks random images 1-18 to display
    int i=0;
    int temp=0;
    int rando=0;
#ifdef Q_WS_WIN
		LARGE_INTEGER cycles;
		QueryPerformanceCounter(&cycles);
		srand(cycles.QuadPart);
#endif
    for(i=1;i<=18;i++){
    rando = rand() % 18 + i;
    if(rando>18){
        rando=18;
    }
    temp = r[i];
    r[i]=r[rando];
    r[rando]=temp;
    }
}


The array 'r' is used to pick 18 random letters and display them. Sometimes, very rarely, there are bad words that CAN appear. I have used the program a whole lot and never seen them, but I do understand that there is a statistical possibility.

Anyhow, I want to remove these combinations:
 
#define BADWORDS {{11,17,14,5},{18,4,17,5},{7,8,6,1},{2,17,11,15},{8,14,17,18},{18,3,8,5},{5,17,7,10}} 


I tried lfind() in <search.h>, but I can only get it to tell me if there is a certain single int inside the array. What I would like is a quick way to search for these arrays, as I don't want any noticeable slowdown and the user is able to ask for random values many times per second.

I apologize if I have overlooked anything, I am probably searching using the wrong terms.
This is my solution, hope it helps someone else. It works quick enough, although I want to believe in a better way:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//Initialize Badword array
static int badwords[7][4]=BADWORDS;
//Create compare function for lfind() to use
extern "C" {
int compare(const void *a,const void *b){
	return(*(int *)a-*(int *)b);
	}
}
//Create a checkForBadWords function
void display::checkForBadWords(void){
		void *pFirst=NULL;
		size_t size=19;
		int j=0;
		for(i=0;i<NUMBER_OF_BADWORDS;i++){
			pFirst=lfind(badwords[i],&r[1],&size,sizeof(int),compare); //lfind should always return a pointer here
			if(pFirst){ //check to make sure it did its job
				if(*((int *)pFirst+3) != 0){ //check the fourth int to make sure it is something real
					if((badwords[i][1] == *((int *)pFirst+1)) && (badwords[i][2] == *((int *)pFirst+2)) && (badwords[i][3] == *((int *)pFirst+3))){//check to see if the rest of the word is there
						for(j=1;j<=18;j++){//If I find a bad word, standardize the array
							r[j]=j;
						}
						return;//don't check for other bad words, because one is enough
					}
				}
			}//move on to the next word
		}
}


I extended the array 'r' to contain zeros at the end, that way if lfind() returns a pointer to the last real value in 'r', there won't be any overflow when checking against the remaining values.

Like I said, this works great for seven 4-letter words...but I am sure there are n, N-letter words that need to be removed in some math class somewhere, and this solution will not work for that.
Topic archived. No new replies allowed.