Number of characters in the statistics file (with command line arguments)
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
Char ch;
FILE *FP;
Long count=0;
if (argc!=2)
{
printf ("File name is:%s\n", argv[0]);
Exit (Exit_failure);
}
if ((Fp=fopen (argv[1], "r+") ==null)
{
fprintf (stderr, "Cannot open file \"%s\ "\ n", argv[1]);
Exit (Exit_failure);
}
while ((CH=GETC (FP))!=eof)
{
PUTC (ch,stdout);
++count;
}
Fclose (FP);
printf ("File%s has%ld characters\n", argv[1],count);
return 0;
}
Number of characters in the statistics file (without command line arguments)
#include <stdio.h>
#include <stdlib.h>
#define MAX 80
int main (void)
{
FILE *FP;
Char ch;
Char Name[max];
Long count=0;
printf ("Please enter the file name:");
Gets (name);
if ((Fp=fopen (name, "r+")) ==null)
{
fprintf (stderr, "Cannot open file%s\n", name);
Exit (Exit_failure);
}
while ((CH=GETC (FP))!=eof)
{
PUTC (ch,stdout);
count++;
}
Fclose (FP);
printf ("File%s has%ld characters\n", name,count);
return 0;
}
Learn C language to do exercises? The number of characters in the statistics file