这篇文章主要讲了如何将一个数组写入文件中并读取出来 ,有一定的参考价值,感兴趣的朋友可以参考一下,希望对你有所帮助!
#include<stdio.h> #define N 5 int main(){ //从键盘输入的数据放入a,从文件读取的数据放入b int a[N], b[N]; int i, size = sizeof(int); FILE *fp; if( (fp=fopen("D:\\demo.txt", "rb+")) == NULL ){ printf("Cannot open file, press any key to exit!\n"); getch(); exit(1); } //从键盘输入数据 并保存到数组a for(i=0; i<N; i++){ scanf("%d", &a[i]); } //将数组a的内容写入到文件 fwrite(a, size, N, fp); //将文件中的位置指针重新定位到文件开头 rewind(fp); //从文件读取内容并保存到数组b fread(b, size, N, fp); //在屏幕上显示数组b的内容 for(i=0; i<N; i++){ printf("%d ", b[i]); } printf("\n"); fclose(fp); return 0; }
【相关教程推荐】
2. php从入门到精通
3. bootstrap教程

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment