我遇到了问题。这是一个处理宽字符串宽度的函数。我的程序在 BREAKPOINT 1 之后进入无限循环。我的循环出了什么问题?
static void ft_wstr_width(void)
{
wchar_t *temp;
size_t delta;
size_t len;
size_t i;
wint_t wc;
len = ft_wstrlen(g_ws);
delta = (size_t)g_fmt.width - ft_wstrsize(g_ws);
printf("(%d %zd)\n", g_fmt.width, ft_wstrsize(g_ws));
temp = (wchar_t *)malloc(sizeof(wchar_t) * (len + delta + 1));
temp[len + delta] = L'\0';
if (g_fmt.flags[0])
{
wc = (QWSZ ? L'0' : L' ');
i = 0;
while (i < delta);
{
temp[i] = wc;
++i;
}
ft_wcopy(temp, g_ws, delta, len);
}
else
{
printf("[bp0]"); getchar(); // BREAKPOINT 0
ft_wcopy(temp, g_ws, 0, len);
i = len;
printf("[bp1]"); getchar(); // BREAKPOINT 1
while (i < len + delta);
{
printf("[bp2]"); getchar(); // BREAKPOINT 2
temp[i] = L' ';
++i;
}
}
printf("[bp3]"); getchar(); // BREAKPOINT 3
free(g_ws);
g_ws = temp;
}
----- UBUNTU TERMINAL OUTPUT -----
stanislav:gh_ft_printf >>: ./a.out
(15 3)
[bp0]
[bp1] No reaction here (program keeps running) and
^C <---- I have to kill the process with Ctrl+C
答案 0 :(得分:1)
while(i&lt; len + delta);
半结肠。