summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dynotify.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/dynotify.c b/dynotify.c
index 9ee06ce..8061398 100644
--- a/dynotify.c
+++ b/dynotify.c
@@ -36,6 +36,9 @@
#include<libnotify/notify.h>
#define DYROOM_ID_LEN 9
+// utf-8 most chinese characters 3 bytes, my longest name currently is 2 chinese characters, 2*3=6, +1 for \0
+// but gcc will not error when not consider \0, maybe the complier auto add one more element?
+#define DYROOM_NAME_LEN 6
struct memory {
char *response;
@@ -43,20 +46,18 @@ struct memory {
};
struct dyroom {
- // utf-8 most chinese characters 3 bytes, my longest msg currently is 5 chinese characters, 5*3=15, +1 for \0
- // but gcc will not error when use 15, maybe the complier auto add one more element?
- const char msg[16];
- const char id[DYROOM_ID_LEN];
+ const char name[DYROOM_NAME_LEN];
+ const unsigned int id;
bool up;
};
// /home/xyz/archive/programs/private_archive_codes/c/c_primer_plus/practices/Chapter14/14-1monthStruct.c
struct dyroom room[5]={
- {"阿冉开播","4605243",false},
- {"甜汤开播","2766480",false},
- {"少君开播","9640128",false},
- {"鸽子她开播","236288",false},
- {"郑正开播","10883525",false}
+ {"阿冉",4605243,false},
+ {"甜汤",2766480,false},
+ {"少君",9640128,false},
+ {"她她",236288,false},
+ {"郑正",10883525,false}
};
// copy from `man CURLOPT_WRITEFUNCTION`
@@ -94,8 +95,11 @@ int main (void)
// manpage assign 0 to struct, it seems because C11 when cast 0 to void* is same as NULL? see:
// https://www.geeksforgeeks.org/null-pointer-in-c/
struct memory chunk = {0};
+ char id_str[DYROOM_ID_LEN];
+ // or itoa()
+ sprintf(id_str, "%d", room[i].id);
char url[29+DYROOM_ID_LEN]="https://www.douyu.com/betard/";
- strcat(url,room[i].id);
+ strcat(url,id_str);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cb);
@@ -108,7 +112,11 @@ int main (void)
{
if(!room[i].up)
{
- n = notify_notification_new (room[i].msg, NULL, NULL);
+ // 开播 is 2*3=6 bytes
+ char msg[DYROOM_NAME_LEN+6];
+ sprintf(msg,"%s开播",room[i].name);
+
+ n = notify_notification_new (msg, NULL, NULL);
notify_notification_set_urgency(n, NOTIFY_URGENCY_CRITICAL);
notify_notification_show (n, NULL);