Read data from file - C program ?

This is a discussion on Read data from file - C program ? within the C Programming forums, part of the General Programming Boards category; Hi, I am new to C programming. I want to read the whole data from a text file. Can anybody ...

  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
    Katy, Texas
    Posts
    2,309
    There are numerous examples in the FAQ section of this web site.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  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, 11:31 AM
  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

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