int main()

int i,j;
int ascii_value;
char c;

FILE *plain;


    printf("%d %c\n",ascii_value,c);

return 0;

the file xx.dat is 12sdfsldkfj
MY output is

49 1

50 2

115 s

100 d

102 f

115 s

108 l

100 d

107 k

102 f

106 j


I am unable to understand why 10 in the last line is printed. Please help...Inline Code Example Here

Recommended Answers

All 2 Replies

The file probably has a '\n' after the last character. Edit the ffile to remove the last '\n'

variable c should be declared as int, not char, because fgets() returns an int.

int c;

line 17: It is not necessary to do that, just print like this:

printf("%d %c\n",c,c);

commented: nice one bro! Fastest fingers... +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.