Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
prog-2-lab-assigments
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
20041679 .
prog-2-lab-assigments
Commits
fe511cc4
Commit
fe511cc4
authored
1 year ago
by
20041679
Browse files
Options
Downloads
Patches
Plain Diff
added Esercizi n. 1
parent
9c3d3cf1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Esercizi n. 1/main.c
+62
-0
62 additions, 0 deletions
Esercizi n. 1/main.c
with
62 additions
and
0 deletions
Esercizi n. 1/main.c
0 → 100644
+
62
−
0
View file @
fe511cc4
#include
<stdio.h>
#include
<stdlib.h>
typedef
struct
{
char
first_name
[
20
];
char
last_name
[
25
];
unsigned
int
age
;
}
Person
;
void
person_input
(
Person
*
person
)
{
puts
(
"nome"
);
scanf
(
"%s"
,
person
->
first_name
);
puts
(
"cognome"
);
// FIXME: buffer overflow
scanf
(
"%s"
,
person
->
last_name
);
puts
(
"anni"
);
scanf
(
"%u"
,
&
person
->
age
);
}
void
person_array_input
(
Person
people
[],
size_t
n
)
{
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
printf
(
"persona %zu
\n
"
,
i
);
person_input
(
&
people
[
i
]);
}
}
void
person_output
(
Person
*
person
)
{
printf
(
"nome: %s, cognome: %s, anni: %u
\n
"
,
person
->
first_name
,
person
->
last_name
,
person
->
age
);
}
void
person_array_idx_output
(
Person
people
[],
size_t
i
)
{
person_output
(
&
people
[
i
]);
}
void
person_array_output
(
Person
people
[],
size_t
n
)
{
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
person_array_idx_output
(
people
,
i
);
}
}
void
split_adulthood
(
Person
people
[],
size_t
n
,
Person
minors
[],
Person
adults
[])
{
minors
=
malloc
(
sizeof
(
*
people
)
*
n
);
adults
=
malloc
(
sizeof
(
*
people
)
*
n
);
size_t
count_minors
=
0
;
size_t
count_adults
=
0
;
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
Person
*
dst
=
people
[
i
].
age
<
18
?
&
minors
[
count_minors
++
]
:
&
adults
[
count_adults
++
];
*
dst
=
people
[
i
];
}
minors
=
realloc
(
minors
,
sizeof
(
*
people
)
*
count_minors
);
adults
=
realloc
(
adults
,
sizeof
(
*
people
)
*
count_adults
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment