测算新建文本长度并建立相应长度动态数组
#include
#include
#include
#pragma warning(disable : 4996)
int main(void) {
//read
int c = 0;
static FILE* f = fopen("data.txt", "r");//需要文件中拥有内容
fseek(f, 0L, SEEK_END);/*定位到文件末尾*/
c = ftell(f);/*文件长度获取*/
fseek(f, 0L, SEEK_SET);/*定位到文件开头*/
if (f) {
char* buf = new char[c];
for (int i = 0; i < c; i++) {
char ch = fgetc(f);
if (ch != EOF) {
buf[i] = ch;
}
else {
break;
}
}
printf("%s/n", buf);
fclose(f);
}
共有 0 条评论