简体   繁体   中英

How to get a char from ASCII number

Hello. Im reading file using FILE and reading that using fgetc to read that.

fgetc function returns me int value of my chars in ASCII.

Now i want to print that data in char values.

How to convert my ascii numbers to chars?

You most likely don't need any conversion. If the native character set on your system is ASCII (which is the most common) then no conversion is needed. 'A' == 65 etc.

That means to print a character you just print it, with eg putchar or printf or any other function that allows you to print characters.

int x = 48;
printf("%c", x);

it will print 0, also you can do this

int x = 48;
char xx = (char)x;

Specify format as for a char, like so:

printf("%c", number);

printf("%c", 65); // A
#include <stdio.h>

int main()
{
int i;
for (i=97; i <=200 ; i++)
{
    printf("%d  %c,\t",i,i);
};
return 0;}

This will give you the whole chart upto 200.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM