Off Topic Posts


V

vze7jsc0

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

usenet is a strange place
 
Ad

Advertisements

F

Frederick Gotham

Somebody posted:
Has anyone computed the percentage of off topic posts in this group

No.


using ANSI C?


ANSI C does not provide a facility for accessing Usenet, and thus one
cannot write a portable program for calculating such a percentage.
 
M

Morris Dovey

Frederick Gotham (in [email protected]) 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;
}
 
V

vze7jsc0

Frederick said:
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.

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
 
J

Jack Klein

Frederick Gotham (in [email protected]) 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);

Undefined behavior if the value represented by argv [1] is outside the
range representable in a signed long.
posts = atol(*++argv);

Undefined behavior if the value represented by argv [2] is outside the
range representable in a signed long.
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;
}

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

Morris Dovey

Jack Klein (in (e-mail address removed)) 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...
 
Ad

Advertisements

D

Dave Thompson

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.

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
 
Ad

Advertisements

F

Flash Gordon

Dave said:
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.

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top