70,022
社区成员




#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
int main(int argc, char *argv[])
{
char ch;
FILE *fp;
long count = 0;
if(argc != 2)
{
printf("Usage: %s filename\n", argv[0]);
exit(1);
}
fp = fopen(argv[1], "r");
if(fp == NULL)
{
printf("Can't open %s", argv[1]);
exit(1);
}
ch = getc(fp);
while(ch != EOF)
{
count++;
putc(ch, stdout);
ch = getc(fp);
}
fclose(fp);
printf("File %s has %d characters\n", argv[1], count);
return 0;
}
cd /d d:\mydir
myprog myinput.txt
cd /d c:\
d:\mydir\myprog d:\mydir\myinput.txt
d:myprog d:myinput.txt
cd /d d:\mydir
myprog myinput.txt
ch = getc(fp);
while(ch != EOF)
{
count++;
putc(ch, stdout);
ch = getc(fp);
}