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

One of you EXPERT C PROGRAMMERS rewrite this

Name: Anonymous 2010-11-01 5:47

I'm reading K&R; doing the opposite of exercise 1-16. This really shouldn't take that much code, should it?

// Write a program to print all input lines that are shorter than 80 characters.

#include <stdio.h>
#define LINEMAX 80

int main()
{
    int c, i = 0, j, thisstr[LINEMAX];
    while ((c = getchar()) != EOF) {
        // end of a line?
        if (c == '\n') {
            // if line short enough, print the line
            if (i < LINEMAX) {
                for (j = 0; j < i; j++)
                    putchar(thisstr[j]);
                putchar('\n');
            }
            // and clear the variables for the next one
            for (i = 0; i < LINEMAX; i++)
                thisstr[i] = 0;
            i = 0;
        } else if (i < LINEMAX) {
            // store character in array
            thisstr[i] = c;
            i++;
        }
    }
    return 0;
}


Feel free to correct the shit out of me.
P.S. ((c = getchar()) != EOF) is PIG DISGUSTING

Name: Anonymous 2010-11-04 16:54

import sys
filter(lambda s:len(s)<80,sys.read().split('\n'))


inb4 15-character Perl implementation

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