Advertisement
Guest User

Untitled

a guest
Apr 6th, 2021
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4.  
  5. typedef struct
  6. {
  7.     unsigned char x;
  8.     int y;
  9.     bool z;
  10. } type_a;
  11.  
  12. typedef struct
  13. {
  14.     int a;
  15.     int b;
  16. } type_b;
  17.  
  18. void transmit_struct(int numb, unsigned int *data_struct);
  19.  
  20. int main()
  21. {
  22.     type_a data_a = {0};
  23.     type_b data_b = {0};
  24.  
  25.     data_a.x = 12;
  26.     data_a.y = 100;
  27.     data_a.z = true;
  28.  
  29.     data_b.a = 150;
  30.     data_b.b = 2000;
  31.  
  32.     system("chcp 1251");
  33.     system("cls");
  34.  
  35.     transmit_struct(0, &data_a);
  36.     transmit_struct(1, &data_b);
  37.  
  38.     system("pause");
  39.  
  40.     return 0;
  41. }
  42.  
  43. void transmit_struct(int numb, unsigned int *data_struct)
  44. {
  45.     switch (numb)
  46.     {
  47.         case 0:
  48.         {
  49.             printf("Значение x: %d.\n", ((type_a *)(data_struct))->x);
  50.             printf("Значение y: %d.\n", ((type_a *)(data_struct))->y);
  51.             printf("Значение z: %d.\n", ((type_a *)(data_struct))->z);
  52.             break;
  53.         }  
  54.  
  55.         case 1:
  56.         {
  57.             printf("Значение a: %d.\n", ((type_b *)(data_struct))->a);
  58.             printf("Значение b: %d.\n", ((type_b *)(data_struct))->b);
  59.             break;
  60.         }
  61.        
  62.         default:
  63.         {
  64.             printf("Oooops\n.");
  65.             break;
  66.         }
  67.     }
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement