By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

Off Topic Posts

P: n/a
Has anyone computed the percentage of off topic posts in this group
using ANSI C?

usenet is a strange place

Jul 2 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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.
--

Frederick Gotham
Jul 2 '06 #2

P: n/a
Frederick Gotham (in Mk*******************@news.indigo.ie) 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
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
Jul 2 '06 #3

P: n/a
Frederick Gotham wrote:
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.
--

Frederick Gotham
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[i], "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

Jul 2 '06 #4

P: n/a
On Sun, 2 Jul 2006 13:03:29 -0500, "Morris Dovey" <mr*****@iedu.com>
wrote in comp.lang.c:
Frederick Gotham (in Mk*******************@news.indigo.ie) 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.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 2 '06 #5

P: n/a
Jack Klein (in 7s********************************@4ax.com) 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'? ;->

<sighOk - 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
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto
Jul 2 '06 #6

P: n/a
On Sun, 02 Jul 2006 17:26:04 GMT, Frederick Gotham
<fg*******@SPAM.comwrote:
Somebody posted:
Has anyone computed the percentage of off topic posts in this group
<snip>
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.
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
Jul 10 '06 #7

P: n/a
Dave Thompson wrote:
On Sun, 02 Jul 2006 17:26:04 GMT, Frederick Gotham
<fg*******@SPAM.comwrote:
>Somebody posted:
>>Has anyone computed the percentage of off topic posts in this group
<snip>
>>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.

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.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
Jul 10 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.