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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:12:40+00:00 2026-06-03T14:12:40+00:00

i want to extract number string values of a char array. Actually I want

  • 0

i want to extract number string values of a char array. Actually I want to extract numbers embeded in file names for some file management. For example if there is a file name as file21 then i want the decimal number 21 from this file name.

How can i extract these values?

I tried the following but it results in an unexpected value. I think it is as a result of the implicit typecasting from the char to int while doing the arthimetic operation.

char * fname;
cout<<"enter file name";
cin>>fname;

int filenum=fname[4]%10+fname[5];
cout<<"file number is"<<filenum;

NOTE:
The filenamse are strictly in the format fileXX, XX being numbers between 01 and 99

  • 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-03T14:12:41+00:00Added an answer on June 3, 2026 at 2:12 pm

    You need to subtract '0' to get the decimal value of a digit character:

    int filenum=(fname[4]-'0')*10+(fname[5]-'0');
    

    Better yet, you should use atoi:

    int filenum = atoi(fname+4);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to extract some numbers from the input line which is a string.
i want to extract number and add these numbers using Java and String remain
I want to extract the 73 from this string: wiring_details_1-6-73 The numbers 1, 6
I want to extract numbers from a string in PHP like following : if
I want to extract numbers from a string in javascript like following : if
I want to extract the number out of a string that might contain non-numeric
I have a string as follows: 2012/02/01,13:27:20,872226816,-1174749184,2136678400,2138578944,-17809408,2147352576 I want to extract the number: 872226816,
I want to extract valid(on the basis of format) mobile numbers from a text.
I want to extract the text between the last () using javascript For example
i want to extract a certain number from a site. String1&nbsp;:&nbsp; <font style=color:#EE6564; >

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.