fgets 语法: #include <stdio.h> char *fgets( char *str, int num, FILE *stream );
int i=0;
FILE *fp;
char buff[5];
//将数组赋值为9,便于后面与赋值的地方比较
memset(buff,9,sizeof(buff));
char *fName = "d:/123.txt";
fp = fopen(fName,"r");
fgets(buff,sizeof(buff),fp);
//打印出数组的ascii码
printf("buff数组内容:\n");
for(i=0;i<sizeof(buff);i++)
{
printf("%d ",(int)buff[i]);
}
printf("\n");
//继续获取下一行字符,验证文件句柄的位置
memset(buff,9,sizeof(buff));
fgets(buff,sizeof(buff),fp);
//打印出数组的ascii码
printf("下一行buff数组内容:\n");
for(i=0;i<sizeof(buff);i++)
{
printf("%d ",(int)buff[i]);
}
printf("\n");
fclose(fp);
1234 asdf
49 50 51 0 下一行buff数组内容: 52 10 0 9
buff数组内容: 49 50 51 52 0 下一行buff数组内容: 10 0 9 9 9
49 50 51 52 10 0 9 9 9 9 下一行buff数组内容: 97 115 100 102 0 9 9 9 9 9
FILE *fp;
char *fName = "d:/123.txt";
fp = fopen(fName,"r+");
fseek(fp,3,SEEK_CUR);
fputs("Insert Strings",fp);
fclose(fp);
1234 Second Line. Second Strings.
123Insert Strings. Second Strings.
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有