Hi, i am making a hangman game in C and i have a problem.
I am using 2 arrays to store the word to be guessed, and another array that stores the users guesses.
Ok now, this program runs untill the user tells it to stop. Because of this, i need to reset the array that stores the user guesses. i.e: keep the same size, but clear all the data out of it.
I have used memset(guesses,0,50); (i tried both 0 and '/0')
but this does not seem to work. When i do this, and print out the array, i get blank spaces, but in my program, it keeps saying that the user has already tried this letter.
Any ideas people? Cheers
4 6240
Hi, i am making a hangman game in C and i have a problem.
I am using 2 arrays to store the word to be guessed, and another array that stores the users guesses.
Ok now, this program runs untill the user tells it to stop. Because of this, i need to reset the array that stores the user guesses. i.e: keep the same size, but clear all the data out of it.
I have used memset(guesses,0,50); (i tried both 0 and '/0')
but this does not seem to work. When i do this, and print out the array, i get blank spaces, but in my program, it keeps saying that the user has already tried this letter.
Any ideas people? Cheers
when I did my hangman I did not have to worry about all this because I did not use an array to store the user's input. All I did was take the input character and call my replace function. If a character has already been input, the replace does not change the answer array so nothing happens(and the player is not penalised). It also does not limit some aspects of the program.
For example, what size did you declare your inputs array to be? Would not that size limit you in your application of the game for different scenarios.
the reason as to why im using an array is because i want to print out the users past guesses.
But at the end of the game, i need to clear this array.
one thing i just found out.
if i use the memset thing, it will work properly the second time round if the first thing that the user inputs is /0
thats with : memset(guesses,'/0',0);
ideas?
Banfa 9,065
Expert Mod 8TB
You have not really posted enough code for use to be able to tell you the problem, you have assumed the problem is in the memset line of you code but looking at it it looks correct to me to clear an array that is 50 bytes long.
Assuming guesses is an array a better way to call memset is
memset(guesses,0,sizeof guesses);
'/0' is wrong, I suspect you meant '\0' which is the 0 character.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Miki Tebeka |
last post by:
Hello All,
I'd like to bind <CTRL+L> so that it will clear IDLE's screen (in the
interactive prompt).
Any pointers/suggetions?
Thanks.
Miki
|
by: Gary |
last post by:
Hi
How does one clear an Array?
Situation is when I am executing my program everything works fine, but when
I try and repeat the program without resetting my program I get this error,...
|
by: Terry Andersen |
last post by:
I have an array that I initialize to zero, like:
Buffer = {0x00};
How do I in my code reset this array to all zeros ones more? Without running
a whole for loop?
Best Regards
Terry
|
by: Liz - Newbie |
last post by:
Does anyone know how to clear arrays? My C# books talk
about creating arrays or talk about using Clear or
RemoveAt but these methods don't appear to be available
for my array.
I have an array...
|
by: Steven Watanabe |
last post by:
I know that the standard idioms for clearing a list are:
(1) mylist =
(2) del mylist
I guess I'm not in the "slicing frame of mind", as someone put it, but
can someone explain what the...
|
by: Adam Honek |
last post by:
Instead of the ZeroMemory API what would one use in VB.NET to
clean an array using a custom structure?
The .clear isn't a member of it by default.
Any suggestions?
Thanks,
Adam
|
by: timothytoe |
last post by:
I can think of several easy ways to clear out an array. The most
obvious:
arr=;
arr.length=0;
arr=null;
What do most JavaScript programmers expect to see? Since JS is
transmitted, do I...
|
by: Ed Bitzer |
last post by:
Trying to send groups of email with program using System.Net.Mail. I
do not clear MailMessage but repeatedly loop changing only the Bcc
entries. Works fine if all addresses are valid. As a simple...
|
by: Martin |
last post by:
Is clearing a structure the following way well defined in C89? The
structure ACTION contains no floating point or pointer members. Only
integral types. My thoughts concern the padding - can and...
|
by: gobblegob |
last post by:
I am trying to clear the array STR but it does not clear it.
This sub is in a module.
Dim STR As Array
'Dim str(6) As String
STR =...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |