Thread: How to read a .dat file in C.

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

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, 02: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