Thread: c program error

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    21

    c program error

    hello,
    can someone help in removing these errors from my c code:


    prog.h code:

    Code:
    typedef struct iosig
    {
       int signal_name;
       int signal_sub;
    }IoSignal;
    
    
    typedef struct contsig
    {
      int diff;	/* 1, 2, etc.  0 if no derivative */
      int power;	/* 2, 3, etc.  1 if no power */
      IoSignal iosig;
      struct contsig *next;
    }ContSig;
    
    typedef struct contterm
    {
      double coeff;
      ContSig *csig, *csig_tail; /* could be NULL if just const coeff */
      struct contterm *next;
    }ContTerm;
    
    typedef struct Conteqn
    {
      double coeff;
      ContTerm *cterm, *cterm_tail; /* could be NULL if just const coeff */
      struct conteqn *next;
    }ContEqn;
    extern ContEqn *new_conteqn(int i,ContTerm *cterm);
    
    extern ContTerm *new_cterm( ContSig *csig);
    
    extern ContSig * new_csig ( int i,IoSignal iosig,int j);
    
    extern IoSignal iosign( int i,int j);
    
    extern void append_conteqn( ContEqn *conteqn,ContTerm *cterm);
    
    extern ContEqn*  append_cterm( ContEqn *conteqn, int sig ,ContTerm *cterm);
    
    extern void append_csig( ContTerm *cterm,ContSig *csig);
    prog.c code starting from line 44

    Code:
    Conteqn *new_conteqn(int i,ContTerm *cterm)
    {
          struct Conteqn *e = malloc( sizeof( struct conteqn ));
         if( e == NULL)
         {
               yyerror( "new_node: malloc failed");
               exit(1);
         }
         e->coeff = i;
         e->cterm = e->cterm_tail = cterm;
         e->next = NULL;
         return e;
    }              
    
    void append_conteqn( Conteqn *conteqn,ContTerm *cterm)
    {
        conteqn->cterm_tail->next =cterm;
        conteqn->cterm_tail=cterm;   
    
    }
    
    ContTerm *new_cterm( ContSig *csig)
    {
       struct contterm *e = malloc( sizeof( struct ContTerm) );
       if( e == NULL)
       {
           yyerror( "new_node: malloc failed");
           exit(1);
       }
       e->csig = e->csig_tail = csig;
       e->next = NULL;
       return e;
    
    }
    
    void append_cterm( ContTerm *cterm, int sig, ContSig *csig)
    {   
        cterm->csig_tail->next = csig;
        cterm->csig_tail = csig;
        cterm->coeff = sig;
    }
       
    ContSig * new_csig ( int i, IoSig iosig, int j)
    {
        struct contsig *e = malloc( sizeof( struct ContSig));
        if( e == NULL)
        {
            yyerror( "new_node: malloc failed");
            exit(1);
        }
        e->iosig = iosig;
        e->diff=i;
        e->power =j;
        e->next = NULL;
        return e;
    }
    
    void append_csig( ContSig *csig , IoSignal* iosig )
    {
        csig->iosig.next = iosig;
        csig->iosig = iosig;
        csig->diff = csig->diff;
        csig->power = csig->power;   
    }  
    
    IoSignal iosign( int i,int j)
    {
       IoSignal x;
       x.signal_name = i;
       x.signal_sub = j;
       return x;
    }
    errors:
    jpj.c: At top level:
    jpj.c:44: parse error before '*' token
    jpj.c:45: warning: return type defaults to `int'
    jpj.c:45: conflicting types for `new_conteqn'
    jpj.h:52: previous declaration of `new_conteqn'
    jpj.c: In function `new_conteqn':
    jpj.c:46: sizeof applied to an incomplete type
    jpj.c:55: warning: return from incompatible pointer type
    jpj.c: At top level:
    jpj.c:58: parse error before '*' token
    jpj.c: In function `append_conteqn':
    jpj.c:59: number of arguments doesn't match prototype
    jpj.h:60: prototype declaration
    jpj.c:60: `conteqn' undeclared (first use in this function)
    jpj.c:60: `cterm' undeclared (first use in this function)
    jpj.c: In function `new_cterm':
    jpj.c:67: sizeof applied to an incomplete type
    jpj.c: At top level:
    jpj.c:80: conflicting types for `append_cterm'
    jpj.h:62: previous declaration of `append_cterm'
    jpj.c:86: parse error before "IoSig"
    jpj.c: In function `new_csig':
    jpj.c:87: number of arguments doesn't match prototype
    jpj.h:56: prototype declaration
    jpj.c:88: sizeof applied to an incomplete type
    jpj.c:94: `iosig' undeclared (first use in this function)
    jpj.c:95: `i' undeclared (first use in this function)
    jpj.c:96: `j' undeclared (first use in this function)
    jpj.c: At top level:
    jpj.c:102: conflicting types for `append_csig'
    jpj.h:64: previous declaration of `append_csig'
    jpj.c: In function `append_csig':
    jpj.c:103: structure has no member named `next'
    jpj.c:104: incompatible types in assignment

    regards,
    cutelucks

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I'll help you with the first thing I saw:

    Code:
    Conteqn *new_conteqn(int i,ContTerm *cterm)
    What type is Conteqn? This is your declaraction of the function:

    Code:
    extern ContEqn *new_conteqn(int i,ContTerm *cterm);
    See the problem?

    *cough* Case sensitivity. *cough*.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    And one more here which i can see

    Code:
    typedef struct contterm
    {
      double coeff;
      ContSig *csig, *csig_tail; /* could be NULL if just const coeff */
      struct contterm *next;
    }ContTerm;

    Code:
    ContTerm *new_cterm( ContSig *csig)
    {
       struct contterm *e = malloc( sizeof( struct ContTerm) );
       if( e == NULL)
       {
           yyerror( "new_node: malloc failed");
           exit(1);
       }
       e->csig = e->csig_tail = csig;
       e->next = NULL;
       return e;
    
    }
    ssharish

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Got a problem here too:

    Code:
    extern void append_conteqn( ContEqn *conteqn,ContTerm *cterm);
    Code:
    void append_conteqn( Conteqn *conteqn,ContTerm *cterm)
    Todd

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    on lines 44-45:
    Code:
    Conteqn *new_conteqn(int i,ContTerm *cterm)
    {
    Where are your function prototypes? because one of the errors is telling you that the prototype and function return or arguments don't match.

    EDIT: Sorry, I don't know how I missed the prototypes. The problem is - as I said before - that they don't match.
    compare the two - the first one above - :
    Code:
    extern ContEqn *new_conteqn(int i,ContTerm *cterm);
    You see any difference? again *cough* case sensitivity *cough*
    Last edited by Abda92; 12-21-2007 at 08:18 AM.

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    21
    hiee

    i corrected that error but still even when the names are consistent i get many more errors which i am unable to figure out.can anyone tell what else is wrong in my code?

    thanx & Regards,
    cutelucks

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Well, post your latest code and the errors you get whilst compiling it.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Before you write your next program, read this:
    http://cboard.cprogramming.com/showthread.php?t=88495
    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.

  9. #9
    Registered User
    Join Date
    Apr 2007
    Posts
    21

    my code

    jpj.h
    Code:
    /* dynamically copy string or exit if malloc fails */
    
    char *estrdup( const char *str);
    
    /* have to declare this somewhere... */
    
    extern void yyerror( const char *msg);
    
    typedef struct iosig
    {
       int signal_name;
       int signal_sub;
    }IoSignal;
    
    
    typedef struct contsig
    {
      int diff;	/* 1, 2, etc.  0 if no derivative */
      int power;	/* 2, 3, etc.  1 if no power */
      IoSignal iosig;
      struct contsig *next;
    }ContSig;
    
    typedef struct contterm
    {
      double coeff;
      ContSig *csig, *csig_tail; /* could be NULL if just const coeff */
      struct contterm *next;
    }ContTerm;
    
    typedef struct Conteqn
    {
      double coeff;
      ContTerm *cterm, *cterm_tail; /* could be NULL if just const coeff */
      struct conteqn *next;
    }ContEqn;
    
    extern ContEqn *new_conteqn(int i,ContTerm *cterm);
    
    extern ContTerm *new_cterm( ContSig *csig);
    
    extern ContSig * new_csig ( int i,IoSignal iosig,int j);
    
    extern IoSignal iosign( int i,int j);
    
    extern void append_conteqn( ContEqn *conteqn,ContTerm *cterm);
    
    extern void  append_cterm( ContEqn *conteqn, int sig ,ContTerm *cterm);
    
    extern void append_csig( ContTerm *cterm,ContSig *csig);
    
    void print_fn();
    jpj.c :
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include "jpj.h"
    
    /* dynamically copy string or exit if malloc fails */
    
    
    char *estrdup( const char *str)
    {
      char *s = malloc( strlen(str) + 1);
      if( s == NULL)
      {
        yyerror( "estrdup: malloc failed");
        exit(1);
      }
      strcpy( s, str);
      return s;
    }
    
    ContEqn *new_conteqn(int i,ContTerm *cterm)
    {
         struct ContEqn *e = malloc( sizeof( struct ContEqn ));
         if( e == NULL)
         {
               yyerror( "new_node: malloc failed");
               exit(1);
         }
         e->coeff = i;
         e->cterm = e->cterm_tail = cterm;
         e->next = NULL;
         return e;
    }              
    
    void append_conteqn( ContEqn *conteqn,ContTerm *cterm)
    {
        conteqn->cterm_tail->next =cterm;
        conteqn->cterm_tail=cterm;   
    
    }
    
    ContTerm *new_cterm( ContSig *csig)
    {
       struct ContTerm *e = malloc( sizeof( struct ContTerm) );
       if( e == NULL)
       {
           yyerror( "new_node: malloc failed");
           exit(1);
       }
       e->coeff = e->coeff;
       e->csig = e->csig_tail = csig;
       e->next = NULL;
       return e;
    
    }
    
    void append_cterm( ContEqn *conteqn, int sig ,ContTerm *cterm)
    {   
        conteqn->cterm_tail->next =cterm;
        conteqn->cterm_tail=cterm;   
        conteqn->coeff = sig;
        conteqn->next = NULL;
        
    }
       
    ContSig * new_csig ( int i, IoSig iosig, int j)
    {
        struct ContSig *e = malloc( sizeof( struct ContSig));
        if( e == NULL)
        {
            yyerror( "new_node: malloc failed");
            exit(1);
        }
        e->iosig = iosig;
        e->diff=i;
        e->power =j;
        e->next = NULL;
        return e;
    }
    
    void append_csig(ContTerm *cterm,ContSig *csig)
    {
        cterm->csig_tail->next = csig;
        cterm->csig_tail = csig;
        cterm->next = NULL;
        cterm->coeff = cterm->coeff;
        
    }  
    
    IoSignal iosign( int i,int j)
    {
       IoSignal x;
       x.signal_name = i;
       x.signal_sub = j;
       return x;
    }
    
    void print_fn()
    {
    	printf("dummy");
    }
    Regards,
    cutelucks

  10. #10
    Registered User
    Join Date
    Apr 2007
    Posts
    21

    errors:

    hiie,
    sorry i missed the errors part.

    Errors:
    jpj.c: In function `new_conteqn':
    jpj.c:46: sizeof applied to an incomplete type
    jpj.c:52: dereferencing pointer to incomplete type
    jpj.c:53: dereferencing pointer to incomplete type
    jpj.c:53: dereferencing pointer to incomplete type
    jpj.c:54: dereferencing pointer to incomplete type
    jpj.c:55: warning: return from incompatible pointer type
    jpj.c: In function `new_cterm':
    jpj.c:67: sizeof applied to an incomplete type
    jpj.c:73: dereferencing pointer to incomplete type
    jpj.c:73: dereferencing pointer to incomplete type
    jpj.c:74: dereferencing pointer to incomplete type
    jpj.c:74: dereferencing pointer to incomplete type
    jpj.c:75: dereferencing pointer to incomplete type
    jpj.c:76: warning: return from incompatible pointer type
    jpj.c: At top level:
    jpj.c:81: conflicting types for `append_cterm'
    jpj.h:62: previous declaration of `append_cterm'
    jpj.c:89: parse error before "IoSig"
    jpj.c: In function `new_csig':
    jpj.c:90: number of arguments doesn't match prototype
    jpj.h:56: prototype declaration
    jpj.c:91: sizeof applied to an incomplete type
    jpj.c:97: dereferencing pointer to incomplete type
    jpj.c:97: `iosig' undeclared (first use in this function)
    jpj.c:98: dereferencing pointer to incomplete type
    jpj.c:98: `i' undeclared (first use in this function)
    jpj.c:99: dereferencing pointer to incomplete type
    jpj.c:99: `j' undeclared (first use in this function)
    jpj.c:100: dereferencing pointer to incomplete type
    jpj.c:101: warning: return from incompatible pointer type


    jpj.c starts from line 46

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Your first few errors are here.
    Code:
    ContTerm *new_cterm( ContSig *csig)
    {
       struct ContTerm *e = malloc( sizeof( struct ContTerm) );
       if( e == NULL)
       {
           yyerror( "new_node: malloc failed");
           exit(1);
       }
       e->coeff = e->coeff;
       e->csig = e->csig_tail = csig;
       e->next = NULL;
       return e;
    
    }
    The compiler is complaining because the type struct ContTerm doesn't exist. If you declare a structure like this
    Code:
    typedef struct {
        /* ... */
    } newtype;
    then you can only use newtype, not struct newtype.

    In your case,
    Code:
    typedef struct contterm
    {
      double coeff;
      ContSig *csig, *csig_tail; /* could be NULL if just const coeff */
      struct contterm *next;
    }ContTerm;
    you can use the types "ContTerm" and "struct contterm".

    You should either use a typedef and no "struct"s, or don't use a typedef and use "struct"s everywhere. Your choice. You could use both, but it's just plain confusing.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The first error, I think, was pointed out earlier. There is no struct called "ContEqn" - there is a typedef by that name, but no struct. Compiler can't tell the difference between "You added struct in front of a typedef" and "I haven't heard of a struct called ContEqn".

    General rule when it comes to fixing errors [aside from "Don't write lots of code then try to compile it"] is to fix the first error, then compile again. I suspect you will find that sometimes a whole bunch of errors are caused by a single mistake in the code.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    Registered User
    Join Date
    Apr 2007
    Posts
    21
    thanx a lot.i could correct most of my errors now.i have only one more doubt.what does this error mean?


    jpj.c: In function `new_conteqn':
    jpj.c:46: sizeof applied to an incomplete type
    jpj.c: In function `new_cterm':
    jpj.c:67: sizeof applied to an incomplete type


    thanx & Regards,
    cutelucks

  14. #14
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    The same thing, probably.
    Code:
    #include <stdio.h>
    
    int main() {
        printf("&#37;d\n", (int)sizeof(struct this_does_not_exist));
    
        return 0;
    }
    Code:
    c.c: In function ‘main’:
    c.c:4: error: invalid application of ‘sizeof’ to incomplete type ‘struct this_does_not_exist’
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  15. #15
    Registered User
    Join Date
    Apr 2007
    Posts
    21
    thanx a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM