#include
#include
int main(int argc, char *argv[])
{
char ch;
FILE *fp, *fo; //fp:输入文件指针 fo:输出文件指针
long count = 0;
int i = 0;
char s[20] = {0};
//gets(s);
//puts(s);
printf("argc: %d \n", argc);
// printf("argv[0]: %s", argv[0]);
for(i = 0; i < argc; i++ )
printf("argv[%d]: %s\n",i, argv[i]);
if(argc != 3) //三个形参,分别是程序名 源文件名 目标文件名
{
printf("Usage: %s source_filename target_filename\n", argv[0]);
exit(1);
}
if((fp = fopen(argv[1], "r")) == NULL)
{
printf("Can't open %s\n", argv[1]);
exit(1);
}
if((fo = fopen(argv[2], "w")) == NULL)
{
printf("Can't creat %s\n", argv[2]);
exit(1);
}
while((ch = getc(fp))!= EOF) // 0
{
if(ch == '\n')
{
//printf("我遇到了回车!\n");
//fputc('\n',fo);
}
else
{
if( ch == '0')
if(ch = getc(fp) == 'x') // x
{
if(ch = getc(fp) == 'f') //第一个字节是0xff
{
ch = getc(fp); // f
ch = getc(fp); // ,
ch = getc(fp); // '空格'
ch = getc(fp); // 0
ch = getc(fp); // x
if(ch = getc(fp) == 'f')//第二个字节是0xff
{
putc('0', fo);putc('x', fo);putc('0', fo);putc('0', fo);putc(',', fo);putc(' ', fo);
}
else //第二个字节是0x00
{
putc('0', fo);putc('x', fo);putc('0', fo);putc('f', fo);putc(',', fo);putc(' ', fo);
}
}
else //第一个字节是0x00
{
ch = getc(fp); // 0
ch = getc(fp); // ,
ch = getc(fp); // '空格'
ch = getc(fp); // 0
ch = getc(fp); // x
if(ch = getc(fp) == 'f')//第二个字节是0xff
{
putc('0', fo);putc('x', fo);putc('f', fo);putc('0', fo);putc(',', fo);putc(' ', fo);
}
else //第二个字节是0x00
{
putc('0', fo);putc('x', fo);putc('f', fo);putc('f', fo);putc(',', fo);putc(' ', fo);
}
}
}
ch = getc(fp); // 0/f
ch = getc(fp); // ,
ch = getc(fp); // 空格
}
}
}
评论0