Quote (Eep @ Oct 26 2012 06:12am)
godlike
I thought the problem was something else entirely, didn't pay attn to his string decs
not god like; just common sense. its the first thing i picked up on as well.
@op: declare your arrays to wordlength + 1 then use strlen to find the length of the string or use a while loop checking for '\0'.
ex: hangman would be an array of 8;
0 = h
1 = a
2 = n
3 = g
4 = m
5 = a
6 = n
7 = '\0' //C automanticall puts this here.
so your declaration would be
Code
words[8];
varrients of this declaration include
Code
words[] = "hangman"; //automatically sets the array elements for you compile time.
and for your for loops i suggest switch them to
Code
#include <strings.h>
for(h = 0; h < strlen(words); h++)
or personally my favorite
Code
char *q = words;
while(*++q != '\0')
id just stick with the for loop and since i assume you are going to want to loop through this project and use a wordlist eventually id declare the words[n] size to be around 26 simply because there is no 26 letter words in a dictionary.
edit:: hint when you do go to change words out to another during your program if you copy a shorter word then your last word you will have fragments of the word at the end. i suggest using a call to memcpy. ex:
Code
memcpy(words, '\0', sizeof(words));
the windows api funciton zeromemory() works as well but youd have to include windows.h which is allot of overhead for such a simple program.
This post was edited by AbDuCt on Oct 26 2012 12:08pm