--- In [email protected], Pawan Kumar <[EMAIL PROTECTED]> wrote:
>
> 
> 
> Jack Go <[EMAIL PROTECTED]> wrote:              HI all, 
>    
>       I am new here, need some advice. I  need to know how to read 
a record line by line. 
>    
>   Cheers,
>   Inid2know
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com   
> 
>          
> 
>  __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com
>
hey friend please just see this program .i am very new user of c 
language .so please dont mis understand me.
#include<stdio.h>
#include<conio.h>

struct student
   {
   char name[20];
   int roll,age;
   }S;
void main()
   {
   FILE *fp;
   struct student S;
   char ch;
   int size,roll;
   size = sizeof(S);
   fp = fopen("Stud.dat","rb+");
   if(fp==NULL)
      fp = fopen("Stud.dat","wb+");
   clrscr();
   fseek(fp,0,SEEK_END);
     do
      {
      printf("\nEnter the details of the studemt ");
      scanf("%s %d %d",S.name,&S.roll,&S.age);

      fwrite(&S,size,1,fp);


      printf("\nCont ..........");
      fflush(stdin);
      scanf("%c",&ch);

       }while(ch=='y');

   rewind (fp);
   printf("\nthe details of the student are \n");
   while(fread(&S,size,1,fp)!=0)
      printf("\n%s \t%d \t%d\n",S.name,S.roll,S.age);

   rewind(fp);
   printf("\nEnter the roll ");
   scanf("%d",&roll);

   printf("\nthe details of the student are \n");
   while(fread(&S,size,1,fp)==1)
         {
         if(roll == S.roll)
            {
            printf("\nFound the  record ");
            printf("\n%s \t%d \t%d\n",S.name,S.roll,S.age);
            S.age=100;
            fseek(fp,-size,SEEK_CUR);
            fwrite(&S,size,1,fp);
            break;
            }
         }
   if(feof(fp))
      printf("\nRecord not found ");


   rewind (fp);
   clrscr();
   printf("\nthe details of the student after modification are \n");
   while(fread(&S,size,1,fp)==1)
         {
            printf("\n%s \t%d \t%d\n",S.name,S.roll,S.age);
         }




   getch();
   }




Reply via email to