more error handling

This commit is contained in:
SuperNovaa41 2024-01-12 12:50:10 -05:00
parent d0427725a6
commit 3dc1ab7722
2 changed files with 8 additions and 1 deletions

BIN
isbn

Binary file not shown.

9
main.c
View File

@ -136,7 +136,7 @@ void parse_json(string* s)
printf("Author(s): %s\n", authors->valuestring); printf("Author(s): %s\n", authors->valuestring);
} }
printf("Year of Publication: %d\n", cJSON_GetObjectItemCaseSensitive(child, "publish_year")->child->valueint); printf("(First) Year of Publication: %d\n", cJSON_GetObjectItemCaseSensitive(child, "first_publish_year")->valueint);
printf("Page length: %d\n", cJSON_GetObjectItemCaseSensitive(child, "number_of_pages_median")->valueint); printf("Page length: %d\n", cJSON_GetObjectItemCaseSensitive(child, "number_of_pages_median")->valueint);
} }
@ -150,6 +150,13 @@ int main(int argc, char* argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
size_t input_len = strlen(argv[1]);
if (!(13 == input_len || 10 == input_len)) {
fprintf(stderr, "Invalid ISBN submitted!");
return EXIT_FAILURE;
}
/** /**
* We must initialize cURL * We must initialize cURL
*/ */