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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:20:18+00:00 2026-05-13T21:20:18+00:00

given a string say a 19 b c d 20, how do I test

  • 0

given a string say ” a 19 b c d 20″, how do I test to see if at that particular position on the string there is a number? (not just the character ‘1’ but the whole number ’19’ and ’20’).

char s[80];
strcpy(s,"a 19 b c d 20");

int i=0;
int num=0;
int digit=0;
for (i =0;i<strlen(s);i++){
    if ((s[i] <= '9') && (s[i] >= '0')){    //how do i test for the whole integer value not just a digit

        //if number then convert to integer
        digit = s[i]-48;
        num = num*10+digit;
    }

    if (s[i] == ' '){
        break; //is this correct here? do nothing
    }
    if (s[i] == 'a'){
       //copy into a temp char
    }
}
  • 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-13T21:20:19+00:00Added an answer on May 13, 2026 at 9:20 pm

    These are C solutions:

    Are you just trying to parse the numbers out of the string? Then you can just walk the string using strtol().

    long num = 0;
    char *endptr = NULL;
    while (*s) {
      num = strtol(s, &endptr, 10);
      if (endptr == s) { // Not a number here, move on.
        s++;
        continue;
      }
      // Found a number and it is in num. Move to next location.
      s = endptr;
      // Do something with num.
    }
    

    If you have a specific location and number to check for you can still do something similar.
    For example: Is ’19’ at position 10?

    int pos = 10;
    int value = 19;
    if (pos >= strlen(s))
      return false;
    if (value == strtol(s + pos, &endptr, 10) && endptr != s + pos)
      return true;
    return false;
    

    Are you trying to parse out the numbers without using any library routines?

    Note: I haven’t tested this…

    int num=0;
    int sign=1;
    while (*s) {
      // This could be done with an if, too.
      switch (*s) {
        case '-':
          sign = -1;
        case '+':
          s++;
          if (*s < '0' || *s > '9') {
            sign = 1;
            break;
          }
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
          // Parse number, start with zero.
          num = 0;
          do {
            num = (num * 10) + (*s - '0');
            s++;
          } while (*s >= '0' && *s <= '9');
          num *= sign;
          // Restore sign, just in case
          sign = 1;
          // Do something with num.
          break;
        default:
          // Not a number
          s++;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No such built-in helper exists, but it's trivially easy to… May 16, 2026 at 4:36 pm
  • Editorial Team
    Editorial Team added an answer It should give you a TypeError exception -for trying to… May 16, 2026 at 4:36 pm
  • Editorial Team
    Editorial Team added an answer You could use aubquery to calculate a running total. In… May 16, 2026 at 4:35 pm

Trending Tags

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

Top Members

Related Questions

Is there a way of printing out every character that satifies a given regular
Generating a truly random string of a given length is a fairly straightforward (and
First of all, I do know about the Fisher-Yates shuffle. But lets say for
Lets say I have a simple ecommerce site that sells 100 different t-shirt designs.
I have an app that creates and stores a session with a given start
I'm writing some code that takes a report from the mainframe and converts it
Given the following text /feeds/tag/remote-desktop 1320 17007 22449240 /feeds/tag/terminal-server 1328 15805 20989040 /foo/23211/test 1490
I've current got a line at the top of all my tests that looks
Is there some limit to what I can select in a range via VBA?
I have a buffer of raw values, say, void* buffer or better, char* buffer

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.