code syntax help

This is a discussion on code syntax help within the C++ Programming forums, part of the General Programming Boards category; Hey guys, I have the following two pieces of code and I am trying to combine them so it will ...

  1. #1
    182
    182 is offline
    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,662
    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
    182
    182 is offline
    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
    21,735
    I'm tryng to say something lik ethe following
    Maybe you should say outright what you are trying to solve.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    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, 04:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  4. Replies: 6
    Last Post: 04-04-2003, 09: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, 03:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21