Problem in reading data

This is a discussion on Problem in reading data within the C Programming forums, part of the General Programming Boards category; I want to change the contents of a .txt file from horizontally arranged floating numbers to vertically arranged floating points. ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    3

    Problem in reading data

    I want to change the contents of a .txt file from horizontally arranged floating numbers to vertically arranged floating points.

    0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 17.60556235 5.09424285 20.67048223 45.64494129 94.33648809 84.16611543 52.53576193 63.10182116 46.07339099 37.60582628 32.11722051 47.45955704 84.29114844 90.54343806 300.00000000 300.00000000 55.71783858 50.47574458 53.51314986 75.63478589 52.64265728 13.72463279 0.00000000 0.00000000 0.00000000 0.00000000 19.23875546 17.48404899 0.00000000 3.86948361 0.00000000 7.25989233 15.60895902 24.10598640 22.02594380 37.54693145 33.82047117 0.00000000

    to

    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    17.6056
    5.0942
    20.6705
    45.6449
    94.3365
    84.1661
    52.5358
    63.1018
    46.0734
    37.6058
    32.1172
    47.4596
    84.2911
    90.5434
    300.0000
    300.0000
    55.7178
    50.4757
    53.5131
    75.6348
    52.6427
    13.7246
    0
    0
    0
    0
    19.2388
    17.4840
    0
    3.8695
    0
    7.2599
    15.6090
    24.1060
    22.0259
    37.5469
    33.8205
    0

    Please help

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    write a function to read the file into a data structure of some sort.
    write a function to do the rounding you want.
    write a function to do the output to a file
    write main to glue these together, job done.

    Want more help.... provide code(in tags)
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
          double value;
          while ( fscanf(file, "%lf", &value) == 1 )
          {
             printf("%.*f\n", value ? 4 : 0, value);
          }
    Last edited by Dave_Sinkula; 05-04-2005 at 09:51 PM. Reason: Tweaked output formatting.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Oddities reading binary data
    By KingCandyCorn in forum C Programming
    Replies: 6
    Last Post: 02-15-2009, 05:47 PM
  2. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  3. Replies: 48
    Last Post: 09-26-2008, 04:45 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 11:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21