
Mr.V Kim Hiu 1

 !"a$
%!&'()*+,%&(-,'
.'/0)'

1a234567
8'eae
:';e
<';e;
=';e
>';;
?';e
@';e,
A';e
B';,e
8C';,;
88';,
8:';,
8<';ea3
8=';e,e
8>';a;
8?';eeD
8@';e,
8A';e
8B';Ee
:C'e
:8'ea
::'e

Mr.V Kim Hiu 2
:<',e
:=',;
:>',
:?',a
:@',
:A'ee
:B'eae
<C'eE3
<8'a;
<:'e;
<<'e;
<=',;
<>'a;
<?',;e
<@',a
<A'e
<B',;F;,;Fa3,;
ee


3eaeGH5IJKeaLM
N%OaPQDaR-,S,O'
 e

#include <stdio.h>
int main(void)
{
FILE *fp;
char ch;

Mr.V Kim Hiu 3
/* mo tep tin de ghi */
fp = fopen("DUMMY.FIL", "w");
/*gay nen mot loi bang cach doc file*/
ch = fgetc(fp);
printf("%c\n",ch);
if (ferror(fp))
{
/* xuat ra man hinh thong bao loi */
printf("Error reading from DUMMY.FIL\n");
/* xoa tin hieu loi */
clearerr(fp);
}
fclose(fp);
return 0;
}
!"e


;eGH5IJKeaLM
!,&aDaFeaRT,'UVWCF&
WJ7HGXYZD)+,L
 e

#include <string.h>
#include <stdio.h>
int main(void)
{
FILE *fp;
char buf[11] = "0123456789";
fp = fopen("DUMMY.FIL", "w");
fwrite(&buf, strlen(buf), 1, fp);
/* dong tep */
fclose(fp);
return 0;
}
!e!



Mr.V Kim Hiu 4
;e;GH5IJKeaLM
3[\D\aT,!)Q,aa'])!)Q,W
ZDCF &WC
 e

#include <stdio.h>
int main(void)
{
FILE *stream;
/* mo mot tep de doc */
stream = fopen("DUMMY.FIL", "r");
/* doc mot ky tu tu tep */
fgetc(stream);
/*kiem tra xem cuoi tep hay chua */
if (feof(stream))
printf("We have reached end-of-file\n");
/* dong tep*/
fclose(stream);
return 0;
}
!e


;eGH5IJKeaLM
U\aOaR,'WZDC)!OF &WC'
 e

#include <stdio.h>
int main(void)
{
FILE *stream;
/* mo tep de ghi */
stream = fopen("DUMMY.FIL", "w");
/* gay ra mot loi bang cach doc*/
(void) getc(stream);
if (ferror(stream)) /* kiem tra loi tren tep*/
{
/* ghi loi ra man hinh*/
printf("Error reading from DUMMY.FIL\n");

Mr.V Kim Hiu 5
/* xoa tin hieu loi*/
clearerr(stream);
}
fclose(stream);
return 0;
}
!!"


;;GH5IJKeaLM
3[&[^a,'])VZCF&W
J7H
 e

#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <io.h>
void flush(FILE *stream);
int main(void)
{
FILE *stream;
char msg[] = "This is a test";
/* tao 1 tep */
stream = fopen("DUMMY.FIL", "w");
/*ghi mot vai du lieu len tep */
fwrite(msg, strlen(msg), 1, stream);
clrscr();
printf("Press any key to flush DUMMY.FIL:");
getch();
flush(stream);
printf("\nFile was flushed, Press any key to quit:");
getch();
return 0;
}
void flush(FILE *stream)
{
int duphandle;
/* lam sach vung dem */
fflush(stream);