Logo 
Search:

C Programming Forum

Ask Question   UnAnswered
Home » Forum » C Programming       RSS Feeds

student database

  Asked By: Tishad    Date: Dec 10    Category: C Programming    Views: 5480
  

Consider the following structure:
struct student
{
char name[20];
char semCode[10];
int enrollNo;
int assignSub;
int marks;
int attendence;
};
Please write functions to add, edit and delete record from a file database (Binary Read/Write). Write a
program to illustrate your work.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Abhishek Singh     Answered On: May 23

#include <stdio.h>

02 #include <stdlib.h>

03 struct student{

04 char firstname[100];

05 char lastname[100];

06 };

07

08 int main ()

09 {

10 FILE * pFile;

11 FILE * f;

12 int count;

13 int gpac;

14 struct student student[20];

15 int age[1];

16 float s=0;

17 float gpa=0;

18

19

20 printf("-------------------------");

21 printf("STUDENT DTATBASE PROJECT");

22 printf("-------------------------\n\n");

23 FILE *in;

24 char c;

25 in = fopen("sdata.txt", "r");

26 if(in != NULL)

27 {

28 while((c = fgetc(in)) != EOF) putchar(c);

29 printf("Current Students in Database\n%[]\n",c);

30 fclose(in);

31 }

32

33 for ( count = 1; count <11; count++)

34 {

35 pFile = fopen ("sdata.txt","a");//Student Database File//

36 printf("please enter student No[%d] First name\n",count);

37 scanf("%s",student[count].firstname);

38 printf("please enter student No[%d] Last name\n",count);

39 scanf("%s",student[count].lastname);

40 printf("please enter The Age for %s %s\n\n",student[count].firstname, student[count].lastname);

41 scanf("%d",&age[1]);

42 for ( gpac = 1; gpac <6; gpac ++)

43 {

44 printf("please enter Course Credit For Course No[%d/5] Grade for %s %s\n\n",gpac,student[count].firstname, student[count].lastname);

45 scanf("%f",&gpa);

46 s=gpa+s;

47 s=s/5;

48 };

49 printf("%s %s gpa value is %f.\n\n",student[count].firstname, student[count].lastname,s);

50 fprintf (pFile, "First Name [%s]\nLast Name [%s]\nAge [%d]\nGPA[%6.1f]\n------------------\n", student[count].firstname,student[count].lastname,age[1],s);

51 age[1]=0;

52 fclose (pFile);

53

54 FILE *in;

55 char c;

56 in = fopen("sdata.txt", "r");

57 if(in != NULL)

58 {

59 while((c = fgetc(in)) != EOF) putchar(c);

60 printf("%[]\n",c);

61 fclose(in);

62 }

63 }

64

65 return 0;

66 }

 
Didn't find what you were looking for? Find more on student database Or get search suggestion and latest updates.




Tagged: