-2

I am writing a program to take a users input and turn it into Morsecode as an output. I have a few errors that are popping up in my program. I am unsure as what i should do or try from here. I have the conversions done from the alphabet to morsecode. I switched from using letters to the binary input because it was not liking the letters.

I was trying to scan for the phrase and use a string to store it in. Then using a for loop to increment string[i] up 1 each loop so it would check each address of the string. each time the loop would run it would store the string value in a INT A then go check in the if= else - if statements for a match and return and print the value.

# include <stdio.h>

void checkphrase ( char string[], int *px)

{
int i;
printf(" PHRASE ENTERED IS\n %s\n" , string[i]);
/* Prints the Phrase entered */

/* Start for loop to compare letters to the morse code equivalent */

for( i=0; i <= 30; i++) 
    {
        px = string[i];     // pointer points the string value
        a = px;         // int a is assgined the value of px to be     compared to morsecode
        findmorse()     // calls function to compare morsecode
    }
return 0;               // returns to main 

}

void findmorse (int a)
/* originoally had a = the aphpabet but converted to binary */
{
if (a == 01000001)
    Printf(" • —  \n");
else if (a == 01000010)
    Printf(" — • • •  \n");
else if (a == 01000011)
    Printf(" — • — •  \n");
else if (a == 01000100)
    Printf(" — • •  \n");
else if (a == 01000101)
    Printf(" •   \n");
else if (a == 01000110)
    Printf(" • • — • \n");
else if (a == 01000111)
    Printf(" — — •  \n");
else if (a == 01001000)
    Printf(" • • • • \n");
else if (a == 01001001)
    Printf(" • •  \n");
else if (a == 01001010)
    Printf(" • — — —  \n");
else if (a == 01001011)
    Printf(" — • —  \n");
else if (a == 01001100)
    Printf(" • — • • \n");
else if (a == 01001101)
    Printf(" — —  \n");
else if (a == 01001110)
    Printf(" — •  \n");
else if (a == 01001111)
    Printf(" — — —  \n");
else if (a == 01010000)
    Printf(" • — — •  \n");
else if (a == 01010001)
    Printf(" — — • —  \n");
else if (a == 01010010)
    Printf(" • — •  \n");
else if (a == 01010011)
    Printf(" • • •  \n");
else if (a == 01010100)
    Printf(" —  \n");
else if (a == 01010101)
    Printf(" • • —  \n");
else if (a == 01010110)
    Printf(" • • • —  \n");
else if (a == 01010111)
    Printf(" • --  \n");
else if (a == 01011000)
    Printf(" -• • -  \n");  
else if (a == 01011001)
    Printf(" -• --  \n");
else if (a == 01011010)
    Printf(" --• •  \n");

/* Numbers */

else if (a == 1)
    Printf(" · – – – –  \n");
else if (a == 2)
    Printf(" · · – – –  \n");
else if (a == 3)
    Printf(" · · · – –  \n");
else if (a == 4)
    Printf(" · · · · –  \n");
else if (a == 5)
    Printf(" · · · · · \n");
else if (a == 6)
    Printf(" – · · · ·  \n");
else if (a == 7)
    Printf(" – – · · ·  \n");
else if (a == 8)
    Printf(" – – – · · \n");    
else if (a == 9)
    Printf(" – – – – ·  \n");
else if (a == 0)
    Printf(" – – – – –  \n");

/* return to check phrase */

return string[};
}

int main()                          // main function

{
printf("PLEASE ENTER A PHRASE UNDER 30 CHARACTERS\n");
scanf(" %s " , string[]);
checkphrase ()                      // takes string to the    checkphrase function
return 0;
}
Pwoods
  • 105
  • 2
  • 4
  • 15
  • 2
    What is your question? – Jonathan Wood Apr 18 '13 at 19:47
  • First problem 01001100 means the decimal number 1,001,100. I think you want a binary literary, which isnt straightforward http://stackoverflow.com/questions/2611764/can-i-use-a-binary-literal-in-c-or-c – gbtimmon Apr 18 '13 at 19:51
  • when running its not stepping through the functions as i thought it should, is there a problem with the way i had set it up? or with my arguments in the functions? – Pwoods Apr 18 '13 at 19:51
  • i wanted the pointer to point at the string values individually then check them in the Morse-code conversion in letter not in binary but when i was trying that it didn't seem to like the letters. – Pwoods Apr 18 '13 at 19:53
  • The letters themselves should work perfectly if making comparisons with char literals (like 'a', 'b', etc.). In any case, you should use a switch for this situation rather than a bunch of if-elses. – Guillermo René Ramírez Apr 18 '13 at 19:55
  • this code wont even compile, when calling functions you are passing no arguments while you have defined them to take some: `checkphrase ()` vs `void checkphrase ( char string[], int *px)`, same thing for `findmorse`. Also you are missing the semicolons after the closing bracket of a function call. You didn't run you program yet since there is no binary at all. – A4L Apr 18 '13 at 19:56
  • 1
    @gbtimmon 01001100 means decimal 262720 (octal 1001100) in C, as 0 denotes octal literal. You're correct that binary literals aren't straightforward (without compiler vendor extensions). – mrb Apr 18 '13 at 20:09

1 Answers1

0

findmorse requires an argument.

void findmorse (int a)

In checkphrase, you call it without one.

        px = string[i];     // pointer points the string value
        a = px;         // int a is assgined the value of px to be     compared to morsecode
        findmorse()     // calls function to compare morsecode

In main you've got weird brackets in your function argument.

    scanf(" %s " , string[]);

And then checkphrase might need some of the arguments it's declared to receive AND a terminating semicolon (;) for the expression statement.

checkphrase ()                      // takes string to the    checkphrase function

You need to enable (or heed) the compiler warnings (gcc -Wall -Wextra).

luser droog
  • 18,988
  • 3
  • 53
  • 105