Thread: incompatible types in assignment

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    46

    incompatible types in assignment

    following is main function of my program
    Code:
    #include<stdio.h>
    #include"header.h"
    
    main()
    {
        unsigned char crc;
        unsigned char ar;
        pdt pv;
        adt av;
        frame *f1;
        frame fr;
        
        int src1=0;
        int dest1=1;
    
        av.ack=9;
        
    //opens a file and assigns a file descriptive to fp
        fp=fopen("txtfile","r");
    
       //generates stuffed information
       stuff(&pv,fp);
       
        //creates the control byte
        control_byte(&pv);
    
        //crc is generated for the information
        crc=crc_gent(&pv);
    
        //frame is created..
        f1=(frame *)make_frame(&pv,crc,src1,dest1);
        
        //push that frame into a buffer
        push(f1);
        
    //check for the acknowledgement from the receiver side
        ar=ack_check(&av);
    
    //sliding window is created...
        fr = slide(512,ar); //incompatibe type in assignment
    }

    my header file is
    Code:
    #include<stdio.h>
    //typedef int frame_type;
    
    FILE * fp;
    
    typedef struct payload {
    	int frm_typ;
    	unsigned char cb;
    	unsigned char stuf_info[5];
    }pdt;
    
    typedef struct frame {
    	char st_flag;
    	int src_addr;
    	int dest_addr;
    	pdt p;
    	unsigned char crc;
    	char end_flag;
    }frame;
    struct frame f4[512];
    
    typedef struct ack_frme
    {
    char st_flg;
    int src_addr;
    int dest_addr;
    unsigned char ack;
    char end_flg;
    }adt;
    i have problem in
    fr = slide(512, ar);


    slide function is returning a frame..
    but for that line its giving error as incompatible types in assignment.
    Last edited by vapanchamukhi; 09-18-2008 at 10:23 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So where is the prototype for slide() in all of that.

    The make_frame() cast is almost certainly wrong for the same reason, except all that you've managed to do is stop the compiler from complaining about it.
    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.

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    46
    thats my main header file.... for each function one library is created and also a header file. in that the function prototypes are declared....

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If slide() is defined in slide.c and prototyped in slide.h, then you also need
    #include "slide.h"
    in your main
    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.

  5. #5
    Registered User
    Join Date
    Aug 2008
    Posts
    46
    This is my slide function... i have taken 'f' as a variable of frame type. and slide function is returning this 'f' which is of frame type.... so in the main function also im receiving this in a variable which is also of type frame... so also it is giving error... im actually not understanding any thing why its giving error????


    Code:
     #include<stdio.h>
     #include"header.h"
    
      int sequence(unsigned char seq);
    
    
    frame slide(int size,unsigned char seq)    //for sliding window of size 5
     {
        int frameN;
        frame f;
        static int i=-1,j=-1,c=0;           /* i indicates the index of start of window and j indicates the index of last frame sent in the window, required the values of i and j to be static as to persist in the next function calls*/
    	    int k;                                 //index of the frame to sent is remembered in k
        frameN=sequence(seq);
        if(c==5 && frameN==0)                            /* if no acknowledgement is received when window size is over then setting the values of i and j to                                                         retransmit frames*/
        {
          j=i;
          c=0;                                   //resetting window size counter to zero
        }
       else                  
           if(frameN==0)                       // if window counter is less than 5,and acknowledgement is not received then keep on sending frames        
           {
               c++;
               j++;
           }
        else                   //when acknowledgement is received the indices i and j are set according to the sequence no. mentioned in acknowledgement 
           {
    	       i=j=frameN;
               c=0;
           }
            k=j;             // index of the frame to sent is remembered in k
            j++;             //as sendind of frame takes place, index j is increased by one
        f = f4[k];
        return f;
     }

  6. #6
    Registered User
    Join Date
    Sep 2008
    Posts
    1
    check your compiler version?

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I don't see a prototype of slide() in your header.h file -- and unprototyped functions return int.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Incompatible types in assignment.
    By killpoppop in forum C Programming
    Replies: 36
    Last Post: 12-22-2008, 12:08 PM
  2. assignment from incompatible pointer types
    By iunah in forum C Programming
    Replies: 13
    Last Post: 10-12-2008, 03:32 AM
  3. incompatible types in assignment
    By vapanchamukhi in forum C Programming
    Replies: 1
    Last Post: 09-18-2008, 11:35 PM
  4. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  5. Incompatible types in assignment error
    By Zildjian in forum C Programming
    Replies: 12
    Last Post: 10-03-2003, 01:15 PM