C Programming: Created loop to compare strings, but how do I display a 'not found' message? - how do i track dupage county inmates
int i;
for (i = 0, i \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; QUANTITYADDED = i + +)
(
if ((strcmp (STRUCTARRAY, SEARCHVARIABLE)) == '\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ 0')
printf ( "Found% s \\ \\ \\ \\ \\ \\ \\ \\ n", aSearch);
)
This code is on the track list (structarray) with a string variable to compare (searchvaraible) and where to find "structarray ', say that you found.
However, I would be able to an index that sought to delete the user and displays a message if (can not find in the research to be done with if / else?)
I've tried a few pieces of code and not in a position to find a solution.
I had the original with "change structarray ',' searchvariable copied", etc., in the case of my teacher, he thinks the Internet.
Any help is welcome!
4 comments:
Other -----------------
Use as a Boolean variable flag
flag = false
Things \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; your loop here ---- If it is found, the party flag = true>
outside the loop, use the state flag in the decision-making structure to decide whether to display the message
If flag = false then \\ \\ \\ \\ \\ \\ \\ \\ u0026lt calls with None found message>
Sorry to those familiar with the syntax I'm not missing with C
Try this:
int i;
for (i = 0, i \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; QUANTITYADDED = i + +)
(
if ((strcmp (STRUCTARRAY, SEARCHVARIABLE)) == '\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ 0')
break;
)
if (i> QUANTITYADDED) printf ( "not found \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ n");
printf ( "Found% s \\ \\ \\ \\ \\ \\ \\ \\ n", aSearch);
The complete "break" the loop when the item is found. This reduces the operating time N / 2 (two times faster on average).
If i is greater than QUANTITYADDED after the loop, the index of the last and could not find him.
The error you are seeing here is the use of strcmp
Who does not return NULL
0 if both strings are equal
> 0, if a character in string1 is greater than the corresponding characters in string2
(strcmp (eg hello, hello) gives a value> 0)
\\ \\ \\ \\ \\ \\ \\ \\ U0026lt, 0 if channel 2 higher
must
if ((strcmp (STRUCTARRAY, SEARCHVARIABLE)) == 0)
Post a Comment