It takes a long time for my comp to execute this simple loop.


Now the final do while gives me the problem,even if i use if statement,it takes about 10 secs before displaying the result,which is quite ridiculous.

int counters[255] = {0};

   ifstream in("ut2.txt", ios::binary);
   unsigned char c;
   while( in.read((char *)&c, 1) )
   {   
   counters[c]++;
   }

   int h1=0,hm=0;

   
   int da=0;
   for(hm=0;hm<256;hm++)
   {
   da=counters[hm]+da;
   }
   da=da/256;




   do
   {
   h1=0;   
  
   for(hm=0;hm<256;hm++)
   {
   if(counters[hm]>=da){h1++;}
   }
  
   da--;
   if(h1==192){da++;break;}
   }
   while(h1<=192);

Can i use h1 as the condition for while and change it to 0 in the main loop ?

a loop within a loop.

You are asking it to loop chars + 256 + (256 * 192)
which is
chars+49408;

of course it's gonna take its time

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.