我正在使用ncurses,cJSON和libcurl在C中编写a simple program,当你按一个键时,它会获取Chuck Norris的事实,并且由于某种原因,无论运行多少次,事实都保持不变。 / p>
我认为有问题的代码是here:
for(;;) {
/* get the json data */
res = curl_easy_perform(curl_handle);
/* check for errors */
if (res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n",\
curl_easy_strerror(res));
} else {
/*
* Now, our chunk.memory points to a memory block that is chunk.size
* bytes big and contains the remote file.
*
* Do something nice with it!
*/
cJSON* root = cJSON_Parse((char *) chunk.memory);
char* joke = cJSON_GetObjectItem(root, "value")->valuestring;
printw("Here's a joke:\n %s\n", joke);
cJSON_Delete(root);
getch();
}
}
为什么它不能按预期工作?写这个的正确方法是什么?