Any one knows what is the ASCII value of i.
I try printf(\"%d\",EOF);
but its print -1
and also try printf(\"%c\",EOF
for all intents and purposes 0x04 EOT (end of transmission as this will normaly signal and read function to stop and cut off file at that point.
As Heffernan said, it's system defined. You can access it via the EOF constant (is it a constand?):
#include <stdio.h>
int main(void)
{
printf("%d\n", EOF);
}
After compiling:
c:\>a.exe
-1
c:\>
EOF is not an ASCII character. Its size is not 1 byte as against size of a character and this can be checked by
int main() {
printf("%lu", sizeof(EOF));
return 0;
}
However, it is always defined to be -1. Try
int main() {
printf("%d",EOF);
return 0;
}
The key combination for EOF is Crtl+D. The character equivalent of EOF is machine dependent. That can be checked by following:
int main() {
printf("%c", EOF)
return 0;
}
The actual value of EOF is system defined and not part of the standard.
EOF
is an int
with negative value and if you want to print it you should use the %d
format string. Note that this will only tell you its value on your system. You should not care what its value is.
there is not such thing as ascii value of EOF. There is a ASCII standard that includes 127 characters, EOF is not one of them. EOF is -1 because that's what they decided to #defined as in that particular compiler, it could be anything else.
EOF do not have ASCII value as they said .... no problem with this
also you can avoid the strange character that appear in the end (which is the numeric representation of EOF ) by making if
condition here is an example:
#include <stdio.h>
int main(void)
{
FILE *file = fopen("/home/abdulrhman/Documents/bash_history.log", "r");
FILE *file2 = fopen("/home/abdulrhman/Documents/result.txt", "w");
file =
file2 =
char hold = 'A';
while(hold != EOF)
{
hold = getc(file);
if(hold == EOF) break; // to prevent EOF from print to the stream
fputc(hold, file2);
}
fclose(file);
return 0;
}
that is it