[pyar] Fortune en Python
QliX=D! [aka EHB]
qlixed en gmail.com
Jue Sep 23 17:52:11 ART 2010
2010/9/23 "Matías A. Bellone" <matiasbellone en gmail.com>:
>>>> import random
>>>> random.choice(db)
> 'un reglon\n'
>>>> print random.choice(db).strip()
> tres renglones
Casi lo mismo en C (sacado del fortune src):
void display(FILEDESC * fp)
{
register char *p, ch;
unsigned char line[BUFSIZ];
open_fp(fp);
fseek(fp->inf, (long) Seekpts[0], 0);
for (Fort_len = 0; fgets(line, sizeof line, fp->inf) != NULL &&
!STR_ENDSTRING(line, fp->tbl); Fort_len++)
{
if (fp->tbl.str_flags & STR_ROTATED)
for (p = line; (ch = *p); ++p)
if (isupper(ch))
*p = 'A' + (ch - 'A' + 13) % 26;
else if (islower(ch))
*p = 'a' + (ch - 'a' + 13) % 26;
fputs(line, stdout);
}
fflush(stdout);
}
+ el main... + otras "yerbas decorativas" q tiene el fortune.c
More information about the pyar
mailing list