Thread: file .txt and vector

  1. #1
    Registered User
    Join Date
    Mar 2021
    Posts
    9

    file .txt and vector

    So, i'm having some problems with this project.
    The objective is, read the word from the .txt (35042 words) and store them in the vector s, where each element of the vector is a word.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    What sort of problems are you having? (we don't know, you didn't post code).

    How far have you got?
    - open and close the file
    - read one word from the file and print it using printf
    - read all the words from the file, and print them

    What kind of vector are you thinking of using?

    char words[35042][20];
    Is very clunky, but it allows you to get the rest of the code working without the complication of pointers and malloc.
    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
    Apr 2021
    Posts
    140
    When you say, "vector" I immediately think you might be asking a C++ question. This is the C programming forum - you're likely to get much more answers if you ask C++ questions in the right place.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 09-22-2013, 07:00 AM
  2. Write a Vector to a File
    By RiceFiend in forum C++ Programming
    Replies: 9
    Last Post: 06-22-2009, 05:02 AM
  3. Reading from a vector to a file
    By veronicak5678 in forum C++ Programming
    Replies: 5
    Last Post: 04-10-2008, 12:57 AM
  4. Save vector to file...
    By IndioDoido in forum C++ Programming
    Replies: 1
    Last Post: 10-18-2007, 04:09 PM
  5. Putting strings from a file into a vector
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 04-09-2002, 08:15 AM

Tags for this Thread