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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:13:19+00:00 2026-06-08T21:13:19+00:00

Im currently writing a c++ program that needs to extract string and numeric data

  • 0

Im currently writing a c++ program that needs to extract string and numeric data from a text file. The format of the data is the following;

3225 C9+     ELECTR  C8      C        *      1.00E-6  -0.30       0.0

first entry is an integer, next 5 entries are strings and the last 3 are floats. No string is ever greater than 7 characters long.

I am reading the file line by line and then extracting the data using;

sscanf(ln.c_str(),"%d  %s  %s  %s  %s  %s  %e  %e  %e",
&rref[numre],&names[numre][0],&names[numre][1],&names[numre][2],&names[numre][3],
&names[numre][4],&nums[numre][0],&nums[numre][1],&nums[numre][2]);

this works fine untill I meet a line like;

  3098 SIC2H3+ ELECTR  SIC2H2  H        *      1.50E-7  -0.50       0.0

where one of the entrys is the full 7 characters long. In this case I get;

names[3097][0] = "SIC2H3+ELECTR"

and,

names[3097][1] = "ELECTR"

Anybody got any ideas…they will be much 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-06-08T21:13:20+00:00Added an answer on June 8, 2026 at 9:13 pm

    The most likely problem is in the declaration of names: if you declared it as holding seven characters or less, and forgot to allocate space for terminating zero, you’d get the results that you are describing.

    char names[MAX][4][7]
    

    will have enough space for strings of length 6 or less; for strings of length 7, you need

    char names[MAX][4][8]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a program that needs to compare each file in an ArrayList
I'm currently writing a java program that requires some Data to run. The data
I'm writing a cross-platform Qt-based program that from time to time needs to play
I am currently writing a program using Weka that builds a model (using one
I am writing a program that generates excel reports, currently using the Microsoft.Interop.Excel reference.
I am currently writing an app in python that needs to generate large amount
Currently, I have a program that reads a file and uses an XMLTextWriter to
I'm writing a Linux program that currently compiles and works fine on x86 and
Hey guys, Im working with wpf 3d, im currently writing a program that will
I'm currently writing an iPhone application which gets some data from the user and

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.