new to C , error C2371: 'error" : redefinition; diffrent basic types -


i've submit assigment in few hours , i'm nervous, it's sort of gas station managing programs, handeling input files, , printing results... it's 1 .c file , that's first code lines, defines structs

#include <stdio.h> #include <string.h> #include <stdlib.h>    struct gas_station *pgasstationhead = null; typedef struct gas_station {    char *name;    double octan95ss;  double octan95fs;  double octan98ss;  double octan98fs;  double gassoldtotal;  double gassoldss;  double gassoldfs;  struct gas_station* pgasstationnext;  struct client_list* pclienthead; } station;  typedef struct client_list {    char carid[10];  char gastype[3];    double gasamount;  char servicetype[12];  struct client_list* pclientnext; } client; 

and problematic functions , main :

void commandsswitch(char *orders) {  file *input , *output;  input = fopen(orders, "rt");  output = fopen("result.txt" , "wt");  if (input == null) {    error("can't open file, might not exists");  }  else if (output == null) {    error("can't open file");  }  else {   {    int i;    char *ptemp, *pfuncnum, *pcarid , *pstationname;     ptemp = fgets(ptemp , 80 , input);    if (ptemp[0] != '#') {     pfuncnum = strtok(ptemp , ",");     = (int)pfuncnum[0];     switch (i)     {      case 1:      howmuchgasperstation(output);      break;       case 2 :      pstationname = strtok(pstationname , ",");      averagegasinspecieficstation(output , pstationname);      break;       case 3 :      howmuchgasinallstations(output);      break;       case 4 :      howmuchgasfsinallstations(output);      break;       case 5 :      pcarid = strtok(ptemp , ",");      howmuchgassoldbycarid(output , pcarid);      break;      case 6 :      pcarid = strtok(ptemp , ",");      pstationname = strtok(pstationname , ",");      howmuchgassoldbystationpercarid(output , pcarid , pstationname);      break;      case 7 :      pcarid = strtok(ptemp , ",");      stationswithclientbycarid(output , pcarid);      break;      case 8 :      pcarid = strtok(ptemp , ",");      pstationname = strtok(pstationname , ",");      howmuchclientspentbystation(output , pcarid , pstationname);      break;      case 9 :      pcarid = strtok(ptemp , ",");      howmuchclientspentintotalbycarid(output , pcarid);      break;       case 10 :      pstationname = strtok(pstationname , ",");      clientdetailsbyspecieficstation(output , pstationname);      break;     }    }   }while(!feof(input));   }  fclose(input);  fclose(output); }  static void error(char *msg) {  fprintf(stderr , "error: %s\n", msg);  exit(1); }  int main (int argc, char* argv[]) {  int i;  file *f;  char *orders = argv[1];  (i = 2; < argc; i++) {   f = fopen(argv[i] , "rt");   if (f == null) {    error("can't open file, might not exists");   }   else {    addstation(f);   }   fclose(f);  }  commandsswitch(orders);  } 

now error points static void error(char *msg) function before pointed void commandsswitch(char *orders), commandsswitch give same error.

plz try , guide me, i'm confused. tnx.

one of problems use of error function in commandswitch.

void commandsswitch(char *orders) {  file *input , *output;  input = fopen(orders, "rt");  output = fopen("result.txt" , "wt");  if (input == null) {    error("can't open file, might not exists");  }  else if (output == null) {    error("can't open file");  }  /* ...more... */ 

you use error function before actual declaration of error function further down:

static void error(char *msg) {  fprintf(stderr , "error: %s\n", msg);  exit(1); } 

you ran implicit function declaration feature of c, allows use function if implicitly declared, not using function prototypes.

to compiler, acts though there's function declared as

int error(...); 

which conflict function:

static void error(char *); 

so basically, code acts though there function called error declared, , default return type of int. compiler run void error() function declaration, , complain there redefinition of function error.

the easiest method fix issue, @ least, move error function before void commandsswitch.

you want read function declarations , prototypes:


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -