Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct hold {
  4.    int age;
  5.    char name[30];
  6. };
  7. void all(){
  8.     struct hold *ptr;
  9.     int i, n;
  10.     printf("Enter the number of persons: ");
  11.     scanf("%d", &n);
  12.     ptr = (struct hold*) malloc(n * sizeof(struct hold));
  13.     for(i = 0; i < n; ++i){
  14.         printf("Enter first name and age respectively: ");
  15.         scanf("%s %d", (ptr+i)->name, &(ptr+i)->age);
  16.     }
  17.     printf("Displaying Information:\n");
  18.     for(i = 0; i < n; ++i)
  19.         printf("Name: %s\tAge: %d\n", (ptr+i)->name, (ptr+i)->age);
  20. }
  21. int main(){
  22.     int type;
  23.     printf("Enter type: ");
  24.     scanf("%d", type);
  25.     switch(type){
  26.         case '1':
  27.             all();
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement