How to read a .dat file in C.

This is a discussion on How to read a .dat file in C. within the C Programming forums, part of the General Programming Boards category; I have created a .dat file (input.dat) which is a 2-dimensional array containing the x and y corordinates of points. ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    1

    How to read a .dat file in C.

    I have created a .dat file (input.dat) which is a 2-dimensional array containing the x and y corordinates of points. Example

    1.000, 2.0000
    3.000, -1.000
    -2.000, 0.000 .........

    I want to open this file, read the data and use the data given here to do some calculations and store the result in another output file (output.dat) which will again be a 2-dimensional file.

    How to read the data ?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    fopen to open the file
    fgets in a while loop, to read each line
    sscanf to parse each line
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM

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