Thread: How to store contents from a text file into arrays?

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    14

    How to store contents from a text file into arrays?

    Could you guys show me a sample code that stores contents of txt files into arrays? or could you explain to me how it works?I haven't used text files as input before. I need it for my word search program cheers!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What have you read up and tried? What is the file format that you are thinking of?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2015
    Posts
    112
    You need to know the format as laserlight said, ascii, binary, etc? Since you mentioned words I would think ascii and how do you know a word starts and ends?

  4. #4
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Quote Originally Posted by JohnRaphael View Post
    Could you guys show me a sample code that stores contents of txt files into arrays? or could you explain to me how it works?I haven't used text files as input before. I need it for my word search program cheers!
    If you only need to search for words, then probably storing all content into a single char array will suffice. You can google how to achieve it. Then, if you have any problems, you can post here your code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing contents of a text file
    By never_lose in forum C Programming
    Replies: 10
    Last Post: 04-28-2011, 09:25 AM
  2. read contents of a text file into a struct
    By lemonwaffles in forum C++ Programming
    Replies: 2
    Last Post: 08-03-2009, 02:20 PM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. storing text file contents into a string
    By m.mixon in forum C Programming
    Replies: 4
    Last Post: 07-20-2006, 11:52 AM
  5. displaying contents of a text file
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 02-26-2002, 02:05 PM

Tags for this Thread