0% found this document useful (0 votes)
17 views3 pages

10-5-21 To 12-5-21 File Programmes Discussed in The Online Class

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

10-5-21 To 12-5-21 File Programmes Discussed in The Online Class

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

10-5-21 to 12-5-21 file programmes discussed in the online class.

//1.Read Existing file from the disk


#include<stdio.h>
#include<conio.h>
void main()
{
char c;
FILE *fp;
//read the file
clrscr();
fp=fopen("INPUT.TXT","r");
while((c=getc(fp))!=EOF)
{
printf("%c",c);
}
fclose(fp);
getch();
}

//2. write a new file


#include<stdio.h>
void main()
{
FILE *fp;//data structure
char c;
clrscr();

fp=fopen("123.txt","w");

printf("Enter the data into file\n");

while((c=getchar())!=EOF)
{
putc(c,fp);
}

fclose(fp);

getch();
}
//3.Read data from different file like (pdf,xl,ms-word)
#include<stdio.h>
void main()
{
FILE *fp;
char c;
clrscr();
fp=fopen("p1.pdf","r");//.txt (note pad),.docx(ms word),.xlsx(xl),.pdf
printf("Data from the file\n");
while((c=getc(fp))!=EOF) //a,c=a,a,c,v,f,g,s,d,f,f,e,e,(ctrl+z)
{
printf("%c",c); //c->fp->p1.txt
}
fclose(fp);
getch();
}

//4.we can write/read data to and from the file(.xlsx,.pdf,.java)


#include<stdio.h>
void main()
{
FILE *F1;
char c;
clrscr();
F1=fopen("mydoc_12_5_21.pdf","w");
while((c=getchar())!=EOF)
{
putc(c,F1);
}
fclose(F1);

F1=fopen("mydoc_12_5_21.pdf","r");
while((c=getc(F1))!=EOF)
{
printf("%c",c);
}
fclose(F1);
getch();
}

//5.copy one file data into another file.


#include<stdio.h>
void main()
{
FILE *F1,*F2;
char c;
clrscr();
F1=fopen("p1.c","r");
F2=fopen("new_12_5_21.c","w");
while((c=getc(F1))!=EOF)
{
putc(c,F2);
}
fclose(F1);
fclose(F2);
F2=fopen("new_12_5_21.c","r");
while((c=getc(F2))!=EOF)
{
printf("%c",c);
}
fclose(F2);
getch();
}

You might also like