Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Morse_Code
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fabian.troller
Morse_Code
Commits
98336f2f
Commit
98336f2f
authored
4 years ago
by
poulpe
Browse files
Options
Downloads
Patches
Plain Diff
[Update] Fix error with \n for Z char
parent
207cfcb5
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.c
+2
-0
2 additions, 0 deletions
main.c
morse.c
+44
-11
44 additions, 11 deletions
morse.c
with
46 additions
and
11 deletions
main.c
+
2
−
0
View file @
98336f2f
...
...
@@ -5,6 +5,8 @@
int
main
(
int
argc
,
char
**
argv
)
{
arbre
tree
=
arbre_build
(
"code-morse.txt"
);
// printf("%c\n",decoder("--..",tree));
decoder_fichier
(
"text.morse"
,
tree
);
exit
(
0
);
// print(tree,1); // impression de l'arbre
// if (2 == argc) {
...
...
This diff is collapsed.
Click to expand it.
morse.c
+
44
−
11
View file @
98336f2f
...
...
@@ -23,7 +23,7 @@ char decoder(char *code, arbre tree)
uint32_t
len
=
strlen
(
code
);
for
(
uint32_t
i
=
0
;
i
<
len
;
i
+=
1
)
{
tmp
=
tmp
->
child
[(
code
[
i
]
==
'
.
'
)
?
0
:
1
];
tmp
=
tmp
->
child
[(
code
[
i
]
==
'
-
'
)
?
1
:
0
];
}
return
tmp
->
lettre
;
}
...
...
@@ -37,17 +37,30 @@ void decoder_fichier(char *filename, arbre tree)
// lecture d'un mot de caract�res dans 'A'..'Z'
FILE
*
fp
=
fopen
(
filename
,
"r"
);
assert
(
NULL
!=
fp
);
int
lg
=
0
;
// char* res = calloc(1024, sizeof(char));
uint32_t
index
=
0
;
char
code
[
6
];
printf
(
"Text :
\n
"
);
while
(
!
feof
(
fp
))
{
char
ch
=
(
char
)
fgetc
(
fp
);
switch
(
ch
)
if
(
ch
==
' '
)
{
//� compl�ter
printf
(
"%c"
,
decoder
(
code
,
tree
));
memset
(
code
,
0
,
6
);
index
=
0
;
}
else
if
(
ch
==
'/'
)
{
printf
(
" "
);
}
else
if
(
ch
==
'-'
||
ch
==
'.'
)
{
code
[
index
]
=
ch
;
index
+=
1
;
}
}
fclose
(
fp
);
printf
(
"
\n\n
"
);
}
//-----------------------------------------------------------
...
...
@@ -79,8 +92,23 @@ void encoder_fichier(char *filename, int n, int m, char alphabet_morse[n][m])
void
placer
(
char
*
chaine
,
arbre
*
tree
)
{
arbre
tmp
=
*
tree
;
int
length
=
strlen
(
chaine
);
// � compl�ter
uint32_t
length
=
strlen
(
chaine
);
for
(
uint32_t
i
=
1
;
i
<
length
-
1
;
i
+=
1
)
{
uint8_t
pos
=
(
chaine
[
i
]
==
'-'
)
?
1
:
0
;
if
(
tmp
->
child
[
pos
]
==
NULL
)
{
tmp
->
child
[
pos
]
=
calloc
(
1
,
sizeof
(
node
));
tmp
=
tmp
->
child
[
pos
];
tmp
->
lettre
=
'?'
;
}
else
{
tmp
=
tmp
->
child
[
pos
];
}
}
tmp
->
lettre
=
chaine
[
0
];
}
...
...
@@ -96,6 +124,7 @@ void table_build(char *filename, int n, int m, char alphabet_morse[n][m])
fclose
(
fp
);
}
//----------------------------------------------------------
// procedure lisant le fichier code-morse.txt et cr�ant --
// l'arbre binaire correspondant --
...
...
@@ -109,15 +138,20 @@ arbre arbre_build(char *filename)
assert
(
NULL
!=
fp
);
char
line
[
100
];
uint32_t
line_number
=
0
;
while
(
!
feof
(
fp
))
{
arbre
tmp_ptr
=
tree
;
line_number
+=
1
;
fgets
(
line
,
100
,
fp
);
char
cur_char
=
line
[
0
];
char
*
morse
=
calloc
(
strlen
(
line
),
sizeof
(
char
));
sprintf
(
morse
,
"%s"
,
line
+
1
);
printf
(
"%c : %s : %d
\n
"
,
cur_char
,
morse
,
strlen
(
morse
));
for
(
uint32_t
i
=
0
;
i
<
strlen
(
morse
)
-
1
;
i
+=
1
)
if
(
morse
[
strlen
(
morse
)
-
1
]
==
'\n'
)
{
morse
[
strlen
(
morse
)
-
1
]
=
'\0'
;
}
for
(
uint32_t
i
=
0
;
i
<
strlen
(
morse
);
i
+=
1
)
// strlen() - 1 for decrement '\n' char
{
uint8_t
pos
=
(
morse
[
i
]
==
'-'
)
?
1
:
0
;
if
(
tmp_ptr
->
child
[
pos
]
==
NULL
)
...
...
@@ -131,7 +165,6 @@ arbre arbre_build(char *filename)
tmp_ptr
=
tmp_ptr
->
child
[
pos
];
}
}
printf
(
"Save value : '%c' in addr : %p
\n
"
,
cur_char
,
tmp_ptr
->
lettre
);
tmp_ptr
->
lettre
=
cur_char
;
free
(
morse
);
}
...
...
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