克隆
#include <stdio.h>
#include <malloc.h>
typedef char *String;
int main() {
FILE *t = fopen("test.txt", "w");
fputs("hello\nworld", t);
fclose(t);
String s = (String) malloc(4096);
FILE *f1 = fopen("test.txt", "r");
FILE *f2 = fopen("test2.txt", "w");
while (fgets(s, 4096, f1)) {
fputs(s, f2);
}
fclose(f1);
fclose(f2);
return 0;
}
行号
#include <stdio.h>
#include <malloc.h>
typedef char *String;
int main() {
int count = 0;
String s = (String) malloc(4096);
FILE *f = fopen("test.txt", "r");
while (fgets(s, 4096, f))count++;
printf("%d", count);
return 0;
}