adds proper error handling

This commit is contained in:
SuperNovaa41 2024-01-12 12:29:09 -05:00
parent 5c327958e2
commit d0427725a6
3 changed files with 12 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
isbn

BIN
isbn

Binary file not shown.

12
main.c
View File

@ -108,6 +108,16 @@ void parse_json(string* s)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
cJSON* numFound = cJSON_GetObjectItemCaseSensitive(json, "numFound");
if (0 == numFound->valueint) {
fprintf(stderr, "No ISBN found!\n");
exit(EXIT_FAILURE);
} else if (numFound->valueint > 1) {
fprintf(stderr, "Multipled ISBNs found, exiting!\n");
exit(EXIT_FAILURE);
}
cJSON* docs = cJSON_GetObjectItemCaseSensitive(json, "docs"); cJSON* docs = cJSON_GetObjectItemCaseSensitive(json, "docs");
cJSON* child = docs->child; // this is the JSON object that stores all of the books information cJSON* child = docs->child; // this is the JSON object that stores all of the books information
@ -132,7 +142,7 @@ void parse_json(string* s)
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
char isbn_buf[14]; char isbn_buf[14]; // want to hold a max of 14 so we can hold up to ISBN13s
CURLcode res; CURLcode res;
if (2 != argc) { if (2 != argc) {