Saturday, 27 October 2012

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();
 
   }
 
 

No comments:

Post a Comment