#include<stdio.h>
#include<string.h>
int main()
{
FILE *f=fopen("words.txt","r");
int i=0,len,temp,j;
char c;
char word[15];
char shuffil_word[15],guessword[15];
start:
printf("WELCOME TO JUMBLED WORDS");
printf("Guess the correct word\n");
for (i=0;!feof(f);i++)
{
if((c=getc(f))==' ')
break;
else
shuffil_word[i]=word[i]=c;
}
len=i;
for(i = 0; i < len; i++)
{
j = (rand()%len);
temp = shuffil_word[i];
shuffil_word[i] = shuffil_word[j];
shuffil_word[j] = temp;
}
printf("\n");
for(i=0; i<len; i++)
{
printf("%c", shuffil_word[i]);
}
printf("\n\n");
again:
printf("Enter your guess...\n");
gets(guessword);
int guesslen = strlen(guessword);
if(guesslen!=len)
{
printf("\nThe Length of Guessed word and Actual Word is Mismatched\nTry Again...\n\n");
goto again;
}
for(i=0;i<len;i++){
if(guessword[i]!=word[i]){
printf("\nYou lost.");
goto gameloop;
}
}
printf("\nCongratulations! You Won the Game...!!!\n\n");
gameloop:
printf("\nDo you want to play again? (y/n)\n\n");
if(getch()=='y'||getch()=='Y')
goto start;
else
return;
}
NOTE: you need to create a text document with name of words and put program and text document in same folder
you need to enter the words in text document and program takes words from that document and jumbles it.
by
Kalyan Kurasala
No comments:
Post a Comment