Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

errors in program

Status
Not open for further replies.

sssvvv

Programmer
Joined
Apr 20, 2002
Messages
2
Location
NL
hi,
i have the following program.
Code:
/*Hangman.c*/
#include <string.h>/*needed for strlen() and strncpy()*/
#include <ctype.h>
#include <conio.h> /*neede for getch()*/
#include <stdio.h>
#define MAXLEN 20
#define MAX 10
#define YES 1
#define NO 0
#define STARS '********************'

void main()
          {
          char word[MAXLEN+1],solution[MAXLEN+1],ch,
                    char *w_ptr,*s_ptr;
          int num_guess=len=found = 0;

          printf(&quot;\nWelcome to Hangman\n&quot;);
          printf(&quot;Enter the word for the player to guess > &quot;);
          gets(word);
          for(*w_ptr = word; *w_ptr; w_ptr++ )
                    *w_ptr = toupper(*w_ptr); /*upper case string*/
          len = strlen(word);
          strncpy(solution,STARS,len);/*copy stars into solution*/
          solution = '\0';

          while(num_guess < MAX) /* number of guesses loop*/
                    {
                    printf(&quot;\n\nWord so far is %s, Guesses so far %d&quot;,
                              solution,num_guess++);
                    printf(&quot;\nEnter a letter >&quot;);
                    ch = toupper(getch());
                    s_ptr = solution; w_ptr = word; found = NO;
                    while(*w_ptr)/*test if letter in word*/
                              {
                              if(ch == *w_ptr)
                                        {
                                        *s_ptr = ch; found = YES;
                                        }
                              w_ptr++; s_ptr++;
                              }
                    /*if word is the same as the solution, user wins !*/
                    if(solution == word)
                    break;
                    if found
                    printf(&quot;\nThe letter %c was in the the answer&quot;, ch);
                    }
                    if(num_guess < MAX)
                    printf(&quot;\nYou got it ! It took %d tries&quot;,num_guess);
                    else
                    printf(&quot;\nYou had %d goes, the word was %s&quot;, MAX,word);

                           
                              }
it shows me the following erors, can anyone help me please.
--------------------Configuration: hangman - Win32 Debug--------------------
Compiling...
hangman.c
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(15) : error C2059: syntax error : 'type'
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(16) : error C2065: 'len' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(16) : error C2065: 'found' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(21) : error C2065: 'w_ptr' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(21) : error C2100: illegal indirection
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(21) : warning C4047: '=' : 'int ' differs in levels of indirection from 'char *'
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(21) : error C2100: illegal indirection
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(22) : error C2100: illegal indirection
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(22) : error C2100: illegal indirection
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(24) : error C2015: too many characters in constant
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(25) : error C2106: '=' : left operand must be l-value
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(33) : error C2065: 's_ptr' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(33) : warning C4047: '=' : 'int ' differs in levels of indirection from 'char *'
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(33) : warning C4047: '=' : 'int ' differs in levels of indirection from 'char *'
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(34) : error C2100: illegal indirection
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(36) : error C2100: illegal indirection
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(38) : error C2100: illegal indirection
c:\program files\microsoft visual studio\myprojects\hangman\hangman.c(45) : error C2061: syntax error : identifier 'found'
Error executing cl.exe.

hangman.exe - 15 error(s), 3 warning(s)



 
For starters, try reading the errors. They tell you exactly what's wrong. They aren't there to annoy you, they're there to help you fix the problem.

Here're a few problems:

Code:
char word[MAXLEN+1],solution[MAXLEN+1],ch, char *w_ptr,*s_ptr;
Code:
                                           ^^^^
That
Code:
char
can only come at the beginning of a declaration. Either replace the
Code:
,
right before it with a
Code:
;
or just get rid of that
Code:
char
altogether.


Code:
int num_guess=len=found = 0;

That just doesn't work.
Code:
len
and
Code:
found
need to be declared before they can be used. Initialize them all to 0 separately.


Read the errors and find the other mistakes on your own.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top