Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAXLINE 20
- int main(){
- FILE *fpin;
- char line[MAXLINE];
- char guess[MAXLINE];
- char character;
- char current_guess;
- char word_guess[MAXLINE];
- int lifes_remaining=10;
- int y,q;
- if((fpin=fopen("unknown1.txt","r"))== NULL)
- { printf("Cannot open file\n"); /* open unknown1.txt as a read only file */
- exit(EXIT_FAILURE);
- }
- fscanf(fpin,"%s",line); /* taking the text from unknown1.txt and copying it to line */
- { printf("Ready to start!, the word is");}
- int x=strlen(line);
- for(y=0;y<x;y++)
- { guess[y]='*'; }
- guess[y]='\0';
- printf("%s\n",guess);
- /* creating our guess line, which displays how many letters to be guessed/how many they have already guessed*/
- printf("the number of guesses remaining is %d\n", lifes_remaining); /* telling the user how many lives they have left*/
- printf("would you like to guess the word [w] or guess a letter [l]\n:"); /* asking the user for word or letter */
- scanf("%c", &character);
- printf("\n%c\n", character);
- if(character == 'l' || character == 'L') /* if user selects l or L, guessing letter */
- { printf("please choose a letter to guess in the word:\n");
- char current_guess = getchar();
- while (getchar() != '\n');
- for(q=0;q<x;q++)
- { if(current_guess==line[q])
- { guess[q]=current_guess;}
- }
- printf("%s\n", guess);
- }
- fclose(fpin);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement