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

  • SEARCH
  • Home
  • 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 7086361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:32:25+00:00 2026-05-28T07:32:25+00:00

#include <stdio.h> #include <string.h> int main(void) { char s[]= 9; printf(atoi = %d,atoi(s)); system(pause);

  • 0
#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[]= "9";
    printf("atoi = %d",atoi(s));
    system("pause");
    return 0;
}

int atoi(char s[])
{
    int i=0,n=0;

    for(i;s[i]>='0' && s[i]<='9';i++)
        n=10*n + (s[i]-'0');
    return n;

}

In above program it gave me result 9 as per program it should print ascii value for 9
and I don’t understand what this for loop does.

for(i;s[i]>='0' && s[i]<='9';i++)
n = 10*n + (s[i]-'0');
  • 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-28T07:32:25+00:00Added an answer on May 28, 2026 at 7:32 am

    Lets break this down:

    for (i;
    

    This creates a for loop, with the loop variable i. This is not necessary, but more of a coding style.

    s[i] >= '0' && s[i] <= '9'
    

    This checks to make sure that the character at that index is inside the range for a decimal character (0 – 9), and if it is not, it exits the loop, then returns the number.

    i++
    

    After the loop runs, this increases the index you are checking in the string by one.

    n = 10 * n
    

    This adds an extra digit to ‘n’ by multiplying by 10, because you know that if you have one more character in your number, it must be multiplied by ten (say I start parsing 100, I read the first two strings, and have 10, there is one more character, so I multiply by ten to get 100.

    + (s[i]-'0');
    

    This adds the next digit to ‘n’, the result, which is determined by subtracting the character at the current index by ‘0’, which, when in the range of 0 – 9, returns the integer for that number (if this confuses you, take a look at an ASCII Chart.

    Hopefully this helped you understand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <stdio.h> #include <string.h> int main(void) { char *w; strcpy(w, Hello Word); printf(%s\n, w);
#include <string.h> #include <stdlib.h> #include <stdio.h> int main(void) { unsigned char *stole; unsigned char
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { // int char str[40],ch; FILE*fp,*fp1,*fp2; fp=fopen(ide_input,w); fp1=fopen(error_log,w); fp2=fopen(lex_output,w);
#include<stdio.h> #include<zlib.h> #include<unistd.h> #include<string.h> int main(int argc, char *argv[]) { char *path=NULL; size_t size;
#include <stdio.h> #include <ctype.h> #define STRING_LEN 500 void stripspaces(char, char, char); int main(void) {
Consider the following code: #include <stdio.h> int main (void) { char str1[128], str2[128], str3[128];
So basically: #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> int main(void){ //test strrev
I have the following test application: #include <stdlib.h> #include <string.h> #include <stdio.h> int main(void){
Please see this piece of code: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int i
The following code outputs Illegal seek: #include <stdio.h> #include <errno.h> #include <string.h> int main()

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.