printf: can't print less than 1 character with %*c

Viewed 311

I have a code which intends to print some white-spaces after a string (to erase what could eventually be here, since I'm moving the cursor).

So, I used something like this:

int some_length = 0;
char some_string[]="hello world";
printf( "%*c%s\n", some_length, ' ', some_string );

Which I thought would produce "hello world", but no, it produces " hello world" (note that in my real code, the spaces are printed after the string, since the goal is to erase, not to indent, I'm simply doing this here to have working sample).

So, is this behavior intended? Since some_length is 0, one could reasonably hope to print nothing, right? Is this an undefined behavior, or could it be a but in the standard lib (I doubt it, but...)?

2 Answers
Related