Advertisement
ben_gustafson04

Weird string issue

Feb 20th, 2024
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6.  
  7. int main(void) {
  8.    
  9.     char inputString[50];
  10.    
  11.     printf("Welcome to hangman! This game requires 2 players.\n");
  12.     printf("Enter a string that is less than 50 characters and only lowercase letters.\n");
  13.     printf("Please enter a string for other player to guess: ");
  14.    
  15.     scanf("%s", inputString);
  16.    
  17.     system("clear");
  18.    
  19.     char currentGuess;
  20.     int i;
  21.     int j = 0;
  22.     int length = strlen(inputString);
  23.     char weird = inputString[0];
  24.    
  25.     for (i = 0; i < 5; i++) {
  26.        
  27.         printf("Enter character to guess:");
  28.         scanf("%s", &currentGuess);
  29.        
  30.         for (j = 0; j < length; j++) {
  31.            
  32.             if (inputString[j] == currentGuess) {
  33.                 printf("Correct character!\n");
  34.             }
  35.             else {
  36.                 printf("Incorrect character.\n");
  37.             }
  38.            
  39.         }
  40.        
  41.        
  42.        
  43.     }
  44.    
  45.    
  46.    
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement