第一题:
#include<stdio.h> #include<stdlib.h> int main(void/*int argc, char *argv[]*/) { int ch, argc; char argv[88]; FILE *fp; unsigned long count = 0; printf("input argc and name: "); scanf("%d %s", &argc, argv); printf("%d %s", argc, argv); if(argc != 2) { printf("usage: %s filename ", argv[0]); exit(EXIT_FAILURE); } if((fp = fopen(argv, "r")) == NULL) { printf("can't open %s ", argv[1]); exit(EXIT_FAILURE); } while((ch = getc(fp)) != EOF) { putc(ch, stdout); count++; } fclose(fp); printf("file %s has %lu characters ", argv, count); return 0; }
第二题,第三题:
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<ctype.h> int main(int argc, char *argv[]) { int ch; FILE *fp, *out; char name[88]; unsigned long count = 0; if(argc != 2) { printf("usage: %s filename ", argv[0]); exit(EXIT_FAILURE); } if((fp = fopen(argv[1], "r")) == NULL) { printf("can't open %s ", argv[1]); exit(EXIT_FAILURE); } strncpy(name,argv[1],88); name[88] = '