*char comditional matching problem

This is a discussion on *char comditional matching problem within the C++ Programming forums, part of the General Programming Boards category; let's say this code: Code: char bufferx[] = "abc~defghi" char buf[111]; char *a_full_parm(const char *bufferx) { int i =0; int ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    114

    *char comditional matching problem

    let's say this code:


    Code:
    	
    char bufferx[] = "abc~defghi"
    
    
    char buf[111];
    
    char *a_full_parm(const char *bufferx)
    {
    	int i =0;
    	int j = 0;
    	int bkm;
    
    
    
    
    	for(i=0; i< 256; i++)  
    	{
    		if (bufferx[i] == '~')
    		{
    			bkm= i;
    			for(j=0; j < bkm ; j++)
    			{
    				buf[j] = bufferx[j];
    
    
    			
    			}
    			buf[j] = '\0';
    
    
    
    			return buf;
    		}
    	}
    }

    how i need to match it


    if (full_parm(buffer ) == "abc") <=== BIG PROBLEM
    {do something}

    BIG PROBLEM :
    but i cant match it coz itz not exactly the same??
    do i need to do casting??
    how do i go about doing the matching to "abc" here?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    Read about strcmp() in your manual pages
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Or use std::string, since it has overloaded the == and != operators.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    you can't compare a char* to a hardcoded string in this fashion. Your logic is right, but things aren't happening as you would like them to.

    Take Salem's advice.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM

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