hi,
i have the following program.
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)
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("\nWelcome to Hangman\n");
printf("Enter the word for the player to guess > ");
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("\n\nWord so far is %s, Guesses so far %d",
solution,num_guess++);
printf("\nEnter a letter >");
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("\nThe letter %c was in the the answer", ch);
}
if(num_guess < MAX)
printf("\nYou got it ! It took %d tries",num_guess);
else
printf("\nYou had %d goes, the word was %s", MAX,word);
}
--------------------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)