readfile.c
#include <stdio.h>
#include <stdlib.h>
int main (
)
{
FILE *fp = stdin;
char readbuf[4];
int cnt = 0;
int count = 0;
while (!feof (fp))
{
count = fread (readbuf, 1, 4, fp);
printf ("cnt: %d, data size: %d\n", ++cnt, count);
}
return 0;
}
Makefile
# Program, flags, ect.
ASM = wcl
TARGET = readfile.exe
OBJ = readfile.obj
everything: $(TARGET)
clean: .symbolic
[tab]@if exist $(TARGET) del $(TARGET)
[tab]@if exist $(OBJ) del $(OBJ)
$(TARGET): $(OBJ)
[tab]$(ASM) -bcl=dos $< -fe=$@
.c.obj:
[tab]$(ASM) -c $*.c
參考資料:
[C] 使用 fread 讀取檔案的觀念 - 小心使用 End-of-file (EOF)
沒有留言:
張貼留言