/**************************************************************
****************用于平时对某些函数功能的测试***********************
***************************************************************/
#include
#include
#include
int main(void)
{
int i_fd = -1,i_ret = 0;
char *buf;
int sum = 0;// SUM 初始值为0
int i = 0;
buf = (char*)malloc(10*sizeof(char));
i_fd = open("text.txt",O_RDONLY);
i_ret = read(i_fd,buf,10);
while(i_ret > 0)
{
sum += i_ret; // sum 加上i_ret的返回值
buf = realloc(buf,sizeof(char)*sum+10); // 分配buf加20个内存大小
i_ret = read(i_fd,buf+sum,10);
}
for(i = 0;i
printf("buf[%d] = %c\n",i,buf[i]);
return 0;
}
阅读(1215) | 评论(0) | 转发(0) |