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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:50:37+00:00 2026-05-14T06:50:37+00:00

I need parse through a file and do some processing into it. The file

  • 0

I need parse through a file and do some processing into it. The file is a text file and the data is a variable length data of the form “PP1004181350D001002003……….”. So there will be timestamps if there is PP so 1004181350 is 2010-04-18 13:50. The ones where there are D are the data points that are three separate data each three digits long, so D001002003 has three coordonates of 001, 002 and 003.

Now I need to parse this data from a file for which I need to store each timestamp into a array and the corresponding datas into arrays that has as many rows as the number of data and three rows for each co-ordinate. The end array might be like

TimeStamp[1] = "135000", low[1] = "001", medium[1] = "002", high[1] = "003"
TimeStamp[2] = "135015", low[2] = "010", medium[2] = "012", high[2] = "013"
TimeStamp[3] = "135030", low[3] = "051", medium[3] = "052", high[3] = "043"
....

The question is how do I go about doing this in C? How do I go through this string looking for these patterns and storing the values in the corresponding arrays for further processing?

Note: Here the seconds value in timestamp is added on our own as it is known at each data comes after 15 seconds.

  • 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-14T06:50:38+00:00Added an answer on May 14, 2026 at 6:50 am

    edit: updated to follow your specs.

    While your file seems to be variable length, your data isn’t, you could use fscanf and do something like this:

    while(fscanf(file,"PP%*6d%4d", &timestamp, &low, &medium, &high)) 
    {
        for(int i = 0; fscanf(file, "D%3d%3d%3d", &low, &medium, &high); i++)
        {
            timestamp=timestamp*100+i*15;
            //Do something with variables (e.g. convert to string, push into vector, ...)
        }
    }
    

    Note that this reads the data into integers (timestamp, low, medium and high are int’s), A string version looks like this (timestamp, low, medium and high are char arrays):

    int first[] = {'0', '1', '3', '4'};
    int second[] = {'0','5'};
    
    while(fscanf(file,"PP%*6d%4c", &timestamp, &low, &medium, &high)) 
    {
        for(int i = 0; fscanf(file, "D%3c%3c%3c", &low, &medium, &high); i++)
        {
            timestamp[i][4]=first[i%4];
            timestamp[i][2]=second[i%2];
        }
    }
    

    edit: some more explanation about the formatting string, with %*6d I mean: look for 6 digits and discard them (* means: do not put in a variable). %4d or %4c means in this context the same (as 1 digit will be one char), but we do save them in corresponding variables.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Check out this article: http://aberkut.wordpress.com/2010/05/04/the-maximum-number-of-web-parts-for-all-zones-on-this-page-has-been-exceeded-error/ Wasn't easy to find, but… May 14, 2026 at 10:46 pm
  • Editorial Team
    Editorial Team added an answer Have a look at the documentation for defining routes. Something… May 14, 2026 at 10:46 pm
  • Editorial Team
    Editorial Team added an answer Your site is vulnerable to session fixation Why are you… May 14, 2026 at 10:46 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

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.