To write a block of data into a file , the syntax is
fwrite(ptr , m , n , fp)
Where ptr is an address of array or structure to be written into the file , m is the size of the array , n is the number of structures or arrays to be written and fp is the file pointer.
Following program demonstrate how to write an array onto a file.
fwrite(ptr , m , n , fp)
Where ptr is an address of array or structure to be written into the file , m is the size of the array , n is the number of structures or arrays to be written and fp is the file pointer.
Following program demonstrate how to write an array onto a file.
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- FILE *fp;
- int a[5],i;
- clrscr();
- if((fp=fopen("text1.dat","wb"))==NULL)
- {
- exit(1);
- }
- for(i=0;i<5;i++)
- scanf("%d",&a[i]);
- fwrite(a,sizeof(a),1,fp);
- fclose(fp);
- }
Post a Comment