Tuesday 24 July 2012

perform I/O in a given file using Integer I/O

 perform I/O in a given file using Integer I/O

/* Program to perform I/O in a given file using Integer I/O */


#include<stdio.h>

main()
{
//declaring pointer to file
FILE *fp;

int num;
char chr='\n';

printf("------------Writing in file:-----------------\n");
/* Writing in File*/

//Opening file for writing
fp=fopen("number.dat","wb");

//Checking file exists or not
if(fp==NULL)
{
printf("Error in opening file:\n");
return 0;
}

else

//If the file exists then writing numbers into it
{
printf("Writing numbers in File...");
for(num=1;num<=10;num++)
 {
putw(num,fp);
}
 printf("Done...");
 } //Closing the file
fclose(fp);
/* Reading in File*/
//Opening file for reading printf("\n\n------------Reading from file:-----------------\n");
 fp=fopen("number.dat","rb");
 if(fp==NULL)
 {
printf("Error in opening file:\n");
 return 0;
} //If the file exists then reading through it
 else
{
printf("Text found in the file is:\n");
while((num=getw(fp))!= EOF)
 printf("%d \n",num);
} //closing the file fclose(fp); }
Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: