Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8314753
  • 博文数量: 1413
  • 博客积分: 11128
  • 博客等级: 上将
  • 技术积分: 14685
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-13 10:03
个人简介

follow my heart...

文章分类

全部博文(1413)

文章存档

2013年(1)

2012年(5)

2011年(45)

2010年(176)

2009年(148)

2008年(190)

2007年(293)

2006年(555)

分类: C/C++

2006-06-06 15:04:17

//读取文件中每一行的前四个字符
//memcpy与strncpy的功能差不多一样
//要调用上面两个函数要先引入库string.h
//使用malloc要调用stdlib.h库
#i nclude
#i nclude
#i nclude
int main()
{
 char *sfrom="1234567890";
 char *sto=(char*) malloc(10);
 memcpy(sto,sfrom,3);
 printf(sto);
 strncpy(sto,sfrom,3);
 printf("\n");
 printf(sto);
 printf("\n");

 FILE *fp=fopen("du.txt","r");
 char ln[100];
 char *out=(char*) malloc(10);
 while(!feof(fp))
 {
  fgets(ln,1024,fp);
  memcpy(out,ln,4);
  printf(out);
  printf("\n");

 }
 return 0;
}

阅读(3107) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~