-3

Previously I took static array like : char ch[20]. but I changed this style bcoz may it need to be >20. So I declared it as char *ch; While I ported my code it look like below with given prices.

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       }**    

Error:

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]

How to remove these error?

Catty
  • 406
  • 1
  • 7
  • 15

2 Answers2

1

Some hints/pointers:

Line 182 should be } while ( bytesReceived == MAX_BUF_LENGTH ); [semicolon at the end]

You don't need the 'ch variable at all, you can just substitute word for ch[i]

Line 184: I'm not familiar with std::string, but strtok() modifies the input string -- and needs a call to strtok at the end of the loop.

Consider using a better tokenizing routine, SO has a lot of questions + answers on tokenizing std::string -- https://stackoverflow.com/questions/tagged/tokenize%20string%20c%2b%2b.

Community
  • 1
  • 1
Edward Clements
  • 4,917
  • 2
  • 19
  • 27
  • I edited the code, please varify whether bold part has any logical error. It compiles! – Catty Sep 07 '13 at 19:06
  • bold doesn't come through in code blocks! you still need `excluded_string[j]= strdup(word);` and a better way of tokenizing `rcv` -- there are a huge amount of questions/answers on this at SO, a simple one is http://stackoverflow.com/a/14267455/1850797 – Edward Clements Sep 07 '13 at 19:15
1

The more complex we think, easy thing become complex! 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++; 
        }