5 Replies - 1088 Views - Last Post: 04 March 2011 - 02:48 PM Rate Topic: -----

#1 zakhussain299  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 25-February 11

check condition for end of integer array

Posted 02 March 2011 - 05:57 PM

I am writing a program in which i need a check condition to check the end of an integer array in a while loop, can anyone help me out with this, i tried

while(outmsg[status.MPI_TAG]!=NULL)
{
  ......
}



but it says that the pointer cannot be assigned to an integer

This post has been edited by zakhussain299: 02 March 2011 - 06:00 PM

Is This A Good Question/Topic? 0
  • +

Replies To: check condition for end of integer array

#2 BetaWar  Icon User is online

  • #include "soul.h"
  • member icon

Reputation: 1148
  • View blog
  • Posts: 7,151
  • Joined: 07-September 06

Re: check condition for end of integer array

Posted 02 March 2011 - 06:12 PM

That is the problem with an integer array. Unlike a c style string (which has a specific character letting the computer, and you know when you have hit the end), an integer array has nothing of the sort, unless you have added one yourself, though there is a chance that that will appear when people are inputting numbers making it unreliable unless you don't allow the value you are looking for. The easiest way to accomplish what you are attempting to do is simply keep a variable around which has the number of integers in your array.

It is also important to note that NULL is a pointer, and if you attempt to compare a pointer with a non-pointer you have to do the appropriate cast.

Hopefully that makes sense.
Was This Post Helpful? 0
  • +
  • -

#3 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: check condition for end of integer array

Posted 02 March 2011 - 06:24 PM

Can you use a negative integer to flag the end?
Was This Post Helpful? 0
  • +
  • -

#4 zakhussain299  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 25-February 11

Re: check condition for end of integer array

Posted 02 March 2011 - 06:54 PM

ok...i have added "25" to the end of the array and i m trying to make that as a flag so my code now looks like

while(inmsg[m+1]!=25)
{
   ....
}



but still its not breaking from the loop when i want it to....
Was This Post Helpful? 0
  • +
  • -

#5 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3102
  • View blog
  • Posts: 19,142
  • Joined: 14-September 07

Re: check condition for end of integer array

Posted 02 March 2011 - 09:25 PM

Post the loop contents.
Was This Post Helpful? 0
  • +
  • -

#6 zakhussain299  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 25-February 11

Re: check condition for end of integer array

Posted 04 March 2011 - 02:48 PM

got it working...thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1