Passing Argument from incompatible pointer type

This is a discussion on Passing Argument from incompatible pointer type within the C Programming forums, part of the General Programming Boards category; Hi I am getting this error can anybody help me ASAP SET.c: In function `Set_Similarity': SET.c:186: warning: passing arg 1 ...

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    3

    Passing Argument from incompatible pointer type

    Hi I am getting this error
    can anybody help me ASAP



    SET.c: In function `Set_Similarity':
    SET.c:186: warning: passing arg 1 of `Set_Size' from incompatible pointer type
    SET.c:188: warning: passing arg 1 of `Set_Size' from incompatible pointer type
    SET.c: In function `main':
    SET.c:283: warning: passing arg 1 of `Set_Contains' from incompatible pointer ty
    pe
    SET.c:285: warning: passing arg 1 of `Set_Contains' from incompatible pointer ty
    pe
    SET.c:294: warning: passing arg 1 of `Set_Size' from incompatible pointer type
    SET.c:295: warning: passing arg 1 of `Set_Size' from incompatible pointer type
    SET.c:300: warning: passing arg 1 of `Set_Empty' from incompatible pointer type
    SET.c:305: warning: passing arg 1 of `Set_Empty' from incompatible pointer type
    SET.c:322: warning: passing arg 1 of `Set_Union' from incompatible pointer type
    SET.c:322: warning: passing arg 2 of `Set_Union' from incompatible pointer type
    SET.c:324: warning: passing arg 1 of `Set_Print' from incompatible pointer type
    SET.c:329: warning: passing arg 1 of `Set_Intersection' from incompatible pointe
    r type
    SET.c:329: warning: passing arg 2 of `Set_Intersection' from incompatible pointe
    r type
    SET.c:331: warning: passing arg 1 of `Set_Print' from incompatible pointer type
    SET.c:336: warning: passing arg 1 of `Set_Similarity' from incompatible pointer
    type
    SET.c:336: warning: passing arg 2 of `Set_Similarity' from incompatible pointer
    type
    SET.c:343: warning: passing arg 1 of `Set_Print' from incompatible pointer type
    SET.c:345: warning: passing arg 1 of `Set_Print' from incompatible pointer type
    SET.c:358:2: warning: no newline at end of file

  2. #2
    Registered User
    Join Date
    Aug 2010
    Posts
    3

    Heri is the code :)

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include "SET.H"
    
    void Set_Create(Set **set)
    {
     (*set)=(Set *)malloc(sizeof(Set));
     (*set)->value=0;
     (*set)->next=NULL;
    }
    
    Boolean Set_Insert(Set **set, SetEntry value)
    {
     Set *new_set=(Set *)malloc(sizeof(Set));
     Set *temp=*set;
     if((*set)==NULL)
      return(FALSE);
     while(temp->next!=NULL)
     {
      if(temp->value==value)
       return(FALSE);
      else
       temp=temp->next;
     }
     if(new_set==NULL)
      return(FALSE);
     else
     {
      new_set->value=value;
      new_set->next=*set;
      *set=new_set;
      return(TRUE);
     }
    }
    
    Boolean Set_Delete(Set **set, SetEntry value)
    {
     Set *temp=*set,*prev=*set;
     if((*set)==NULL)
      return(FALSE);
     while(temp->next!=NULL)
     {
      if(temp->value==value)
      {
       if(temp==prev)
        (*set)=(*set)->next;
       else
        prev->next=temp->next;
       free(temp);
       return(TRUE);
      }
      else
      {
       prev=temp;
       temp=temp->next;
      }
     }
     return(FALSE);
    }
    
    Boolean Set_Contains(const Set **set, SetEntry value)
    {
     const Set *temp=*set;
     while(temp->next!=NULL)
     {
      if(temp->value==value)
       return(TRUE);
      else
       temp=temp->next;
     }
     return(FALSE);
    }
    
    int Set_Size(const Set **set)
    {
     const Set *temp=*set;
     int size=0;
     while(temp->next!=NULL)
     {
      size++;
      temp=temp->next;
     }
     return(size);
    }
    
    Boolean Set_Empty(const Set **set)
    {
     const Set *temp=*set;
     int size=0;
     while(temp->next!=NULL)
     {
      size++;
      temp=temp->next;
     }
     return(size==0?TRUE:FALSE);
    }
    
    void Set_Clear(Set **set)
    {
     (*set)=NULL;
    }
    
    void Set_Union(const Set **set1, const Set **set2, Set **ret)
    {
     Set *new_set=(Set *)malloc(sizeof(Set)), *new_set2;
     const Set *temp1=*set1, *temp2=*set2;
     SetEntry temp_value;
     Boolean entry=TRUE;
     new_set->value=0;
     new_set->next=NULL;
     while(temp1->next!=NULL)
     {
      new_set2=(Set *)malloc(sizeof(Set));
      new_set2->value=temp1->value;
      new_set2->next=new_set;
      new_set=new_set2;
      temp1=temp1->next;
     }
     while(temp2->next!=NULL)
     {
      temp_value=temp2->value;
      temp1=*set1;
      entry=TRUE;
      while(temp1->next!=NULL)
      {
       if(temp1->value==temp_value)
       {
        entry=FALSE;
        break;
       }
       else
        temp1=temp1->next;
      }
      if(entry==TRUE)
      {
       new_set2=(Set *)malloc(sizeof(Set));
       new_set2->value=temp2->value;
       new_set2->next=new_set;
       new_set=new_set2;
      }
      temp2=temp2->next;
     }
     (*ret)=new_set;
    }
    
    void Set_Intersection(const Set **set1, const Set **set2, Set **ret)
    {
     Set *new_set=(Set *)malloc(sizeof(Set)), *new_set2;
     const Set *temp1=*set1, *temp2=*set2;
     SetEntry temp_value;
     Boolean entry=FALSE;
     new_set->value=0;
     new_set->next=NULL;
     while(temp1->next!=NULL)
     {
      temp_value=temp1->value;
      temp2=*set2;
      entry=FALSE;
      while(temp2->next!=NULL)
      {
       if(temp2->value==temp_value)
       {
        entry=TRUE;
        break;
       }
       else
        temp2=temp2->next;
      }
      if(entry==TRUE)
      {
       new_set2=(Set *)malloc(sizeof(Set));
       new_set2->value=temp_value;
       new_set2->next=new_set;
       new_set=new_set2;
      }
      temp1=temp1->next;
     }
     (*ret)=new_set;
    }
    
    double Set_Similarity(const Set **set1, const Set **set2)
    {
     Set *res1,*res2;
     int size1,size2;
     Set_Union(&(*set1),&(*set2),&res1);
     size1=Set_Size(&res1);
     Set_Intersection(&(*set1),&(*set2),&res2);
     size2=Set_Size(&res2);
     return((double)size2/(double)size1);
    }
    
    void Set_Print(const Set **set)
    {
     const Set *temp=*set;
     printf("{");
     while(temp->next!=NULL)
     {
      printf("%d,",temp->value);
      temp=temp->next;
     }
     printf("}");
    }
    
    int main()
    {
     Set *set1=NULL, *set2=NULL, *ret=NULL;
     SetEntry value;
     Boolean result;
     int choice, set_choice;
     double res;
     do
     {
      clrscr();
      printf("\n\t----------MENU----------");
      printf("\n\n\t1. Create Sets");
      printf("\n\t2. Insert into Set");
      printf("\n\t3. Delete from Set");
      printf("\n\t4. Set Contains");
      printf("\n\t5. Set Size");
      printf("\n\t6. Set Empty");
      printf("\n\t7. Clear Sets");
      printf("\n\t8. Union of Sets");
      printf("\n\t9. Intersection of Sets");
      printf("\n\t10. Similarity of Sets");
      printf("\n\t11. Print Sets");
      printf("\n\t12. Exit");
      printf("\n\n\t\tEnter your choice (1-12): ");
      scanf("%d", &choice);
      switch(choice)
      {
       case 1:
    	Set_Create(&set1);
    	printf("\n\n\t\tSet A created successfully.");
    	Set_Create(&set2);
    	printf("\n\n\t\tSet B created successfully.");
    	printf("\n\n\n\t\tPress any key to continue");
    	getch();
    	break;
       case 2:
    	printf("\n\n\t\tEnter the value to be entered: ");
    	scanf("%d",&value);
    	printf("\t\tEnter the set in which to be entered (1/2): ");
    	scanf("%d",&set_choice);
    	if(set_choice!=1&&set_choice!=2)
    	 printf("\n\n\t\tInvalid set selected for insertion.");
    	else if(set_choice==1)
    	 result=Set_Insert(&set1,value);
    	else
    	 result=Set_Insert(&set2,value);
    	if(result==FALSE)
    	 printf("\n\n\t\tCan't insert the value into set.");
    	else
    	 printf("\n\n\t\tValue Inserted Successfully.");
    	printf("\n\n\t\tPress any key to continue");
    	getch();
    	break;
       case 3:
    	printf("\n\n\t\tEnter the value to be deleted: ");
    	scanf("%d",&value);
    	printf("\t\tEnter the set from which to be deleted (1/2): ");
    	scanf("%d",&set_choice);
    	if(set_choice!=1&&set_choice!=2)
    	 printf("\n\n\t\tInvalid set selected for deletion.");
    	else if(set_choice==1)
    	 result=Set_Delete(&set1,value);
    	else
    	 result=Set_Delete(&set2,value);
    	if(result==FALSE)
    	 printf("\n\n\t\tCan't delete the value from set.");
    	else
    	 printf("\n\n\t\tValue Deleted Successfully.");
    	printf("\n\n\t\tPress any key to continue");
    	getch();
    	break;
       case 4:
    	printf("\n\n\t\tEnter the value to be searched: ");
    	scanf("%d",&value);
    	printf("\t\tEnter the set in which to be searched (1/2): ");
    	scanf("%d",&set_choice);
    	if(set_choice!=1&&set_choice!=2)
    	 printf("\n\n\t\tInvalid set selected for searching.");
    	else if(set_choice==1)
    	 result=Set_Contains(&set1,value);
    	else
    	 result=Set_Contains(&set2,value);
    	if(result==FALSE)
    	 printf("\n\n\t\tValue is not present in the set.");
    	else
    	 printf("\n\n\t\tValue is present in the set.");
    	printf("\n\n\t\tPress any key to continue");
    	getch();
    	break;
       case 5:
    	printf("\n\n\t\tSize of Set 1 is: %d", Set_Size(&set1));
    	printf("\n\n\t\tSize of Set 2 is : %d", Set_Size(&set2));
    	printf("\n\n\n\t\tPress any key to continue.");
    	getch();
    	break;
       case 6:
    	result=Set_Empty(&set1);
    	if(result==TRUE)
    	 printf("\n\n\t\tSet 1 is empty.");
    	else
    	 printf("\n\n\t\tSet 1 is not empty.");
    	result=Set_Empty(&set2);
    	if(result==TRUE)
    	 printf("\n\n\t\tSet 2 is empty.");
    	else
    	 printf("\n\n\t\tSet 2 is not empty.");
    	printf("\n\n\n\t\tPress any key to continue.");
    	getch();
    	break;
       case 7:
    	Set_Clear(&set1);
    	printf("\n\n\t\tSet A cleared successfully.");
    	Set_Clear(&set2);
    	printf("\n\n\t\tSet B cleared successfully.");
    	printf("\n\n\n\t\tPress any key to continue");
    	getch();
    	break;
       case 8:
    	Set_Union(&set1,&set2,&ret);
    	printf("\n\n\t\tUnion of two sets: ");
    	Set_Print(&ret);
    	printf("\n\n\n\t\tPress any key to continue.");
    	getch();
    	break;
       case 9:
    	Set_Intersection(&set1,&set2,&ret);
    	printf("\n\n\t\tIntersection of two sets: ");
    	Set_Print(&ret);
    	printf("\n\n\n\t\tPress any key to continue.");
    	getch();
    	break;
       case 10:
    	res=Set_Similarity(&set1,&set2);
    	printf("\n\n\t\tSet Similarity: %f",res);
    	printf("\n\n\n\t\tPress any key to continue.");
    	getch();
    	break;
       case 11:
    	printf("\n\n\t\tSet 1: ");
    	Set_Print(&set1);
    	printf("\n\n\t\tSet 2: ");
    	Set_Print(&set2);
    	getch();
    	break;
       case 12:
    	break;
       default:
    	printf("\n\n\t\tInvalid choice. Try Again!!!");
    	printf("\n\n\t\tPress any key to continue.");
    	getch();
    	break;
      }
     }while(choice!=12);
     return 0;
    }
    Last edited by Salem; 08-16-2010 at 10:02 AM. Reason: CODE TAGS - learn about them NOW

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    3

    SET.H file :)

    Code:
    typedef int SetEntry;
    
    typedef enum boolean{TRUE=1,FALSE=0} Boolean;
    
    typedef struct set
    {
    	SetEntry value;
    	struct set *next;
    } Set;
    
    void Set_Create(Set **set);
    Boolean Set_Insert(Set **set, SetEntry value);
    Boolean Set_Delete(Set **set, SetEntry value);
    Boolean Set_Contains(const Set **set, SetEntry value);
    int Set_Size(const Set **set);
    Boolean Set_Empty(const Set **set);
    void Set_Clear(Set **set);
    void Set_Union(const Set **set1, const Set **set2, Set **ret);
    void Set_Intersection(const Set **set1, const Set **set2, Set **ret);
    double Set_Similarity(const Set **set1, const Set **set2);
    void Set_Print(const Set **set);
    Last edited by Salem; 08-16-2010 at 10:01 AM. Reason: CODE TAGS!

  4. #4
    cas
    cas is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    991
    Please use code tags when posting code (see the sticky thread on the main page for posting guidelines).

    It would appear, though, that the problem is that you're doing something like this:
    Code:
    void f(const T **);
    ...
    T *x;
    f(&x);
    Where “T” is some type. This is not legal. T** is not compatible with const T**. It appears unintuitive, I know, but it's how C works. In fact, there's a good reason: if such an assignment were legal, you'd be able to subvert “const” in some situations (without a cast).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing argument from incompatible pointer type
    By bhdavis1978 in forum C Programming
    Replies: 5
    Last Post: 03-17-2010, 12:42 PM
  2. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  3. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM

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