Thread: strcmp failing

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    12

    strcmp failing

    Hi,

    I'm receiving the following error upon compiling my program. Can anyone point me in the right direction to get the strcmp to work?

    Function argument assignment between types "const char*" and "char**" is not allowed.

    Code:
    typedef struct
    	{
    		char *aname[MAX_LEN]; */
    	} name;
    
    int	low(name *list, size_t first, size_t last)
    {
    	int	i, n, j;
    	int 	min;
    
    	for (i = 0; i < last; i++) 
    	{
    		min = i;
    		for (j = i + 1; j < last ; j++) 
    		{
    		if (strcmp(list[j].aname, list[min].aname) < 0) 
    			{
    			min = j;
    			}
    		}
    	}
    	return min;
    }

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    36
    I got your requirement.But,if you post your full code,it will be better.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    26
    In the structure you have declared ,
    char *aname[MAX_LEN]
    It represents array of pointer.Whether you want this as a array of pointer or like the following.
    char aname[MAX_LEN].
    And in strcmp function you have used list[j].aname.
    If you want char *aname[MAX_LEN] then in strcmp function you can't use simply list[j].aname.

  4. #4
    Registered User
    Join Date
    Nov 2008
    Location
    INDIA
    Posts
    64

    Thumbs up problem in name *list

    The problem is in the argument "name *list".The name structure should have some number of string.
    You have checked the values of the list with the remaining values in the list, and you returning the position of last occurrence of the first value.

    For example ,

    Have the first value of the list as "apple" and have the 4the value of the list as "apple".so the strcmp will get success.And return the value 4 from the function.

    Make sure that you are passing the list to the low function.

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fucntion returns -1, Why?
    By Taper in forum C Programming
    Replies: 16
    Last Post: 12-08-2008, 06:30 PM
  2. help with switch statement
    By agentsmith in forum C Programming
    Replies: 11
    Last Post: 08-26-2008, 04:02 PM
  3. problem with strings
    By agentsmith in forum C Programming
    Replies: 5
    Last Post: 04-08-2008, 12:07 PM
  4. strcmp
    By kryonik in forum C Programming
    Replies: 9
    Last Post: 10-11-2005, 11:04 AM
  5. initializes all components of failing to false
    By romeoz in forum C++ Programming
    Replies: 21
    Last Post: 08-01-2003, 09:30 PM