Hey I have been making an auction kind of prgram where the lowest unique bid wins. Upon compilation I ran into these errors that I could not fix:
Auctions.c: In function ‘main’:
Auctions.c:27: error: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
Auctions.c: In function ‘insertNewBid’:
Auctions.c:60: error: passing argument 1 of ‘insertNewBid’ from incompatible pointer type
Auctions.c:62: error: passing argument 1 of ‘insertNewBid’ from incompatible pointer type
Here is the code, any help/tips are appreciated:
Code:#include <stdio.h> #include <stdlib.h> typedef struct bids *Bids; #define TRUE 1 #define FALSE 0 struct bids { int bidAmount; int unique; struct Bids *right; struct Bids *left; }; int findLowestUnique (Bids Auction); Bids newBid(int bid); void insertNewBid(Bids Auction, Bids newBids); int main (void) { int bid; Bids newBids = malloc(sizeof(Bids)); Bids Auction = malloc(sizeof(Bids)); // while(getchar() != NULL) { scanf("%d", &bid); newBids = newBid(bid); insertNewBid(Auction, newBids); printf("Bid of %d: ", bid); if (newBids->unique == FALSE) { printf("not unique "); } else if (findLowestUnique(Auction) == bid) { printf("new lowest unique bid! "); } else { printf("unique but not lowest "); } printf("[best bid: %d]", findLowestUnique(Auction)); //} return(0); } Bids newBid(int bid) { Bids bids = malloc(sizeof(Bids)); bids->bidAmount = bid; bids->unique = TRUE; bids->left = NULL; bids->right = NULL; return (bids); } void insertNewBid(Bids Auction, Bids newBids) { if (Auction == NULL) { Auction = newBids; } else if (newBids->bidAmount < Auction->bidAmount) { insertNewBid(Auction->left, newBids); } else if (newBids->bidAmount > Auction->bidAmount) { insertNewBid(Auction->right, newBids); } else if (newBids->bidAmount == Auction->bidAmount) { newBids->unique = FALSE; Auction->unique = FALSE; } }



LinkBack URL
About LinkBacks



I strongly recommend you ditch the typedef and use pointers directly instead of hiding them, because that's the root of your problem. But I know you won't, so this is what your structure definition should be like: