69,369
社区成员
发帖
与我相关
我的任务
分享
int main(int argc, char *argv[])
{
int i = 0;
FILE *fp = NULL;
fp = fopen("c:\\下载\\1.txt", "r");
if (!fp) {
printf("文件打开失败!\n");
sleep(3);
exit(1);
}
int length = 0;
fseek(fp, 0L, SEEK_END);
length = ftell(fp);
fseek(fp, 0L, SEEK_SET);
char* str = (char*)calloc(length + 1, sizeof(char));
if (!str) {
printf("内存分配失败!\n");
sleep(3);
exit(1);
}
fread(str, sizeof(char), length, fp);
printf("%s\n", str);
fclose(fp);
fp = NULL;
quit_enter(1);
return 0;
}