The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Ignore a particular element?
Discuss Ignore a particular element? in the C Programming forum on Dev Shed. Ignore a particular element? C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 3rd, 2012, 04:53 AM
|
|
Registered User
|
|
Join Date: Feb 2012
Posts: 24
Time spent in forums: 6 h 27 m 36 sec
Reputation Power: 0
|
|
|
Ignore a particular element?
Hello,
i have a small problem in this function code.I want when the IN[n]+1 become bigger than 4 to ignore in this particular n the P[n].VALUE and P[n].LINE.
Can you help me?
Code:
int compair_value()
{
int min,i,c,j;
for(n=0;n<4;n++){
IN[n]=0;
}
for(c=0;c<20;c++){
for(n=0;n<4;n++){
IN[n]=P[n].LINE;
P[n].VALUE=A[n][IN[n]];
}
min=P[0].VALUE;
for(j=0;j<4;j++){
if(min>P[j].VALUE)
{
min=P[j].VALUE;
}}
for(n=0;n<4;n++){
if(min==P[n].VALUE){
P[n].LINE=IN[n]+1;
B[c]=P[n].VALUE;
}}
}
}
|

December 3rd, 2012, 05:02 AM
|
 |
Contributed User
|
|
|
|
It would help if you could indent code.
Code:
int compair_value()
{
int min, i, c, j;
for (n = 0; n < 4; n++) {
IN[n] = 0;
}
for (c = 0; c < 20; c++) {
for (n = 0; n < 4; n++) {
IN[n] = P[n].LINE;
P[n].VALUE = A[n][IN[n]];
}
min = P[0].VALUE;
for (j = 0; j < 4; j++) {
if (min > P[j].VALUE) {
min = P[j].VALUE;
}
}
for (n = 0; n < 4; n++) {
if (min == P[n].VALUE) {
P[n].LINE = IN[n] + 1;
B[c] = P[n].VALUE;
}
}
}
}
> I want when the IN[n]+1 become bigger than 4
So how about
Code:
if ( IN[n]+1 <= 4 ) {
// do stuff
}
|

December 3rd, 2012, 05:16 AM
|
|
Registered User
|
|
Join Date: Feb 2012
Posts: 24
Time spent in forums: 6 h 27 m 36 sec
Reputation Power: 0
|
|
|
thank you for the quick answer but IN[n]<=4 do what??
|

December 3rd, 2012, 05:39 AM
|
 |
Contributed User
|
|
|
|
|
> thank you for the quick answer but IN[n]<=4 do what??
If you're asking that, how did you manage to write all that code to begin with!?
|

December 3rd, 2012, 06:22 AM
|
|
Registered User
|
|
Join Date: Feb 2012
Posts: 24
Time spent in forums: 6 h 27 m 36 sec
Reputation Power: 0
|
|
|
Your answer is very general and wrong!
|

December 3rd, 2012, 06:37 AM
|
 |
Contributed User
|
|
|
|
Well I guess that's a function of your vague and ill-defined question.
We can't compile it, because you don't declare IN, or what the structure behind it is.
We can't run it, because there is no data.
Your vaguest of questions can only be interpreted as "how do I do an if statement". If you're still stuck, then read your C book.
Then swing by here before asking another question
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|