Ya only two choices ....
1. Keep track of insertion and deletion as said above.
2. OR Count all over again
Rhohitman
Junior Poster in Training
86 posts since Dec 2007
Reputation Points: 10
Solved Threads: 5
There is no direct way to know how much content you have in an array, versus the size of the array. Except, of course, when your array is of type char and you are using it properly for strings.
Consider an array of integers. Just because some element has a value 0, does that make it an unused element? Zero might well be a valid data value.
Hansels's suggestion to keep track of data as it's entered, and pass that value around along with the array, is about the best general solution.
If I understand what you're doing, when the data is in a string might be a good time to capture the length of the data ( str.size() )
Sounds like an awful lot of work just to reverse the array. Why convert (copy?) from the char array to an int array? Char's are, after all, just small integers.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
Have you tried to use a vector?
You can only get the capacity of the array by this:
sizeof( iarray ) / sizeof( int )
BevoX
Junior Poster in Training
57 posts since Jan 2009
Reputation Points: 77
Solved Threads: 12
How are these integers input? Do you read them from a file?
Since you are storing them to array of char, you can, to a small degree, initially treat them as strings, thus use the strlen( ) function to find how many digits were entered.
Don't forget you have to check for a positive/negative sign.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
You should perhaps read those two value in two strings variables. And then write your own add function which would find there sum.
siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
you can simply use a char array to store the integer array and then use strlen(array) function of string.h lib to get the length,
or you can also break the integer array in to units by using modulus operator and division.
arshad115
Junior Poster in Training
65 posts since Nov 2008
Reputation Points: 7
Solved Threads: 2