一个命令行参数程序帮忙看看怎么回事
#include <stdio.h>#include <stdlib.h>
int main(int argc,char *argv[])
{
int i;
char a[100];
char ch,b;
FILE *fp;
ch=argv[1][0];
if(argc=2)
{
int count=0;
puts("input your file name");
gets(a);
if((fp=fopen(a,"r"))==NULL)
{
printf("Can't open %s",a);
exit(1);
}
else
{
while((b=getc(fp))!=EOF)
{
if(ch==b)
count++;
}
}
printf("the %c show %d times",ch,count);
fclose(fp);
}
if(argc>2)
{
for(i=2; i<argc; i++)
{
int count=0;
printf("\nFILE %d -- %s:\n",i-1,argv[i]);
if ( (fp = fopen(argv[i],"r")) == NULL)
{
printf ("Can't open %s\n", argv[i]);
exit(1);
}
while((b=getc(fp))!=EOF)
{
if(ch==b)
count++;
}
printf("the %c show %d times",ch,count);
fclose(fp);
}
}
return 0;
}
参数大于2时 为什么程序不进入下面那个 if(argc>2)里面