概述
1.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 256
char *s_gets(char arr[], int n);
int main(int argc, char *argv[])
{
int ch;
FILE *fp;
char arr[SIZE];
unsigned long count = 0;
puts("Please input filename: ");
s_gets(arr, SIZE);
if((fp = fopen(arr,"r")) == NULL)
{
printf("Can't open %sn",argv[1]);
exit(EXIT_FAILURE);
}
while((ch = getc(fp)) != EOF)
{
putc(ch,stdout);
count++;
}
putchar('n');
fclose(fp);
printf("File %s has %lu charactersn",arr,count);
system("pause");
return 0;
}
char *s_gets(char arr[], int n)
{
char *ret1;
ret1 = fgets(arr,n,stdin);
if(ret1)
{
char * ret2;
ret2 = strchr(arr, 'n');
if(ret2)
{
*ret2 = '