c - Currency conversion database structure from text file -


i've been working on program data structure reads in file of different currencies, call use conversion. i've been running on days on end , tried fgets, fscanfs, , such, , i'm lost @ point pretty new programming.

the dat. file outlined on separate lines this:

dollar 1.00  yen 0.0078  franc 0.20  mark 0.68  pound 1.96 

my code far:

  typedef struct {    string currency;    double rate;    } currencyt;    typedef struct {    currencyt cur[maxcurrencytypes];    int ncurrency;    } *currencydb;     static currencydb readdatabase(void);     static readoneline(file *infile, currencydb db);      static currencydb readdatabase(void)  {    file *infile;    currencydb db;       int ncurrency;     db = new(currencydb);    infile = fopen(exchangefile, "r");        while (readoneline(infile, db));    fclose(infile);    return(db);  }    static readoneline(file *infile, currencydb db)   {    currencyt cur;    char termch, currency;    double rate;    int nscan, ncurrency;      ncurrency = 0;     while(1) {        nscan = fscanf(infile, "%20s %f%c", db->cur[ncurrency].currency,    &db->cur[ncurrency].rate, &termch);            if(nscan = eof) break;            if(nscan != 3 || termch != '\n') {                error("improper file format");                }            ncurrency++;            }        db->ncurrency = ncurrency;      }    static void processexchange(currencydb db)  {   }     main()  {    currencydb currencies;     currencies = readdatabase();     processexchange(currencies);    } 

see 8 & 9 first.

  1. maxcurrencytypes undeclared, let's assume

    #define maxcurrencytypes (5) 
  2. string undeclared, let's assume

    typedef char * string; 
  3. currencydb pointer type, recommend instead declaring structure type

    typedef struct {   currencyt cur[maxcurrencytypes];   int ncurrency; } currencydb;  // drop * 
  4. static readoneline() should use explicit return type.

    static int readoneline() 
  5. int ncurrency; not used in readdatabase().

  6. new() in db = new(currencydb) not declared nor defined. assume allocate uninitialized memory *db.

  7. exchangefile not declared.

  8. if (nscan = eof) -> if (nscan == eof)

  9. readoneline() needs return value.

  10. main() should explicitly state return type , parameters.

    int main(void)   

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -