我是一名具有强大的 Java for Android 背景的程序员。我对 C 语言非常陌生,我只是学习它来为 Pebble 编写配套应用程序。编辑:我正在使用 cloudpebble,所以我无法控制库。
这是我认为问题所在的代码部分的摘要:
#include <pebble.h>
static int s_time_a_min;
static int s_time_a_h;
static int s_time_b_min = 0;
static int s_time_b_h = 0;
static int s_time_b_total;
char* c_time_string_min;
char* c_time_string_h;
int str_cut(char *str, int begin, int len){ //I got this method from the internet
int l = strlen(str);
if (len < 0) len = l - begin;
if (begin + len > l) len = l - begin;
memmove(str + begin, str + begin + len, l - len + 1);
return len;
}
static void update_text(){
time_t current_time;
c_time_string_min = ctime(¤t_time); //set these two strings the same: current time
c_time_string_h = ctime(¤t_time); //they are only strings so that they can be substringed
c_time_string_min = str_cut(c_time_string_min, 14, 16); //substring so that the each string has either min or h
c_time_string_h = str_cut(c_time_string_h, 11, 13);
s_si_h = atoi(c_time_string_h); //make the strings integers so that I can do math with them
s_si_min = atoi(c_time_string_min);
s_time_b_total = (((s_si_h) * 3600) + ((s_si_min) * 60)) * (123/99); //do some math. Don't ask what it's for.
do{
s_time_b_total = s_time_b_total - 10000; //do some more math. Also don't ask what it's for.
s_time_b_h = s_time_b_h + 1;
}while(s_ra_all > 10000);
do{
s_time_b_total = s_time_b_total - 100;
s_time_b_min = s_time_b_min + 1;
}while(s_ra_all > 100);
//Here is where I think the problem lies.
const char* buf = (char)(((int)0)+s_time_b_h) + ":" + (char)(((int)0)+s_time_b_min); //create a string that merges the two integers together and puts a colon in the middle
text_layer_set_text(s_time_layer, buf); //Set text
}
然后是通常的 Window_load、main、init 等。
请告诉我我做错了什么。谢谢。