c语言中空行作用,用C语言删除空行(上一行)。

满意答案

dcebd7a0de6265b6ccae5ead692f1eab.png

winters74

2017.03.31

dcebd7a0de6265b6ccae5ead692f1eab.png

采纳率:42%    等级:11

已帮助:1125人

#include 

#include //for function exit()

#include //for functions strcpy() and strlen()

const int MAXSIZE = 200;//行最多字符数

int main() {

char line[MAXSIZE],pline[MAXSIZE];

FILE *inp;//被修改的磁盘文件

FILE *outp;//修改后的磁盘文件

char oldfile[] = "indata.txt";

char newfile[] = "outdata.txt";

if((inp = fopen(oldfile,"rt")) == NULL || (outp = fopen(newfile,"wt")) == NULL) {

printf("打开文件时出错!\n");

exit(1);

}

fscanf(inp,"%s",pline);

while(!feof(inp)) {

fscanf(inp,"%s",line);

if(strlen(line) >= 1) {//本行不是空行

fprintf(outp,"%s%s",pline,line);//上一行和本行被全部写入新文件

}

else {//本行是空行

fprintf(outp,"%s",line);//仅写入本行,上一行被丢弃

}

strcpy(pline,line);// 当前行变成了上一行

}

fclose(inp);

fclose(outp);

return 0;

}

00分享举报

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值