Off Topic Posts

Discussion in 'C Programming' started by vze7jsc0, Jul 2, 2006.

  1. vze7jsc0

    vze7jsc0 Guest

    Has anyone computed the percentage of off topic posts in this group
    using ANSI C?

    usenet is a strange place
     
    vze7jsc0, Jul 2, 2006
    #1
    1. Advertisements

  2. Somebody posted:

    ANSI C does not provide a facility for accessing Usenet, and thus one
    cannot write a portable program for calculating such a percentage.
     
    Frederick Gotham, Jul 2, 2006
    #2
    1. Advertisements

  3. vze7jsc0

    Morris Dovey Guest

    Frederick Gotham (in MkTpg.10967$) said:

    | one cannot write a portable program for calculating such a
    | percentage.

    Eh?

    #include <stdio.h>
    #include <stdlib.h>

    int main(int argc,char **argv)
    { long off_topic,posts;
    if (argc < 3)
    { printf("Usage: %s <off_topic posts> <total_posts>\n",*argv);
    exit(EXIT_FAILURE);
    }
    off_topic = atol(*++argv);
    posts = atol(*++argv);
    if (!posts && !off_topic) puts("No traffic.");
    else if (!posts) puts("You're kidding, right?");
    else printf("%G%% of %ld posts were off topic.\n",
    (100.0*off_topic)/posts,posts);
    return 0;
    }
     
    Morris Dovey, Jul 2, 2006
    #3
  4. vze7jsc0

    vze7jsc0 Guest

    Hypothetically, if one were to run a news server, one could write a
    program to analyze content. Such a program might look like this:

    <code>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    enum {
    BUFLEN = 131072,
    MAXTOK = 4096
    };

    static int fgetline(char *, int, FILE *);
    static int count(FILE *);

    int
    main(int argc, char *argv[])
    {
    FILE *fp;

    if (argc < 2) {
    fprintf(stderr, "usage: %s file \n", argv[0]);
    return 2;
    }

    if ((fp = fopen(argv[1], "rt")) == NULL) {
    fprintf(stderr, "can't open %s\n", argv[1]);
    return 2;
    }

    return count(fp);
    }


    static int
    count(FILE *fp)
    {
    char *tok[MAXTOK], *p;
    char buf[BUFLEN];
    int len, n, i, count = 0;


    while ( (len = fgetline(buf, BUFLEN, fp)) > 0) {
    p = buf;
    tok[0] = strtok(p, " ,\t\n");
    for (n = 1; n < MAXTOK && (tok[n] = strtok(NULL, " ,\t\n"));
    n++)
    ;

    for (i =0; i < n; i++)
    if (0 == strncasecmp(tok, "off topic"))
    ++count;
    }
    return count;
    }

    /* fgetline: read a line from fp, return length */
    static int
    fgetline(char *line, int max, FILE *fp)
    {
    if (fgets(line, max, fp) == NULL)
    return 0;
    else
    return strlen(line);
    }


    </code>

    Were such a person to pass in the file containing the comp.lang.c
    cache, a rough estimate of the count of off topic posts could be
    obtained.

    Using the value the program returned, divided by the number of posts,
    would give a percentage.

    Please excuse the sloppy programming, as it was intended to be a proof
    of concept, not an actual program.

    I think the percentage would be above 80%


    usenet is still a strange place
     
    vze7jsc0, Jul 2, 2006
    #4
  5. vze7jsc0

    Jack Klein Guest

    Undefined behavior if the value represented by argv [1] is outside the
    range representable in a signed long.
    Undefined behavior if the value represented by argv [2] is outside the
    range representable in a signed long.
    strtol() is much preferred, even for gag posts.
     
    Jack Klein, Jul 2, 2006
    #5
  6. vze7jsc0

    Morris Dovey Guest

    Jack Klein (in ) said:

    | strtol() is much preferred, even for gag posts.

    It's a value call. In my mind anyone who wastes time worrying over the
    /percentage/ of OT posts (much less anyone who claims that such a
    percentage can't be /calculated/ using C) richly deserves the whole
    herd of nasal demons whizzing out one nostril, in the other, and
    wreaking noisome mischief in their sinus cavities. [7.20.1] is my
    friend in this instance - I just wish the demons were more reliable.
    You /did/ notice that I managed to resist the nearly overpowering urge
    to name one of the variables 'total'? ;->

    <sigh> Ok - everyone who doesn't care what the actual percentage is
    should consider themselves invited to make that change before
    discarding the program for being as worthless as it is - and everyone
    who feels it's actually worth calculating the percentage is invited to
    use it as is...
     
    Morris Dovey, Jul 2, 2006
    #6
  7. Standard C does not access _networks_, and particularly the Internet.
    Usenet and more specifically netnews (which was originally only a
    subset) predated the Internet, and although other transports have now
    vanished AFAIK, it is defined and still operated so that each server
    has a complete (modulo glitches) copy of all messages for however long
    it chooses. And classically such servers kept these messages in simple
    text files that not only can be read from C but easily so. Although I
    haven't kept track of whether they still do, and I suspect not.

    - David.Thompson1 at worldnet.att.net
     
    Dave Thompson, Jul 10, 2006
    #7
  8. vze7jsc0

    Flash Gordon Guest

    At least some local news servers, such as leafnode, still do this.
    However, you still have the problem of how to read the directory which C
    does not support.
     
    Flash Gordon, Jul 10, 2006
    #8
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.