0 c
我创建代码以显示多个页面(最多5行/页)与一个列表中的人:
/* PRE: page : number of the page we want to show, starting with 1
* RETURNS: pagenumber of the page showing if there is one, 0 otherwise */
const int buf_length = 255;
const int max_num_lines = 15;
const int num_person_per_page = max_num_lines / 3;
const int num_person = person_get_num_person(personmgr);
char buf[buf_length+1];
int i, count, cur = 0;
/* List Header */
snprintf(buf, buf_length, "List of person on page (%d/%d)):", page, num_person/num_person_per_page);
list_set_text( list, cur++, buf);
list_set_hilight(list, -1);
Run Code Online (Sandbox Code Playgroud)
如果列表中的人数不是5的倍数(在我的示例中为72),则最后一页的列表标题将页面总数返回为14而不是15(14/15).
首页列表标题:
List of person on page: 1/14:
01. AAA
02. BBB
03. CCC
04. DDD
05. EEE
Run Code Online (Sandbox Code Playgroud)
第二页列表标题:
List of person on page: 2/14:
06. FFF
07. GGG
08. HHH
........................
Run Code Online (Sandbox Code Playgroud)
最后一页列表标题:
List of person on page: 14/15:
71. XXX
72. ZZZ
Run Code Online (Sandbox Code Playgroud)
我想要舍入到下一个整数(要正确显示的页码).
72 / 5 = 14.4 => 15
70 / 5 = 14 => 14
36 / 5 = 7.2 => 8
Run Code Online (Sandbox Code Playgroud)
首页列表标题:
List of person on page: 1/15:
01. AAA
02. BBB
03. CCC
04. DDD
05. EEE
Run Code Online (Sandbox Code Playgroud)
第二页列表标题:
List of person on page: 2/15:
06. FFF
07. GGG
08. HHH
........................
Run Code Online (Sandbox Code Playgroud)
最后一页列表标题:
List of person on page: 15/15:
71. XXX
72. ZZZ
Run Code Online (Sandbox Code Playgroud)