Tuesday, 25 December 2012

WAP to enter numbers(Using File Handling) and print them.

#include<stdio.h>
#include<conio.h>
void main()
{
    FILE *fp;
    int n;
    fp=fopen("file.txt","w");
    do
    {
    printf("Enter a number(enter 0 to stop)");
    scanf("%d",&n);
    putw(n,fp);
    }
    while(n!=0);
    fclose(fp);
    fp=fopen("file.txt    ","r");
    while((n=getw(fp))!=EOF)
    printf("%d\n",n);
    fclose(fp);
    }

1 comment: