Counting number of elements in an array which aren't empty?

i tried using this method to count an array which has 100 elements but it doesn't go past the while statement which i cant figure out?
public static void countCust()
int cntr = 0;
int z;
for (int c = 0; c < 100; c++)
while (customer[c].indexOf(':') != -1)
cntr++;
javax.swing.JOptionPane.showMessageDialog(null, "There are " + cntr + " customers on record");
}

Are you getting NullPointerExceptions?
Are you sure customer[] has been allocated?
Are you sure each element in the array is non-null?
BTW, it's traditional to use variables in loops that are closer to their mathematical usage. I mean, for an array index, usually you'd use variables named i or j, unless the indices map to coordinates in space, in which case you'd use x, y, and z.
If neither of these is applicable, use a variable with a more meaningful name.

Similar Messages

  • Total number of elements in an array

    Hello, 
    I am trying to count the total number of elements in an array. 
    I have a simulate signal VI, that simulates a square pulse, this is being written into an excel file using the write to measurement VI, all for a given period of time. 
    I want to further chop a window of the signal depending on different paramenters (a trigger, which I intend to incorperate later, for now I am working of learning how to chop the data)
    In order to chop the data I need to know the array size, I use the array size funtion, I right click on the appeneded array in the front pannel and click show last element (array size -1) it doesnt match with the number of rows in the excel file written by the write to measurement VI, in fact it macthes with the "number of samples" I selected in the simulate signal VI. 
    Am I doing something wrong? 
    Why is there a miss match??
    I have attached my VI, Please help
    Thank You
    SP
    Attachments:
    FlashERGTrialVI 150218.vi ‏93 KB

    Hello RavensFan
    Thank you for the reply, I did incorperate the changes, but the same number is displayed in the indicator.  I've attahced my VI
    SP
    Attachments:
    FlashERGTrialVI 150218.vi ‏106 KB

  • Number of elements in an array

    Hi,
    I have been trying looking for a simple function to get number of elements is an array. Have gone though older posts but could not find answer to it.
    The function should work for following examples:
    char* name = "nInstruments"
    float state[] = {1.0, 2.0}
    I tried sizeof but it returns size of "type" in bytes. For example in example 2, it will just return 4.
    Does someone know a way to do it?
    Ciao
    RB
    Solved!
    Go to Solution.

    RB,
    In C, if an array is declared on the heap, as opposed to on the stack as in your example above, the sizeof operator only returns the length of the pointer that holds the array which, in a 32-bit program, is always 4 bytes. This is because the compiler has no way of knowing how many elements that array actually holds. The length of a C array is a fairly fluid concept. The real size of the array is usually determined by some memory manager somewhere (usually, malloc), but it's not something that the language itself has anything to say about.
    When you declare the entire array as a local variable, however, the compiler must create room for the full array on the stack, and therefore it is able to return the true size of the array via the sizeof operator. (The same is true if it's a global variable, even if it's not on the stack, in that case)
    For this reason, using the sizeof(array) / sizeof(array[0]) trick is iffy. It might work, or it might not work, depending on how the array is declared.
    For this reason, most C APIs that accept or return arrays, will usually also have some method of communicating the length of the array, usually as an additional parameter of some function. Because .NET APIs usually have no need to do this, the C wrapper for a .NET API in CVI does this for you when it handles .NET arrays. For example, here's what a function signature might look like:
    int CVIFUNC Namespace1_Class1_Test1DArrays (Namespace1_Class1 __instance, int * inA, int __inALength, char *** outA, int * __outALength, Namespace1_Class2 ** refA, int * __refALength, double ** __returnValue, int * ____returnValueLength, CDotNetHandle * __exception);
    Luis

  • How Do I Print the Number of Elements in An Array

    How do I print: "There are ____ number of elements in the array?"

    If you have a String holding a sentence, and if you split on non-empty sequences of whitespace (if the string has newlines in it, you'd probably need to pass the argument that makes \s match newlines, and for that you would probably need to use java.util.regex.Pattern -- see the docs and try some tests), when you'd get an array of Strings that were the non-whitespace parts of the original String. That makes for a reasonably good definition of the words in the sentence, although you could arguably get into some gray areas (does "isn't" count as one or two words? Does a sequence of numbers or punctuation qualify as a word?). In that case, counting the number of elements in the resulting array of String. using .length, would be a reasonable way to get the number of words in that sentence, yes.
    But rather than asking for confirmation on forums, why don't run some tests?
    import java.io.*;
    public class TestWordCount {
      public static void main(String[] argv) {
        try {
          BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
          String line;
          while((line = in.readLine()) != null) {
            int count = // your code here, to count the words
            System.out.println("I see " + count + " words.");
        } catch (IOException e) {
          e.printStackTrace();
    }Put your word-counting code in there, then run it from the command line. Type in a sentence. See how many words it thinks it found. Does it match with your expectation, or the examples given (hopefully) with your homework assignment?

  • Actively changing number of elements in an array

    How do you use a control in the front panel to actively change the number of rows in an array which full of numeric controls?
    Is it possible to have this happen without the program to be running? Thanks for any help.
    Solved!
    Go to Solution.

    Chris B. wrote:
    Is it possible to have this happen without the program to be running? Thanks for any help.
    So you want this to work at edit time? Are you talking about the number of visible elements or are you talking about the actual size of the array (these numbers are unrelated!).
    In order for something to happen, "something" needs to be running. You could run another VI and use scripting to make changes to the array structure.
    You could also make an Xcontrol containing an array and a numeric. Xcontrols are fully operational even if the VI itself is in edit mode.
    If this is a program to run standalone, simply make sure the program is always running, but is in an idle state if nothing needs to be done at the moment. Now you can handle resize events if needed.
    LabVIEW Champion . Do more with less code and in less time .

  • Enable the Number of Elements in the Array

     
    once the Un-Initializing the array(1D or Multi) Placed ,we can not select the Number of element to Enable.
    byproviding the below option we can easily Enable the Elements in any array dimention.

    Already possible by typing a value (usually the default value) once you've set the indices to the size you want to initialize

  • Count number of elements

    Dear All,
    probably there is somethin wrong in how I use the xmlsequence...
    I have a table called XML_WORD with a fiels with XML Docs called XML_CONTENT
    As you see what I want to try is to count the number of elements into a certain node...
    What is wrong in the statement I wrote?
    Thanks a lot and hope this will solve my problem with XML_SEQUENCE.
    Stefano
    SQL> desc XML_WORD
    Name Null? Type
    ID NUMBER
    WORD_ID CHAR(40)
    LEMMA CHAR(60)
    XML_CONTENT SYS.XMLTYPE(XMLSchema "http:
    //word.xsd" Element "word")
    STORAGE Object-relational TY
    PE "word5828_T"
    IS_ACTIVE NUMBER
    RELEASE_CODE NUMBER
    SQL> edit
    Wrote file afiedt.buf
    1 select count(*)
    2 from XML_WORD,
    3 table (xmlsequence(extract(XML_CONTENT,'count(/word/noun/sense[1]/collocation')))
    4* where ID=9973
    SQL> /
    from XML_WORD,
    ERROR at line 2:
    ORA-31013: Invalid XPATH expression

    Sure - thanks for the time and thoughts.
    I am using the schema you helped me with a bit ago, Re: unique constraint defined in xsd
    I have tried to create a stored function that will return the number of maps per username and also one that will return the map elements based on a passed username.
    CREATE OR REPLACE FUNCTION COUNTMAPS(userName varchar2)
    return number
    as numMaps number;
    begin
    select count(*)
    into numMaps
    from mapsetxml,
    table (xmlsequence(extract(object_value,'/mapset/map')))
    where existsNode(object_value, '/mapset[" ' ||userName|| ' "]')=1;
    return numMaps;
    end;
    I get the total number of maps, not the number of maps associated with a particular user.

  • Iterating through every other (or specified number) of element in an array using a for loop

    I am trying to go through an array but instead of autoindexing I want to skip every other element or maybe a number of elements that will be specified for the user.
    Basic functionality that I want to acheive is the following in C code.
    int temp_var = 10;
    int i=0;
    for(i=0; i<=1000; i=i+temp_var)
    I am very new to LabVIEW and I did not know how to use internal variables.
    Can this be acheived using shift registers?
    I am attaching the code I currently have for this. Let me know what you think.
    Thanks guys.
    Solved!
    Go to Solution.
    Attachments:
    24_Sep_NchanNSamp.vi ‏44 KB

    tbob wrote:
    I have been asking for a new For Loop style that would allow us to specify start, stop, and step conditions, but it seems that many people are just not for this idea.  Don't know why?
    See here.
    I wouldn't say there aren't many people for it.  The idea you linked to was one of a half dozen of basically duplicate ideas, including another one of your own.
    These two ideas have a fairly large number of kudoes showing people want the idea.
    Smart Iterators with Loops
    For Loop Increment

  • Counting number of elements

    Suppose you have xml that has repeated nodes, like:
    <foo>
    <bar>some</bar>
    <bar>stuff</bar>
    <bar>here</bar>
    </foo>
    What query would I give to count the number of <bar> elements? Also, is there a query that would concatenate the contents of all of them?
    Thanks.

    This is covered in the standard XDB Demo
    select count(*)
    from purchaseorder,
    table (xmlsequence(extract(object_value,'/PurchaseOrder/LineItems/LineItem'))) l

  • Fill an array which is initially empty

    Hi,
    My array is defined by the variable:
    <variable name="array" element="imp1:array">
    where the array is:
    <element name="array" type="tns:ArrayType"/>
    <complexType name="ArrayType">
    <sequence>
    <element name="offer" type="tns:LoanOfferType" maxOccurs="unbounded" />
    </sequence>
    </complexType>
    I want to fill this variable with one value at a time through a while activity and without using a Java exec.
    I read the DataManipulation Tutorial and the Array sample but they don't help me!
    Which ora:function should I use? and in which assign construct?
    Because the following snippet returns a bpws:selectionFailure fault:
    <assign
    <copy>
    <from variable="inServiceOffer" part="payload" query="/auto:loanOffer"/>
    <to variable="array" query="/imp1:offert[bpws:getVariableData('index')]"/>
    </copy>
    </assign>
    Where 'index' is an integer variable.
    The problem is that the child node doesn't exist, so the above query returns a bpws:selectionFailure fault.
    Maybe I can use the ora:addChildNode or ora:appendToList function, but I don't know where...
    Thank you for your reply

    What I want to say is that with the ora:addChildNode function I can add a DOM child element without any relationship with the child type defined in a XML Schema array. In short, my array could be the follow:
    <element name="array" type="tns:arrayType"/>
    <compexType name="arrayType">
    <element name="para" type="anyURI:NCName" maxOccurs="unbounded"/>
    </complexType>
    and the following snippet works all the same!!!
    <assign name="FillArray">
    <copy>
    <from expression="ora:addChildNode(bpws:getVariableData('array','/imp1:array'),bpws:getVariableData('inServiceOffer','payload','/auto:loanOffer'))">
    </from>
    <to variable="array" query="/imp1:array"/>
    </copy>
    </assign>
    In fact, in the above example, the source child type is "auto:loanOfferType" while the target child type can be "anyURI:anyType".
    So I think the ora:addChildNode function doesn't fill an array but adds children of any type to an element.
    Can you help me?
    Thanks and sorry for my english.

  • Set number of elements in a two dimensional array

    Hi,
    Does anyone know how to set the number of elements in a two dimensional array directly in teststand.
    To set a one dimsional array is simple:
    SetNumElements( locals.somearray,4)
    Is there a method to do this for a two dimensional array?
    Sean

    From the help file (TestStand 4.2.0):
    PropertyObject.SetNumElements
    SetNumElements Method
    Syntax
    PropertyObject.SetNumElements ( numElements, options = 0)
    Purpose
    Sets the number of elements of a single dimensional array.
    Remarks
    This method is only valid for single dimensional arrays. The elements in the array retain their values. Use the PropertyObjectType.ArrayDimensions property to set the number of elements in each dimension of a multi-dimensional array.
    Parameters
    numElements As Long
    [In] New number of elements for the array.
    options As Long
    [In] Pass 0 to specify the default behavior, or pass one or more PropertyOptions constants. Use the bitwise-OR operator to specify multiple options.
    This parameter has a default value of 0.
    So you could use, for example: Locals.MultidimensionalArray.Type.ArrayDimensions.SetBounds({1,0},{3,4}) to set an array to have three dimensions (1,2,3), each with five elements (0,1,2,3,4).

  • Get the number of elements in Array

    Hi everyone,
    Could anyone give me idea on how to get the number of elements in an Array (not number of rows) ?
    I tried to find that in both property node and array functions but nothing.
    Thanks,
    -Kun

    You are going to have to provide some proof that the Array Size does not work correctly. Right click on the input to it and select 'Create Indicator'. Run the VI. Go to the front panel and select 'Edit>Make Current Values Default'. Save the VI and attach it to your post.
    You can also check the array size yourself. Right click on the index display of the array and select 'Advanced>Show Last Element'. I will bet you that number shown is equal to Array Size -1.
    p.s. The number of elements in an array is equal to the number of rows in a 1D array. If you define the number of elements as anything else, you are mistaken.
    Message Edited by Dennis Knutson on 04-21-2009 10:40 AM

  • Number range elements

    Hello,
    I've tried to maintain number ranges for controlling documents. Transaction KANK.
    The system displays a message: No elements exists for the object/sub-object ESCO (which is my controlling area)
    The problem are missing number range elements (bus.transactions) to which I want to assign number ranges.
    Does anybody know how to fill these missing elemnts, so that I could assign number ranges?
    Thanks in advance,
    Marija

    Hello
    There is a related SAP note available on this.
    Just go to SAP Note search, give the error message number, you would get the note.
    Its a correction program that has to be run.
    Try this program RKCORR01., if it doesnt work then go ahead and go by the above process.
    Regards
    Anantha

  • How to find the elements of an array

    I want to find the number of elements in an array, and I can't find the tutorial that shows how to find it. If anyone could point me in the right direction, it would be greatly appreciated.

    warnerja wrote:
    flounder wrote:
    DrLaszloJamf wrote:
    You mean x.length?<pbs>
    Depends upon your interpretation of "number of elements in the array"
    int[] numbers = new int[10];
    numbers[0] = 42;
    numbers[1] = 666;Number of elements in the array is 2 not 10.
    </pbs>If you used something other than a primitive type for the array element type you could have a case. A value of integer zero for the other elements is still a value, so there are indeed 10 elements there.Even if it were not primitive, every element would have a value. That value would either be null or a reference.

  • Function: create an array through initial/step/number of elements

    Does LabVIEW have the function which directly creates an array by giving intial value, step and number of elements?
    thanks,
    WT
    Solved!
    Go to Solution.

    You can use the Build Waveform function.
    It is located in the Programming >> Waveform palette
    Cory K

Maybe you are looking for

  • Eliminating Download tab in gallery view window

    Is there a way to prevent people from downloading photos? I am building a site for my photography business and I didn't choose sharing option. I found no way to download the photos until I saw the download button in the secondary navigation bar when

  • Sequence Numbers within IFS!!

    Guys I wish to maintain and generate an automatic number. How can I do this? Here is the scenario, when a user log into IFS they will input information that needs to be held in a Temp table or a group of objects. But, there need to be some automatic

  • Refresh Cube Error

    Oracle Analytic Workspace Manager 9.2.0.4 Oracle database 9.2.0.6 I have a cube with data pre-aggregated using NASKIP2. Everything worked fine until we needed to update our data (already updated in the relational tables). I tried to refresh the analy

  • How to book return costs on AP Creditnote

    Hello, How do you book return costs on a AP Creditnote. Customers receives AP Creditnote but has to pay some restocking costs for the items. Customers does not want to work with discount in the AP Creditnote It is also not possible to book negative a

  • Empêche la fermeture

    bonjours, j'ai constater qu'itune 10.5 enpeche mon mac de s'eteindre. En effect quand je decide de fermer ma session mon ecran devient gris et un petit cercle gris au centre de l'ecran tourne indefiniment. je doit a chaque fois forcer la fermeture en