fork download
  1. # include<stdio.h>
  2. # include<stdlib.h>
  3. # include<string.h>
  4.  
  5. typedef struct student
  6. {
  7. int rollno;
  8. char name[20];
  9. struct student *snext;
  10. }Student;
  11.  
  12. typedef struct branch
  13. {
  14. char branchname[3];
  15. int noofstudents;
  16. Student *stdptr;
  17. struct branch *bnext;
  18. }Branch;
  19.  
  20. typedef struct collage
  21. {
  22. char collname[20];
  23. int cregno;
  24. Branch *branchptr;
  25. struct collage *cnext;
  26. }Collage;
  27.  
  28. typedef struct university
  29. {
  30. char uname[20];
  31. Collage *collptr;
  32. }University;
  33.  
  34. University *Initialize(University *u)
  35. {
  36. if(u != NULL)
  37. {
  38. strcpy(u->uname, "BPUT");
  39. }
  40. return u;
  41. }
  42.  
  43. University *insertcollage(University *u)
  44. {
  45. int rno, collexist = 0;
  46. if(u == NULL)
  47. {
  48. printf("\nUniversity doesnot exist");
  49. return NULL;
  50. }
  51.  
  52. if(u->collptr == NULL)
  53. {
  54. u->collptr = (Collage *)malloc(sizeof(Collage));
  55. }
  56. printf("\n\nEnter the collage registration id");
  57. scanf("%d", &rno);
  58.  
  59.  
  60. if(collexist)
  61. {
  62. printf("\n\nAlready a collage exist with this registration id");
  63. return NULL;
  64. }
  65. else
  66. {
  67. Collage *c=(Collage *)malloc(sizeof(Collage));
  68. c->cregno = rno;
  69. printf("\n\nEnter the collage name");
  70. scanf("%s", &c->collname);
  71. c->cnext = u->collptr;
  72. u->collptr = c;
  73.  
  74. return u;
  75. }
  76. }
  77.  
  78. void viewdetails(University *u)
  79. {
  80. if(u == NULL)
  81. {
  82. printf("\n\nUniversity doesnot exist\n");
  83. exit(0);
  84. }
  85.  
  86. printf("\n\nUniversity Name : %s", u->uname);
  87.  
  88. printf("\n--------------------\n");
  89. printf("\nCollage List");
  90. printf("\n--------------------\n");
  91. printf("Reg. No\t\tColl Name");
  92. printf("\n-------------------------\n");
  93.  
  94. while(u->collptr)
  95. {
  96. printf("\n");
  97. printf("%d\t\t%s", u->collptr->cregno, u->collptr->collname);
  98. u->collptr = u->collptr->cnext;
  99. }
  100. }
  101.  
  102. int main()
  103. {
  104. int ch, x;
  105. University *u = (University *)malloc(sizeof(University));
  106. u = Initialize(u);
  107.  
  108. do
  109. {
  110. printf("\n\nEnter your choice\n\n");
  111. printf("\n1. Insert");
  112. printf("\n2. Delete");
  113. printf("\n3. Modify");
  114. printf("\n4. View Details");
  115. printf("\n5. Exit");
  116. scanf("%d", &ch);
  117.  
  118. switch(ch)
  119. {
  120. case 1:
  121.  
  122. printf("\n\nWhat do you want to Insert? Enter your choice.\n");
  123. printf("\n1. Collage");
  124. printf("\n2. Branch");
  125. printf("\n3. Students");
  126. scanf("%d", &x);
  127.  
  128. if(x == 1)
  129. {
  130. u = insertcollage(u);
  131. }
  132. else if(x == 2)
  133. {
  134.  
  135. }
  136. else if(x == 3)
  137. {
  138.  
  139. }
  140.  
  141. break;
  142.  
  143. case 2:
  144. break;
  145.  
  146. case 3:
  147. break;
  148.  
  149. case 4:
  150. viewdetails(u);
  151. break;
  152.  
  153. case 5:
  154. exit(0);
  155. }
  156. }
  157. while (ch != 5);
  158. return 0;
  159. }
Success #stdin #stdout 0.01s 2860KB
stdin
1
1
101
NIST
1
1
102
ICFAI
4
5
stdout

Enter your choice


1. Insert
2. Delete
3. Modify
4. View Details
5. Exit

What do you want to Insert? Enter your choice.

1. Collage
2. Branch
3. Students

Enter the collage registration id

Enter the collage name

Enter your choice


1. Insert
2. Delete
3. Modify
4. View Details
5. Exit

What do you want to Insert? Enter your choice.

1. Collage
2. Branch
3. Students

Enter the collage registration id

Enter the collage name

Enter your choice


1. Insert
2. Delete
3. Modify
4. View Details
5. Exit

University Name : BPUT
--------------------

Collage List
--------------------
Reg. No		Coll Name
-------------------------

102		ICFAI
101		NIST
0		

Enter your choice


1. Insert
2. Delete
3. Modify
4. View Details
5. Exit