1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <conio.h>
void randomize(char*);
void Guess(char*,int*,int*);
void main()
{
char word[256] = {'\0'};
long int x;
int b, score=0, ctr2=0;
time_t t;
FILE* inFile;
srand((unsigned)time(&t));
b:
inFile = fopen("words.txt", "r");
if (inFile == NULL)
{
printf("The file was not opened succesfully\n");
exit(1);
}
fseek(inFile, 0L,SEEK_SET);
x = rand()%1000;
fseek(inFile, x, SEEK_SET);
fscanf(inFile, "%s", word);
if (strlen(word)<6)
{
fclose(inFile);
goto b;
}
printf("%s\n\n\n", word);
fclose(inFile);
randomize(word);
score = ctr2 = 0;
Guess(word,&score,&ctr2);
printf("\n\n\t\tYou got a %d", score);
getch();
}
void randomize(char* y)
{
char A[256] = {'\0'};
int i=0, x, k, j, z;
int n[256]= {'\0'};
time_t t;
x = strlen(y);
srand((unsigned)time(&t));
printf("\n\n\n\t\t\t\t");
while (i<x)
{
a:
j = rand()%x;
z = 0;
for (k=0,z=0; k<i; k++)
if (n[k]==j)
z++;
if (z!=0) goto a;
else
{
n[i] = j;
A[i] = y[j];
printf("%c ", A[i]);
i++;
}
}
return;
}
void Guess(char* word,int* score,int* ctr2)
{
int ctr;
FILE* inFile;
char guess[256] = {'\0'};
a:
ctr = *score;
printf("\n What is your guess? %d ", *ctr2);
scanf("%s", guess);
if (strcmpi(guess,"EXIT")==0)
exit(1);
inFile = fopen("words.txt", "r");
fseek(inFile, 0l, SEEK_SET);
while (feof(inFile)==0)
{
fscanf(inFile, "%s", word);
if (strcmpi(word, guess)==0)
{
*score += strlen(guess)*10;
printf("\t%d", strlen(guess)*10);
break;
}
}
fclose(inFile);
if (*score==ctr)
{
printf("\nYou had a wrong guess\n\n Try again!!\n");
goto a;
}
else if(*score>ctr && *score<100)
{
printf("\n\n \t\tYou got it right\nGuess another word");
goto a;
}
else
{
printf("\m \n\t\tCONGRATULATIONS\n\n You got all right \n");
return;
}
}
| |