[Solved] Finding commas inside a char array


clearing the array , which would have some values in it, would solve this, and this is because when you print it, and there are some other values in it, you get them printed too

  for( int i = 0; i < maxL;  ++i )
   newdata[i] = (char)0;

solve it completely .

EDIT:
And to anyone who needs, this is the complete function that works :

char * getHeader( char localString[], int seperatorNum)
{


   int maxL=50;
   const char seperator=":";
   char newdata[maxL];
   int counter=0;
   int divider=0;
   //clear array when it has garbage it added
   for( int i = 0; i < maxL;  ++i )
      newdata[i] = (char)0;

   for(int k=0;k<maxL;k++)
   {


        if ( localString[k]==  seperator   )
       {

           counter++;
           divider=k+1;
           if(counter==seperatorNum)
           {   return newdata;     } 
       }
         if(  (seperatorNum-1) ==counter)
             newdata[k-divider]=localString[k];

   }


 }

1

solved Finding commas inside a char array