From 3b80d08881db83903c0d948b22e4ff8644de03a7 Mon Sep 17 00:00:00 2001 From: Jonas Date: Sat, 26 Dec 2020 23:09:38 +0100 Subject: [PATCH] Debug --- http.c | 6 +++++- lichess.c | 6 ++++-- main.c | 5 +++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/http.c b/http.c index ead8ee3..42d5bd4 100644 --- a/http.c +++ b/http.c @@ -20,6 +20,10 @@ char* request(char *url) CURL *httpHandler = curl_easy_init(); CURLcode return_code; if(httpHandler) { + for(int i=0;i<128;i++) + { + fprintf(stderr,"%x",url[i]); + } curl_easy_setopt(httpHandler,CURLOPT_URL, url); curl_easy_setopt(httpHandler,CURLOPT_WRITEFUNCTION, httpResponseCallback); curl_easy_setopt(httpHandler,CURLOPT_USERAGENT, "cWikiBot/0.1 (https://git.zom.bi/cpp/cWikiBot; cpp@zom.bi) libcurl4/7.64.0"); @@ -33,7 +37,7 @@ char* request(char *url) } if(return_code != CURLE_OK) { - fprintf(stderr, "HTTP Error: %s",curl_easy_strerror(return_code)); + fprintf(stderr, "HTTP Error: %s\n",curl_easy_strerror(return_code)); return NULL; } return httpResponse.response; diff --git a/lichess.c b/lichess.c index dd023ec..3c80436 100644 --- a/lichess.c +++ b/lichess.c @@ -13,8 +13,10 @@ json_object* query_lichess(char* username) char* api_base = "https://lichess.org/api/user/"; char user_url[128]; int retries = 5; - strcpy(user_url,api_base); - strcat(user_url,username); + //strcpy(user_url,api_base); + //strcat(user_url,username); + int user_url_length = sprintf(user_url,"%s%s\0",api_base,username); + user_url[user_url_length]=0; printf("querying %s\n",user_url); char* http_response = request(user_url); while(http_response == NULL) diff --git a/main.c b/main.c index 8fde49b..a1f4f0d 100644 --- a/main.c +++ b/main.c @@ -41,8 +41,11 @@ int main(int argc, char **argv) } fputs("lichess_id,name\n",output); char line [128]; + int j=0; while(fgets(line, sizeof line, playersfile) != NULL) { + printf("%i",j); + j++; char outline[256]; char name[128]; line[strlen(line)-1] = '\0'; @@ -65,6 +68,8 @@ int main(int argc, char **argv) sprintf(outline, "%s,%s\n",line,name); printf("OK\n"); fputs(outline,output); + fclose(output); + fopen("output.csv","a"); } fclose(output); fclose(playersfile);