.TH toascii() "" "" "ctype Function (libc)"
.PC "Convert characters to ASCII"
\fB#include <ctype.h>\fR
\fBint toascii(\fIc\^\fB)\fR int \fIc\^\fB;\fR
.PP
The function
\fBtoascii()\fR
takes the integer value
.IR c ,
keeps the low seven bits unchanged, and changes the others to zero.
This, in effect, transforms the integer value to an ASCII character.
.B toascii()
then returns the transformed integer.
If
.I c
is already a valid ASCII character,
.B toascii()
returns it unchanged.
.SH 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.
.DM
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
.DE
.DM
main()
{
	FILE *fp;
	int ch;
	int filename[20];
.DE
.DM
	printf("Enter file name: ");
	fflush(stdout);
	gets(filename);
.DE
.DM
	if ((fp = fopen(filename, "r")) != NULL) {
		while ((ch = fgetc(fp)) != EOF)
			putchar(isascii(ch) ? ch : toascii(ch));
	} else {
		printf("Cannot open %s\en", filename);
		exit(EXIT_FAILURE);
	}
	return(EXIT_SUCCESS);
}
.DE
.SH "See Also"
.Xr "isascii()," isascii
.Xr "libc" libc
.R
.SH 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.
