Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

[C] post your gets()

Name: Anonymous 2013-03-14 2:49

As we know, gets() is unsafe, fgets() annoyingly retains the '\n', getline() is non-standard, and scanf() always stops at spaces.  Many of us wind up rolling our own.

This one
1. always NUL-terminates
2. is efficient since there are only two tests in the main loop
3. discards everything until the end of the line if truncation occurs.

void
getstr(char *s, size_t siz)
{
        int     c;
        char    *max = s + siz - 1;

        while ((c = getchar()) != '\n' && s < max)
                *s++ = c;
        *s = '\0';
        while (c != '\n')
                c = getchar();
}

Name: Anonymous 2013-03-14 18:37

AND Y DO U THINK DEANIS RICKY KIKKED DA BUKKET? DONT YA THINK IT'S STRANGE DAT HE DIED TWO DAYS THE STANDARD PASSED ITS FINAL DRAFT REVIEW? I KNOWN RICKY ALL MY LIFE, EVEN BAK FRUM WEN HE DESIGNED DA LANGUAGE, N I ALSO KNO WHY RICKY KIKKED DA BUKKET, IN FACT I WAS DER WHEN IT HAPPENED. WE WERE SITTIN AT HIS HOUSE N HE TURNED TO ME N SAID, "Lambda, as I watch these hyenas claw, tear, and butcher the language I designed with my bare hands, I begin to question why I should live any longer." N IT WAS AT DAT MOMENT DAT RICKY PULLED OUT A PISTOL N DID HIMSELF IN. I KNOW DA TRUTH COZ I WAS DER. DOSE FAT CATS AT ISO, DEYR DA KILLERS. DOSE SAME FUCKERS WHO THREW ME OFF DA COMMITTEE JUST CUZ I WAS SHOUTIN AT PEOPLE.

THERE AIN'T NO STANDARD BUT C89.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List