is it possible to fix that?strlen should return the number of characters before the first null, though in NXC it does not really do that. It returns ArrayLen - 1.
[resolved]NXC:bug?feature?printing non-printable-ASCII-chars
Re: [resolved]NXC:bug?feature?printing non-printable-ASCII-chars
thx, again a little wiser...
-
- Posts: 358
- Joined: 01 Oct 2010, 06:37
- Location: Denmark
- Contact:
Re: NXC: bug? feature? when printing non-printable-ASCII-chars
But it is true. Your OS might display it in some way, however there is no guarantee. In Windows, printf does not produce any output for GUI applications even if you run it from the console (which is not the case on Linux iirc). And for console applications the user can specify that it should be written to a file instead of it being displayed. What happens is completely implementation dependent.doc-helmut wrote:but back to topic...what ????printf() doesn't display anything on your screen
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
Re: [resolved]NXC:bug?feature?printing non-printable-ASCII-chars
I just searched around a bit:
The behavior of printf is defined in the ANSI standard and it usually is implemented in the stdio.h library (which, of course, has to be included!).
printf writes formatted data to stdout (i.e., the screen) - so it's a standard C (and even C++ !) command for visualizing data on the screen:
http://www.cplusplus.com/reference/clib ... io/printf/
http://www.codingunit.com/printf-format ... ted-output
So how you can write
"printf() doesn't display anything on your screen... TextOut() visualizes data on the NXT screen... I can't see the connection."
is really beyond me.
The behavior of printf is defined in the ANSI standard and it usually is implemented in the stdio.h library (which, of course, has to be included!).
printf writes formatted data to stdout (i.e., the screen) - so it's a standard C (and even C++ !) command for visualizing data on the screen:
http://www.cplusplus.com/reference/clib ... io/printf/
http://www.codingunit.com/printf-format ... ted-output
printf is a standard output function which can display numbers as well as letters or strings, all optionally formatted, all-in-one. Originally it also supports multi-variant-multi-format input (unfortunately not possible to mimic by NXC for the moment), opposite to NumOut which only can display just 1 unformatted number or TextOut which only can display just 1 unformatted string.Compatibility
Particular library implementations may support additional specifiers and sub-specifiers.
Those listed here are supported by the latest C and C++ standards (both published in 2011).
Previous versions of these standards only supported a subset of these: Most notably, C++ 1998/2003 (that followed C90), did only support the h, l and L length sub-specifiers, and had no explicit support for the a, A and F specifiers.
So how you can write
"printf() doesn't display anything on your screen... TextOut() visualizes data on the NXT screen... I can't see the connection."
is really beyond me.
-
- Posts: 358
- Joined: 01 Oct 2010, 06:37
- Location: Denmark
- Contact:
Re: [resolved]NXC:bug?feature?printing non-printable-ASCII-chars
(Can't check your second link, server is down currently.)doc-helmut wrote:I just searched around a bit:printf writes formatted data to stdout (i.e., the screen) - so it's a standard C (and even C++ !) command for visualizing data on the screen:
http://www.cplusplus.com/reference/clib ... io/printf/
The point is that while it might be specified how it writes to stdout (i.e. what I called 'stream'), you can't assume that stdout is displayed on the screen, or how it is displayed.
To quote cplusplus again:
Some consoles also support piping which directs stdout into stdin on another application. And as said, on Windows pure-GUI applications stdout is not displayed even when running it from the console.http://www.cplusplus.com/reference/clibrary/cstdio/stdout/ wrote:Although it is commonly assumed that the default destination for stdout is going to be the screen, this may not be the case even in regular console systems, since stdout can generally be redirected on most operating systems at the time of invoking the application. For example, many systems, among them DOS/Windows and most UNIX shells, support the following command syntax:
myapplication > example.txt
to redirect the output of myapplication to the file example.txt instead of the console.
How the output is displayed in the console differs dramatically with different system/console combinations I have seen (especially with control codes), so it is difficult for me to believe there is much if any standardization on how to display stdout. However I have failed to actually find the specification of the standard library so I can't confirm it.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
Re: [resolved]NXC:bug?feature?printing non-printable-ASCII-chars
don't know what you are talking about - don't try to make excuses in doing it unnecessarily complicated.
printf is a standard display command in C, while TextOut is not.
And of course I was never talking about non-Ansi-C-compliant environments.
We have been talking about printing chars on the screen using printf, so what makes you think that I might be talking about systems without a screen (all one if stdout or not, and else, how would you use "TextOut" then? )
Or what makes you assume that printf was not meant to work with the NXT screen, so that you dare to assert
printf is a standard display command in C, while TextOut is not.
And of course I was never talking about non-Ansi-C-compliant environments.
We have been talking about printing chars on the screen using printf, so what makes you think that I might be talking about systems without a screen (all one if stdout or not, and else, how would you use "TextOut" then? )
Or what makes you assume that printf was not meant to work with the NXT screen, so that you dare to assert
No, admit it, that's nonsense. Probably you've been using it simply the wrong way or you confused it with sprintf (which writes formatted data to string) or fprintf (which writes formatted data to stream) or whatever.spillerrec wrote:"printf() doesn't display anything on your screen... TextOut() visualizes data on the NXT screen... I can't see the connection." ???
Re: [resolved]NXC:bug?feature?printing non-printable-ASCII-chars
Please quit arguing about this. It just doesn't matter. If you think of the NXT screen as a GUI window then printf would not write to it. Instead you would use other Windows API functions to draw text to the GUI. If you think of the NXT screen as a console then printf would write to it just like printf writes to a DOS command prompt window. Spillerec is simply saying that if you are drawing a GUI with images and shapes then it an real C program you would not call a function like printf to draw text on that same GUI.
John Hansen
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
http://bricxcc.sourceforge.net/
Re: [resolved]NXC:bug?feature?printing non-printable-ASCII-chars
no, sorry, I never was talking about drawing images to a GUI canvas
I am talking about writing characters to the screen like to stdout in C
(see thread title: printing non-printable-ASCII-chars),
using C-like-printf.
It's not me who is arguing but spillerec who claims "printf() doesn't display anything on your screen" .
You can't leave this nonsensical assertion uncontradicted?!
(And of course NXC-printf is faked by a wrap around TextOut)
I am talking about writing characters to the screen like to stdout in C
(see thread title: printing non-printable-ASCII-chars),
using C-like-printf.
It's not me who is arguing but spillerec who claims "printf() doesn't display anything on your screen" .
You can't leave this nonsensical assertion uncontradicted?!
(And of course NXC-printf is faked by a wrap around TextOut)
-
- Posts: 358
- Joined: 01 Oct 2010, 06:37
- Location: Denmark
- Contact:
Re: [resolved]NXC:bug?feature?printing non-printable-ASCII-chars
I see there is now a printf() in NXC, I didn't notice that this have been added. I don't know how it is implemented and whether it is ANSI-C compliant or not. Whenever I heard of printf() in the context of NXC, I thought of a simple macro wrapper around FormatVal() and TextOut(). This might have caused me to misunderstand some of the posts in this thread, I'm sorry about that.
To clarify, whenever I mentioned printf() I was talking of printf() in C and not NXC.
So to avoid further misunderstandings, I will restate my point:
printf() in ANSI-C does not produce visual output by its definition, it writes formated data to the standard output stream (stdout). What happens to stdout is entirely implementation dependent and is not guarantied to make any visual output. If there is a visual output, this is again completely implementation dependent.
If NXC choose to visualize stdout, how this is done is completely up to its developers, as nothing about this is defined in ANSI-C AFAIK.
To clarify, whenever I mentioned printf() I was talking of printf() in C and not NXC.
So to avoid further misunderstandings, I will restate my point:
printf() in ANSI-C does not produce visual output by its definition, it writes formated data to the standard output stream (stdout). What happens to stdout is entirely implementation dependent and is not guarantied to make any visual output. If there is a visual output, this is again completely implementation dependent.
If NXC choose to visualize stdout, how this is done is completely up to its developers, as nothing about this is defined in ANSI-C AFAIK.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
Re: [resolved]NXC:bug?feature?printing non-printable-ASCII-chars
Don't mind, that's exactly what it is and what it ever was. But not the way of it's NXC implementation caused the "misunderstanding" but what you assumed if it works (or not) for screen output.spillerrec wrote:Whenever I heard of printf() in the context of NXC, I thought of a simple macro wrapper around FormatVal() and TextOut().
In John Hansen's implementation it just writes always at the top left of the screen,
in my own implementation it writes by moving the cursor and wraps around to the next line at eol (like in an ANSI C console).
But what implementation you ever used or tried (if you actually once did): it always wrote to screen and still does, just like it usually (admittedly not always in very specifically configured systems) does in ANSI C:
Good to see that we both now finally are in agreement. :)I wrote:printf usually displays everything on the screen.
Who is online
Users browsing this forum: No registered users and 19 guests