Practical#4
AIM: WAP to read a character from file and write a charater to a file.
Program: on RHS
#include "stdio.h"
#include "conio.h"
void main()
{
FILE *f;
clrscr();
char ch;
f=fopen("first.txt","w");
printf("Enter data");
while((ch=getchar())!=EOF)
{
putc(ch,f);
}
fclose(f);
f=fopen("first.txt","r");
while((ch=getc(f))!=EOF)
{
printf("%c",ch);
}
fclose(f);
getch();
}
Output: on LHS
AIM: WAP to read a character from file and write a charater to a file.
Program: on RHS
#include "stdio.h"
#include "conio.h"
void main()
{
FILE *f;
clrscr();
char ch;
f=fopen("first.txt","w");
printf("Enter data");
while((ch=getchar())!=EOF)
{
putc(ch,f);
}
fclose(f);
f=fopen("first.txt","r");
while((ch=getc(f))!=EOF)
{
printf("%c",ch);
}
fclose(f);
getch();
}
Output: on LHS
No comments:
Post a Comment