Hi,
I do not think this is a problem as such but an interesting behaviour to watch.
I have little piece of C (to do with trying later Unicode, Polish characters and text files).
I was trying to find a position of a Polish character in the alphabet string. Had some problems
so I devised this simple temp. count display.
See the comment line 35 starting: // observe the lines below. I have there simple 3xprintf() to print two
lines being like a ruler and the alphabet string under:
000000000111 and so on up to 7
123456789012 and so on up to 0 - so ruller to 70-th pos
AaĄąCcĆćDdEe and the rest of the Polish alphabet
So the lines must be one under the other. The first might be: printf("000000000111\n"); see the \n
then printf("12345678912\n"); the \n and printf("AaĄąCcĆćDdEe\n"0;
All was fine until I wanted to stop the execution just after the first printf(); to see
what was printed. I put the getchar(); there next after the ptintf() and press just ENTER
I am getting an empty line like this:
000000000111
_
123456789012
AaĄąCcĆćDdEe
ect.
The getchar() function (cursor) waits IN THE newline and the ruler is split with it like above.
SO for the purpose of testing the first printf() but still have the proper behaviour - newlines
behaving properly I have to remove the \n from the printf() function. Then getchar() waits
at the, just printed, line grabs the ENTER key (which acts like a \n in the printf() and prints the rest ok.
I just found it as an interesting a little confusing BUT NORMAL behaviour.
=====================
/*
This routine will operate within
the Unicode area of characters especially
the Polish 'ogonki' so it requires
the use of wide characters headers
and wide chars functions. At the moment
*/
#include <wchar.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
FILE *fp_in, *fp_out;
// the lines below are to create a kind of measuring ruler
// this in standard string
char *top_ndx = "0000000001111111111222222222233333333334444444444555555555566666666667\0";
char *bot_ndx = "1234567890123456789012345678901234567890123456789012345678901234567890\0";
int c;
// as above but with wide char strings
wchar_t *topw_ndx = L"0000000001111111111222222222233333333334444444444555555555566666666667\0";
wchar_t *botw_ndx = L"1234567890123456789012345678901234567890123456789012345678901234567890\0";
wchar_t *pl_alfa_wd = L"AaĄąCcĆćDdEeĘęFeGgHhIiJjKkLlłŁMmNnOoÓóPpQqRrSsŚśTtUuWwXxYyZzŹźŻż<#>.,\0";
setlocale(LC_ALL, "pl_PL.utf8"); //Set localisation for utf8-polish
// getchar();
// observe the lines below printf() and getchar()
printf("STD CHARS - \n%s", top_ndx);
getchar();
printf("%s\n", bot_ndx);
// getchar();
printf("%ls\n", pl_alfa_wd);
printf("\nNOW LONG STR CHARS LLL\n\n");
printf("%ls\n", topw_ndx);
printf("%ls\n", botw_ndx);
printf("%ls\n", pl_alfa_wd);
exit(0);
}
=====================