Thread: code syntax help

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    133

    code syntax help

    Hey guys, I have the following two pieces of code and I am trying to combine them so it will say if hello is found and it is at the start or the prevous character is whitespace then add one to the count but when i try to combine these two pieces of code to do that my syntax is all wrong.

    Any help would be great. Thanks.

    Code:
    char * ch = array;
    while((ch = strstr( ch, "hello")) != 0)
    {
     Count++;
    ch++;
    }
    Code:
    if(ch == array || isspace(*(ch-1)))
    {
    	count++					
    	ch++							
    	}

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Code:
    if(ch == array)
    {
    
        //do something, but not count++ or ch++
    
    }
    else if( isspace(*(ch-1)))
    {
        //do something, but not count++ or ch++
    }
    ......

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    133
    Quote Originally Posted by 7stud
    Code:
    if(ch == array)
    {
    
        //do something, but not count++ or ch++
    
    }
    else if( isspace(*(ch-1)))
    {
        //do something, but not count++ or ch++
    }
    ......
    I'm tryng to say something like the following but cant get the right syntax for it:

    Code:
    if(ch=strstr "hello", ch, array) !=0 )&& ch == array || isspace(*(ch-1)))
    {
    	count++					
    	ch++							
    	}

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I'm tryng to say something lik ethe following
    Maybe you should say outright what you are trying to solve.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I'm tryng to say something like the following but cant get the right syntax for it:
    Code:
    char str1[] = "the hello";
    char* ptr = 0;
    
    if
    ( 
    	( ptr=strstr(str1, "hello") ) != 0 
    	&& 
    	( 
    		ptr == str1 || isspace(*(ptr-1)) 
    	)
    )
    {
    	cout<<"found one"<<endl;
    }
    else
    	cout<<"nope"<<endl;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Replies: 6
    Last Post: 04-04-2003, 10:09 PM
  5. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM