Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to convert morse code to english. struggling
    primarykey
    data
    text
    <p>I'm trying to create a function to read Morse code from one file, convert it to English text, print the converted text to the terminal, and write it to an output file. Here's a rough start...<br> <code>#define TOTAL_MORSE 91</code> <code>#define MORSE_LEN 6</code></p> <pre><code>void morse_to_english(FILE* inputFile, FILE* outputFile, char morseStrings[TOTAL_MORSE][MORSE_LEN]) { int i = 0, compare = 0; char convert[MORSE_LEN] = {'\0'}, *buffer = '\0'; //read in a line of morse string from file // fgets(buffer, //then what? while(((convert[i] = fgetc(inputFile)) != ' ') &amp;&amp; (i &lt; (MORSE_LEN - 1))) { i++; } if (convert[i + 1] == ' ') convert[i + 1] = '\0'; //compare read-in string w/morseStrings for (i = 48, compare = strcmp(convert, morseStrings[i]); //48 is '0' i &lt; (TOTAL_MORSE - 1) &amp;&amp; compare != 0; i++) { compare = strcmp(convert, morseStrings[i]); } printf("%c", (char)i); } </code></pre> <p>I have initialized morseStrings to the morse code. That's my function right now. It does not work, and I'm not really sure what approach to take.</p> <p>My original algorithm plan was something like this:<br> <code>1. Scan Morse code in from file, character by character, until a space is reached</code><br> <code>1.1 save to a temporary buffer (convert)</code><br> <code>2. loop while i &lt; 91 &amp;&amp; compare != 0</code> </p> <pre><code> compare = strcmp(convert, morseString[i]) </code></pre> <p><code>3. if (test ==0) print ("%c", i);</code> <code>4. loop through this until eof</code></p> <p>but.. I can't seem to think of a good way to test if the next char in the file is a space. So this has made it very difficult for me. </p> <p>I got pretty frustrated and googled for ideas, and found a suggestion to use this algorithm</p> <ol> <li>Read a line </li> <li><p>Loop </p> <p>-strchr() for a SPACE or EOL -copy characters before the space to another string<br> -Use strcmp() and loop to find the letter -Test the next character for SPACE.<br> -If so, output another space -Skip to next morse character</p></li> <li><p>List item</p></li> </ol> <p>Endloop</p> <p>But, this loops is kind of confusing. I would use fgets() (I think), but I don't know what to put in the length argument.</p> <p>Anyways, I'm tired and frustrated. I would appreciate any help or insight for this problem. I can provide more code if necessary. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload