![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
IO练习
Jason Statham_jeb
专业从事汽车电子领域软件开发,对汽车总线、CAN总线、UDS检测系统有专业研究!
展开
-
每日练习十一
读取一个文件后10KB数据并写入新文件! #include <stdio.h> #include <stdio.h> #include <unistd.h> #include <sys/stat.h> #include <fcntl.h> #define BUFFER_SIZE 1024 //每次读写缓存大小 #define OFFSET 10240 //复制的数据大小 int main(int argc, char **argv) {原创 2021-06-29 23:24:58 · 144 阅读 · 0 评论 -
每日练习十
利用文件I/O方法获取文件的字节数! #include <stdio.h> #include <unistd.h> #include <sys/stat.h> #include <fcntl.h> #define N 30 int main(int argc, char **argv) { int fd,nbyte,sum=0; char buf[N]; if((fd=open("2.txt", O_RDONLY))<0) //只读方式打开 {原创 2021-06-29 22:13:15 · 48 阅读 · 0 评论 -
每日练习9
程序中每隔3秒读取文件内容,显示并写入另一个文件,同时,写入时间戳! #include <stdio.h> #include <time.h> #include <unistd.h> #include <errno.h> #include <stdlib.h> #include <string.h> #include <windows.h> #define N 64 int main(int argc, char **arg原创 2021-06-29 19:30:03 · 70 阅读 · 0 评论 -
每日练习8
按奇数位读取学生数据并打印显示; #include <stdio.h> #include <stdlib.h> struct student { char name[10]; int num; int age; char addr[15]; }stu[10]; int main(int argc, char **argv) { int i; FILE *fp; if((fp=fopen("stud.txt","r"))==NULL) { p原创 2021-06-29 08:55:25 · 89 阅读 · 0 评论 -
每日练习7
利用二位数组获取文件1的内容并将其存储至文件2; #include <stdio.h> #include <errno.h> #define N 128 int main(int argc, char **argv) { FILE *fp1,*fp2; int i; char s[5][N]; if((fp1=fopen("1.txt","r"))==NULL) { perror("open"); return -1; } for(i=0;i<5;i+原创 2021-06-28 20:44:27 · 42 阅读 · 0 评论 -
每日练习6
从文件中读取10组学生数据并显示出来! #include <stdio.h> struct student { char name[10]; int num; int age; char addr[15]; }stu[10]; //定义10组数据 void read() { FILE *fp1 ; if((fp1=fopen("stu.dat","r"))==NULL) { printf("open is failure\n");原创 2021-06-28 19:32:41 · 108 阅读 · 0 评论 -
每日练习5
** 从键盘输入10组学生数据并保存进磁盘文件! ** #include <stdio.h> #include <errno.h> #define N 10 struct student { char name[10]; int num; int age; char addr[15]; }stu[10]; //定义结构体 int i; FILE *fp1; void save() //定于保存函数 { if((fp1=fopen(原创 2021-06-28 19:10:31 · 52 阅读 · 0 评论 -
每日练习4
从键盘读取若干字符串,对他们按字母大小的顺序排序,排好序后输出(以流的方式读写) #include <stdio.h> #include <string.h> #include <stdlib.h> #define N 10 int main(int argc, char **argv) { char s[3][N],temp[10]; int i,j; for(i=0;i<3;i++) fgets(s[i],10,stdin); //存储从键盘输入的字原创 2021-06-26 17:34:17 · 58 阅读 · 0 评论 -
每日练习3
利用fseek和ftell函数获取文件大小! #include <stdio.h> int main(int argc, char **argv) { FILE *fp; if(argc<2) { printf("Usage : %s<file>\n",argv[0]); return -1; } if ((fp=fopen(argv[1],"r"))==NULL) { perror("fail to open\n"); return -1;原创 2021-06-25 16:43:03 · 46 阅读 · 0 评论 -
每日练习2
利用fgetc及fputc函数将一个文件内容复制到另外一个文件中! #include <stdio.h> #define N 10 int main(int argc, char **argv) { FILE *fp1,*fp2; char file_name1[N],file_name2[N],ch; printf("please input the input filename:\n"); scanf("%s",file_name1); getchar(); printf("pl原创 2021-06-24 14:14:50 · 42 阅读 · 0 评论 -
每日练习1
题目:从键盘输入一些字符,并逐个把他们送到文件当中。 #include<stdio.h> #include<stdlib.h> #include<errno.h> int main(){ FILE *fp; //定义文件指针 char filename[10],ch; //以字符数组形式存储文件名 printf("请输入文件名:"); scanf("%s",filename); //输入文件名 getchar(); if((fp=fopen(f原创 2021-06-23 15:32:07 · 47 阅读 · 0 评论