0

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?

2
  • With putchar(ch); which also takes int value. Commented May 27, 2017 at 10:57
  • 1
    fgetc() is not guaranteed to return an ASCII value. That is common but, strictly speaking, implementation-defined behaviour. Different values will be returned on systems that work with non-ASCII character sets. Commented May 27, 2017 at 11:21

4 Answers 4

3

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 e.g. putchar or printf or any other function that allows you to print characters.

Sign up to request clarification or add additional context in comments.

Comments

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

it will print 0, also you can do this

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

Comments

1

Specify format as for a char, like so:

printf("%c", number); printf("%c", 65); // A 

Comments

0
#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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.