Im supposed to make a little game in which you're supposed to guess a letter in 6 tries. It reads the letters from a text file. I get a bunch of errors and dont really know what to do. Any suggestions?

#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#define MAXGUESSES 6

//this function provides instructions to the user on how to play the game
void Instructions( );

//this function runs one entire game. It for checks either 6 incorrect guesses or a correct guess.
//It returns a 0 if the game is over and the player did not guess the letter, otherwise it returns 1.
int PlayGuess(char solution);

//this function prompts the player to make a guess and returns that guess
//this function is called from inside the PlayGuess( ) function described above
char  GetLetter( );

//this function takes two arguments, the guess from the player 
//and the solution letter from the file. 
//It lets the user know if the guess comes alphabetically before or after the answer 
//The function returns 1 if the guess matches the solution and returns a 0 if they do not match
int CompareLetters(char guess, char solution);


int main()
{
    FILE* infile;
    FILE* outfile;
    char guess = 0; 
    char solution = 0;
    char c = solution; 
    int gamesToPlay = 0,
    i = 0;

    Instructions();
    infile = fopen(" .text","r");
    scanf(" %d", &gamesToPlay);



    for(i=0;i<gamesToPlay;i++)
    {
        fscanf(infile," %c", &guess);
        PlayGuess(char (solution));
        CompareLetters(char (guess), char (solution));
    }

    fclose(infile);
    return 0;
}

//Function definitions
//this function provides instructions to the user on how to play the game
void Instructions( )
{
    printf("Welcome to my mini game\n");
    printf("Guess the right letter in order to win the game\n");
    printf("You will have 6 chances to guess the letter\n");
    printf("Let's begin, good luck\n");
}

//this function runs one entire game. It for checks either 6 incorrect guesses or a correct guess.
//It returns a 0 if the game is over and the player did not guess the letter, otherwise it returns 1.
int PlayGuess(char solution)
{   
    int numGuesses = 0;
    int MAXGUESSES = 6;
    while(numGuesses < MAXGUESSES)
    {   
        GetLetter( );
        CompareLetters(char guess, char solution);
        if(numGuesses > MAXGUESSES)
        {
            printf("You weren't able to guess the letter in 6 tries. Sorry but you LOSE!\n");
        }
        numGuesses = numGuesses +1;
        }

}

//this function prompts the player to make a guess and returns that guess
//this function is called from inside the PlayGuess( ) function described above
char  GetLetter(  )
{
    char guess = 0;
    printf("What is your guess?\n");
    scanf(" %c", &guess);
}

//this function takes two arguments, the guess from the player 
//and the solution letter from the file. 
//It lets the user know if the guess comes alphabetically before or after the answer 
//The function returns 1 if the guess matches the solution and returns a 0 if they do not match
int CompareLetters(char guess, char solution)
{
    char guess = 0;
    char solution = 0;
    if (guess == solution)
    {
        printf("congratulations! You won!");
        return 1;
    }
    else if(guess < solution)
    {
        printf("Sorry that's incorrect. The letter is alphabetically higher. Please try again.\n");
        GetLetter( );
        return 0;
    }
    else if(guess > solution)
    {
        printf("Sorry that's incorrect. The letter is alphabetically lower. Please try again.\n");
        GetLetter( );
        return 0;
    }
} 

I get a bunch of errors and dont really know what to do. Any suggestions?

Sure. Fix them. The errors tell you what line number and what the problem is, so look there and correct it.

commented: :P +1 +2

which errors are you getting ? Can you specify some errors which you getting ?

in the line one , you have defined a macro, but where is the value of that macro ? In the one go, i have seen that. After telling errors, it will be east to figure out problem. thanks.

these are the errors i get. I don't know how to fix them that's the problem.

c:\users\wendy\desktop\project1\project1\project1.c(43): error C2143: syntax error : missing ')' before 'type'
c:\users\wendy\desktop\project1\project1\project1.c(43): error C2198: 'PlayGuess' : too few arguments for call
c:\users\wendy\desktop\project1\project1\project1.c(44): error C2143: syntax error : missing ')' before 'type'
c:\users\wendy\desktop\project1\project1\project1.c(44): error C2198: 'CompareLetters' : too few arguments for call
c:\users\wendy\desktop\project1\project1\project1.c(66): error C2143: syntax error : missing ';' before 'constant'
c:\users\wendy\desktop\project1\project1\project1.c(66): warning C4091: ' ' : ignored on left of 'int' when no variable is declared
c:\users\wendy\desktop\project1\project1\project1.c(66): error C2106: '=' : left operand must be l-value
c:\users\wendy\desktop\project1\project1\project1.c(70): error C2143: syntax error : missing ')' before 'type'
c:\users\wendy\desktop\project1\project1\project1.c(70): error C2198: 'CompareLetters' : too few arguments for call
c:\users\wendy\desktop\project1\project1\project1.c(70): error C2059: syntax error : ')'
c:\users\wendy\desktop\project1\project1\project1.c(95): error C2082: redefinition of formal parameter 'guess'
c:\users\wendy\desktop\project1\project1\project1.c(96): error C2082: redefinition of formal parameter 'solution'

Ok, a few things:

  1. When calling a function, you do not need to define the type of the parameters. For insatnce, on line 42, you would use PlayGuess(solution);.
  2. On line 65, you try to declare a variable called MAXGUESSES. This is alreay defined on line 3. The compiler uses #define to find and replace all instances of the identifier (in this case MAXGUESSES) with the value (although you can define "functions" as well). So the compiler would change line 65 to int 6 = 6;, which doesn't make sense. Since MAXGUESSES is already defined as 6, remove line 65.
  3. On line 69, guess isn't defined in the scope of the function.
  4. On line 94/95, you trying to redeclare the function parameters.

few arguments means prototype and defination has different number of arguments or from where you are calling the function don't have same number of arguments which function defination have.

secondly, ')' ';' errors are self-explaintroy.

thirdly, l-value means = operator expects the l-value which needs to be satisfied. this means it needs a value where value need to be stored.

We will help you only by giving hints, you should try and if will face problem, then feel free to post here ;)

ok thanks for the help! i got it to run but when i type a letter to guess it crashes and these errors come up.. I posted my updated code aswell

'Project1.exe': Loaded 'C:\Users\Wendy\Desktop\Project1\Debug\Project1.exe', Symbols loaded.
'Project1.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
'Project1.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\sechost.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\dwmapi.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\cryptbase.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\clbcatq.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file
Microsoft Visual Studio C Runtime Library has detected a fatal error in Project1.exe.

#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#define MAXGUESSES 6

//this function provides instructions to the user on how to play the game
void Instructions( );

//this function runs one entire game. It for checks either 6 incorrect guesses or a correct guess.
//It returns a 0 if the game is over and the player did not guess the letter, otherwise it returns 1.
int PlayGuess(char solution);

//this function prompts the player to make a guess and returns that guess
//this function is called from inside the PlayGuess( ) function described above
char  GetLetter( );

//this function takes two arguments, the guess from the player 
//and the solution letter from the file. 
//It lets the user know if the guess comes alphabetically before or after the answer 
//The function returns 1 if the guess matches the solution and returns a 0 if they do not match
int CompareLetters(char guess, char solution);


int main()
{
    FILE* infile;
    char guess = 0; 
    char solution = 0;
    char c = solution; 
    int gamesToPlay = 0,
    i = 0;

    Instructions();
    infile = fopen(" .text","r");
    scanf(" %d", &gamesToPlay);



    for(i=0;i<gamesToPlay;i++)
    {
        fscanf(infile," %c", &guess);
        PlayGuess(solution);
        CompareLetters(guess, solution);
    }

    fclose(infile);
    return 0;
}

//Function definitions
//this function provides instructions to the user on how to play the game
void Instructions( )
{
    printf("Welcome to my mini game\n");
    printf("Guess the right letter in order to win the game\n");
    printf("You will have 6 chances to guess the letter\n");
    printf("Let's begin, good luck\n");
}

//this function runs one entire game. It for checks either 6 incorrect guesses or a correct guess.
//It returns a 0 if the game is over and the player did not guess the letter, otherwise it returns 1.
int PlayGuess(char solution)
{   
    int numGuesses = 0;
    char guess = 0;
    while(numGuesses < MAXGUESSES)
    {   
        GetLetter( );
        CompareLetters(guess, solution);
        if(numGuesses > MAXGUESSES)
        {
            printf("You weren't able to guess the letter in 6 tries. Sorry but you LOSE!\n");
        }
        numGuesses = numGuesses +1;
        }

}

//this function prompts the player to make a guess and returns that guess
//this function is called from inside the PlayGuess( ) function described above
char  GetLetter(  )
{
    char guess = 0;
    printf("What is your guess?\n");
    scanf(" %c", &guess);
}

//this function takes two arguments, the guess from the player 
//and the solution letter from the file. 
//It lets the user know if the guess comes alphabetically before or after the answer 
//The function returns 1 if the guess matches the solution and returns a 0 if they do not match
int CompareLetters(char guess, char solution)
{
    if (guess == solution)
    {
        printf("congratulations! You won!");
        return 1;
    }
    else if(guess < solution)
    {
        printf("Sorry that's incorrect. The letter is alphabetically higher. Please try again.\n");
        GetLetter( );
        return 0;
    }
    else if(guess > solution)
    {
        printf("Sorry that's incorrect. The letter is alphabetically lower. Please try again.\n");
        GetLetter( );
        return 0;
    }
} 

firstly,ensure that the files are in the same directory in which your exe file is.

secondly, ensure that files are read-able.

thirdly, ensure the data in the files are compatible with the data types you are using for reading and writing into.

fourthly, ensure that files have the valid data and ensure that the files exists and name you have given is same as the name of file.

thanks
;)

Those aren't really errors (except for the last line), they just say that a PDB file couldn't be found for the DLLs, which is just a file that contains debug information for the particular libraries.

Could you post the text in the input file you are using?

Also, PlayGuess() and GetLetter() are supposed to return int and char respectively, but neither do.

the text in the inputLetter.txt file is
r
a
y
n
o
i
s
c
d
f
g
j

is that what you mean? and am i supposed type return int 0; ? return char c;? im not exactly sure what to do there

Then reread the section on writing functions.

i got it to run but now when i type a letter and press enter, instead of crashing, the program just closes and this appears. I can't figure what's wrong :(

'Project1.exe': Loaded 'C:\Users\Wendy\Desktop\Project1\Debug\Project1.exe', Symbols loaded.
'Project1.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'Project1.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
The program '[1512] Project1.exe: Native' has exited with code 0 (0x0).

#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#define MAXGUESSES 6

//this function provides instructions to the user on how to play the game
void Instructions( );

//this function runs one entire game. It for checks either 6 incorrect guesses or a correct guess.
//It returns a 0 if the game is over and the player did not guess the letter, otherwise it returns 1.
int PlayGuess(char solution);

//this function prompts the player to make a guess and returns that guess
//this function is called from inside the PlayGuess( ) function described above
char  GetLetter( );

//this function takes two arguments, the guess from the player 
//and the solution letter from the file. 
//It lets the user know if the guess comes alphabetically before or after the answer 
//The function returns 1 if the guess matches the solution and returns a 0 if they do not match
int CompareLetters(char guess, char solution);


int main()
{
    FILE* infile;
    char guess = 0; 
    char solution = 0;
    char c = solution; 
    int gamesToPlay = 0,
    i = 0;

    Instructions();
    infile = fopen("inputLetter.txt","r");
    scanf(" %d", &gamesToPlay);



    for(i=0;i<gamesToPlay;i++)
    {
        fscanf(infile," %c", &guess);
        PlayGuess(solution);
        CompareLetters(guess, solution);
    }

    fclose(infile);
    return 0;
}

//Function definitions
//this function provides instructions to the user on how to play the game
void Instructions( )
{
    printf("Welcome to my mini game\n");
    printf("Guess the right letter in order to win the game\n");
    printf("You will have 6 chances to guess the letter\n");
    printf("Let's begin, good luck\n");
}

//this function runs one entire game. It for checks either 6 incorrect guesses or a correct guess.
//It returns a 0 if the game is over and the player did not guess the letter, otherwise it returns 1.
int PlayGuess(char solution)
{   
    int numGuesses = 0;
    char guess = 0;
    while(numGuesses < MAXGUESSES)
    {   
        GetLetter( );
        CompareLetters(guess, solution);
        if(numGuesses > MAXGUESSES)
        {
            printf("You weren't able to guess the letter in 6 tries. Sorry but you LOSE!\n");
        }
        numGuesses = numGuesses +1;
        }
    return 0;
}

//this function prompts the player to make a guess and returns that guess
//this function is called from inside the PlayGuess( ) function described above
char  GetLetter(  )
{
    char guess = 0;
    printf("What is your guess?\n");
    scanf(" %c", &guess);
    return 0;
}

//this function takes two arguments, the guess from the player 
//and the solution letter from the file. 
//It lets the user know if the guess comes alphabetically before or after the answer 
//The function returns 1 if the guess matches the solution and returns a 0 if they do not match
int CompareLetters(char guess, char solution)
{
    char c = solution;
    if (guess == solution)
    {
        printf("congratulations! You won!");
        return 1;
    }
    else if(guess < solution)
    {
        printf("Sorry that's incorrect. The letter is alphabetically higher. Please try again.\n");
        GetLetter( );
        return 0;
    }
    else if(guess > solution)
    {
        printf("Sorry that's incorrect. The letter is alphabetically lower. Please try again.\n");
        GetLetter( );
        return 0;
    }
} 

Looks to me your compiler isn't set up correctly. Other than that, I haven't a clue. Maybe reinstall?

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.