0
#include<stdio.h>
#include<stdlib.h>

int main()
{

int i,j;
int ascii_value;
char c;

FILE *plain;

plain=fopen("xx.dat","r");

while((c=getc(plain))!=EOF)
{
    ascii_value=c;
    printf("%d %c\n",ascii_value,c);
    printf("~~~~~~~~~~~~~~~~~~~~\n");
}

fclose(plain);
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

10 

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

Edited by pritaeas: Closed duplicate.

3
Contributors
2
Replies
15
Views
3 Years
Discussion Span
Last Post by pritaeas
1

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);

Edited by Ancient Dragon

Votes + Comments
nice one bro! Fastest fingers...