ok. so after much grooming my code looks like this:
Code:
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include <time.h>
char *list[12] ={ //variables and stuff
"banana", "programmer",
"tongue", "favourite",
"serendipity", "sportman",
"harmony", "goalkeeper",
"operation", "hamstring",
"vibration", "wonderful"
};
int main(void) // start of main function
{
int wordi, lives; //more variables
char word[20];
char str1[20];
int wordlength;
int i;
char guess;
int win;
char *ptr;
char yesno;
srand((unsigned int)time(NULL)); // <----------- does anyone know what this line does???
//working code body
while(lives!=7000) //start of game while (7000 is so it doesnt end unless return 0)
{
wordi = rand() % 12; // word selection (this particular line will be
printf("\n rand index is %d \n ", wordi); // replaced by the computer so it can control the
strcpy(word,list[wordi]); // word in order to test and mark the code
lives=8; // initial settings
strcpy(str1,word);
wordlength=strlen(str1);
memset (str1,'_',wordlength);
printf("\n Let's start. You have %d lives \n ", lives);
printf("%s",str1);
while (lives>0) // start of guesses while
{
printf("\n Next Guess: ");
scanf("%c",&guess);
printf("%c",guess);
for ( i=0 ; i<wordlength ; i++ ){
if ( word[i] == guess){
str1[i] = word[i];}
else{
lives=lives-1;}}
if (strchr(str1, '_') == NULL){
win = 1;}
else{}
if (win == 1){
printf(" The word is %s, you have won !! \n",str1);}
else if (lives != 0){
printf(" Lives: %d, Current word: %s \n", lives, str1);}
else if (lives ==0){
printf(" Game Over \n");}
} // end of guesses while
printf("\n Do you want to play again [Y/N] \n");
scanf('%c',&yesno);
if (yesno == 'N')
return 0;
else if (yesno == 'n')
return 0;
else if (yesno == 'Y')
break;
else if (yesno == 'y')
break;
else
return 0;
} // end of game while
return 0;
} // end of main function
i'm still working on the yes/no rester the game thingo because it has the whole multi charachter constant thing going, but otherwise, it compiles and kinda works, gotta skrew aroung with the lives and stuff.
mr commontater, if i could beg of you please, could you post your working copy of the code so i can compare it to mine and see why mine doesnt work!!! i only have half an hour until submission is due, but i plan to keep working on my copy after that till it works properly, you know, the whole learning thing