64,649
社区成员
发帖
与我相关
我的任务
分享
//看这个吧,我改进了下,这个可以过滤空行
#include <stdio.h>
#include <process.h>
#include <fstream.h>
#include <string>
void main()
{
FILE *fp;
char *str=" ";
char buff[256];
fp=fopen("1.bat","r");
if (fp==NULL)
{
printf("can not open file\n");
exit(0);
}
while(fgets(buff,256,fp))
{
int p=strnicmp(buff,str,2);
if (!p)
{
printf("%s",buff);
}
}
printf("\n");
fclose(fp);
}
1.bat内容
AO= \
XY
BO= \
AB
CD
EF
EO= \
ME
FE
Result under VC6:
XY
AB
CD
EF
ME
FE
Press any key to continue
//可以这么写
#include <stdio.h>
#include <process.h>
#include <iostream.h>
#include <memory.h>
#include <iostream.h>
#include <fstream.h>
#include <string>
void main()
{
FILE *fp;
char *str="=";
char buff[256];
fp=fopen("1.bat","r");
if (fp==NULL)
{
printf("can not open file\n");
exit(0);
}
while(fgets(buff,256,fp))
{
char *p=strpbrk(buff,str);
if (!p)
{
printf("%s",buff);
}
}
printf("\n");
fclose(fp);
}