c - What really is EOF for binary files? Condition? Character? -


i have managed far knowledge eof special character inserted automatically @ end of text file indicate end. feel need more clarification on this. checked on google , wikipedia page eof couldn't answer following, , there no exact stack overflow links either. please me on this:

  • my book says binary mode files keep track of end of file number of characters present in directory entry of file. (in contrast text files have special eof character mark end). story of eof in context of binary files? confused because in following program use !=eof comparison while reading .exe file in binary mode:

     #include<stdio.h>  #include<stdlib.h>   int main()  {    int ch;      file *fp1,*fp2;    fp1=fopen("source.exe","rb");   fp2=fopen("dest.exe","wb");    if(fp1==null||fp2==null)   {   printf("error opening files");   exit(-1);   }    while((ch=getc(fp1))!=eof)   putc(ch,fp2);    fclose(fp1);   fclose(fp2);    } 
  • is eof special "character" @ all? or condition wikipedia says, condition computer knows when return particular value -1 (eof on computer)? example of such "condition" being when character-reading function finishes reading characters present, or when character/string i/o functions encounter error in reading/writing?

    interestingly, stack overflow tag eof blended both definitions of eof. tag eof said "in programming realm, eof sequence of byte (or chacracter) indicates there no more contents after this.", while said in "about" section "end of file (commonly abbreviated eof) condition in computer operating system no more data can read data source. data source called file or stream."

but have strong feeling eof won't character every other function seems returning when encounters error during i/o.

it nice of if can clear matter me.

the various eof indicators c provides not have how file system marks end of file.

most modern file systems know length of file because record somewhere, separately contents of file. routines read file keep track of reading , stop when reach end. c library routines generate eof value return you; not returning value in file.

note eof returned c library routines not character. c library routines return int, , int either character value or eof. e.g., in 1 implementation, characters might have values 0 255, , eof might have value –1. when library routine encountered end of file, did not see –1 character, because there no such character. instead, told underlying system routine end of file had been reached, , responded returning –1 you.

old , crude file systems might have value in file marks end of file. various reasons, undesirable. in simplest implementation, makes impossible store arbitrary data in file, because cannot store end-of-file marker data. 1 could, however, have implementation in raw data in file contains indicates end of file, data transformed when reading or writing arbitrary data can stored. (e.g., “quoting” end-of-file marker.)

in cases, things end-of-file markers appear in streams. common when reading terminal (or pseudo-terminal or terminal-like device). on windows, pressing control-z indication user done entering input, , treated reach end-of-file. not mean control-z eof. software reading terminal sees control-z, treats end-of-file, , returns end-of-file indications, different control-z. on unix, control-d commonly similar sentinel marking end of input.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -