pack_fgets(3alleg4)

✨ NAME ✨

okay so bestie, this page is all about pack_fgets(3alleg4) from the Allegro manual β€” it's the one that reads a line from the stream. Allegro game programming library, periodt. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <allegro.h>

char *pack_fgets(char *p, int max, PACKFILE *f);

πŸ’– DESCRIPTION πŸ’–

So here's the vibe: pack_fgets reads a line from the stream f, and it stores that line at the location pointed to by p. It stops when a linefeed is encountered, or when max bytes have been read. Simple as that, no cap. ✨

The end of line is handled by detecting the right combination of characters for the platform. It supports CR-LF (DOS/Windows), LF (Unix), and CR (Mac) formats. But β€” and this is the important part β€” the trailing carriage return is not included in the returned string, so your code stays easily portable across platforms. If you actually need that carriage return, you gotta use pack_fread() and/or pack_getc() instead. 🫢

Note: this function internally may make calls to pack_ungetc, so you cannot use pack_ungetc directly afterwards. Not me warning you twice, but like… be aware. 😭

Example, because we love a little demo:

char buf[256];
...
while (pack_fgets(buf, sizeof(buf), input_file)) {
   /* Process input line. */
}
fclose(input_file);

🌈 RETURN VALUE 🌈

It returns the pointer p on success, or NULL on error. That's it, that's the whole mood. πŸ‘‘


πŸŽ€ SEE ALSO πŸŽ€


Allegro version 4.4.3, bestie β€” that's the source and version for this lil manual page. Go read some lines, slay, and don't forget your carriage returns unless you're using pack_fread() or pack_getc(). mwah πŸ’‹πŸŒΈ