Earn by twitter on twivert

Sign up for PayPal and start accepting credit card payments instantly.

Monday, September 27, 2010

WAP to File-copy which copies text, .com and .exe files


/*WAP to File-copy which copies text, .com and .exe files */
#include "fcntl.h"
#include "types.h"  /* if present in sys directory use 
          "c:tc\\include\\sys\\types.h" */
#include "stat.h"  /* if present in sys directory use 
         "c:\\tc\\include\\sys\\stat.h" */

main ( int  argc, char  *argv[ ] )
{
 char  buffer[ 512 ], source [ 128 ], target [ 128 ] ;
 int  inhandle, outhandle, bytes ;

 printf ( "\nEnter source file name" ) ;
 gets ( source ) ;

 inhandle = open ( source, O_RDONLY | O_BINARY ) ;
 if ( inhandle == -1 )
 {
  puts ( "Cannot open file" ) ;
  exit( ) ;
 }

 printf ( "\nEnter target file name" ) ;
 gets ( target ) ;

 outhandle = open ( target, O_CREAT | O_BINARY | O_WRONLY,       S_IWRITE ) ;
 if ( inhandle == -1 )
 {
  puts ( "Cannot open file" ) ;
  close ( inhandle ) ;
  exit( ) ;
 }

 while ( 1 )
 {
  bytes = read ( inhandle, buffer, 512 ) ;

  if ( bytes > 0 )
   write ( outhandle, buffer, bytes ) ;
  else 
   break ;
 }

 close ( inhandle ) ;
 close ( outhandle ) ;
}

WAP of A menu-driven program for elementary database management


/*WAP of A menu-driven program for elementary database management */

#include<stdio.h>
#include<conio.h>
main( )
{
 FILE  *fp, *ft ;
 char  another, choice ; 
 struct emp 
 {
  char  name[40] ;
  int  age ;
  float  bs ;
 } ;
 struct emp  e ;
 char  empname[40] ;
 long int  recsize ;

 fp = fopen ( "EMP.DAT", "rb+" ) ;

 if ( fp == NULL )
 {
  fp = fopen ( "EMP.DAT", "wb+" ) ;

  if ( fp == NULL )
  {
   puts ( "Cannot open file" ) ;
   exit( ) ;
  }
 }

 recsize = sizeof ( e ) ;

 while ( 1 )
 {
  clrscr( ) ;

  gotoxy ( 30, 10 ) ;
  printf ( "1. Add Records" ) ;
  gotoxy ( 30, 12 ) ;
  printf ( "2. List Records" ) ;
  gotoxy ( 30, 14 ) ;
  printf ( "3. Modify Records" ) ;
  gotoxy ( 30, 16 ) ;
  printf ( "4. Delete Records" ) ;
  gotoxy ( 30, 18 ) ;
  printf ( "0. Exit" ) ;
  gotoxy ( 30, 20 ) ;
  printf ( "Your choice" ) ;

  fflush ( stdin ) ;
  choice = getche( ) ;
  switch ( choice )
  {
   case '1' :

    fseek ( fp, 0 , SEEK_END ) ;
    another = 'Y' ;

    while ( another == 'Y' )
    {
   printf ( "\nEnter name, age and basic sal. " ) ;
    scanf ( "%s %d %f", e.name, &e.age, &e.bs ) ;
     fwrite ( &e, recsize, 1, fp ) ; 
    printf ( "\nAdd another Record (Y/N) " ) ;
     fflush ( stdin ) ;
     another = getche( ) ;
    }

    break ;
   
   case '2' :

    rewind ( fp ) ;

    while ( fread ( &e, recsize, 1, fp ) == 1 )
   printf ( "\n%s %d %f", e.name, e.age, e.bs ) ; 

    break ;

   case '3' :

    another = 'Y' ;
    while ( another == 'Y' )
    {
   printf ( "\nEnter name of employee to modify " ) ;
     scanf ( "%s", empname ) ;

     rewind ( fp ) ;
    while ( fread ( &e, recsize, 1, fp ) == 1 )
     {   
     if ( strcmp ( e.name, empname ) == 0 )
      {
    printf ( "\nEnter new name, age & bs" ) ;
    scanf ( "%s %d %f", e.name, &e.age,&e.bs ) ;
     fseek ( fp, - recsize, SEEK_CUR ) ; 
      fwrite ( &e, recsize, 1, fp ) ; 
       break ; 
      }
     }

    printf ( "\nModify another Record (Y/N) " ) ;
     fflush ( stdin ) ;
     another = getche( ) ;
    }

    break ;
   
   case '4' :

    another = 'Y' ;
    while ( another == 'Y' )
    {
   printf ( "\nEnter name of employee to delete " ) ;
     scanf ( "%s", empname ) ;

     ft = fopen ( "TEMP.DAT", "wb" ) ;

     rewind ( fp ) ;
    while ( fread ( &e, recsize, 1, fp ) == 1 )
     {
     if ( strcmp ( e.name, empname ) != 0 )
      fwrite ( &e, recsize, 1, ft ) ; 
     }

     fclose ( fp ) ;
     fclose ( ft ) ;
     remove ( "EMP.DAT" ) ;
     rename ( "TEMP.DAT", "EMP.DAT" ) ;

     fp = fopen ( "EMP.DAT", "rb+" ) ;

    printf ( "Delete another Record(Y/N) " ) ;
     fflush ( stdin ) ;
     another = getche( ) ;
    }
    break ;

   case '0' :
    fclose ( fp ) ;
    exit( ) ;
  }
 }
 getch();
}

WAP to Reads records from binary file and displays them on VDU


/*WAP to Reads records from binary file and displays them on VDU */
#include "stdio.h"
main( )
{
 FILE  *fp ;
 struct emp 
 {
  char  name[40] ;
  int  age ;
  float  bs ; 
 } ;
 struct emp  e ;

 fp = fopen ( "EMP.DAT", "rb" ) ;

 if ( fp == NULL )
 {
  puts ( "Cannot open file" ) ;
  exit( ) ;
 }

 while ( fread ( &e, sizeof ( e ), 1, fp ) == 1 )
  printf ( "\n%s %d %f", e.name, e.age, e.bs ) ; 

 fclose ( fp ) ;
}

WAP to Receives records from keyboard and writes them to a file in binary mode


/*WAP to Receives records from keyboard and writes
them to a file in binary mode */

#include "stdio.h"
main( )
{
 FILE  *fp ;
 char  another = 'Y' ; 
 struct emp 
 {
  char  name[40] ;
  int  age ;
  float  bs ;
 } ;
 struct emp  e ;
 
 fp = fopen ( "EMP.DAT", "wb" ) ;

 if ( fp == NULL )
 {
  puts ( "Cannot open file" ) ;
  exit( ) ;
 }

 while ( another == 'Y' )
 {
  printf ( "\nEnter name, age and basic salary: " ) ;
  scanf ( "%s %d %f", e.name, &e.age, &e.bs ) ;
  fwrite ( &e, sizeof ( e ), 1, fp ) ; 

  printf ( "Add another record (Y/N) " ) ;
  fflush ( stdin ) ;
  another = getche( ) ;
 }

 fclose ( fp ) ;
}

WAP to Read records from a file using structure


/*WAP to Read records from a file using structure */
#include "stdio.h"
main( )
{
 FILE  *fp ;
 struct emp 
 {
  char  name[40] ;
  int  age ;
  float  bs ;
 } ;
 struct emp  e ;

 fp = fopen ( "EMPLOYEE.DAT", "r" ) ;

 if ( fp == NULL )
 {
  puts ( "Cannot open file" ) ;
  exit( ) ;
 }

 while ( fscanf ( fp, "%s %d %f", e.name, &e.age, &e.bs ) != EOF )
  printf ( "\n%s %d %f", e.name, e.age, e.bs ) ; 

 fclose ( fp ) ;
}

WAP to Receives strings from keyboard and writes them to file


/*WAP to Receives strings from keyboard and writes them to file*/
#include "stdio.h"
main( )
{
 FILE  *fp ;
 char  s[80] ;

 fp = fopen ( "file1.TXT", "w" ) ;
 if ( fp == NULL )
 {
  puts ( "Cannot open file" ) ;
  exit( ) ;
 }

 printf ( "\nEnter a few lines of text:\n" ) ;
 while ( strlen ( gets ( s ) ) > 0 )
 {
  fputs ( s, fp ) ;
  fputs ( "\n", fp ) ;
 }
 
 fclose ( fp ) ;
}

WAP to read a file and write(copy) data in another file


/*WAP to read a file and write(copy) data in another file*/
#include<stdio.h>
#include<conio.h>
main( )
{
 FILE  *fs, *ft ;
 char  ch ;

 fs = fopen ( "pr1.c", "r" ) ;
 if ( fs == NULL )
 {
  puts ( "Cannot open source file" ) ;
  exit( ) ;
 }

 ft = fopen ( "pr2.c", "w" ) ;
 if ( ft == NULL )
 {
  puts ( "Cannot open target file" ) ;
  fclose ( fs ) ;
  exit( ) ;
 }

 while ( 1 )
 {
  ch = fgetc ( fs ) ;

  if ( ch == EOF )
   break ;
  else
   fputc ( ch, ft ) ;
 }

 fclose ( fs ) ;
 fclose ( ft ) ;
       getch();
}

WAP to Count chars, spaces, tabs and newlines in a file


/*WAP to Count chars, spaces, tabs and newlines in a file*/
#include<stdio.h>
#include<conio.h>
main( )
{
 FILE  *fp ;
 char  ch ;
 int  nol = 0, not = 0, nob = 0, noc = 0 ;
 
 fp = fopen ( "PR1.C", "r" ) ;

 while ( 1 )
 {
  ch = fgetc ( fp ) ;

  if ( ch == EOF )
   break ;

  noc++ ;

  if ( ch == '  ' )
   nob++ ;

  if ( ch == '\n' )
   nol++ ;

  if ( ch == '\t' )
   not++ ;
 }

 fclose ( fp ) ;
 printf ( "\nNumber of characters = %d", noc ) ;
 printf ( "\nNumber of blanks = %d", nob ) ;
 printf ( "\nNumber of tabs = %d", not ) ;
 printf ( "\nNumber of lines = %d", nol ) ;
       getch();
}


WAP to check existing file empty or not


/*WAP to check existing file empty or not*/
#include<stdio.h>
#include<conio.h>
main( )
{
 FILE  *fp ;

 fp = fopen ( "PR1.C", "r" ) ;
 if ( fp == NULL )
 {
  puts ( "cannot open file" ) ;
  exit( ) ;
 }
       getch();
}

WAP to Display contents of a file on screen


/*WAP to Display contents of a file on screen*/
#include<stdio.h>
#include<conio.h>

main( )
{
 FILE  *fp ;
 char  ch ;
 
 fp = fopen ( "PR1.C", "r" ) ;

 while ( 1 )
 {
  ch = fgetc ( fp ) ;

  if ( ch == EOF )
   break ;

  printf ( "%c", ch ) ;
 }

 fclose ( fp ) ;
  getch();
}

WAP to that includes a method inside a class



/*WAP to that includes a method inside a class*/
class Box {
double width;
double height;
double depth;
// display volume of a box
void volume() {
System.out.print("Volume is ");
System.out.println(width * height * depth);
}
}
class BoxDemo3 {
public static void main(String args[]) {
Box mybox1 = new Box();
Box mybox2 = new Box();
// assign values to mybox1's instance variables
mybox1.width = 10;
mybox1.height = 20;
mybox1.depth = 15;
/* assign different values to mybox2's
instance variables */
mybox2.width = 3;
mybox2.height = 6;
mybox2.depth = 9;
// display volume of first box
mybox1.volume();
// display volume of second box
mybox2.volume();
}
}

WAP to declares two Box class objects




/*WAP to declares two Box class objects*/
class Box {
double width;
double height;
double depth;
}
class BoxDemo2 {
public static void main(String args[]) {
Box mybox1 = new Box();
Box mybox2 = new Box();
double vol;
// assign values to mybox1's instance variables
mybox1.width = 10;
mybox1.height = 20;
mybox1.depth = 15;
/* assign different values to mybox2's
instance variables */
mybox2.width = 3;
mybox2.height = 6;
mybox2.depth = 9;
// compute volume of first box
vol = mybox1.width * mybox1.height * mybox1.depth;
System.out.println("Volume is " + vol);
// compute volume of second box
vol = mybox2.width * mybox2.height * mybox2.depth;
System.out.println("Volume is " + vol);
}
}

WAP that calculate volume of Box


/*WAP that calculate volume of Box
Save as BoxDemo.java
*/
class Box {
double width;
double height;
double depth;
}
// This class declares an object of type Box.
class BoxDemo {
public static void main(String args[]) {
Box mybox = new Box();
double vol;
// assign values to mybox's instance variables
mybox.width = 10;
mybox.height = 20;
mybox.depth = 15;
// compute volume of box
vol = mybox.width * mybox.height * mybox.depth;
System.out.println("Volume is " + vol);
}
}

ADS

How to earn online

How to earn online:
Step - 1 :
signup for PayPal, to recieve your online earning
click here:
https://www.paypal.com/in/mrb/pal=CZ7224TZBMCBL
step - 2 : Singup these 4 sites & earn & enjoy! Read site to know how to earn.
1. trekpay
Earn up to $0.02 (2 cents) per click.
http://www.trekpay.com/?ref=34690
2. neobux
Earn up to $0.02 (2 cents) per click.
Click here:
http://www.neobux.com/?r=Moneyearner786

AddMe

Bookmark and Share