Thread: (split) how to read a file

  1. #1
    Registered User
    Join Date
    Aug 2014
    Posts
    1

    (split) how to read a file

    Hello I am new to this forum, Please tell me how to create text file in C programming. And after some changing in that text file off the running code of C, I want to read that modified text file back in C running code. e.g

    Created file may have number 1, after changing this value to 2 let say, than I want to read that 2 value which is in text file.

    thanks
    fazal nasir

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,663
    Opening and closing a file is done with fopen() and fclose()

    Reading and writing lines is done with fgets() and fputs()
    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.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    This site also has a tutorial page covering this topic with examples. Maybe you could try that page for examples? As Salem mentioned use fgets and fputs as they are the best for line-based input and output

    C File I/O Tutorial - Cprogramming.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. read a line from file and split it
    By quo in forum C Programming
    Replies: 4
    Last Post: 05-24-2011, 07:28 AM
  2. Split binary file(.exe) via delimiter
    By Coukapecker in forum C Programming
    Replies: 10
    Last Post: 09-16-2010, 03:24 PM
  3. EOF woes - split from File I/O
    By sion5 in forum C++ Programming
    Replies: 3
    Last Post: 01-16-2007, 02:13 PM
  4. split file
    By andriss in forum C Programming
    Replies: 4
    Last Post: 10-18-2006, 03:47 PM
  5. Windows Commander Split File
    By GaPe in forum C Programming
    Replies: 0
    Last Post: 12-26-2001, 03:10 PM