why it does not enter the if statement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-06 9:11 PM
I have a code made to check an if statement and then perform something. here is the if statement
for(int j=0;j<10;j++)
{
if(removed_Num==USERS[j])
{ //do something}
}
USERS[j] is a 13 element array and removed_Num is also a 13 element array. I've check in the debug mode and saw USERS[j] is equal with removed_Num. but it doesn't enter the if statement. why is that?
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-06 11:30 PM
Clive1 is right.
If you compare two array with all indexes, you need select index one by one and compare them.
​
I wrote a example,
- Int Issamearray;
- for(int j=0;j<10;j++)
- {
- Issamearray = false;
- if(removed_Num[j] ==USERS[j])
- { Issamearray = True;}
- }
- If (Issamearray == True)
- {
- //do something}
- } ​
​Not; if you make this with while not for, it can will work faster.
I hope you understand clearly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-06 10:51 PM
As described that isn't how C works.
The comparison here is of the address of an array vs the element in a second array. You basically ask it to compare apples and oranges, which usually they don't.​
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-06 11:07 PM
so what's the right way to do it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-06 11:30 PM
Clive1 is right.
If you compare two array with all indexes, you need select index one by one and compare them.
​
I wrote a example,
- Int Issamearray;
- for(int j=0;j<10;j++)
- {
- Issamearray = false;
- if(removed_Num[j] ==USERS[j])
- { Issamearray = True;}
- }
- If (Issamearray == True)
- {
- //do something}
- } ​
​Not; if you make this with while not for, it can will work faster.
I hope you understand clearly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-09-07 12:00 AM
thank you all guys! you're amazing!:)
