Click here to Skip to main content
14,766,280 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hello everyone!!
I did a game who has 2 players trying to find a hidden word(The first one is hiding and the other one write a word ,then the system hide some letters and the player trying to find it.
I can "give" a simple word such as "hello" or a sentence like "try to find me"
using fgetc(stdin) and fgets() and an if statement in get_word() function as input method.
The problem is that when player 1 give the words: "engineering intelligence" ,when the player 2 find it ,program ask for another character(to complete the words),but the words have found...Why is this happenning???

You can run the following code and try some examples giving simple words ,sentence and the above words like "engineering intelligence" to understand what I said.
I give you the whole code ,because it's big and if had to explain ,it would get me hours...

Thanks a lot and I hope you find that small (I suppose) problem I have...

What I have tried:

Code[^]
Posted
Updated 25-Sep-20 8:55am
Comments
Rick York 25-Sep-20 12:23pm
   
It would take you hours to explain but you expect us to download and dig through it for you?

All right then.
jeron1 25-Sep-20 12:35pm
   
"I give you the whole code ,because it's big and if had to explain ,it would get me hours..."
Which means you have to attempt to narrow down the problem area to something manageable, like a particular loop or some particular conditional statement... Also, your description what what is supposed to happen and what is happening is (at least to me) very unclear.
Richard MacCutchan 25-Sep-20 12:40pm
   
"Why is this happenning???"
At a guess I would say there is a bug in your code.

Quote:
Funny problem with game in C

Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

1.11 — Debugging your program (stepping and breakpoints) | Learn C++[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
   
Comments
Nick_is_asking 25-Sep-20 14:27pm
   
Ok I found the problem.Thanks by the way
You need to use the debugger and start a debugging process in your code.

tip: it is best to make some output in the most important areas like error case or unhandled code pathes like some missing else-code on if-braces.

Do you really expect that we will do your job?
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900