首页 > 技术文章 > 读写txt

gaoquanning 2013-08-19 11:34 原文

读写txt

abc1223@126.com
11222
aadad222@qq.com
1243444
vvv4444@qq.com
5444444
把邮箱的数字排除掉

#include <stdio.h>
#include <stdlib.h>

int main()
{
FILE * fp = fopen("in.txt", "rb");
if (fp == NULL)
{
fprintf(stderr, "cannot open file");
exit(0);
}

FILE * wfp = fopen("out.txt", "w");
if (wfp == NULL)
{
fprintf(stderr, "cannot open file");
exit(0);
}

char buf[1024];
char * p;
bool isDigit = true;
while (fgets(buf, 1024, fp))
{
isDigit = true;
p = buf;
while (p != '\0')
{
if ((*p) <'0' && (*p) > '9')
{
isDigit = false;
break;
}
p++;
}
if (isDigit == true)
fprintf(wfp, buf);
else
continue;
fprintf(wfp, "\n");
}
fclose(fp);
fclose(wfp);
return 0;
}


推荐阅读