0

This is strange.

Code:

for(i=ncx-1;i>=0;i--)
{
    fprintf(stderr,"|%-21s|\n",clist[i].label);
}
fprintf(stderr,"0-2-4-6-8-0-2-4-6-8-0-2-4\n");

Output:

    |5g(²G)              |
    |5f(²F°)            |
    |5d(²D)              |
    |5s(²S)              |
    |5p(²P°)            |
    |4f(²F°)            |
    |4d(²D)              |
    |4s(²S)              |
    |4p(²P°)            |
    |3d(²D)              |
    |3s(²S)              |
    |3p(²P°)            |
    |2s(²S)              |
    |2p(²P°)            |
    |1s(²S)              |
    0-2-4-6-8-0-2-4-6-8-0-2-4

Why aren't these lining up correctly?

I've changed the length and it still doesn't line up correctly.

Thanks.

Mannix
  • 411
  • 10
  • 23
  • I recon the length specifier is actually working correctly, and that it's your use/understanding of it that's really to blame... – Software Engineer Feb 28 '14 at 22:46
  • Probably you're using UTF-8 or another multibyte code set and the byte count is correct but some characters are using 2 bytes of data for one byte of display and others use just one. – Jonathan Leffler Feb 28 '14 at 22:47
  • Note that the entries with two 'special' (non-ASCII) characters are 2 spaces shorter than the ones with one special character; and these are shorter than the 21 characters you expected. How to solve it? Maybe convert the string to `wchar_t` and print with `wfprintf()`. Look up 'wprintf utf8' on SO to get better advice. – Jonathan Leffler Feb 28 '14 at 23:03

0 Answers0