string help

This is a discussion on string help within the C++ Programming forums, part of the General Programming Boards category; Hi im making a ai program for scrabble and cant get my string to = another string here is my ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    110

    string help

    Hi im making a ai program for scrabble and cant get my string to = another string
    here is my code and I marked it with a **HERE**

    Code:
    #include <fstream>
    #include <iostream>
    #include <cstring>
    
    
    using namespace std;
    
    struct Words {
    	char str[30];
    };
    int main()
    {
      char str[30];
      string word[32000];
      int i = 0;
      
      ifstream b_file ( "Final.txt" );
    
      while(!b_file.eof())
      {
      b_file>> str;
      word[i] = str;
    
      i++;
      
      }
      b_file.close();
      string finallist[32000];
      int count = 0;
      int letters = 0;
      string phrase = "EDW";
    	int x = 0;
      for(letters = 0;letters<=phrase.length();letters++)
      {
    
      for(count = 0;count<=i;count++)
      {
    	  if(word[count][0] == phrase[letters])
    	  {
    		  strcpy(finallist[x],word[count]); //**HERE**
    		  x++;
    	  }
      }
      }
    
      cout<< "Reduced to this many words " << x << endl;
      system("pause");
    
      return EXIT_SUCCESS;
    }

  2. #2
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712
    You need to use C++ strings.
    You should use this:
    #include <string>
    ....

    I can't even compile your code.
    Function strcpy has this prototype:
    Code:
    char *strcpy(
       char *strDestination,
       const char *strSource 
    );
    Pay attention char * and not string...

    - Micko
    Last edited by Micko; 08-10-2005 at 01:38 AM.
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  3. #3
    Banned
    Join Date
    Jun 2005
    Posts
    594
    string mystring = "a bunch of words yet i dont need [ ] c++ strings are awsome";

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >Hi im making a ai program for scrabble and cant get my string to = another string
    Instead of:
    Code:
    		  strcpy(finallist[x],word[count]); //**HERE**
    Use:
    Code:
    		  finallist[x] = word[count];

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 03:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 05:30 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21