Showing posts with label Coding Of Append Records Using c. Show all posts
Showing posts with label Coding Of Append Records Using c. Show all posts

Wednesday, 31 October 2012

Program Of Unary Operator Overloading In C++

#include<iostream.h>
#include<conio.h>
 
{
 
    private:
 
    int a;
 
    public:
  
  void getdata(int x)
 
    {
 
      a= x;   
 
    }
  
    {
 
    a++;
 
    }
 
    void display()
 
    {
     
 cout<<"\n a="<<a;   
 
    }
 
}
 
main()
 
{
 
clrscr();
 
box b1;
 
int x;
 
cout<<"Enter x=";
 
cin>>x;
 
++b1;
 
++b1;
 
++b1;
 
++b1;
 
getch();
 
}

Saturday, 27 October 2012

Program Of Write Arguments From Memory In C


#include  <stdio.h>
#include <conio.h>
 
 int  argc;                   
 
   char *argv[];               
 
   {
   
    FILE   *fp;
      
 int  i;
     
  char word[15];

       
fp = fopen(argv[1], "w");
    
   printf("\nNo. of arguments in Command line = %d\n\n",argc);
    
   for(i = 2; i < argc; i++)
    
    fclose(fp);

    Writing Content Of The File To Screen 


       printf("Contents of %s file\n\n", argv[1]);
     
  fp = fopen(argv[1], "r");
       
for(i = 2; i < argc; i++)
 
       {
   
 printf("%s ", word);
       }

      
 fclose(fp);
      
 printf("\n\n");

     Writing the Arguments From Memory

       for(i = 0; i < argc; i++)
     
  getch();
   }

Reading Data From Command Line

 Reading Data From Command Line


#include  <stdio.h>
 
#include <conio.h>
 
                                     int  argc;            /*   argument count */
                        
                                   char *argv[];        /* list of arguments */
 
   {
      
 FILE   *fp;
  
     int  i;
      
 char word[15];
     
       fp = fopen(argv[1], "w"); /* open file with name argv[1] */
   
    printf("\nNo. of arguments in Command line = %d\n\n",argc);
 
       for(i = 2; i < argc; i++)
    
          fprintf(fp,"%s ", argv[i]);      /* write to file argv[1]  */
       
fclose(fp);

 
    getch();
   }

Program Of Append Records Using C

Coding Of Append Records Using c


#include<stdio.h>
 
#include<conio.h>
 
   {
    
   char   name[10];
   
    int    number;
  
     float  price;
   
    int    quantity;
 
   };
 
 void main()
 
   {
  
    char  filename[10];
    
   int   response; 

       FILE  *fp;
 
       long  n;
   
      printf("Type filename:");
 
      scanf("%s", filename);
    
   fp = fopen(filename, "a+");
 
       do
 
       {
 
      append(&item, fp);
    
  printf("\nItem %s appended.\n",item.name);
     
 printf("\nDo you want to add another item\        (1 for YES /0 for NO)?");
    
  scanf("%d", &response);
 
       } 
 while (response == 1);
    
       n=ftell(fp);
 
       fclose(fp);
    
   fp = fopen(filename, "r");
 
  while(ftell(fp) < n)
 
       {
    
  fscanf(fp,"%s %d %f %d",
      item.name, &item.number, &item.price, &item.quantity); 
     
 fprintf(stdout,"%-8s %7d %8.2f %8d\n",
    
  item.name, item.number, item.price, item.quantity);
 
       }
   
    fclose(fp);
 
  getch();
 
   }