简体   繁体   English

如何从 ASCII 数字中获取字符

[英]How to get a char from ASCII number

Hello.你好。 Im reading file using FILE and reading that using fgetc to read that.我使用 FILE 读取文件并使用 fgetc 读取该文件。

fgetc function returns me int value of my chars in ASCII. fgetc 函数以 ASCII 格式返回我的字符的 int 值。

Now i want to print that data in char values.现在我想以字符值打印该数据。

How to convert my ascii numbers to chars?如何将我的 ascii 数字转换为字符?

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.如果您系统上的本机字符集是 ASCII(这是最常见的),则不需要转换。 'A' == 65 etc. 'A' == 65

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.这意味着打印一个您刚刚打印的字符,例如使用putcharprintf或任何其他允许您打印字符的函数。

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

it will print 0, also you can do this它会打印 0,你也可以这样做

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.这将为您提供最多 200 的整个图表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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