Another C question

Posted by maddy on Stack Overflow See other posts from Stack Overflow or by maddy
Published on 2010-04-29T11:51:54Z Indexed on 2010/04/29 11:57 UTC
Read the original article Hit count: 317

Filed under:

Hi all, I have a piece of code shown below

      #include <stdio.h>
      #include <stdlib.h>
      void Advance_String(char [2],int );
      int Atoi_val;
      int Count22;
      int Is_Milestone(char [2],int P2);
      char String[2] = "00";
      main()
      {
         while(1)
         {

           if(Is_Milestone(S,21==1)
           {
                 if(atoi(S)==22)
                 {
                     Count_22 = Count_22 + 1;
                 }
           }
           Atoi_val = atoi(S);
          Advance_String(S,Atoi_val); 
         }
       }
      int Is_Milestone(char P1[2],int P2)
      {
             int BoolInit;
             char *Ptr = P1;

             int value = atoi(Ptr);
             BoolInit = (value > P2);
             return BoolInit;
      }
     void Advance_String(char P1[2],int Value)
     {

             if(Value!=7)
             {
                 P1[1] = P1[1]+1;
             }
             else
             {
                 P1[1] = '0';
                  P1[0] = P1[0]+1 ;
             }
     }

Now my problem is Count22 never increments as the char increments never achieves the value 21 or above.Could anyone please tell me the reason for this unexpected behaviour?My question here is to find the value of Count22.Is there any problem with the code?

             Thanks and regards
             Maddy

© Stack Overflow or respective owner

Related posts about c