Monday, June 18, 2012

To read data from keyboard into a file and then display the same on the screen


/* Program to read data from keyboard into a file and then display the same on the screen */

#include<stdio.h>

#include<conio.h>

void main()

{

  FILE *fp;

  char ch;

  clrscr();

  printf("Data Input:\n");

  fp=fopen("MYFILE","w");

  while((ch=getchar())!=EOF)

    putc(ch,fp);

  fclose(fp);

  printf("Data Output:\n");

  fp=fopen("MYFILE","r");

  while((ch=getc(fp))!=EOF)

    printf("%c",ch);

  fclose(fp);

  getch();

}

 

OUTPUT

Data Input:

hello how are you.^Z

Data Output:

hello how are you.

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.