find the longest word in a string

my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace std;
char*maxlenword(char*str)
{
char*ret=str;
int curlen=0,maxlen=0;
for(;*str;str++)
{
 if(*str!=" ")
 curlen+=1;
 else if (curlen>maxlen)
 {
      ret=str-curlen;
      maxlen=curlen;
      curlen=0;
      	*str = 0;
      }
      else
      {
          curlen=0;
          }   
      }
      if(curlen>maxlen)
      ret=str-curlen;
      return ret;
      }
      int main()
      {
          char*str="how do you doing";
          cout<<maxlenword(str);
          return 0;
          }

but the compiler said that
c:\users\danny\documents\visual studio 2010\projects\snow\snow\main.cpp(9): error C2446: '!=' : no conversion from 'const char *' to 'int'
1> There is no context in which this conversion is possible
1>c:\users\danny\documents\visual studio 2010\projects\snow\snow\main.cpp(9): error C2040: '!=' : 'int' differs in levels of indirection from 'const char

it looks very weird and how to fix it?
Line 9: You're trying to compare a char with a char array. *str points to a single character. The right side (" ") is a character array. As the compiler stated, there is no implicit comparison between a character and a character array. You want to compare to a single character.
 
 if(*str!=' ')

Topic archived. No new replies allowed.