struct - Conflicting types for "function" error (C) -


i keep getting error: [error] conflicting types 'average_grade' , cant find mistake.. new in c need here.

struct card {      char on[20];     char ep[20];     float b;     int ap;     struct card *next; };  struct card *first,*last,*t;  int ch;  int main() {      float mo;     {         printf("\n1.initialize\n2.add end\n3.show list\n4.average grade\n0.exit\nchoice:");         scanf("%d",&ch);         switch(ch) {             case 1: init_list(&first,&last);                     break;             case 2: t=create_node();                     add_to_end(t,&first,&last);                     break;             case 3: show_list(first);                     break;             case 4: mo=average_grade(&first);                     printf("%f",&mo);                     break;                           case 0: printf("bye!\n");                     break;             default:printf("try again.\n");                     break;         } /* switch */     } while (ch!=0);     system("pause");     return 0; }  float average_grade(struct card *arxh) {      struct card *i;     float sum=0;     int cnt=0;     (i=arxh; i!=null; i=i->next)     {         sum= sum + i->b;         cnt++;     }     return sum/cnt; } void init_list(struct card **arxh, struct card **telos) {      *arxh=null;     *telos=null; }  struct card *create_node() {      struct card *r;      r=(struct card *)malloc(sizeof(struct card));     printf("give data:");     scanf("%s %s %f %d",r->on,r->ep,&r->b,&r->ap);     r->next=null;      return r; }  void add_to_end(struct card *neos,struct card **arxh,struct card **telos) {      if (*arxh==null)     {         *arxh=neos;         *telos=neos;     }     else     {         (*telos)->next=neos;         *telos=neos;     } }   void show_list(struct card *arxh) {      struct card *i;      (i=first; i!=null; i=i->next)         printf("%s %s %.1f %d\n",i->on, i->ep, i->b, i->ap); } 

in c, if there's no visible prototype found @ time of calling function, compiler implicitly declares prototypes (pre-c99 -- since c99, implicit int rule has been removed) int return type.

but when actual definitions found later, type (floats) conflict ones compiler declared you. so, declare function prototypes @ beginning of file (or put them in header file) or move functions above main().


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -