Began to study the structure. I want to write this correctly so that the compiler does not swear.

#include<conio.h> #include<stdio.h> struct selfish { char city[30]; }; struct Man { char *fio[60]; int year; int month; struct selfish; }; int main() { struct Man myself; gets_s(myself.fio); puts(myself.fio); _getch(); return 0; } 
  • Comments are not intended for extended discussion; conversation moved to chat . - Qwertiy

2 answers 2

You need an array of characters, not an array of pointers.

 char *fio[60]; 
 char fio[60]; 

And then there is something wrong:

 struct selfish; 

either you forgot to write the name of the field, or you should delete it altogether.

  • and the array of pointers will not behave in the same way as a two-dimensional array? - Elvin
  • No, in order for it to become two-dimensional, you must also allocate memory. - Qwertiy
  • Another question appeared: how such a structure is called a struct Man {char * fio [60]; int year; int month; struct selfish; } structure in structure? and why it is also necessary to add a struct selfish bd field for internal purposes; - Elvin

Began to study the structure

And what is there to study something?

Any closet in your house is a structure:

 Шкаф { нижняя полка, называется bottom; средняя полка, называется middle; верхняя полка, называется top; }; 

Each of the shelves can also be a structure that contains other structures :) For example, each of them can store a box containing boxes for small items. And in these boxes you can store indivisible elements. For example, one thing ( year , month ), or several screws of the same type ( char fio[] ).