#include <stdlib.h>
#include <string.h>
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;
}
#include <string.h>
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;
}
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/986/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表