Sorting ByPrice - doesn't work
Wanzaz opened this issue · 0 comments
Wanzaz commented
Comparing Function
- Other parts of the function work just fine
- It can be cause by using the FLOAT type in C
- File: src/comparing.c
- Link: https://github.com/Wanzaz/Cryptocurrency-database/blob/main/src/comparing.c
/*
* Comparing Functions
* */
int compare(TCryptocurrency x, TCryptocurrency y, CompareType type)
{
switch (type) {
case ById:
return x.id - y.id;
case ByFoundationYear:
return x.foundation_year - y.foundation_year;
case ByName:
return strcmp(x.name, y.name);
case ByFounderName:
return strcmp(x.founder_name, y.founder_name);
case ByPrice:
return x.price - y.price;
}
}
Calling the Function
- File: src/main.c
- Link: https://github.com/Wanzaz/Cryptocurrency-database/blob/main/src/main.c
case 9: clear();
sort(stdout, crypto, ByPrice);
break;
Output of the Program
Cryptocurrency Database Program:
0 - exit
1 - write out a whole database
2 - add a record
3 - change a record
4 - remove a record
5 - search data by a cryptocurrency name
6 - sort by a foundation year
7 - sort by a cryptocurrency name
8 - sort by a founder
9 - sort by a price
10 - sort by id
11 - filter data by a foundation year
12 - summary
13 - data backup
Choose an operation: 9
+----+-----------------+---------------+-------------------+-----------+
| id | Foundation year | Crypto name | Founder name | Price $ |
|----+-----------------+---------------+-------------------+-----------|
| 6 | 2013 | Dogecoin | Jackson-Palmer | 0.07 |
| 11 | 2017 | Cardano | Charles-Hoskinson | 0.53 |
| 5 | 2012 | Peercoin | Sunny-King | 0.45 |
| 7 | 2014 | Titcoin | Edward-Mansfield | 0.00 |
| 4 | 2011 | Namecoin | Vincent-Durham | 1.30 |
| 9 | 2015 | Tether | Jan-Ludovicus | 1.00 |
| 13 | 2021 | SafeMoon | SafeMoon-LLC | 6.81 |
| 8 | 2014 | XLM | Jed-McCaleb | 16.00 |
| 3 | 2010 | Litecoin | Satoshi-Nakamoto | 81.11 |
| 12 | 2017 | Bitcoin-Cash | - | 128.71 |
| 10 | 2015 | Ethereum | Vitalik-Buterin | 1705.19 |
+----+-----------------+---------------+-------------------+-----------+