0

好的,我有一个功能

    int main
{
   ....
   char *wordl=word();//wordl pointer is an array of characters
   ...
   gamewindow(wordl,length);
}


void gamewindow(char &wordl,int length);

我的问题是如何传递指针,使传递的指针指向同一个数组列表。我可以通过 gamewindow 函数中的 wordl[i] 访问它。

从下面的评论中,实现word()

   char* word() 
    { int j=1988497762; cout<<j<<endl ; 
    static char original[25]; 
    int x;
     ifstream fin("out.txt"); 
    for (j=0;!fin.eof();j++) 
    fin.getline(original,25); 
    fin.close(); 
    srand ( (unsigned) time(NULL) ); 
    x = rand()%j; cout<<x<<"\n"; 
    cout<<rand()<<endl; 
    char c; 
    ifstream finn("out.txt"); 
    for (j=0; !finn.eof(); j++)
     { finn>>c; finn.getline(original,25); if (x==j) break; } 
    finn.close(); 
    return original; }
4

2 回答 2

3

如果您真的只想像这样使用它(而不是使用std::vectoror std::string),您需要更改gamewindowvoid gamewindow(char *wordl,int length);Then 您可以char使用word1[i].

于 2013-05-21T05:29:53.840 回答
2

Better use std::string, std::vector and other standard containers. If on C++2011, use perhaps std::array

So declare instead

 void gamewindow(std::string&str);
于 2013-05-21T05:28:40.407 回答