How to test the length of a new line when using u_fgets in ICU4C ustdio.h?

51 views Asked by At

In ICU4C,

UChar * u_fgets(UChar *s, int32_t n, UFILE *f)

will read one line from f into buffer s, which size is n.

But how can I know this one line's length ?

What will happen if n is not enough for this one line ?

1

There are 1 answers

0
the busybee On

But how can I know this one line's length ?

If u_fgets() works similarly to the standard fgets() it will put a '\0' after the last character read. Then you can get the length by calling strlen() or its equivalent version for your system.

What will happen if n is not enough for this one line ?

If u_fgets() works similarly to the standard fgets() it will stop filling characters into the buffer s so that '\0' gets into the last cell. This will be the nth character at s[n - 1]. Characters not stored will remain in the input stream f.


However, please read the documentation! That is always your first stop.