Thread: recieve data form file

  1. #1
    Registered User vddking2's Avatar
    Join Date
    Nov 2006
    Location
    Vietnam
    Posts
    12

    Lightbulb recieve data form file

    I have file data.txt like this:

    Code:
    hello        chao //space  by tab(ascii:9)
    good        tot
    how         the nao
    I have a hash order by alpahabes (26 bucket), in each element, i have: char word1[30], char word2[30], next.

    How can I read data form file and write to a element with each line? What function should I use?

    I don't stydy clearly about file, so I don't know what first I do.
    Thanks
    Last edited by vddking2; 11-22-2006 at 03:29 AM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Pair fgets, to read the line, with sscanf, to parse the line.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I have a hash order by alpahabes (26 bucket), in each element, i have: char word1[30], char word2[30], next.
    Rather than word1[30], word2[30], ... ad infinitum (or 26 anyway), you could use an array like word[26][30].

    Pair fgets, to read the line, with sscanf, to parse the line.
    After the file has been opened with fopen(), of course. fclose() the file when you're done with it.

    C File I/O and Binary File I/O
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Writing and modifying data in a file
    By Micko in forum C Programming
    Replies: 2
    Last Post: 02-17-2005, 03:42 AM