Advertisement
inhuman_Arif

Ques 2

Oct 6th, 2021
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. //Declaring outer and inner structure
  4. struct student
  5. {
  6.     //main structure
  7.     char name[50];
  8.     int age;
  9.     struct uni_info
  10.     {
  11.         //inner structure
  12.         char uni_name[50];
  13.         int uni_id;
  14.     }uni_info[20]; //variable for nested structure
  15. }stu_info[20]; // variable for main structure
  16.  
  17. int main()
  18. {
  19.     #ifndef ONLINE_JUDGE
  20.         freopen("input.txt", "r", stdin);
  21.         freopen("output.txt", "w", stdout);
  22.     #endif
  23.  
  24.     char ch;
  25.     scanf("%s",&stu_info->name); //take name
  26.     scanf("%c",ch); //clear buffer
  27.     scanf("%d",&stu_info->age); //take age
  28.     scanf("%s",&stu_info->uni_info->uni_name); //take nested structure uni name
  29.     scanf("%c",ch); //clear buffer
  30.     scanf("%d",&stu_info->uni_info->uni_id);
  31.     printf("%s\n%d\n%s\n%d",stu_info->name,stu_info->age,stu_info->uni_info->uni_name,stu_info->uni_info->uni_id);
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement