Skip to main content

Hangman game using C programming

 Hangman game using C programming:

Program:

#include <stdio.h> #include <string.h> #include <ctype.h> #define MAX_WRONG_GUESSES 6 #define MAX_WORD_LENGTH 20 int main() { char word[MAX_WORD_LENGTH]; char guessed[MAX_WORD_LENGTH]; int numWrongGuesses = 0; int numCorrectGuesses = 0; int length; int i; char playAgain; do { printf("Enter the word to guess (up to %d characters): ", MAX_WORD_LENGTH - 1); scanf("%s", word); length = strlen(word); // Initialize guessed array with underscores for (i = 0; i < length; i++) { guessed[i] = '_'; } guessed[length] = '\0'; while (numWrongGuesses < MAX_WRONG_GUESSES && numCorrectGuesses < length) { printf("\nWord: %s\n", guessed); printf("Enter a letter: "); char guess; scanf(" %c", &guess); guess = tolower(guess); int found = 0; for (i = 0; i < length; i++) { if (word[i] == guess) { guessed[i] = guess; numCorrectGuesses++; found = 1; } } if (!found) { numWrongGuesses++; printf("Incorrect guess. You have %d guesses left.\n", MAX_WRONG_GUESSES - numWrongGuesses); } } if (numCorrectGuesses == length) { printf("\nCongratulations! You guessed the word: %s\n", word); } else { printf("\nSorry, you ran out of guesses. The word was: %s\n", word); } printf("Do you want to play again? (y/n): "); scanf(" %c", &playAgain); playAgain = tolower(playAgain); // Reset variables for the next game numWrongGuesses = 0; numCorrectGuesses = 0; } while (playAgain == 'y'); return 0; }

Output:

Enter the word to guess (up to 19 characters): game

Word: ____
Enter a letter: g

Word: g___
Enter a letter: a

Word: ga__
Enter a letter: m

Word: gam_
Enter a letter: e

Congratulations! You guessed the word: game
Do you want to play again? (y/n): n


Comments

Popular posts from this blog

Install TensorFlow on Windows 11: Step-by-Step Guide for CPU & GPU

 --- Installing **TensorFlow on Windows 11** requires setting up system dependencies, configuring Python, and ensuring compatibility with CPU or GPU acceleration. This step-by-step guide provides everything needed to install **TensorFlow 2.10 or lower** on **Windows Native**, including software prerequisites, Microsoft Visual C++ Redistributable installation, Miniconda setup, GPU driver configuration, and verification steps.   ### **System Requirements:**   Before installing TensorFlow, ensure your system meets these requirements:   - **Operating System:** Windows 7 or higher (64-bit)   - **Python Version:** 3.9–3.12   - **pip Version:** 19.0 or higher for Linux and Windows, 20.3 or higher for macOS   - **Microsoft Visual C++ Redistributable:** Required for Windows Native   - **Long Paths Enabled:** Ensure long paths are enabled in Windows settings   For **GPU support**, install:   - **NVIDIA ...

Unreal Engine Product Showcase: Mesmerizing Video Sequence Render

  4k Image:

Cloudflare Is Down Worldwide: What Happened, What It Means & What You Can Do

🌍 Cloudflare Is Down Worldwide: What Happened & Why the Internet Broke Today On 18 November 2025 , the internet experienced one of the largest global outages in years as Cloudflare , the backbone of countless websites and online services, went down unexpectedly. The outage caused millions of websites to become slow, unreachable, or return 5xx internal server errors , leading to widespread disruption across businesses, apps, and essential online platforms. This blog post explains what happened, why the internet broke for many users, and what Cloudflare has officially said so far. What Exactly Happened? Around 4:30 PM IST , reports began flooding social media and outage trackers like Downdetector. Users across India, Europe, the US, and Southeast Asia noticed that: Websites were not loading Requests were timing out Services dependent on Cloudflare CDN or DNS stopped responding APIs hosted through Cloudflare were failing Even some security and protection layers were ...