
#include <lcstring.h> void *memxlt(void *blk, const char *table, size_t n);
memxlt translates a block of memory from one character set to
another. The first argument (blk) is the address of the area of
memory to be translated, and the third argument (n) is the number
of characters to be translated. The second argument (table) is a
pointer to a 256-byte translate table, which should be defined so that
table[c] for any character c is the value to
which c should be translated. (The function xltable is
frequently used to build such a table.)
Note: The argument string is translated in place; that is, each character in the string is replaced by a translated character.
memxlt returns a pointer to the translated string.
memxlt is size_t. If a negative number
is passed, massive overlaying of memory occurs.
The effect of memxlt is not defined if the source string and the
translate table overlap.
memxlt unless the function is undefined (by an #undef
statement) to prevent this.
memxlt. The argument
word specified on the command line is translated using a randomly arranged
alphabet. The translated message is then printed to stdout:
#include <lcstring.h>
#include <stdio.h>
#include <stdlib.h>
main(int argc, char *argv[])
{
int len, i, j;
char a;
char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char table[256];
if (argc < 2) {
puts("Specify the secret word on the command line.");
exit(4);
}
len = strlen(argv[1] );
memupr(argv[1], len); /* Uppercase input message. */
/* Randomize the alphabet. */
for (i = 0; i < 26; i++)
for (j = i + 1; j < 26; j++)
if (rand() % 2) {
a = alphabet[i];
alphabet[i] = alphabet[j] ;
alphabet[j] = a;
}
/* Build a translate table. */
xltable(table,"ABCDEFGHIJKLMNOPQRSTUVWXYZ",alphabet);
/* Translate message. */
memxlt(argv[1],table,len);
/* Print message. */
printf("Today's secret word is: n%sn",argv[1]);
return;
}
memlwr, memupr, xltable
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.