Thread: Code Morse ,help...

  1. #1
    Registered User
    Join Date
    Jan 2018
    Posts
    1

    Code Morse ,help...

    Hello, I need some help, I have a school project to use Morse code, so far I have made a structure with 2 soldiers, in which they introduce details about them (age, name, sex). And a function that assigns each letter a specific symbol according to morse code. I have a problem, in fact, more, I want to post my message after entering the details about the soldiers, then translate it to the end. I would like an idea or an example in which to display me in a text on the desktop the soldier whose message contained a word that I chose. I need this project to take the exam, thank you in advance ... I apologize for my bad English ...

    this is the code:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <string.h>
    Struct Soldier
    {
    
    
        int age;
        char name [20];
        char sex [10];
        // F for the woman, M for the man
    
    
    } s1, s2;
    
    
    int main ()
    
    
    {
    
    
        printf ("\ nFirst Soldier \ n");
    
    
        // Enter the name of the first soldier
        printf ("Enter name:");
        scanf ("% s", s1.name);
        // Enter the age of the first soldier
        printf ("Enter age:");
        scanf ("% d", & s1.varsta);
        // Enter the sex of the first soldier
        printf ("Enter sex:");
        scanf ("% s", s1.sex);
    
    
        printf ("The Second Soldier! \ n");
    
    
        // Enter the name of the second soldier
        printf ("Enter name:");
        scanf ("% s", s2.name);
    
    
        // Enter the age of the second soldier
        printf ("Enter age:");
        scanf ("% d", & s2.varsta);
        // Enter the sex of the second soldier
        printf ("Enter sex:");
        scanf ("% s", s2.sex);
    
    
    
    
    
    
            int i, j;
            char l [37] = {'a', 'b', 'c', 'd', 'e', ​​'f', 'g', 'h' , 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',' t ',' u ',' v ',' w ',' x ',' y ',' z ',' 1 ',' 2 ',' 3 ',' 4 ',' 5 ',' 6 ',' 7 ',' 8 ',' 9 ',' 0 ' , ''};
            char m [37] [6] = {{".-"}, {"-..."}, {"- "" - "-" - "" - "" - "-" - '.- .. "}, {" - "}, {" -. "}, {" --- "}, {" .. "}, {" --.- "}, {" , "", "", "" - "}, {" ..- "}, {" ...- "}, {". - "}, {" -.-- "}, {" - .. "}, {" .---- "}, {" ..--- "}, {" ...-- " }, { "....-"}, { "....."}, { "-...."}, { "--..."}, { "--- .." }, { "----."}, { "-----"}, { "//"}};
            char k [10000];
            printf ("Write the message from Soldier 1 for Soldier 2: \ n");
            gets (k);
            for (i = 0; i <k [i]; i ++)
                for (j = 0; j <37; j ++)
                    if (k [i] == l [j])
                        printf ( "% s", m [j]);
            getch ();
    
    
    
    
    
    
    
    
    {
         printf ("The name of the Soldier 1:% s \ n", s1.name);
        printf ("\ nThe Age of Soldier 1:% d \ n", s1.varsta);
        printf ("\ nSex of Soldier 1:% s \ n", s1.sex);
        printf ("\ nNumber of Soldier 2:% s \ n", s2.name);
        printf ("\ nThe Age of Soldier 2:% d \ n", s2.varsta);
        printf ("\ nSex of Soldier 2:% s \ n", s2.sex);
    
    
    
    
    }
    
    
    
    
    
    
    
    
    
    
        return 0;
    }
    Last edited by Raskolnikov LM; 01-05-2018 at 03:12 PM.

  2. #2
    Registered User
    Join Date
    Nov 2015
    Posts
    72
    I find it hard to understand what is your question. You have an already half way written program, all that remains is to complete it. The char l doesn't contain all the letters of the aleph-bet and the Morse codes in char m doesn't translate properly from the char l so that has to be fixed. That and the printf shouldn't be in the curly brackets. If you want the Morse code to come out after the outputs, then you could just let the for-loop be after the printf lines. But I assume that you already know that and merely are sketching the concepts.

    Perhaps you could show an example of two soldiers with a message to be translated to Morse code and show more specifically how you intend the program to behave in the terminal prompt. Like:

    Code:
    Enter name of soldier 1: Andrey Kolmogorov
    Enter his age: 23
    Enter gender: Female to male trans man
    
    
    Enter name of soldier 2: Aleksandr Solzhenitsyn
    Enter his age: 98
    Enter gender: Male
    
    Write message from soldier 1 to solder 2: I just read your book and it is amazing!!!
    
    Output:
    .. / .--- ..- ... - / .-. . .- -.. / -.-- --- ..- .-. / -... --- --- -.- / ..--- ----- ----- / -.-- . .- .-. ... / - --- --. . - .... . .-. / .- -. -.. / .. - / .-- .- ... / ... ..- -.-. .... / .- -. / . -.-- . / --- .--. . -. . .-. / ..-. --- .-. / -- . .-.-.- / .. / -.. .. -.. / -. --- - / -.- -. --- .-- #
    I'm joking a little but I guess you understand what I mean ...
    Last edited by bot; 01-05-2018 at 05:33 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Morse Code
    By tosihiro2007 in forum C Programming
    Replies: 4
    Last Post: 03-02-2013, 06:42 PM
  2. Morse Code(Going the other way)
    By lilbo4231 in forum C Programming
    Replies: 21
    Last Post: 06-16-2011, 03:25 AM
  3. morse code convertor
    By neandrake in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2004, 10:53 AM
  4. Morse code conversion
    By viclaster in forum C Programming
    Replies: 6
    Last Post: 12-04-2003, 09:24 PM
  5. About the Morse code Converter
    By Amber_liam in forum C Programming
    Replies: 17
    Last Post: 05-29-2002, 08:35 AM

Tags for this Thread