我刚开始学习C,我想创建一个基于文本的小型浏览器。当程序启动时,它会显示“输入 URL:”,然后我使用scanf()
, 来获取用户的输入。当它抓住它时,它应该说“正在加载 {USER_INPUT}...”,但它却说“正在加载 {FIRST_LETTER_OF_USERS_INPUT}...”,在这种情况下它是h
. 我确信声明变量有问题。这是我的完整代码:
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
char urlinput;
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
printf("\nEnter a URL to go to: ");
scanf("%c", &urlinput);
printf("\nLoading %c...\n", urlinput);
curl_easy_setopt(curl, CURLOPT_URL, urlinput);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
if(res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
return 0;
}