Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 762201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:55:45+00:00 2026-05-14T15:55:45+00:00

I have a piece of code shown below #include <stdio.h> #include <stdlib.h> void Advance_String(char

  • 0

I have a piece of code shown below

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

           if(Is_Milestone(String,21)==1)
           {
                 if(atoi(String)==22)
                 {
                     Count_22 = Count_22 + 1;
                 }
           }
           Atoi_val = atoi(String);
         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 Count_22 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 Count_22.Is there any problem with the code?

Thanks and regards,

Maddy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:55:45+00:00Added an answer on May 14, 2026 at 3:55 pm

    Your code is probably one of the worst pieces of C code i’ve ever seen (no offense, everybody has to learn sometime).

    It has syntax errors (maybe copy/paste problem), logical problems, meaningless obfuscation, bad practices (globals), buffer overflow (atoi used on a char where there is no place to store the terminating zero byte), uninitialized values (Count_22), surprising naming convention (mixed CamelCase and underscore, variables and functions beginning with capital letter), infinite loop, no header and I forget some.

    More, if you want anyone to help you debug this code, you should at list say what it is supposed to do…

    To answer to the original question: why Count_22 is never incremented ?

    Because Is_Milestone is always false (with or without @Jay change). Is_Milestone intend seems to be to compare the decimal value of the string “22” with the integer 21 (or 1, boolean result of 21 == 1) depending on the version).

    It’s logical because of Advance_String behavior. both because String has bad initial value (should probably be char String[3] = "00";) and because of the Value != 7 test. I guess what you wanted was comparing the digit with 7, but atoi works with a full string. Another minor change to achieve that Atoi_val = atoi(String+1); in the body of your loop. Then again you won’t see much as the loop never stop and never print anything.

    If it is a first attempt at an exercice given by some teacher (something like “programming a two digit counter in base 7” or similar). You should consider not using atoi at all and converting characters digit to value using something like:

    digit_value = char_value - '0';
    

    example:

    char seven_as_char = '7';
    int seven_as_int = seven_as_char - '0';
    

    If you can explain what you are really trying to do, we may be able to show you some simple sample code, instead of the horror you are trying to debug.

    EDIT

    It is really more simple with original code…

    After reading the Ada source, I can confirm it is indeed an Ascii based octal counter. The original code is allready of poor quality, and that explains part of the bad quality of the resulting C code.

    A possible direct port could be as following (but still need a serious cleanup to look like native C code… and is quite dumb anyway as it prints a constant):

    #include <stdio.h>
    #include <stdlib.h>
    
    void Advance_String(char * P1)
    {
         if((P1[1]-'0') != 7){
             P1[1]++;
         }
         else{
             P1[1] = '0';
             P1[0]++ ;
         }
    }
    
    
    int Is_Milestone(char * P1, int P2)
    {
        return (atoi(P1) > P2);
    }
    
    main()
    {
        int Count_11 = 0;
        int Count_22 = 0;
        int Count_33 = 0;
        int Count_44 = 0;
        char S[3] = "00";
    
        int cont = 1;
    
        while(cont)
        {
            if(Is_Milestone(S, 10)){
                if(atoi(S) == 11){
                    Count_11 = Count_11 + 1;
                }
                if(Is_Milestone(S, 21)){
                    if(atoi(S) == 22){
                        Count_22 = Count_22 + 1;
                    }
                    if(Is_Milestone(S, 32)){
                        if(atoi(S) == 33){
                            Count_33 = Count_33 + 1;
                        }
                        if(Is_Milestone(S, 43)){
                            if(atoi(S) == 44){
                                Count_44 = Count_44 + 1;
                            }
                            if (atoi(S) == 77){
                                cont = 0;
                            }
                        }
                    }
                }
            }
            Advance_String(S);
        }
        printf("result = %d\n", Count_11 + Count_22 + Count_33 + Count_44);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 472k
  • Answers 472k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Pass the --depth=1 flag to git clone to only get… May 16, 2026 at 3:41 am
  • Editorial Team
    Editorial Team added an answer Take a look at the documentation for Federated Login using… May 16, 2026 at 3:41 am
  • Editorial Team
    Editorial Team added an answer Just put nothing there, you don't need to concatenate anything:… May 16, 2026 at 3:41 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.