473,385 Members | 2,210 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,385 software developers and data experts.

Checking through Array

11
Is there any more efficient way (for loop?) to check through an array than the following code?:

void submit_check(char guessed_word[], char& submitNow)
{
if ( guessed_word[0] == '?'
|| guessed_word[1] == '?'
|| guessed_word[2] == '?'
|| guessed_word[3] == '?'
|| guessed_word[4] == '?'
|| guessed_word[5] == '?')
{
submitNow = 'n';
}


submitNow is a part of a while loop in main.
Nov 20 '07 #1
2 1236
Laharl
849 Expert 512MB
Yeah, there is a way to do that.

for (int i = STARTING INDEX; i < ENDING INDEX; i++ /*or i--, if you need a reverse traversal */)
[Code involving Array[i] goes here]

Replace STARTING/ENDING INDEX with the appropriate values.

Remember that C/C++ arrays start from index 0.
Nov 20 '07 #2
scruggsy
147 100+
Is there any more efficient way (for loop?) to check through an array than the following code?:
If by "more efficient" you mean "easier for you without being harder for the computer," then use a for loop to check each element of the array in turn.
Nov 20 '07 #3

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

Similar topics

3
by: David P. Jessup | last post by:
Good day folks. Within an ASP I'm working on I need to check whether an array is empty or not. Code: Dim somearray() 'other code: array might have been populated, maybe not if somearray()...
26
by: Sterten | last post by:
when I define int R; and then later access it with x=R;C=7; .... but x happens to be <0 or >99 , then the program's behavious becomes unpredictable. Is there a way to prevent this ? Is...
6
by: Flip | last post by:
I'm reading the O'Reilly's Progamming C# book and I have a question about array bounds checking. On page 174, near the top, they show an example where c# does indeed to array bounds checking cause...
8
by: Brendan | last post by:
There must be an easy way to do this: For classes that contain very simple data tables, I like to do something like this: class Things(Object): def __init__(self, x, y, z): #assert that x,...
21
by: jacob navia | last post by:
Many compilers check printf for errors, lcc-win32 too. But there are other functions that would be worth to check, specially memset. Memset is used mainly to clear a memory zone, receiving a...
4
by: Patient Guy | last post by:
Does anyone have any coding rules they follow when doing argument checking? When arguments fail during check, do you return from the call with an ambiguous return value, or do you throw...
125
by: jacob navia | last post by:
We hear very often in this discussion group that bounds checking, or safety tests are too expensive to be used in C. Several researchers of UCSD have published an interesting paper about this...
11
by: Bryan Crouse | last post by:
I am looking a way to do error checking on a string at compile time, and if the string isn't the correct length have then have the compiler throw an error. I am working an embedded software that...
7
by: CaptainnFungi | last post by:
Hi All, I am very new to C and have been working my way through a few C books with the aim of getting more knowledge in programming. However I have hit a wall and I am not sure how to get over it....
7
by: polas | last post by:
Afternoon everyone. I have a quick question about standard C. Generally speaking, in my experience, whenever one accesses an array there is never any bounds checking done (either statically...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.