- , . :
- ,
- ,
- ,
- .
, . Pascal, .
:
struct ID
{
<> < 1- >;
<> < 2- >;
<> < >;
};
struct , . struct ' , (tag - , ). . '. , .
' , "" .
, , . :
srtuct book
{
char title [50];
char author [30];
float value;
};
struct. , , . ' ' . book. - ' , struct book libry;. book.
' , . . , title . - , .
, - , . . ³ , -, .
, , . , : struct book libry;. libry , book. , ' title, author value. ' ' libry.
struct book libry; struct book , int float .
:
1) :
struct book
{
char title [50];
char author [30];
float value;
} libry;
2) :
struct book {
|
|
char title [50];
char author [30];
float value;
};
...
struct book libry;
...
, ' :
struct
{
char title [50];
char author [30];
float value;
} libry;
. . , ' .
?
. , . , , , . , , , , ' .
, :
static struct book libry;
' , :
static struct book libry = {" " " " 3.95};
".", . , libry.value, libry.title, libry.author. :
scanf ("% f", & libry.value);
:
# include <stdio.h>
# include <windows.h>
#include <locale.h>
# define MAXTIT 50 // # define , .
# define MAXAUT 30
struct book
{
char title [MAXTIT];
char author [MAXAUT];
float value;
};
void main (void)
{
setlocale(LC_CTYPE, "Russian");
struct book libry;
printf ("i : \n ");
gets (libry.title);
printf (" i i : \n ");
gets (libry.author);
printf (" i i: \n ");
scanf ("%f", &libry.value);
printf ("i i i : \n");
printf ("%s %s %f \n", libry.author, libry.title, libry.value);
system("pause");
}
:
struct student
{
char name [50];
int kurs;
int age;
};
kurs, age name. student , struct student . ϳ . struct student.
,
struct student s1, s2;
s1 s2 struct student.
' . ϳ '.
. ,
strcpy (s1.name, " ");
s1.kurs = 3;
s1.age = 20;
:
struct student
{
char name [50];
int kurs;
int age;
} s1, s2;
s1 s2 struct student.
, , . ( ѳ). + + . class.
|
|
s1 s2
s1 = s2
. ϳ s1 , s2. , student1, student2, s1 = s2 .
.
# include <stdio.h>
# include <windows.h>
#include <locale.h>
//
struct student
{
char name [30];
int kurs;
int age;
};
void main ()
{
setlocale(LC_CTYPE, "Russian");
// stud1 stud2 struct student
struct student stud1, stud2;
printf ("i i': ");
//
gets (stud1.name);
printf ("i i: ");
//
scanf ("%d", &stud1.age);
printf ("i : ");
//
scanf ("%d", &stud1.kurs);
// stud2 = stud1 ,
stud2 = stud1;
//
printf (" %s \n", stud2.name);
printf (" %d \n", stud2.kurs);
printf ("i %d \n", stud2.age);
system("pause");
}
, scanf ("%d", &stud1.age); scanf ("%d", &stud1.kurs); & ' , ' ( ).
' . . , 10 ,
struct student stud1 [10];
stud1 - ' , stud1 [0] - , stud1 [1] - ... stud1 [9] - . age ' stud1 [4]. age
kurs stud1 [0]. kurs
.
# include <stdio.h>
# include <windows.h>
#include <locale.h>
//
struct student
{
char name [30];
int kurs;
int age;
};
void main ()
{
setlocale(LC_CTYPE, "Russian");
// 10
struct student stud [10];
int i, n;
printf ("ii i:");
// n ( )
scanf ("%d", &n);
for (i = 0; i <n; i ++)
{
printf ("i i': ");
//
scanf ("%s", &stud[i].name);
printf ("i i: ");
//
scanf ("%d", &stud[i].age);
printf ("i : ");
//
scanf ("%d", &stud[i].kurs);
}
//
for (i = 0; i <n; i ++)
{
printf (" %s\n",stud[i].name);
printf (" %d \n", stud [i].kurs);
printf ("i %d \n", stud[i].age);
}
system("pause");
}
, , . .
.
# include <stdio.h>
# include <windows.h>
#include <locale.h>
//
struct people
{
char name [100];
char job [100];
int old;
};
void show (struct people man);
void main ()
{
setlocale(LC_CTYPE, "Russian");
struct people person = {"Ivanov", "Electric", 30};
show (person);
system("pause");
|
|
}
void show (struct people man)
{
printf ("I': %s \n", man.name);
printf ("i: %s \n", man.job);
printf ("i: %d \n", man.old);
}
' show, struct people - man. , show ' man. , - ' man ' person. . , , .
, .
# include <stdio.h>
# include <windows.h>
#include <locale.h>
//
struct people
{
char name [100];
char job [100];
int old;
};
void show (struct people man);
struct people get ();
void main ()
{
setlocale(LC_CTYPE, "Russian");
struct people person;
person = get ();
show (person);
system("pause");
}
void show (struct people man)
{
printf ("I': %s \n", man.name);
printf ("i: %s \n", man.job);
printf ("i: %d \n", man.old);
}
struct people get ()
{
struct people man;
printf ("I': ");
scanf ("%s", &man.name);
printf ("i: ");
scanf ("%s", &man.job);
printf ("i: ");
scanf ("%d", &man.old);
return man;
}
get (), ' man, . man person, man.
. :
void show (struct people mans [], int size);
size - , mans. .
.
# include <stdio.h>
# include <windows.h>
# include <locale.h>
/* #define ,
,
.*/
#define N 2
//
struct people
{
char name [100];
char job [100];
int old;
};
void show (struct people mans [], int size);
int main ()
{
setlocale(LC_CTYPE, "Russian");
struct people persons [N] = {{"Ivanov", "Elektrik", 35}, {"Petrov", "Vikladach", 50}};
show (persons, N);
system("pause");
}
void show (struct people mans [], int size)
{
for (int i = 0; i <size; i ++)
{
printf ("I':%s \n", mans [i].name);
printf ("i:%s \n", mans [i].job);
printf ("i:%d \n", mans [i].old);
}
}
persons mans size, mans. show () , .
: , ' , . .
|
|
, - ( ) , : , , . (, ). , . , . ? , .
, . . : , .
-, ' &. ,
struct bal {
float balance;
char name [80];
} Person;
struct bal * p; / * * /
person p:
p = &person;
, ->. , , balance:
p-> balance
->, , "", "". , .
, , , , , :
/* - . */
# include <stdio.h>
# include <windows.h>
# include <locale.h>
# define DELAY 12800000
struct my_time {
int hours;
int minutes;
int seconds;
};
void display (struct my_time*);
void update (struct my_time*);
void delay (void);
void main ()
{
setlocale(LC_CTYPE, "Russian");
struct my_time systime;
systime.hours = 0;
systime.minutes = 0;
systime.seconds = 0;
for (;;)
{
update (& systime);
display (& systime);
}
system("pause");
}
void update (struct my_time * t)
{
t-> seconds++;
if (t-> seconds == 60)
{
t-> seconds = 0;
t-> minutes++;
}
if (t-> minutes == 60)
{
t-> minutes = 0;
t-> hours++;
}
if (t-> hours == 24) t-> hours = 0;
delay ();
}
void display (struct my_time * t)
{
printf ("% 02d:", t-> hours);
printf ("% 02d:", t-> minutes);
printf ("% 02d \n", t-> seconds);
}
void delay (void)
{
long int t;
/* , DELAY () */
for (t = 1; t <DELAY; ++t);
}
, DELAY.
my_time, . main () systime 00:00:00. , systime main ().
update () ( ) display () ( ) systime. my_time.
update () display () systime . update () systime, . , "", , , 24, 0. update () :
if (t-> hours == 24) t-> hours = 0;
, t ( systime main ()) hours .
', . , .
|
|
# include <stdio.h>
# include <windows.h>
# include <locale.h>
# include <string.h>
# include <iostream>
struct student
{
char name [10];
char surname [15];
int age;
} Stud;
void main ()
{
setlocale(LC_CTYPE, "Russian");
// stud student
struct student *s; // student
s = &Stud; //
strcpy (s-> name, "Larry"); // strcpy () str2 str1
//
strcpy (s-> surname, "Johnson");
(*s).age = 34; //
printf ("\n I': %s \n i: %s \n i = %i \n", s-> name, s-> surname, s-> age);
system ("pause");
}
- , . , , .
. , .
, . , address emp:
struct emp {
struct addr address; /* */
float wage;
} Worker;
, . addr, . - wage, . zip address 93456.
worker.address.zip = 93456;
, - , - , . 89 15- . 99 63- .