Advertisement
Guest User

Untitled

a guest
Nov 4th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define MAXLINE 20
  5.    
  6.  
  7.  
  8.  
  9.     int main(){
  10.     FILE *fpin;
  11.     char line[MAXLINE];
  12.     char guess[MAXLINE];
  13.     char character;
  14.     char current_guess;
  15.     char word_guess[MAXLINE];
  16.     int lifes_remaining=10;
  17.     int y,q;
  18.  
  19.    
  20.  
  21.     if((fpin=fopen("unknown1.txt","r"))== NULL)
  22.     {   printf("Cannot open file\n");               /* open unknown1.txt as a read only file */
  23.         exit(EXIT_FAILURE);
  24.     }
  25.  
  26.     fscanf(fpin,"%s",line);                 /* taking the text from unknown1.txt and copying it to line */
  27.  
  28.     {   printf("Ready to start!, the word is");}
  29.    
  30.     int x=strlen(line);
  31.     for(y=0;y<x;y++)
  32.     {   guess[y]='*';   }
  33.                
  34.         guess[y]='\0';                     
  35.         printf("%s\n",guess);  
  36.                     /* creating our guess line, which displays how many letters to be guessed/how many they have                                    already guessed*/
  37.  
  38.    
  39.     printf("the number of guesses remaining is %d\n", lifes_remaining);  /* telling the user how many lives they have left*/
  40.  
  41.     printf("would you like to guess the word [w] or guess a letter [l]\n:");  /* asking the user for word or letter */
  42.         scanf("%c", &character);
  43.         printf("\n%c\n", character);
  44.  
  45.     if(character == 'l' || character == 'L')                   /* if user selects l or L, guessing letter */
  46.     {   printf("please choose a letter to guess in the word:\n");    
  47.         char current_guess = getchar();
  48.         while (getchar() != '\n');
  49.         for(q=0;q<x;q++)
  50.         {   if(current_guess==line[q])
  51.             {   guess[q]=current_guess;}
  52.             }
  53.            
  54.                 printf("%s\n", guess);
  55.             }
  56.  
  57.  
  58.    
  59.  
  60.  
  61. fclose(fpin);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement