Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
prog-1-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-1-lab-assigments
Commits
3160fe76
Commit
3160fe76
authored
2 years ago
by
20041679
Browse files
Options
Downloads
Patches
Plain Diff
added todays assigment
parent
2c54f414
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
20230119/in1.txt
+10
-0
10 additions, 0 deletions
20230119/in1.txt
20230119/in2.txt
+10
-0
10 additions, 0 deletions
20230119/in2.txt
20230119/main.c
+94
-0
94 additions, 0 deletions
20230119/main.c
20230119/out.txt
+1
-0
1 addition, 0 deletions
20230119/out.txt
with
115 additions
and
0 deletions
20230119/in1.txt
0 → 100644
+
10
−
0
View file @
3160fe76
1
2
3
4
5
6
7
8
9
-1
This diff is collapsed.
Click to expand it.
20230119/in2.txt
0 → 100644
+
10
−
0
View file @
3160fe76
1
2
3
3
3
9
8
7
6
-1
This diff is collapsed.
Click to expand it.
20230119/main.c
0 → 100644
+
94
−
0
View file @
3160fe76
#include
<stdio.h>
#define ARR_SIZE(arr) (sizeof(arr) / sizeof(*arr))
#define MARK -1
int
write_to_file
(
char
*
filename
,
int
arr
[])
{
int
ret
=
0
;
FILE
*
file
;
if
((
file
=
fopen
(
filename
,
"w"
))
==
NULL
)
{
ret
=
-
1
;
}
else
{
int
i
=
0
;
while
(
arr
[
i
]
!=
MARK
&&
arr
[
i
+
1
]
!=
MARK
)
{
fprintf
(
file
,
"%d-"
,
arr
[
i
]);
++
i
;
}
fprintf
(
file
,
"%d"
,
arr
[
i
]);
fclose
(
file
);
}
return
ret
;
}
int
read_from_file
(
char
*
filename
,
int
arr
[],
int
size
)
{
int
ret
;
FILE
*
file
;
if
((
file
=
fopen
(
filename
,
"r"
))
==
NULL
)
{
ret
=
-
1
;
}
else
{
int
i
=
0
;
int
end
=
0
;
int
buf
;
while
(
i
<
size
&&
!
end
)
{
fscanf
(
file
,
"%d"
,
&
buf
);
if
(
buf
==
MARK
)
{
end
=
1
;
}
else
{
arr
[
i
]
=
buf
;
++
i
;
}
}
if
(
end
)
{
arr
[
i
]
=
MARK
;
ret
=
i
;
}
else
{
arr
[
0
]
=
MARK
;
ret
=
-
1
;
}
fclose
(
file
);
}
return
ret
;
}
void
modify
(
int
arr1
[],
int
arr2
[])
{
int
i
=
0
;
while
(
arr1
[
i
]
!=
MARK
&&
arr2
[
i
]
!=
MARK
)
{
int
a
=
arr1
[
i
];
int
b
=
arr2
[
i
];
if
(
a
==
b
)
{
arr1
[
i
]
=
0
;
}
else
if
(
a
<
b
)
{
arr1
[
i
]
=
b
;
}
else
{
++
arr1
[
i
];
}
++
i
;
}
}
int
main
(
void
)
{
int
ret
=
0
;
int
arr1
[
10
];
if
(
read_from_file
(
"in1.txt"
,
arr1
,
ARR_SIZE
(
arr1
))
<
0
)
{
ret
=
1
;
}
else
{
int
arr2
[
10
];
if
(
read_from_file
(
"in2.txt"
,
arr2
,
ARR_SIZE
(
arr2
))
<
0
)
{
ret
=
1
;
}
else
{
modify
(
arr2
,
arr1
);
write_to_file
(
"out.txt"
,
arr2
);
}
}
return
ret
;
}
This diff is collapsed.
Click to expand it.
20230119/out.txt
0 → 100644
+
1
−
0
View file @
3160fe76
0-0-0-4-5-10-9-8-9
\ No newline at end of file
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