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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:08:18+00:00 2026-05-28T22:08:18+00:00

I have to split a string into several ones. In fact what i need

  • 0

I have to split a string into several ones. In fact what i need is to parse some input from a file that is in the following format (i9, i9, i2) for example.

i9 means a decimal number as:
(5blankspaces)4567

So i need to retrieve that numbers properly. The width is always fixed so every number must obey that.
A correct instance of that format would be

(5spaces)4567(6spaces)453(1space)2
or
(5spaces)4567(6spaces)45322 (where 22 is the argument for i2 in this case)

The white spaces before the numbers are giving me headache, so i thought i could split every argument into a character array and then convert it to integer since the %d specifier ignores all blank space and i dont know how to use the width as well as ignoring spaces.. (if this can be done, i mean, parsing all to integer please say so!!)

If not.. well, i would need help to parse every string into substring, so far i’ve done this but it’s not working:

while (fgets(buffer, 600, f)) {
    sscanf(buffer, "%9[^\n]s %9[^\n]s %2[^\n]s", arg1, arg2, arg3);
    ....
}

Please, any help would be greatly appreciated!!!

  • 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-28T22:08:18+00:00Added an answer on May 28, 2026 at 10:08 pm

    This answer is C. That is why I used the variable name new.

    Use strncpy() and terminate the result properly.

    char part1[10], part2[10], part3[3];
    const char *new = "     4567      45322\n"; /* the line read */
    
    strncpy(part1, new, 9);    part1[9] = 0;
    strncpy(part2, new+9, 9);  part2[9] = 0;
    strncpy(part3, new+18, 2); part3[2] = 0;
    

    I suggest you do not try to write multi-language source files.

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

Sidebar

Related Questions

I need to split long string into a array with following constrains: The input
I have a string ABCD:10,20,,40;1/1;1/2,1/3,1/4 I want to split the string into the following
I have a long string (multiple paragraphs) which I need to split into a
I have a long string of comments that I'd like to split into multiple
I have this string 8S8Q4D1SKCQC2C4S6H4C6DJS2S1C6C How can I split this string into substrings that
I have several strings that look like the following: +H124005992014011/1527399999999I05Z +H7039700000001/$99999999I051 +K122005962050171/120911234C117 I need
i have this: Dim split As String() = temp_string.Split(,) ''#feed all info into global
I have the following code, which splits up a Vector into a string vector
I have a regex expression that I'm doing a split against another string and
I have a string that contains several placeholders in it, and each placeholder is

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.