Thread: Write text file to char array

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    1

    Write text file to char array

    Hey,
    Simple answer i'm sure, but can't seem to find a clear answer...
    How do you write a text file to a character array in C?
    mjh

  2. #2
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    By simply reading its content into a char array using fgets(), just as explained here (urgh, that link is actually pretty bad), better explained here.

    You might also want to read the C string tutorial where an example with fgets() is given.
    Last edited by KONI; 04-02-2007 at 07:59 AM.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    or strcpy and other function fro manipulating strings like sprintf
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  2. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  3. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM
  4. File I/O problems!!! Help!!!
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-17-2002, 08:09 PM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM