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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:58:19+00:00 2026-06-17T07:58:19+00:00

I have the following data file 1.0 2.0 3.0 This is an a file

  • 0

I have the following data file

1.0
2.0
3.0 

This is an a file text.dat. The following code I have so far is in mygetline.c and I compile it into the executable mygetline. Executing it I feed the data file into the executable thus
./mygetline < text.dat in the bash terminal.

I want to read in the data file like that and print to stdout that column, plus some function of it. Here is the code so far.

#include <stdio.h>
int mygetline ( char s[], int lim )
{
  int c, i;

  i = 0;
  while( --lim > 0 && ( c = getchar() ) != EOF && c != '\n' )
  s[i++] = c;
  if ( c == '\n' )
  s[i++] = c;
  s[i] = '\0';
  return i ;
 }

void main()
{
     const int maxline = 10000;
     int nl, length;
     char line[maxline];
     double value ; 
     nl = 0;
     while ( ( length = mygetline( line, maxline ) ) != 0 ) //avoiding blanks
          {
    //Original error  sscanf( "%lf", line, &value ) ; //trying to get each line   
                                               //as the right 
                                              //number
       //FOllowing line is corrected implementation of sscanf()
              sscanf( line, "%lf", &value ) ; 
              printf( "%lf %lf\n", value ,value*value ) ; //trying to output x & x*x
           }
 }

the output is the following

0.000000 0.000000
0.000000 0.000000
0.000000 0.000000

I want something like

1.0 1.0 
2.0 4.0 
3.0 9.0

to whatever precision.
Does anyone have any suggestion as to what I am missing to get my desired output? Thank you

  • 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-17T07:58:20+00:00Added an answer on June 17, 2026 at 7:58 am

    Re-read the documentation for sscanf.

    The format is the second parameter.
    But you put the "%lf" as the first parameter.

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

Sidebar

Related Questions

I have a tab delimited text file with the following data: ahi1 b/se ahi
When I using the following code to read file: lines=file(data.txt).read().split(\n) I have the following
I have a text file containing the data in following format 12345 Abdt3 hy45d
I have a text file with the following type of data in it below:
I have a text file in the following url. http://hosted.stats.com/ifb2009/data.asp?file=en/chlg_standings.txt I want to parse
i have a text file with the following data: Calculated Concentrations 30.55 73.48 298.25
I have the following text file: This is my text file NUM,123 FRUIT DRINK
I have the following data in a plain text file: 1. Value Location :
I have a text file that contains the following data. The first line is
So I have the following code: $(document).on('click', 'a[data-link]', function () { var $this =

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.