adds proper error handling
This commit is contained in:
parent
5c327958e2
commit
d0427725a6
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
isbn
|
12
main.c
12
main.c
@ -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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user