reading a file and splitting the content in an array


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: reading a file and splitting the content in an array

  1. #1
    Join Date
    Jun 2004
    Posts
    1

    reading a file and splitting the content in an array

    that's a piece of the code of a little guessing game i'm writing.. i wanted to improve it making it split the several lines in "dictionary" file and put all this strings (each lines of the file contains a single word) into an array... i would be very glad if someone could help me learning :)

    (this is just a funcition, some variables are not declared here)

    -----------------------------------------

    int obfuscate(char word[30]){

    char ch;
    ifstream infile("dictionary");
    if(!infile){
    cout<< "Cannot open dictionary!" << endl;
    }
    infile >> word;
    infile.close();
    wlenght = strlen(word);
    cout <<"Obfuscated word : ";
    for(int i=0; i<wlenght; i++){
    hint[i]= '-';
    }
    cout << hint << endl;
    return 0;

    }

    ----------------------------------------------



    thank you!

    //blextar

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    amjor improvement would be using a vector instead of an array. You can find examples of using std::vector here: http://www.devx.com/DevX/LegacyLink/9396
    Danny Kalev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center