C Program To Append Contents Into A File


#include< conio.h >
#include< stdio.h >
#include< process.h >
void main()
{
FILE *fp;
char c;
clrscr();
printf("Contents of the file =>\n");
fp=fopen("demo.txt","r");
while(!feof(fp))
{
c=fgetc(fp);
printf("%c",c);

 }
fp=fopen("demo.txt","a");
if(fp==NULL)
{
printf("file can't append\n");
exit(1);
}
printf("\nEnter the string to append\n");
while(c!='.')
{
c=getche();
fputc(c,fp);
}
fclose(fp);
printf("file contents after appending\n");
fp=fopen("demo.txt","r");
while(!feof(fp))
{
c=fgetc(fp);
printf("%c",c);
}
}

----------------------------------------------------------
OUT PUT:
----------------------------------------------------------
Contents of the file =>
This is c prorgam.

Enter the string to append
I upload C++ prorams soon.

File contents after appending
This is c prorgam.I upload C++ prorams soon.

0 comments :

C Program To Copy The Contents Of A One File To Another File


#include< stdio.h >
#include< conio.h >
#include< stdlib.h >
void main()
 {
FILE *fs,*ft;
char ch;
clrscr();
 fs = fopen("file1.txt","r");
 if(fs==NULL)
  {
 printf("Cannot open source file ! Press key to exit.");
 getch();
 exit(0);
  }
ft = fopen("file2.txt","w");
 if(ft==NULL)
{
printf("Cannot copy file !");
 fclose(fs);
 getch();
 exit(0);
 }
while(1)
 {
ch = getc(fs);
if(ch==EOF)
{
 break;
}
else
putc(ch,ft);
}
printf("File copied succesfully!");
fclose(fs);
fclose(ft);
}

----------------------------------------------------------
OUT PUT:
----------------------------------------------------------

File copied successfully!

0 comments :

C Program To Read And Write The Contents Into Of A File


#include< conio.h >
#include< stdio.h >
#include
void main()
{
FILE *fp;
char c;
clrscr();
fp=fopen("demo.txt","w");
if(fp==NULL)
{
printf("can't open file\n");
exit(1);

}
printf("write data and to stop press =>'.'\n");
while(c!='.')
{
c=getche();
fputc(c,fp);
}
fclose(fp);
printf("\n Read Data from File =>\n");
fp=fopen("demo.txt","r");
while(!feof(fp))
printf("%c",getc(fp));
getch();
}

----------------------------------------------------------
OUT PUT:
----------------------------------------------------------
Write data and to stop press => ’.’
C Programs.
 Read Data from File =>
C Programs.

0 comments :

implement C++ program for abstract classes

#include< iostream.h >
#include< conio.h >
class item
{                                                                                          
private:
int a,b,c,d;
public:
void get();
void multiply();
void sum();
};
void item::get()
{
cout<<"enter a & b :" ;
cin>>a>>b;
}
void item::sum()
{
c=a+b;
cout<<"\n sum is"<< c;
}
void item::multiply()
{
d=a*b;
cout<<"\n multiplication is "<< d;
}
void main()
{
clrscr();
item t;
t.get();
t.sum();
t.multiply();
getch();
}

-------------------------------------------------------
Out put
-------------------------------------------------------
Enter a & b : 5
4
Sum is 9
Multiplication is 20

0 comments :

implement C Program of towers of hanoi


Tower of hanoi is a historical problem, which can be easily expressed using recursion. There are N disks of decreasing size stacked on one needle, and two other empty needles. It is required to stack all the disks onto a second needle in the decreasing order of size. The third needle can be used as a temporary storage. The movement of the disks must confirm to the following rules,

1. Only one disk may be moved at a time
2. A disk can be moved from any needle to any other.
3. The larger disk should not rest upon a smaller one.

#include < stdio.h >
#include < conio.h >

void move ( int, char, char, char ) ;

void main( )
{
    int n = 3 ;
    clrscr( ) ;
    move ( n, 'A', 'B', 'C' ) ;
    getch( ) ;
}

void move ( int n, char sp, char ap, char ep )
{
    if ( n == 1 )
        printf ("\nMove from %c to %c ", sp, ep ) ;
    else
    {
        move ( n - 1, sp, ep, ap ) ;
        move ( 1, sp, ' ', ep ) ;
        move ( n - 1, ap, sp, ep ) ;
    }
}

0 comments :