473,387 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

clearing an array?

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
Oct 8 '06 #1
4 6240
r035198x
13,262 8TB
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.
Oct 8 '06 #2
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.
Oct 8 '06 #3
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?
Oct 8 '06 #4
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.
Oct 9 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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
4
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,...
28
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
10
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...
65
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...
13
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
4
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...
16
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...
3
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...
4
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 =...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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...
0
BarryA
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...
0
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...
0
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...
0
Oralloy
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.