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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:23:36+00:00 2026-06-15T10:23:36+00:00

I would like to push the below data into a vector using the below

  • 0

I would like to push the below data into a vector using the below code.But my code works only for integers.How can I do this for the below data? Thank you.

My data:

    M,0.455,0.365,0.095,0.514,0.2245,0.101,0.15,15
    M,0.35,0.265,0.09,0.2255,0.0995,0.0485,0.07,7
    F,0.53,0.42,0.135,0.677,0.2565,0.1415,0.21,9
    M,0.44,0.365,0.125,0.516,0.2155,0.114,0.155,10
    I,0.33,0.255,0.08,0.205,0.0895,0.0395,0.055,7
    I,0.425,0.3,0.095,0.3515,0.141,0.0775,0.12,8
    F,0.53,0.415,0.15,0.7775,0.237,0.1415,0.33,20
    F,0.545,0.425,0.125,0.768,0.294,0.1495,0.26,16
    M,0.475,0.37,0.125,0.5095,0.2165,0.1125,0.165,9
    F,0.55,0.44,0.15,0.8945,0.3145,0.151,0.32,19

My code:

      fp = fopen(argv[1], "r"); //Opening the input file in read mode.
      if(!fp)
      {
          printf("open data source file failed!\n");
          goto MAINEXIT;
      }

      int ivalue;
      //extract data from files
      while(fscanf(fp,"%d,",&ivalue)!=EOF)
      {
          printf("Counter-%d\n",counter++);
          srcdata.push_back(ivalue); //Pushing value by value into the vector with "," delimiter.
      }

      if(fp)
      fclose(fp);
  • 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-15T10:23:38+00:00Added an answer on June 15, 2026 at 10:23 am

    %d is for integers. Change it to %lf for double, and change other parts accordingly, for example, change ivalue to double.


    According to your comment in the question, I think you might need something like

    while(fscanf(fp,"%s", str)!=EOF)
    {
        char* pch = strtok(str, ",");
        pch = strtok(NULL, ","); // skip first
        while (pch != NULL)
        {
            double d = atof(pch);
            printf("Counter-%d\n",counter++);
            srcdata.push_back(d);
            pch = strtok (NULL, ",");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to refresh tk window when I push a button, but I
I would like to transform the following lines of data into a structured table
I have a data file with 3 different sets of information like this below:
What I have below is some notification code. What I would like to achieve
We are developing a Customer feedback application and I would like to push the
I would like to take the memory generated from my struct and push it
Would like to know the c# code to actually retrieve the IP type: Static
I have CSV data loaded into a multidimensional array. In this way each row
So I have a block of code that looks like this: stack.forEach(function(element){ //sys.puts(sys.inspect(element, false,
I would like to ask about the time complexity of my function. Below 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.