-3

以前は : のような静的配列を取りchar ch[20]ました。しかし、私はこのスタイルを bcoz に変更しました。したがってchar *ch; 、コードを移植している間、指定された価格で以下のように宣言しました。

char *word;
char *ch;
char *excluded_string;
char *skp;  
std::string result_string;
std::string rcv; 
i=0,j=0;
    do {
        bytesReceived = recv(*csock, buffer.data(), buffer.size(), 0);
        if ( bytesReceived == -1 )      { 
            fprintf(stderr, "Error receiving data %d \n", errno);
        goto FINISH;    } 
    else 
            rcv.append( buffer.cbegin(), buffer.cend() );         
182:    } while ( bytesReceived == MAX_BUF_LENGTH )  

184: **word = strtok(& rcv[0]," ");
185: while (word!= NULL) {
6           skp = BoyerMoore_skip(word, strlen(word) ); //Booyes moore is string search algo
9           if(skp != NULL)
0       {
201         i++;
2           continue;
3       }
4       bfr << excluded_string[j] << " ";
5       result_string = bfr.str();
6       j++;
7       }**    

エラー:

daemon.cpp:184:8: error: expected ‘;’ before ‘word’
daemon.cpp:188:29: error: invalid conversion from ‘char*’ to ‘char’ [-fpermissive]
daemon.cpp:189:41: error: invalid conversion from ‘char*’ to ‘char’ [-fpermissive]
daemon.cpp:190:51: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive]
In file included from daemon.cpp:2:0:
/usr/include/string.h:395:15: error:   initializing argument 1 of ‘size_t strlen(const char*)’ [-fpermissive]
daemon.cpp:190:53: error: invalid conversion from ‘char’ to ‘char*’ [-fpermissive]
In file included from daemon.cpp:36:0:
dictionary_exclude.h:4:14: error:   initializing argument 1 of ‘char* BoyerMoore_skip(char*, int)’ [-fpermissive]

これらのエラーを取り除く方法は?

4

2 に答える 2

1

複雑に考えれば考えるほど、簡単なことは複雑になります! std::ostringstream bfr;

word = strtok(& rcv[0]," ");
    while (word!= NULL) {
            skp = BoyerMoore_skip(word, strlen(word) );

            if(skp != NULL)
        {
            i++;
            printf("this also \n");
            word = strtok(NULL, " ");
            continue;
        }
        printf("\n Word %s \n",word);
        bfr << word << " ";
        result_string = bfr.str();
        word = strtok(NULL, " ");
        j++; 
        }    
于 2013-09-08T07:16:47.210 に答える
1

いくつかのヒント/ポインタ:

182 行目は} while ( bytesReceived == MAX_BUF_LENGTH );[末尾のセミコロン] にする必要があります。

ch'変数はwordまったく必要ありません。ch[i]

184 行目: には詳しくありませんstd::stringが、strtok()strtokは入力文字列を変更し、ループの最後に を呼び出す必要があります。

より良いトークン化ルーチンの使用を検討してください。トークン化に関する多くの質問と回答がありますstd::string- https://stackoverflow.com/questions/tagged/tokenize%20string%20c%2b%2b

于 2013-09-07T18:52:09.663 に答える