OP 06 June, 2022 - 11:44 AM
Write a value-returning function that accepts a phrase in Morse code and returns the English-language equivalent. However, if the parameter is invalid, the function should return a message telling that the parameter/input is invalid. Use one blank between each Morse-coded letter and three blanks between each Morse-coded word. Embed it in a program. Below is the list of letters and their Morse code equivalent.
this is my code needs to fix
#include <stdio.h>
#include <string.h>
const char morse[][10] = {
"._", // A
"_...", // B
"_._.", // C
"_..", // D
".", // E
".._.", // F
"__.", // G
"....", // H
"..", // I
".___", // J
"_._", // K
"._..", // L
"__", // M
"_.", // N
"___", // O
".__.", // P
"__._", // Q
"._.", // R
"...", // S
"_", // T
".._", // U
"..._", // V
".__", // W
"_.._", // X
"_.__", // Y
"__..", // Z
};
const int SIZE = 1000;
void *decryptMorse(char segment[]){
int space = 0;
int currentLineWord = 0;
char strings[SIZE][SIZE];
for(int i = 0; i <= strlen(segment); i++){
// check for 3 spaces
if(segment[i] == ' '){
space++;
} else {
space = 0;
}
// construct group word
if(space == 3){
char word[100];
char c = 0; // counter for constructing word
for(int j = currentLineWord; j < i-2; j++){
word[c] = segment[j];
c++;
}
c = 0;
// for(int j = currentLineWord; j < i-2; j++){
// printf("%c", word[c]);
// c++;
// }
currentLineWord = i+1;
for(int g = 0; ){
// code
}
printf("\n");
//printf("%s", word);
}
if(segment[i] == 0){
printf("\nend\n");
}
}
}
int main() {
// Write C code here
// test te hello hi
// test te
// hello
// hi
char segment[SIZE];
// prompt user
gets(segment);
decryptMorse(segment);
return 0;
}
this is my code needs to fix
#include <stdio.h>
#include <string.h>
const char morse[][10] = {
"._", // A
"_...", // B
"_._.", // C
"_..", // D
".", // E
".._.", // F
"__.", // G
"....", // H
"..", // I
".___", // J
"_._", // K
"._..", // L
"__", // M
"_.", // N
"___", // O
".__.", // P
"__._", // Q
"._.", // R
"...", // S
"_", // T
".._", // U
"..._", // V
".__", // W
"_.._", // X
"_.__", // Y
"__..", // Z
};
const int SIZE = 1000;
void *decryptMorse(char segment[]){
int space = 0;
int currentLineWord = 0;
char strings[SIZE][SIZE];
for(int i = 0; i <= strlen(segment); i++){
// check for 3 spaces
if(segment[i] == ' '){
space++;
} else {
space = 0;
}
// construct group word
if(space == 3){
char word[100];
char c = 0; // counter for constructing word
for(int j = currentLineWord; j < i-2; j++){
word[c] = segment[j];
c++;
}
c = 0;
// for(int j = currentLineWord; j < i-2; j++){
// printf("%c", word[c]);
// c++;
// }
currentLineWord = i+1;
for(int g = 0; ){
// code
}
printf("\n");
//printf("%s", word);
}
if(segment[i] == 0){
printf("\nend\n");
}
}
}
int main() {
// Write C code here
// test te hello hi
// test te
// hello
// hi
char segment[SIZE];
// prompt user
gets(segment);
decryptMorse(segment);
return 0;
}