Thread: Read data from file - C program ?

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    3

    Read data from file - C program ?

    Hi,

    I am new to C programming. I want to read the whole data from a text file.

    Can anybody tell me the code/syntax for following steps in sequence:

    1) Open a text file.

    1) Read the data from a text file.

    3) If successfully read, then check the size of the data read (means number of characters read from the file). If zero or above range (e.g. 100000 chars) then prompt a message and exists.

    4) If found some size within range, then close the text file and proceed.


    Does fopen, fread help me in this case ? plz advice...

    I'll appreciate if anybody can provide me the code

    Thanks in advance...

    Best Regards
    Pawan Sangal

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    There are numerous examples in the FAQ section of this web site.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    As said above and yes fopen(), fread(), fclose() is all that you need. Check the internet/FAQ/turorial how to use them and note that fread() returns the number of characters read

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Last program!!
    By buckwheat88 in forum C++ Programming
    Replies: 12
    Last Post: 01-17-2006, 12:31 PM
  2. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  3. Replies: 4
    Last Post: 06-14-2005, 05:45 AM
  4. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM