主题:求助!
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define M 20
int main(int argc,char *argv[])
{
char ch[M];
FILE *fp;
if((fp = fopen(argv[2],"r"))==NULL)
{
printf("Can't open file %s",argv[2]);
exit(1);
}
while(fgets(ch,M,fp)!=NULL)
if(strncmp(ch,argv[1],strlen(argv[1]))==0)
puts(ch);
fclose(fp);
return 0;
}
从文件中读取行并找一个字符串,如果在就把这行打印出来!
程序运行了没有反应,但编译器没报错![em6]
#include <string.h>
#include <stdlib.h>
#define M 20
int main(int argc,char *argv[])
{
char ch[M];
FILE *fp;
if((fp = fopen(argv[2],"r"))==NULL)
{
printf("Can't open file %s",argv[2]);
exit(1);
}
while(fgets(ch,M,fp)!=NULL)
if(strncmp(ch,argv[1],strlen(argv[1]))==0)
puts(ch);
fclose(fp);
return 0;
}
从文件中读取行并找一个字符串,如果在就把这行打印出来!
程序运行了没有反应,但编译器没报错![em6]