RUPAK SEARCH ENGINE

Custom Search

Write a program to create/append/disp data of a data file. Also use structure.

Write a program to create/append/disp data of a data file. Also use structure.
#include
#include
#include
# define null 0
struct info{
int roll;
char name[20];
char of_name[20];
char oc_name[20];

};
FILE *ptr;
void dispmenu();
void create(void);
void add(void);
info dispdata(void);
void main()
{
int choice;
info student;
repeat:
dispmenu();
scanf("%d",&choice);
if(choice<1|| choice>4)
goto repeat;
else if (choice==1)
create();
else if (choice==2)
add();
else if (choice==3)
{
clrscr();
if((ptr=fopen("myfile.dat","r"))==null)
printf("File not found.");
else
{
choice=0;
do
{
student=dispdata();
choice++;
printf("%d.%d",choice,student.roll);
printf("%s\n",student.name);
}while(feof(ptr)==0);
getch();
fclose(ptr);
}
}
else if(choice==4)
exit(1);
goto repeat;
}
void dispmenu()
{
clrscr();
printf("\n1.Create New File.\n2.Add(append)");
printf("\n3.Display\n4.Exit\nChoose 1 to 4");
}
void create()
{
info student;
ptr=fopen("myfile.dat","w");
clrscr();
printf("Roll:");
scanf("%d",&student.roll);
printf("name");
scanf("%s",student.name);
?????????????????
fprintf(ptr,"%d%s\n",student.roll,student.name);
fclose(ptr);
}
void add()
{
info student;
clrscr();
ptr=fopen("myfile.dat","a");
printf("Roll:");
scanf("%d",&student.roll);
printf("name:");
scanf("%s",student.name);
fprintf(ptr,"%d%s\n",student.roll,student.name);
fclose(ptr);
}
info dispdata()
{
info student;
{
fscanf(ptr,"%d",&student.roll);
fscanf(ptr,"%[^\n]",student.name);
return(student);
}
}

No comments:

Post a Comment