gashink_t

указатель на структуру

Feb 13th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define N 5
  5.  
  6. struct adres {
  7.     char* city;
  8.     char* street;
  9.     int house;
  10. };
  11.  
  12. void viewer (struct adres *);
  13. void cout (struct adres *);
  14.  
  15. int main () {
  16.  
  17.     struct adres a[N]= {
  18.         "Novosibirsc", "Lenina", 10,
  19.         "Irkutsk", "Michurina", 30 ,
  20.         "Sanct-Peterburg", "Rechnaya", 20 ,
  21.         "Moscov", "Lenino", 2 ,
  22.         "Chita", "Kutuzova", 1
  23.     };
  24.     viewer(a);
  25.     cout(a);
  26. }
  27.  
  28. void viewer (struct adres *a) {
  29.     int i;
  30.     for (i=0; i < N; i++, a++)
  31.     printf("%2d) city:%12s, street:%10s, house:%3d\n", i+1, a->city, a->street, a->house);
  32. }
  33.  
  34. void cout (struct adres *a) {
  35.     char c[15];
  36.     int i;
  37.     printf("enter a city: ");
  38.     gets(c);
  39.     for (i=0; i < N; i++)
  40.             if (strcmp((a+i)->city,c)==0)
  41.                 printf("city:%12s\nstreet:%10s\nhouse:%3d\n", (a+i)->city, (a+i)->street, (a+i)->house);
  42. }
Add Comment
Please, Sign In to add comment