Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
osy.pages.fel.cvut.cz
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
Container 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
osy
osy.pages.fel.cvut.cz
Commits
5e7dff5d
Commit
5e7dff5d
authored
2 years ago
by
Michal Sojka
Browse files
Options
Downloads
Patches
Plain Diff
lab8: Úprava ukázokvého kódu pro větší srozumitelnost
parent
55f6e25a
No related branches found
No related tags found
No related merge requests found
Pipeline
#56079
passed
2 years ago
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hugo/content/docs/cviceni/lab8/_index.md
+16
-14
16 additions, 14 deletions
hugo/content/docs/cviceni/lab8/_index.md
with
16 additions
and
14 deletions
hugo/content/docs/cviceni/lab8/_index.md
+
16
−
14
View file @
5e7dff5d
...
...
@@ -83,15 +83,17 @@ Do BRUTE nahrávejte soubor `hexconv.c` se svou implementací.
jádrem. 64-bitové jádro je možné volat pomocí obou ABI, ale v této úloze
používejte 32-bitové ABI, protože program je kompilován s přepínačem
`-m32`
.
{{
<
/
hint
>
}}
-
Můžete vyjít z kódu níže, který již obsahuje náhradu funkce
`scanf`
.
-
Můžete vyjít z kódu níže, který již obsahuje načítání vstupu místo
funkce
`scanf`
.
-
Pro tisk i načítání můžete použít pole pevné délky např. 20 (maximální výstup
má 8 hexadecimálních znaků).
```
C
#include <unistd.h> /* TODO: write your own system call wrappers */
/* for read, write, exit */
#include <stdio.h> /* TODO: sprintf -- convert number to hex string */
#include <string.h> /* TODO: strlen -- length of output for write */
#include <unistd.h> /* TODO: replace this by writing your own system call */
/* wrappers for read(), write(), exit() */
#include <stdio.h> /* TODO: replace this by your own implementation of */
/* sprintf() (for conversion of a number to hex string) */
#include <string.h> /* TODO: replace this with your implementation of strlen() */
int isnum(char ch)
{
...
...
@@ -110,36 +112,36 @@ static void print(unsigned num)
sprintf(buf, "0x%x\n", num);
int ret = write(STDOUT_FILENO, buf, strlen(buf));
if (ret == -1)
_exit(1); // TODO your new exit
_exit(1); // TODO
:
your new exit
}
/* TODO: main() is called by libc.
Real
entry point is _start(). */
/* TODO: main() is called by libc.
Without libc, the
entry point is
called
_start(). */
int main()
{
char buf[20];
unsigned num = 0;
int i;
int num_digits = 0;
unsigned chars_
in_buffer
= 0;
unsigned chars_
to_process
= 0;
for (/* no init */; /* no end condition */; i++, chars_
in_buffer
--) {
if (chars_
in_buffer
== 0) {
for (/* no init */; /* no end condition */; i++, chars_
to_process
--) {
if (chars_
to_process
== 0) {
int ret = read(STDIN_FILENO, buf, sizeof(buf));
if (ret < 0)
return 1; // TODO replace by exit
return 1; // TODO
:
replace by exit
i = 0;
chars_
in_buffer
= ret;
chars_
to_process
= ret;
}
if (
num_digits > 0
&& (chars_
in_buffer
== 0 /* EOF */ || !isnum(buf[i]))
&& (chars_
to_process
== 0 /* EOF */ || !isnum(buf[i]))
) {
print(num);
num_digits = 0;
num = 0;
}
if (
chars_
in_buffer
== 0 /* EOF */
chars_
to_process
== 0 /* EOF */
|| (!isspc(buf[i]) && !isnum(buf[i]))
)
return 0; // TODO: replace by exit
...
...
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