Checking if word is in the dictionary

I can't seem to check if the word is in the dictionary. It always that the word is not in the dictionary. I think it's because of my comparing. Can somebody help on how to do this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  while ( lower <= upper ) {
	middle = (lower + upper) / 2;
	printf("%d\n", middle);
	if (dict[middle] == word){ 
	 printf("%s\n", dict[middle]);
	 m = 1;
	 break;
        }else if (dict[middle] < word) {lower = middle+1; }
	else{ upper = middle-1; printf("%d\n", upper);}
  }m = 0;
  if(m==0){
        printf("%s\n", word);
	printf("%s\n", dict[middle]);
	printf("%d\n", middle);
	printf("%s doesn't exist in the scrabble dictionary\n", word);
	break;
  }
what data type is dict[] and word?
If they are char strings, you can use http://www.cplusplus.com/reference/cstring/strcmp/?kw=strcmp .
I've change it to this now but it's still not working properly.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
						while ( lower <= upper ) {
							middle = (lower + upper) / 2;
							printf("%d\n", middle);
							printf("%d\n", strcmp(word, dict[middle]));
							if (strcmp(word, dict[middle]) == 0){ 
								 printf("%s\n", dict[middle]);
								 m = 1;
								 break;
							}else if (strcmp(word, dict[middle]) == 1) lower = middle+1; 
							else upper = middle-1;
						}m = 0;
						if(m==0){
							printf("%s\n", word);
							printf("%s\n", dict[middle]);
							printf("%d\n", middle);
							printf("%s doesn't exist in the scrabble dictionary\n", word);
							break;
						}
but you still didnt answer: what data type is dict[] and word?

also you can paste whole code here so we can test it.
It's working now, dict and word are both chars. The only problem that I'm having now is with this.

http://www.cplusplus.com/forum/beginner/113616/
Wait new problem, I can't seem to initialize lower and upper again after this part. But before it, it's okay. Why is not working?

1
2
3
4
5
6
7
8
9
10
while ( lower <= upper ) {
	middle = (lower + upper) / 2;
	if (strcmp(word, dict[middle]) == 0){ 
		 m = 1;
		 break;
	}else if (strcmp(word, dict[middle]) > 0) lower = middle+1; 
	else upper = middle-1; 
}
lower = 0;	
upper = 178692;
Topic archived. No new replies allowed.