Thread: comparing and counting

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    11

    comparing and counting

    hi,
    I'm pulling my hair on this one already a long time...
    if someone can give me some advice on this one ... thanks
    Because my prog. is 1500+ lines i only give the piece that is important....

    What happens :
    1 -> I have files filled with numbers in one line....
    2 -> I've separated them till i have an array f_sep_nums[a][b] (this is an char array...)
    3 -> I've static a static array ne.Nof[m][o]
    4 -> I compare all the numbers in ne.Nof[m][o] with f_sep_nums[a][b]
    5 -> every time there is a match it will add 1 to the array countN[m][p]++

    Everything works fine here... but now i want it to count max 1 of a row...
    so I can calculate a percentage a row...

    What do i need :
    1 -> how can I change or add some code so I get countN[m][p]++ to only count 1 for every row if there is a match or multiple matches in a row, and of course 0 for that row if there is no match

    Code:
     
     for(a = 0; a <=totrows; a++)
        {
          for(b=1;b<=10;b++)
    	{
    	  for(m=0;m<=99;m++)
    	    {
    	      for(o=1;o<=3;o++)
    		{
    		  if(strcmp(f_sep_nums[a][b], ne.Nof[m][o]) == 0)
    		    {
    		      countN[m][p]++;
    		    }
    		}
               }
           }
       }
    thanks
    Last edited by Tordne; 08-25-2009 at 05:05 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    One of those loops is a loop over the rows. (Hint: it might be the one with "rows" in it.) Make sure your count gets incremented only once in that loop.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    11
    Quote Originally Posted by tabstop View Post
    One of those loops is a loop over the rows. (Hint: it might be the one with "rows" in it.) Make sure your count gets incremented only once in that loop.
    the array to count from for a match....
    the loop over the rows is a
    the loop over the colums or numbers in a row is b

    the static array with 99 rows and 3 numbers every row
    m for the rows
    o for the numbers in a row....

    like i said i got no clue otherwise I would have asked
    I tried this but it didn't work
    Code:
     if(strcmp(f_sep_nums[a][b], ne.Nof[m][o]) == 0)
    		    {
                         if(a != a++)
                               {countNN[m][pp]++;
                         countN[m][p]++;
                         }
    Last edited by Tordne; 08-25-2009 at 05:25 PM.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you only want a count of 1 if there has been one or more matches, and a count of zero if there has been no matches, just change this:

    Code:
    countN[m][p]++;
    to this:

    Code:
    countN[m][p] = 1;
    Be sure and set your countN[][] array to zero before you go into this loop.

    That sounds too easy to be your answer, but that is what you asked.

  5. #5
    Registered User
    Join Date
    Aug 2009
    Posts
    11

    found a solution for the counter

    Quote Originally Posted by Adak View Post
    If you only want a count of 1 if there has been one or more matches, and a count of zero if there has been no matches, just change this:

    Code:
    countN[m][p]++;
    to this:

    Code:
    countN[m][p] = 1;
    Be sure and set your countN[][] array to zero before you go into this loop.

    That sounds too easy to be your answer, but that is what you asked.
    after a good night sleep i found it.... when i looked back at your replies.

    at the end of loop "a" when he has checked all the numbers of the row...
    I make a little loop over "m" --> If (countN[m][p] > 0 ) --> if it is bigger it has to increase a new counter countNN[m][pp]++; and countN[m][p] = 0;
    now he'll count max 1 for a row but i lost the counter for the whole array...
    make a third counter that doesn't reset to 0 will do it, must be a more clean way to write this, but for the moment it will do...

    thanks for the replies

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String - word counting!
    By shardin in forum C Programming
    Replies: 2
    Last Post: 07-11-2007, 05:08 PM
  2. comparing int to newline character
    By RedZippo in forum C++ Programming
    Replies: 5
    Last Post: 05-13-2004, 06:37 PM

Tags for this Thread