修改文件结构。
This commit is contained in:
35
POP/14/Exercise03.c
Normal file
35
POP/14/Exercise03.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
char filename[81];
|
||||
FILE* fl;
|
||||
char string[81];
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Insufficient argument\n");
|
||||
return 0;
|
||||
}
|
||||
else if (argc > 2) {
|
||||
printf("Too many arguemtns\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
strncpy(filename, argv[1], 80);
|
||||
|
||||
fl = fopen(filename, "r");
|
||||
|
||||
if (fl == NULL) {
|
||||
printf("Failed to open file.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fscanf(fl, "%80s", string);
|
||||
|
||||
fclose(fl);
|
||||
printf("Content: %s\nStringLength: %d", string, strlen(string));
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user