#include <stdio.h> #include <string.h> #include <stdlib.h> //命令: ./a.out file //功能: 将file读取到buffer,然后打印出来 int main(int argc, char *argv[]) { char buf[1024] = {}; FILE *fp = NULL; int ret; fp = fopen(argv[1], "r"); ret = fread(buf, sizeof(char), sizeof(buf), fp); if (ret <= 0) { printf("fread end or error!\n"); return -1; } printf("readCharNum= %d\n", ret); //打印读取file的字符数 printf("buf = %s\n", buf); //打印file的内容 return 0; }
#include <stdio.h> #include <string.h> #include <stdlib.h> //命令: ./a.out file //功能: 将file读取到buffer,然后打印出来 int main(int argc, char *argv[]) { char buf[1024] = {}; FILE *fp = NULL; int ret; fp = fopen(argv[1], "r"); ret = fread(buf, sizeof(char), sizeof(buf), fp); if (ret <= 0) { printf("fread end or error!\n"); return -1; } printf("readCharNum= %d\n", ret); //打印读取file的字符数 printf("buf = %s\n", buf); //打印file的内容 return 0; }
时间: 2024-11-08 22:01:55