TEXT TWIST CORRECTION

whats wrong with this code? it has 4 errors..

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
#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;
  }
}
Hi!

The errors' solutions in order are:

1: Fix the void main() issue. Main must return an int.

2: Either define strcmpi(), or, as I think you meant, use strcmp(). What were you trying to do there?

3: See #2.

4: What's that escape character \m supposed to do?

5: Get rid of your gotos. Technically this isn't an error, but your code readability's been compromised. I'm pretty sure you can use loops instead. :)

-Albatross
Thanks Albatross, But i can't really detect where the error is..in error 1 to 3 it says wrong number of arguments in function randomize..but in 4 declaration syntax error
Huh... I had no such problem there, nor do I see any such problem (although if you want to be politically correct use char[] instead of char* for the declarations and definitions). My errors were VERY different for yours, but ignoring the fact that I don't have <conio.h> it also came out to 4.

Anyways, the last three true errors (for me) were at lines 89, 98, and 120, and let us know if fixing the problems outlined above makes them go away. :)

-Albatross
I already fixed it.. i renamed the function randomize(); here because in my borland tc there is a predefined randomize(); function so i renamed it to randomiz(); haha but thanks for the help i'll just correct the errors...
Topic archived. No new replies allowed.