COHERENT manpages

This page displays the COHERENT manpage for toascii() [Convert characters to ASCII].

List of available manpages
Index


toascii() -- ctype Function (libc)

Convert characters to ASCII
#include <ctype.h>
int toascii(c) int c;

The function toascii() takes the integer  value c, keeps the low seven bits
unchanged, and changes the others to zero.  This, in effect, transforms the
integer  value   to  an  ASCII  character.    toascii()  then  returns  the
transformed integer.   If c is  already a valid  ASCII character, toascii()
returns it unchanged.

Example

This example  prompts for a file  name.  It then opens  the file and prints
its   contents,  while  converting   all  non-alphanumeric   characters  to
alphanumeric.

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

main()
{
    FILE *fp;
    int ch;
    int filename[20];

    printf("Enter file name: ");
    fflush(stdout);
    gets(filename);

    if ((fp = fopen(filename, "r")) != NULL) {
        while ((ch = fgetc(fp)) != EOF)
            putchar(isascii(ch) ? ch : toascii(ch));
    } else {
        printf("Cannot open %s\n", filename);
        exit(EXIT_FAILURE);
    }
    return(EXIT_SUCCESS);
}

See Also

isascii(),
libc

Notes

This function is not described in the ANSI Standard.  Any program that uses
it does  not conform strictly to  the Standard, and may  not be portable to
other compilers or environments.