Hi guys here is my code, prettty much the same as one posted before but im getting a few errors. Fairly new to this so if someone could help me out i would greatly appreciate it. Thanks in advance:) Here is the code and errors underneath that:

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<time.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<iostream.h>

//char *getWord();
int main()

{

        char randomNumber (int max_number),fileLoc[2000]; 
        int max_number;

        {

           srand(time(NULL));
           int g = (rand() % (max_number + 1));
           return g;
        }



        char *getWord();

    {

        char c[2000];  /* declare a char array */
        int n;
        FILE *file;  /* declare a FILE pointer  */

                        /* Opening words file */

           if (strcmp(fileLoc, "") != 1) 

                {
                  // Here is the text file //

                  file = fopen("input.txt", "r");

                } 

           else 

                {
                   file = fopen(fileLoc, "r");

                }


           /* Incase the file cant be openend */

         if(file==NULL) 

            {
                printf("An error has occured: can't open words file.\nPlease type the location of the words file:\n");
                scanf("%s", fileLoc);
                printf("Reading file '%s'.....\n\n", fileLoc);
                file = fopen(fileLoc, "r");


                if (file == NULL) 

                    {

                        while (file==NULL) 

                        {

                          printf("That file doesn't exist. Enter the location of the words file:\n");
                          scanf("%s", fileLoc);
                          printf("Reading file '%s'.....\n\n", fileLoc);
                          file = fopen(fileLoc, "r");
                        }

                    }

                       printf("File has been read.\n\n");
                       n = fread(c, 1, 2000, file);
                       c[n] = '\0';

            }  else 

                {

                /* Reading the contents of the file */

                  n = fread(c, 1, 2000, file);
                  c[n] = '\0';

                }

  /* Separating the contents, divided by ' ' and declaring variables */

    char *token = strtok(c, " ");
    char *words[2000] = {0};
    int f = 0;
    while(token != NULL)

    {
      /* Allocating memory for the pointer */

      words[f] = (char*)malloc(strlen(token)+1);

      /* Copying entire string to pointer */

      strcpy(words[f],token);

      /* Resetting pointer */

      token = strtok(NULL, "*");
      f++;
    }

    /* Closing the file */

    fclose(file);

    /* Retrieving a random number */

    int wordN = randomNumber(f);

    /* Freeing all the memory allocated for the strings */

    int q;

    for(q=0;q<2000;q++)

    {
        if( q != wordN) 

        {
         free(words[q]);
        }
    }

    /* Returning string */

    return atoi(words[wordN]);

}



{

    char udi[] = "EMPTY";

    while ((strcmp(udi, "END") != 0) && ((strcmp(udi, "AGAIN") == 0) || (strcmp(udi, "EMPTY") == 0))) 

    {

    strcpy(udi, "EMPTY");

    /* Declaring variables */
    /* Random deciding which word is chosen to be guessed:
    guessWord is the word that needs to be guessed
    currentWord is the word that is filled with dots */

 /* Retrieving the word that matches with the wordNumber */
 /* Check which number was chosen: printf("%d", wordNumber); */

 char *tempWord = getWord();

 /* Declaring the guessWord with the length of dkljafoue */

 (char *) malloc ((sizeof(char)*2000)+1);

 /* Copying the string of dkljafoue into guessWord */

 strcpy(guessWord, tempWord);

 /* Freeing the pointer */

 free(tempWord);

 /* Calculate the length of the guessWord */

 int wordlength = strlen(guessWord);

 /* Creating the dotword (name: currentWord) */

 char *currentWord = static_cast wordlength;<---------------------causing errors

 int t;
 for (t = 0; t <= wordlength; t++) 

 {
  if (t == wordlength) 

  {
      currentWord[t] = '\0';
  } 

  else 

  {
      currentWord[t] =  '.';
  }
 }

 /* Currentword check: printf("Currentword: \"%s\"", currentWord); */

 /* Declaring variables */

 int errors = 0; /* Error amount, if its higher than 10 the loop stops */
 int guessedLetter = 0; /* Boolean Integer used to check wether the player entered a correct letter 0 = false, 1 = true */
 int i,n = 1;
 char c;



 /* Printing introduction message */

 printf("%s\n\n%s\n%s\n%s\n%s\n\n%s%s\n\n",
 "Welcome to the game Hangman!",
 "The objective in this game is to guess the word.",
 "You can enter both uppercase and lowercase letters.",
 "If you think you know the word, you can type it in.",
 "You will loose if you have guessed 4 letters wrong.",
 "This is the word you need to guess: ",
 currentWord);
 printf("%d.     %s", n, "Enter the letter(s) you want to guess: ");

 /* As long as the word hasn't been guessed or the errors are lower than 10: */

 while( (strcmp(currentWord, guessWord) != 0) && (errors < 4) )

 {

 scanf("%c", &c); /* Retrieving the user entry */

 c = tolower(c); /* Removing caps */

 if (c != '\n') 

 {

 if (isalpha(c)) { /* Making sure that the letter is alphanumeric */

 /* Checking wether the letter that has been entered (c) occurs in the guessWord */

 for (i = 0; i < wordlength; i++) 
 {

     if (guessWord[i] == c) 

     {
     currentWord[i] = c;
     guessedLetter = 1;

     }
 }

 /* Actions taken if the letter c doesn't occur in the guessWord and when it does */

 if (guessedLetter == 0) 

 {

     errors++;
     printf("\nThat letter was incorrect.\n\n");
 } 

 else 

 {

     guessedLetter = 0;
     printf("\nThat letter was correct.\n\n");
 }


 /* Showing the galg and the amount of errors */


 printf("%s%s\n\n", "The word including the letters you guessed: ", currentWord);
 prn_galg(errors);


 n++; /* Increasing attempt amount */


 /* Showing header if the word has not been guessed and the errors are lower than 10 */

 if ( (strcmp(currentWord, guessWord) != 0) && (errors < 10) ) 

 {
  printf("%d.     %s", n, "Enter the letter(s) you want to guess: ");
 }

 /* If the letter isn't alphanumeric (isalpha()) */

 } 


 else 

 {

  printf("Only alphanumeric symbols are allowed (a-z, A-Z), try again:\n");

 }
 }
 }

 /* Showing the results, wether the player won or not  */

 printf("---------------\n");
 printf("--- Results ---\n");
 printf("---------------\n\n");

 if (errors < 10) 

 {

      if (strcmp(currentWord, guessWord) == 0) 

      {

          printf("Congratulations you have guessed the right word!\n\n");
  } 
      else 

      {

          printf("You have guessed the wrong word, better luck next time!\n\n");
  }
 } 
 else 

 {
     printf("You have guessed the wrong word, better luck next time!\n\n");
 }
 printf("\nLetters guessed wrong: %d\nThe word that needed to be guessed: %s\nThe word you guessed: %s\n", errors, guessWord, currentWord);
 printf("\nEnter 'end' to end the game or enter 'again' to guess another word:\n");


 // Making sure that the user doesn't enter strange things


 while ((strcmp(udi, "END") != 0) && (strcmp(udi, "AGAIN") != 0)) 

 {
  if (strcmp(udi, "EMPTY") != 0) {
      printf("\n\nIt is not allowed to enter anything else than 'again' or 'end', try again:\n");
  }

  // Retrieving the udi (udi = user determined input)

  scanf("%s", udi);

  // Converting the udi to uppercase

  int x;
  for (x = 0; x < 5; x++) 

  {
      udi[x] = toupper(udi[x]);
  }
 }
 printf("\n\n--------------------------------------------\n\n");


}
return 0;
}

}



--------------------Configuration: MyDefaultVSproject - Win32 Debug--------------------
Compiling...
Assignment2.cpp
E:\Assignment2\Assignment2.cpp(174) : error C2065: 'guessWord' : undeclared identifier
E:\Assignment2\Assignment2.cpp(186) : error C2061: syntax error : identifier 'wordlength'
E:\Assignment2\Assignment2.cpp(230) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.

Assignment2.obj - 3 error(s), 0 warning(s)

Did someone ignore the request to read the Member Rules that mentions CODE Tags?
Or the info at the top of the forum that talks about CODE Tags?
How about the background of the text box where the message was entered that also mentions CODE Tags?

What could we have done to make the info about CODE Tags more readily available?

Sorry about that, first time posting on a site like this. Sorry again, anyone any suggestion?
Thanks

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<time.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<iostream.h>

//char *getWord();
int main()

{

char randomNumber (int max_number),fileLoc[2000]; 
int max_number;

{

srand(time(NULL));
int g = (rand() % (max_number + 1));
return g;
}



char *getWord();

{

char c[2000]; /* declare a char array */
int n;
FILE *file; /* declare a FILE pointer */

/* Opening words file */

if (strcmp(fileLoc, "") != 1) 

{
// Here is the text file //

file = fopen("input.txt", "r");

} 

else 

{
file = fopen(fileLoc, "r");

}


/* Incase the file cant be openend */

if(file==NULL) 

{
printf("An error has occured: can't open words file.\nPlease type the location of the words file:\n");
scanf("%s", fileLoc);
printf("Reading file '%s'.....\n\n", fileLoc);
file = fopen(fileLoc, "r");


if (file == NULL) 

{

while (file==NULL) 

{

printf("That file doesn't exist. Enter the location of the words file:\n");
scanf("%s", fileLoc);
printf("Reading file '%s'.....\n\n", fileLoc);
file = fopen(fileLoc, "r");
}

}

printf("File has been read.\n\n");
n = fread(c, 1, 2000, file);
c[n] = '\0';

} else 

{

/* Reading the contents of the file */

n = fread(c, 1, 2000, file);
c[n] = '\0';

}

/* Separating the contents, divided by ' ' and declaring variables */

char *token = strtok(c, " ");
char *words[2000] = {0};
int f = 0;
while(token != NULL)

{
/* Allocating memory for the pointer */

words[f] = (char*)malloc(strlen(token)+1);

/* Copying entire string to pointer */

strcpy(words[f],token);

/* Resetting pointer */

token = strtok(NULL, "*");
f++;
}

/* Closing the file */

fclose(file);

/* Retrieving a random number */

int wordN = randomNumber(f);

/* Freeing all the memory allocated for the strings */

int q;

for(q=0;q<2000;q++)

{
if( q != wordN) 

{
free(words[q]);
}
}

/* Returning string */

return atoi(words[wordN]);

}



{

char udi[] = "EMPTY";

while ((strcmp(udi, "END") != 0) && ((strcmp(udi, "AGAIN") == 0) || (strcmp(udi, "EMPTY") == 0))) 

{

strcpy(udi, "EMPTY");

/* Declaring variables */
/* Random deciding which word is chosen to be guessed:
guessWord is the word that needs to be guessed
currentWord is the word that is filled with dots */

/* Retrieving the word that matches with the wordNumber */
/* Check which number was chosen: printf("%d", wordNumber); */

char *tempWord = getWord();

/* Declaring the guessWord with the length of dkljafoue */

(char *) malloc ((sizeof(char)*2000)+1);

/* Copying the string of dkljafoue into guessWord */

strcpy(guessWord, tempWord);

/* Freeing the pointer */

free(tempWord);

/* Calculate the length of the guessWord */

int wordlength = strlen(guessWord);

/* Creating the dotword (name: currentWord) */

char *currentWord = static_cast wordlength;<---------------------causing errors

int t;
for (t = 0; t <= wordlength; t++) 

{
if (t == wordlength) 

{
currentWord[t] = '\0';
} 

else 

{
currentWord[t] = '.';
}
}

/* Currentword check: printf("Currentword: \"%s\"", currentWord); */

/* Declaring variables */

int errors = 0; /* Error amount, if its higher than 10 the loop stops */
int guessedLetter = 0; /* Boolean Integer used to check wether the player entered a correct letter 0 = false, 1 = true */
int i,n = 1;
char c;



/* Printing introduction message */

printf("%s\n\n%s\n%s\n%s\n%s\n\n%s%s\n\n",
"Welcome to the game Hangman!",
"The objective in this game is to guess the word.",
"You can enter both uppercase and lowercase letters.",
"If you think you know the word, you can type it in.",
"You will loose if you have guessed 4 letters wrong.",
"This is the word you need to guess: ",
currentWord);
printf("%d. %s", n, "Enter the letter(s) you want to guess: ");

/* As long as the word hasn't been guessed or the errors are lower than 10: */

while( (strcmp(currentWord, guessWord) != 0) && (errors < 4) )

{

scanf("%c", &c); /* Retrieving the user entry */

c = tolower(c); /* Removing caps */

if (c != '\n') 

{

if (isalpha(c)) { /* Making sure that the letter is alphanumeric */

/* Checking wether the letter that has been entered (c) occurs in the guessWord */

for (i = 0; i < wordlength; i++) 
{

if (guessWord[i] == c) 

{
currentWord[i] = c;
guessedLetter = 1;

}
}

/* Actions taken if the letter c doesn't occur in the guessWord and when it does */

if (guessedLetter == 0) 

{

errors++;
printf("\nThat letter was incorrect.\n\n");
} 

else 

{

guessedLetter = 0;
printf("\nThat letter was correct.\n\n");
}


/* Showing the galg and the amount of errors */


printf("%s%s\n\n", "The word including the letters you guessed: ", currentWord);
prn_galg(errors);


n++; /* Increasing attempt amount */


/* Showing header if the word has not been guessed and the errors are lower than 10 */

if ( (strcmp(currentWord, guessWord) != 0) && (errors < 10) ) 

{
printf("%d. %s", n, "Enter the letter(s) you want to guess: ");
}

/* If the letter isn't alphanumeric (isalpha()) */

} 


else 

{

printf("Only alphanumeric symbols are allowed (a-z, A-Z), try again:\n");

}
}
}

/* Showing the results, wether the player won or not */

printf("---------------\n");
printf("--- Results ---\n");
printf("---------------\n\n");

if (errors < 10) 

{

if (strcmp(currentWord, guessWord) == 0) 

{

printf("Congratulations you have guessed the right word!\n\n");
} 
else 

{

printf("You have guessed the wrong word, better luck next time!\n\n");
}
} 
else 

{
printf("You have guessed the wrong word, better luck next time!\n\n");
}
printf("\nLetters guessed wrong: %d\nThe word that needed to be guessed: %s\nThe word you guessed: %s\n", errors, guessWord, currentWord);
printf("\nEnter 'end' to end the game or enter 'again' to guess another word:\n");


// Making sure that the user doesn't enter strange things


while ((strcmp(udi, "END") != 0) && (strcmp(udi, "AGAIN") != 0)) 

{
if (strcmp(udi, "EMPTY") != 0) {
printf("\n\nIt is not allowed to enter anything else than 'again' or 'end', try again:\n");
}

// Retrieving the udi (udi = user determined input)

scanf("%s", udi);

// Converting the udi to uppercase

int x;
for (x = 0; x < 5; x++) 

{
udi[x] = toupper(udi[x]);
}
}
printf("\n\n--------------------------------------------\n\n");


}
return 0;
}

}

I get the following errors:

--------------------Configuration: MyDefaultVSproject - Win32 Debug--------------------
Compiling...
Assignment2.cpp
E:\Assignment2\Assignment2.cpp(174) : error C2065: 'guessWord' : undeclared identifier
E:\Assignment2\Assignment2.cpp(186) : error C2061: syntax error : identifier 'wordlength'
E:\Assignment2\Assignment2.cpp(230) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.

Assignment2.obj - 3 error(s), 0 warning(s)

u not defined both variables ..

and on 169th line u allocating memory but u not holding its address ..

I think correct line there may be

guessWord = (char *) malloc ((sizeof(char)*2000)+1);

sry if its wrong not read your full program ..

I made some changes and its down to one error. Here is the code and the error. Thanks for your reply aswell:)

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<time.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<iostream.h>

//char *getWord();

char fileLoc[2000];//Backup file Location//
int main();
int wordlength

{

        char randomNumber (int max_number),fileLoc[2000]; 
     	int max_number;
	
		{

		   srand(time(NULL));
		   int g = (rand() % (max_number + 1));
	   	   return g;
		}

	
		
	    char *getWord();
	
	{
  
		char c[2000];  /* declare a char array */
		int n;
		FILE *file;  /* declare a FILE pointer  */

						/* Opening words file */

           if (strcmp(fileLoc, "") != 1) 
  
				{
			      // Here is the text file //

                  file = fopen("input.txt", "r");

				} 
  
           else 
  
				{
                   file = fopen(fileLoc, "r");

				}

  
		   /* Incase the file cant be openend */

         if(file==NULL) 
  
			{
                printf("An error has occured: can't open words file.\nPlease type the location of the words file:\n");
                scanf("%s", fileLoc);
                printf("Reading file '%s'.....\n\n", fileLoc);
                file = fopen(fileLoc, "r");
    
	
				if (file == NULL) 
	
					{
    
	        	        while (file==NULL) 
		
						{
        
			              printf("That file doesn't exist. Enter the location of the words file:\n");
			              scanf("%s", fileLoc);
			              printf("Reading file '%s'.....\n\n", fileLoc);
			              file = fopen(fileLoc, "r");
						}
    
					}
    
	                   printf("File has been read.\n\n");
                       n = fread(c, 1, 2000, file);
                       c[n] = '\0';

			}  else 
  
				{

                /* Reading the contents of the file */

                  n = fread(c, 1, 2000, file);
                  c[n] = '\0';

				}
    
  /* Separating the contents, divided by ' ' and declaring variables */

    char *token = strtok(c, " ");
    char *words[2000] = {0};
    int f = 0;
    while(token != NULL)
    
	{
      /* Allocating memory for the pointer */

      words[f] = (char*)malloc(strlen(token)+1);

      /* Copying entire string to pointer */

      strcpy(words[f],token);

      /* Resetting pointer */

      token = strtok(NULL, "*");
      f++;
    }
    
	/* Closing the file */

    fclose(file);

    /* Retrieving a random number */

    int wordN = randomNumber(f);

    /* Freeing all the memory allocated for the strings */

    int q;
    
	for(q=0;q<2000;q++)
    
	{
        if( q != wordN) 
		
		{
         free(words[q]);
        }
    }

    /* Returning string */

    return atoi(words[wordN]);

}

 

{

	char udi[] = "EMPTY";

	while ((strcmp(udi, "END") != 0) && ((strcmp(udi, "AGAIN") == 0) || (strcmp(udi, "EMPTY") == 0))) 
	
	{
 
	strcpy(udi, "EMPTY");
 
	/* Declaring variables */
	/* Random deciding which word is chosen to be guessed:
	guessWord is the word that needs to be guessed
	currentWord is the word that is filled with dots */

 /* Retrieving the word that matches with the wordNumber */
 /* Check which number was chosen: printf("%d", wordNumber); */

 char *tempWord = getWord();
 char guessWord;
 /* Declaring the guessWord with the length of dkljafoue */

 guessWord = (char *) malloc ((sizeof(char)*2000)+1);

 /* Copying the string of dkljafoue into guessWord */
  
 strcpy( &guessWord, tempWord);

 /* Freeing the pointer */

 free(tempWord);
 
 /* Calculate the length of the guessWord */

 int wordlength = strlen(&guessWord);

 /* Creating the dotword (name: currentWord) */

 char *currentWord = static_cast wordlength;

 int t;
 for (t = 0; t <= wordlength; t++) 
 
 {
  if (t == wordlength) 
  
  {
      currentWord[t] = '\0';
  } 
  
  else 
  
  {
      currentWord[t] =  '.';
  }
 }

 /* Currentword check: printf("Currentword: \"%s\"", currentWord); */

 /* Declaring variables */

 int errors = 0; /* Error amount, if its higher than 10 the loop stops */
 int guessedLetter = 0; /* Boolean Integer used to check wether the player entered a correct letter 0 = false, 1 = true */
 int i,n = 1;
 char c;

 

 /* Printing introduction message */

 printf("%s\n\n%s\n%s\n%s\n%s\n\n%s%s\n\n",
 "Welcome to the game Hangman!",
 "The objective in this game is to guess the word.",
 "You can enter both uppercase and lowercase letters.",
 "If you think you know the word, you can type it in.",
 "You will loose if you have guessed 4 letters wrong.",
 "This is the word you need to guess: ",
 currentWord);
 printf("%d.     %s", n, "Enter the letter(s) you want to guess: ");

 /* As long as the word hasn't been guessed or the errors are lower than 10: */

 while( (strcmp(&currentWord) & (&guessWord) != 0) && (errors < 4) )
 
 {

 scanf("%c", &c); /* Retrieving the user entry */

 c = tolower(c); /* Removing caps */

 if (c != '\n') 
 
 {

 if (isalpha(c)) 
 
 { /* Making sure that the letter is alphanumeric */

 /* Checking wether the letter that has been entered (c) occurs in the guessWord */

 for (i = 0; i < wordlength; i++) 
 {
  
	 if (guessWord[i] == c) 
	 
	 {
	 currentWord[i] = c;
	 guessedLetter = 1;
  
	 }
 }

 /* Actions taken if the letter c doesn't occur in the guessWord and when it does */

 if (guessedLetter == 0) 
 
 {
  
	 errors++;
	 printf("\nThat letter was incorrect.\n\n");
 } 
 
 else 
 
 {
 
	 guessedLetter = 0;
	 printf("\nThat letter was correct.\n\n");
 }

 
 /* Showing the galg and the amount of errors */

 
 printf("%s%s\n\n", "The word including the letters you guessed: ", currentWord);
 

 
 n++; /* Increasing attempt amount */

 
 /* Showing header if the word has not been guessed and the errors are lower than 10 */

 if ( (strcmp(currentWord, guessWord) != 0) && (errors < 4) ) 
 
 {
  printf("%d.     %s", n, "Enter the letter(s) you want to guess: ");
 }

 /* If the letter isn't alphanumeric (isalpha()) */

 } 
 
 
 else 
 
 {

  printf("Only alphanumeric symbols are allowed (a-z, A-Z), try again:\n");

 }
 }
 }

 /* Showing the results, wether the player won or not  */

 printf("---------------\n");
 printf("--- Results ---\n");
 printf("---------------\n\n");
 
 if (errors < 4) 
 
 {
  
	  if (strcmp(&currentWord, guessWord) == 0) 
	  
	  {
      
		  printf("Congratulations you have guessed the right word!\n\n");
  } 
	  else 
	  
	  {
      
		  printf("You have guessed the wrong word, better luck next time!\n\n");
  }
 } 
 else 
 
 {
     printf("You have guessed the wrong word, better luck next time!\n\n");
 }
 printf("\nLetters guessed wrong: %d\nThe word that needed to be guessed: %s\nThe word you guessed: %s\n", errors, guessWord, currentWord);
 printf("\nEnter 'end' to end the game or enter 'again' to guess another word:\n");

 
 // Making sure that the user doesn't enter strange things

 
 while ((strcmp(udi, "END") != 0) && (strcmp(udi, "AGAIN") != 0)) 
 
 {
  if (strcmp(udi, "EMPTY") != 0) {
      printf("\n\nIt is not allowed to enter anything else than 'again' or 'end', try again:\n");
  }

  // Retrieving the udi (udi = user determined input)

  scanf("%s", udi);

  // Converting the udi to uppercase

  int x;
  for (x = 0; x < 5; x++) 
  
  {
      udi[x] = toupper(udi[x]);
  }
 }
 printf("\n\n--------------------------------------------\n\n");


}
return 0;
}

}

			




  





	
--------------------Configuration: MyDefaultVSproject - Win32 Debug--------------------
Compiling...
Assignment2.cpp
E:\Assignment2\Assignment2.cpp(16) : error C2239: unexpected token '{' following declaration of 'wordlength'
Error executing cl.exe.

Assignment2.obj - 1 error(s), 0 warning(s)

May b mistake at 14th line ..
change ; to declairation .. u wrote for main

and on 170 use char pointer .. u using simple char variable

Hi thanks for reply. Im new to this. Could you please clarify what you mean by this Shankye. Thanks

By the way I was refering to your first point about changing ; to declaration:)

char fileLoc[2000];//Backup file Location//

int main();

int wordlength
{

make this

#
char fileLoc[2000];//Backup file Location//
int main()
int wordlength;
{

and allocating memory using malloc which returns pointer so use pointer

char *guessWord;

U should not use ; for functions .. I think by mistake u wrote that there.. and skipped at variable delclaration .. just a small mistake ..

Gettint these errors now:

--------------------Configuration: MyDefaultVSproject - Win32 Debug--------------------
Compiling...
Assignment2.cpp
E:\Assignment2\Assignment2.cpp(13) : warning C4518: 'int ' : storage-class or type specifier(s) unexpected here; ignored
E:\Assignment2\Assignment2.cpp(13) : error C2146: syntax error : missing ';' before identifier 'wordlength'
E:\Assignment2\Assignment2.cpp(13) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

Assignment2.obj - 2 error(s), 1 warning(s)

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<time.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<iostream.h>

//char *getWord();

char fileLoc[2000];//Backup file Location//
int main()
{

        int wordlength;
        char randomNumber (int max_number),fileLoc[2000]; 
        int max_number;

        {

           srand(time(NULL));
           int g = (rand() % (max_number + 1));
           return g;
        }



        char *getWord();

    {

        char c[2000];  /* declare a char array */
        int n;
        FILE *file;  /* declare a FILE pointer  */

                        /* Opening words file */

           if (strcmp(fileLoc, "") != 1) 

                {
                  // Here is the text file //

                  file = fopen("input.txt", "r");

                } 

           else 

                {
                   file = fopen(fileLoc, "r");

                }


           /* Incase the file cant be openend */

         if(file==NULL) 

            {
                printf("An error has occured: can't open words file.\nPlease type the location of the words file:\n");
                scanf("%s", fileLoc);
                printf("Reading file '%s'.....\n\n", fileLoc);
                file = fopen(fileLoc, "r");


                if (file == NULL) 

                    {

                        while (file==NULL) 

                        {

                          printf("That file doesn't exist. Enter the location of the words file:\n");
                          scanf("%s", fileLoc);
                          printf("Reading file '%s'.....\n\n", fileLoc);
                          file = fopen(fileLoc, "r");
                        }

                    }

                       printf("File has been read.\n\n");
                       n = fread(c, 1, 2000, file);
                       c[n] = '\0';

            }  else 

                {

                /* Reading the contents of the file */

                  n = fread(c, 1, 2000, file);
                  c[n] = '\0';

                }

  /* Separating the contents, divided by ' ' and declaring variables */

    char *token = strtok(c, " ");
    char *words[2000] = {0};
    int f = 0;
    while(token != NULL)

    {
      /* Allocating memory for the pointer */

      words[f] = (char*)malloc(strlen(token)+1);

      /* Copying entire string to pointer */

      strcpy(words[f],token);

      /* Resetting pointer */

      token = strtok(NULL, "*");
      f++;
    }

    /* Closing the file */

    fclose(file);

    /* Retrieving a random number */

    int wordN = randomNumber(f);

    /* Freeing all the memory allocated for the strings */

    int q;

    for(q=0;q<2000;q++)

    {
        if( q != wordN) 

        {
         free(words[q]);
        }
    }

    /* Returning string */

    return atoi(words[wordN]);

}



{

    char udi[] = "EMPTY";

    while ((strcmp(udi, "END") != 0) && ((strcmp(udi, "AGAIN") == 0) || (strcmp(udi, "EMPTY") == 0))) 

    {

    strcpy(udi, "EMPTY");

    /* Declaring variables */
    /* Random deciding which word is chosen to be guessed:
    guessWord is the word that needs to be guessed
    currentWord is the word that is filled with dots */

 /* Retrieving the word that matches with the wordNumber */
 /* Check which number was chosen: printf("%d", wordNumber); */

 char *tempWord = getWord();
 char *guessWord;
 /* Declaring the guessWord with the length of dkljafoue */

 guessWord = (char *) malloc ((sizeof(char)*2000)+1);

 /* Copying the string of dkljafoue into guessWord */

 strcpy( guessWord, tempWord);

 /* Freeing the pointer */

 free(tempWord);

 /* Calculate the length of the guessWord */

 int wordlength = strlen(guessWord);

 /* Creating the dotword (name: currentWord) */

 char *currentWord = static_cast wordlength;

 int t;
 for (t = 0; t <= wordlength; t++) 

 {
  if (t == wordlength) 

  {
      currentWord[t] = '\0';
  } 

  else 

  {
      currentWord[t] =  '.';
  }
 }

 /* Currentword check: printf("Currentword: \"%s\"", currentWord); */

 /* Declaring variables */

 int errors = 0; /* Error amount, if its higher than 10 the loop stops */
 int guessedLetter = 0; /* Boolean Integer used to check wether the player entered a correct letter 0 = false, 1 = true */
 int i,n = 1;
 char c;



 /* Printing introduction message */

 printf("%s\n\n%s\n%s\n%s\n%s\n\n%s%s\n\n",
 "Welcome to the game Hangman!",
 "The objective in this game is to guess the word.",
 "You can enter both uppercase and lowercase letters.",
 "If you think you know the word, you can type it in.",
 "You will loose if you have guessed 4 letters wrong.",
 "This is the word you need to guess: ",
 currentWord);
 printf("%d.     %s", n, "Enter the letter(s) you want to guess: ");

 /* As long as the word hasn't been guessed or the errors are lower than 10: */

 while( (strcmp(&currentWord) & (&guessWord) != 0) && (errors < 4) )

 {

 scanf("%c", &c); /* Retrieving the user entry */

 c = tolower(c); /* Removing caps */

 if (c != '\n') 

 {

 if (isalpha(c)) 

 { /* Making sure that the letter is alphanumeric */

 /* Checking wether the letter that has been entered (c) occurs in the guessWord */

 for (i = 0; i < wordlength; i++) 
 {

     if (guessWord[i] == c) 

     {
     currentWord[i] = c;
     guessedLetter = 1;

     }
 }

 /* Actions taken if the letter c doesn't occur in the guessWord and when it does */

 if (guessedLetter == 0) 

 {

     errors++;
     printf("\nThat letter was incorrect.\n\n");
 } 

 else 

 {

     guessedLetter = 0;
     printf("\nThat letter was correct.\n\n");
 }


 /* Showing the galg and the amount of errors */


 printf("%s%s\n\n", "The word including the letters you guessed: ", currentWord);



 n++; /* Increasing attempt amount */


 /* Showing header if the word has not been guessed and the errors are lower than 10 */

 if ( (strcmp(currentWord, guessWord) != 0) && (errors < 4) ) 

 {
  printf("%d.     %s", n, "Enter the letter(s) you want to guess: ");
 }

 /* If the letter isn't alphanumeric (isalpha()) */

 } 


 else 

 {

  printf("Only alphanumeric symbols are allowed (a-z, A-Z), try again:\n");

 }
 }
 }

 /* Showing the results, wether the player won or not  */

 printf("---------------\n");
 printf("--- Results ---\n");
 printf("---------------\n\n");

 if (errors < 4) 

 {

      if (strcmp(&currentWord, guessWord) == 0) 

      {

          printf("Congratulations you have guessed the right word!\n\n");
  } 
      else 

      {

          printf("You have guessed the wrong word, better luck next time!\n\n");
  }
 } 
 else 

 {
     printf("You have guessed the wrong word, better luck next time!\n\n");
 }
 printf("\nLetters guessed wrong: %d\nThe word that needed to be guessed: %s\nThe word you guessed: %s\n", errors, guessWord, currentWord);
 printf("\nEnter 'end' to end the game or enter 'again' to guess another word:\n");


 // Making sure that the user doesn't enter strange things


 while ((strcmp(udi, "END") != 0) && (strcmp(udi, "AGAIN") != 0)) 

 {
  if (strcmp(udi, "EMPTY") != 0) {
      printf("\n\nIt is not allowed to enter anything else than 'again' or 'end', try again:\n");
  }

  // Retrieving the udi (udi = user determined input)

  scanf("%s", udi);

  // Converting the udi to uppercase

  int x;
  for (x = 0; x < 5; x++) 

  {
      udi[x] = toupper(udi[x]);
  }
 }
 printf("\n\n--------------------------------------------\n\n");


}
return 0;
}

}

Its weird, for some reason it wont recornise 'wordlength. Errors now are:

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<time.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<iostream.h>

//char *getWord();

char fileLoc[2000];//Backup file Location//
int main()
{

int wordlength;
char randomNumber (int max_number),fileLoc[2000]; 
int max_number;

{

srand(time(NULL));
int g = (rand() % (max_number + 1));
return g;
}



char *getWord();

{

char c[2000]; /* declare a char array */
int n;
FILE *file; /* declare a FILE pointer */

/* Opening words file */

if (strcmp(fileLoc, "") != 1) 

{
// Here is the text file //

file = fopen("input.txt", "r");

} 

else 

{
file = fopen(fileLoc, "r");

}


/* Incase the file cant be openend */

if(file==NULL) 

{
printf("An error has occured: can't open words file.\nPlease type the location of the words file:\n");
scanf("%s", fileLoc);
printf("Reading file '%s'.....\n\n", fileLoc);
file = fopen(fileLoc, "r");


if (file == NULL) 

{

while (file==NULL) 

{

printf("That file doesn't exist. Enter the location of the words file:\n");
scanf("%s", fileLoc);
printf("Reading file '%s'.....\n\n", fileLoc);
file = fopen(fileLoc, "r");
}

}

printf("File has been read.\n\n");
n = fread(c, 1, 2000, file);
c[n] = '\0';

} else 

{

/* Reading the contents of the file */

n = fread(c, 1, 2000, file);
c[n] = '\0';

}

/* Separating the contents, divided by ' ' and declaring variables */

char *token = strtok(c, " ");
char *words[2000] = {0};
int f = 0;
while(token != NULL)

{
/* Allocating memory for the pointer */

words[f] = (char*)malloc(strlen(token)+1);

/* Copying entire string to pointer */

strcpy(words[f],token);

/* Resetting pointer */

token = strtok(NULL, "*");
f++;
}

/* Closing the file */

fclose(file);

/* Retrieving a random number */

int wordN = randomNumber(f);

/* Freeing all the memory allocated for the strings */

int q;

for(q=0;q<2000;q++)

{
if( q != wordN) 

{
free(words[q]);
}
}

/* Returning string */

return atoi(words[wordN]);

}



{

char udi[] = "EMPTY";

while ((strcmp(udi, "END") != 0) && ((strcmp(udi, "AGAIN") == 0) || (strcmp(udi, "EMPTY") == 0))) 

{

strcpy(udi, "EMPTY");

/* Declaring variables */
/* Random deciding which word is chosen to be guessed:
guessWord is the word that needs to be guessed
currentWord is the word that is filled with dots */

/* Retrieving the word that matches with the wordNumber */
/* Check which number was chosen: printf("%d", wordNumber); */

char *tempWord = getWord();
char *guessWord;
/* Declaring the guessWord with the length of dkljafoue */

guessWord = (char *) malloc ((sizeof(char)*2000)+1);

/* Copying the string of dkljafoue into guessWord */

strcpy( guessWord, tempWord);

/* Freeing the pointer */

free(tempWord);

/* Calculate the length of the guessWord */

int wordlength = strlen(guessWord);

/* Creating the dotword (name: currentWord) */

char *currentWord = static_cast wordlength;

int t;
for (t = 0; t <= wordlength; t++) 

{
if (t == wordlength) 

{
currentWord[t] = '\0';
} 

else 

{
currentWord[t] = '.';
}
}

/* Currentword check: printf("Currentword: \"%s\"", currentWord); */

/* Declaring variables */

int errors = 0; /* Error amount, if its higher than 10 the loop stops */
int guessedLetter = 0; /* Boolean Integer used to check wether the player entered a correct letter 0 = false, 1 = true */
int i,n = 1;
char c;



/* Printing introduction message */

printf("%s\n\n%s\n%s\n%s\n%s\n\n%s%s\n\n",
"Welcome to the game Hangman!",
"The objective in this game is to guess the word.",
"You can enter both uppercase and lowercase letters.",
"If you think you know the word, you can type it in.",
"You will loose if you have guessed 4 letters wrong.",
"This is the word you need to guess: ",
currentWord);
printf("%d. %s", n, "Enter the letter(s) you want to guess: ");

/* As long as the word hasn't been guessed or the errors are lower than 10: */

while( (strcmp(&currentWord) & (&guessWord) != 0) && (errors < 4) )<---------------error

{

scanf("%c", &c); /* Retrieving the user entry */

c = tolower(c); /* Removing caps */

if (c != '\n') 

{

if (isalpha(c)) 

{ /* Making sure that the letter is alphanumeric */

/* Checking wether the letter that has been entered (c) occurs in the guessWord */

for (i = 0; i < wordlength; i++) 
{

if (guessWord[i] == c) 

{
currentWord[i] = c;
guessedLetter = 1;

}
}

/* Actions taken if the letter c doesn't occur in the guessWord and when it does */

if (guessedLetter == 0) 

{

errors++;
printf("\nThat letter was incorrect.\n\n");
} 

else 

{

guessedLetter = 0;
printf("\nThat letter was correct.\n\n");
}


/* Showing the galg and the amount of errors */


printf("%s%s\n\n", "The word including the letters you guessed: ", currentWord);



n++; /* Increasing attempt amount */


/* Showing header if the word has not been guessed and the errors are lower than 10 */

if ( (strcmp(currentWord, guessWord) != 0) && (errors < 4) ) 

{
printf("%d. %s", n, "Enter the letter(s) you want to guess: ");
}

/* If the letter isn't alphanumeric (isalpha()) */

} 


else 

{

printf("Only alphanumeric symbols are allowed (a-z, A-Z), try again:\n");

}
}
}

/* Showing the results, wether the player won or not */

printf("---------------\n");
printf("--- Results ---\n");
printf("---------------\n\n");

if (errors < 4) 

{

if (strcmp(&currentWord, guessWord) == 0) 

{

printf("Congratulations you have guessed the right word!\n\n");
} 
else 

{

printf("You have guessed the wrong word, better luck next time!\n\n");
}
} 
else 

{
printf("You have guessed the wrong word, better luck next time!\n\n");
}
printf("\nLetters guessed wrong: %d\nThe word that needed to be guessed: %s\nThe word you guessed: %s\n", errors, guessWord, currentWord);
printf("\nEnter 'end' to end the game or enter 'again' to guess another word:\n");


// Making sure that the user doesn't enter strange things


while ((strcmp(udi, "END") != 0) && (strcmp(udi, "AGAIN") != 0)) 

{
if (strcmp(udi, "EMPTY") != 0) {
printf("\n\nIt is not allowed to enter anything else than 'again' or 'end', try again:\n");
}

// Retrieving the udi (udi = user determined input)

scanf("%s", udi);

// Converting the udi to uppercase

int x;
for (x = 0; x < 5; x++) 

{
udi[x] = toupper(udi[x]);
}
}
printf("\n\n--------------------------------------------\n\n");


}
return 0;
}

}

--------------------Configuration: MyDefaultVSproject - Win32 Debug--------------------
Compiling...
Assignment2.cpp
E:\Assignment2\Assignment2.cpp(188) : error C2061: syntax error : identifier 'wordlength'
E:\Assignment2\Assignment2.cpp(232) : error C2660: 'strcmp' : function does not take 1 parameters
E:\Assignment2\Assignment2.cpp(232) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.

Assignment2.obj - 3 error(s), 0 warning(s)

Two things:
This is a C forum. Why are you including

#include<windows.h> -- this should not be necessary
#include<conio.h> -- this is non-standard and should not be necessary
#include<iostream.h> -- this is strictly C++

Learn to consistantly format your code. Here's some information to help. If code is hard for us to follow (which yours is), many will simply ignore your code.

Error 1: In C, all variables must be defined at the top of a function, not when you decide to use them.

Error 2: obvious

Ya dude ..
Break your program into functions..
and post part which is erroneous ..
Thanks for link Walt ..

ok this part seems to be the main problem. Any ideas, errors are beneath

while ((strcmp(udi, "END") != 0) && ((strcmp(udi, "AGAIN") == 0) || (strcmp(udi, "EMPTY") == 0))) 

    {

                strcpy(udi, "EMPTY");

                                                            /* Declaring variables */
                                                            /* Random deciding which word is chosen to be guessed:
                                                            guessWord is the word that needs to be guessed
                                                            currentWord is the word that is filled with dots */

                                                            /* Retrieving the word that matches with the wordNumber */
                                                            /* Check which number was chosen: printf("%d", wordNumber); */

                char *tempWord = getWord();

                                                            /* Declaring the guessWord with the length of dkljafoue */

                char guessWord [strlen(*tempWord)+1];

                                                            /* Copying the string of dkljafoue into guessWord */

                strcpy(guessWord, tempWord);

                                                            /* Freeing the pointer */

                free(tempWord);

                                                            /* Calculate the length of the guessWord */

                int wordlength = strlen(guessWord);

                                                            /* Creating the dotword (name: currentWord) */

                char *currentWord = static_cast<wordlength>;

Errors:

--------------------Configuration: MyDefaultVSproject - Win32 Debug--------------------
Compiling...
Assignment2.cpp
E:\Assignment2\Assignment2.cpp(175) : error C2664: 'strlen' : cannot convert parameter 1 from 'char' to 'const char *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\Assignment2\Assignment2.cpp(175) : error C2133: 'guessWord' : unknown size
E:\Assignment2\Assignment2.cpp(191) : error C2061: syntax error : identifier 'wordlength'
E:\Assignment2\Assignment2.cpp(241) : error C2660: 'strcmp' : function does not take 1 parameters
E:\Assignment2\Assignment2.cpp(241) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.

Assignment2.obj - 5 error(s), 0 warning(s)

Im not understanding what you doing on line 37 ..

I think on line 21 u must remove * ..
strlen takes address, using redirection * u get value at that address ..
so u may change that and check..
Try removing * and check ..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.