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 7738735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:20:38+00:00 2026-06-01T08:20:38+00:00

Sorry for the confusing question, but what I’m trying to do is store an

  • 0

Sorry for the confusing question, but what I’m trying to do is store an array in a variable.

I want to store the numbers in *value so that instead of int value: -12118433669 it will be int value: 123456789.

OUTPUT

123456789
array: '123456789' int value: -1218433669
0001234
array: '0001234' int value: -1218433669
5
array: 'abc5xyz' int value: -1218433669

array: '' int value: -1218433669
987654321
array: '987654321' int value: -1218433669

SOURCE

#include <stdio.h>

MyFNatoi(char *numArray, int *value) {

    int i;

    for (i = 0; i < 10; i++) {
        if (numArray[i] > 47 && numArray[i] < 58) {
            printf("%c", numArray[i] - 0);
        }
    }

}

int main() {

    char numbers[5][10] = { "123456789", "0001234", "abc5xyz", "", "987654321" };
    int i, value;

    for(i = 0; i < 5; i++) {
        MyFNatoi(numbers[i], &value);
        printf("\narray: '%s' int value: %d\n", numbers[i], value);
    }
    return 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-06-01T08:20:40+00:00Added an answer on June 1, 2026 at 8:20 am

    I propose this function:

    void MyFNatoi(const char *str, int *value)
    {
        if (value == NULL)
            return;
    
        *value = 0;
    
        if (str != NULL)
        {
            int negative = 0;
    
            if (*str == '-')
            {
                negative = 1;
                str++;
            }
    
            while (*str && isdigit(*str))
            {
                *value = (*value * 10) + (*str++ - '0');
            }
    
            if (negative)
                *value *= -1;
        }
    }
    

    It handles negative numbers, and only checks leading digits (so wont make a number out of "abc123def456" for example).

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

Sidebar

Related Questions

Sorry for such a silly question but Python docs are confusing... Link 1: Queue
Sorry if the title sounds confusing - but this is what I am trying
Sorry for my last question being so confusing, I was confused my self, but
Sorry if that question is confusing, I'm self-learning javascript. I'm dynamically generating image thumbnails
Sorry if the question if confusing, but I'll make it clear here. What I'm
Sorry if the question sounds confusing. My problem is that I am using the
Sorry if this question is confusing. I have inherited a site that is already
Sorry if the question title is confusing. Let me explain further. I am building
Sorry for the confusing title, but it basically says it all. Here's the structures
I'm sorry if the title is quite confusing but I am wondering if it's

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.