Zitat Zitat von avr-libc-Manual
5.14.3.3
Code:
FILE* fdevopen (int(*put)(char), int(*get)(void), int opts __attribute__ ((unused)));
This function is a replacement for fopen().

It opens a stream for a device where the actual device implementation needs to be provided by the application. If successful, a pointer to the structure for the opened stream is returned. Reasons for a possible failure currently include that neither the put nor the get argument have been provided, thus attempting to open a stream with no IO intent at all, or that insufficient dynamic memory is available to establish a new stream.

If the put function pointer is provided, the stream is opened with write intent. The function passed as put shall take one character to write to the device as argument, and shall return 0 if the output was successful, and a nonzero value if the character could not be sent to the device.

If the get function pointer is provided, the stream is opened with read intent. The function passed as get shall take no arguments, and return one character from the device, passed as an int type. If an error occurs when trying to read from the device, it shall return -1.

If both functions are provided, the stream is opened with read and write intent. The first stream opened with read intent is assigned to stdin, and the first one opened with write intent is assigned to both, stdout and stderr.
Das ist so zu verstehen:
  1. Argument von fdevopen ist eine Funktion, die nen char erhält und nen int liefert, also vom Prototyp int myput (char) ist:
    Code:
     int myput (char c)  { ... }
    
     FILE * pmyfile = fdevopen (myput, ...);
  2. Argument analog
  3. Argument ist ungenutzt

du bekommst dann nen Filepointer und kannst damit via fprintf (myfile, ...) Ausgaben machen. Mich dünkt aber, das ganze brauch malloc wies aussieht. Woher sollte sinst der Filepointer kommen...
Oder wie PicNick geschrieben hat, dann hast du nen FILE und mit stdin = &myfile; geht's weiter oder pmyfile = &myfile; Wenn gas geht spart den malloc (irgendwo im Gedärm von libc, kann aber sein daß du dir den eh einfängst mit printf ("%lf"...

Ausserdem geht auch sowas: stin = stdout = myfile;
Vorausgesetzt, myfile implementiert Ein- und Ausgabe. (stdin ist einfach nur __iob[0])