Stanislav Stanislav -4 years ago 172
C Question

While loop doesn't initialize

I've got a problem. Here is a function that processes the width of a wide-string. My program is entering an infinite loop after BREAKPOINT 1. What's wrong with my loop?

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

Answer Source

while (i < len + delta);

Semi-colon.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download