Please read carefully before you post.
If you dont specify 'b', by default the file is opened in text mode. I guess you need to open a file in binary mode to read the special characters like the TAB character, i.e. 26 etc.
Try out this an watch :
--------------------------
#include<conio.h>
#include<stdio.h>
#include<fcntl.h>
FILE *f;
main()
{
clrscr();
f=fopen("sham.txt","w");
fputc(65,f);
fputc(65,f);
fputc(65,f);
fputc(26,f);
fputc(65,f);
fputc(65,f);
fputc(65,f);
fclose(f);
/********************************************/
/*** Please include <fcntl.h> for raw I/O ***/
{
int fd, err; unsigned char c;
fd=open("sham.txt", O_RDWR);
while (err=read(fd, &c, 1)>0) printf(" %02d", c); printf("\n");
if(err<0) printf("Read Err: %d\n",err);
close(fd);
fd=open("sham.txt", O_RDWR | O_BINARY);
while (err=read(fd, &c, 1)>0) printf(" %02d", c); printf("\n");
if(err<0) printf("Read Err: %d\n",err);
close(fd);
}
/********************************************/
f=fopen("sham.txt","r");
do{ printf("%c",fgetc(f));}while(!feof(f));
fclose(f);
getch();
return 0;
}
Reason:
It is not TAB=0x09 which stops the read stream
it is SUB=0x1A it causes here actually an end of file,
but of course it does not if you open the file in BINARY mode.
I do not want to open file in binary mode becaue it needs more space than text file. Let me explain the whole story.
I have written a program that compresses text file using Huffman algorithm. So i read each symbol from text file, find its frequency and then generate a code for it. Then i group this code with 8 bits in each group then find the corresponding symol for it then write this symbol to compressed file. It is inevitable that i can get the file end symbol from a group and write it to the file. So if I wrote it to text file when i read it it recognizes it as end of file and stops reading. And if I open it in binary mode it takes more space and sometimes more space than the original file. That's what my problem is.