GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Jul-2007, 00:11
pigfromsahara pigfromsahara is offline
New Member
 
Join Date: Jul 2007
Posts: 5
pigfromsahara is on a distinguished road

Convert English phrases to morse code and it‘s reverse process


Use C.
Morse code are as follows:A · ━ Q ━ ━ · ━ 1 · ━ ━ ━ ━
B ━ ··· R · ━ · 2 ·· ━ ━ ━
C ━ · ━ · S ··· 3 ··· ━ ━
D ━ ·· T ━ 4 ····
E · U ··━ 5 ·····
F ·· ━ · V ···━ 6 ━ ····
G ━ ━ · W · ━ ━ 7 ━ ━ ···
H ···· X ━··━ 8 ━ ━ ━··
I ·· Y ━ · ━ ━ 9 ━ ━ ━ ━ ·
J ·━ ━ ━ Z ━ ━ ·· 0 ━ ━ ━ ━ ━
K ━·━ L ·━ ··N ━ · () ━ · ━ ━ · ━
O ━ ━ ━ ━ ━ ··· ━
P ·━ ━· · ·━·━·━
Thank you!!!!
  #2  
Old 10-Jul-2007, 03:21
Kimmo Kimmo is offline
Member
 
Join Date: Mar 2007
Location: Finland
Posts: 229
Kimmo has a spectacular aura aboutKimmo has a spectacular aura about

Re: Convert English phrases to morse code and it‘s reverse process


Huh? So what's the problem?
  #3  
Old 10-Jul-2007, 18:05
pigfromsahara pigfromsahara is offline
New Member
 
Join Date: Jul 2007
Posts: 5
pigfromsahara is on a distinguished road

Re: Convert English phrases to morse code and it‘s reverse process


The problem is I don't know how to programme it.......
  #4  
Old 10-Jul-2007, 21:55
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 452
Howard_L has a spectacular aura aboutHoward_L has a spectacular aura about

Re: Convert English phrases to morse code and it‘s reverse process


Are you interested in learning how?
Have you ...written, compiled and run ...a C program before?
Perhaps you could describe your experience thus far.
  #5  
Old 11-Jul-2007, 03:36
Kimmo Kimmo is offline
Member
 
Join Date: Mar 2007
Location: Finland
Posts: 229
Kimmo has a spectacular aura aboutKimmo has a spectacular aura about

Re: Convert English phrases to morse code and it‘s reverse process


Have you even thought of what is required for such a program? Not getting into the C part, assuming this is an interactive program, you probably need something that

1. Lets user decide which mode the program operates in (character to morse / morse to character)

2. Represents morse shorts, longs and pauses. (I know nothing about morse coding, but I assume there is a pause between codes)

3. Takes input from user.

4. Converts each character or morse code to its respective morse code or character. Character-to-morse should be quite easy. For morse-to-character you could let user enter one code at a time to make it simple.

5. Displays the result.

As Howard suggested, you could also tell if this is some kind of an assignment in a class or if this is just for your own fun. If this is your first C program, then it might indeed be a bit tough.
  #6  
Old 11-Jul-2007, 18:52
pigfromsahara pigfromsahara is offline
New Member
 
Join Date: Jul 2007
Posts: 5
pigfromsahara is on a distinguished road

Re: Convert English phrases to morse code and it‘s reverse process


Really tough work!
I've programmed a Character-to-morse function.But it doesn't work.I've tried from time to time.
  #7  
Old 11-Jul-2007, 19:20
pigfromsahara pigfromsahara is offline
New Member
 
Join Date: Jul 2007
Posts: 5
pigfromsahara is on a distinguished road

Re: Convert English phrases to morse code and it‘s reverse process


CPP / C++ / C Code:
#include<stdio.h>
#include<ctype.h>
main()
{  int i=0,j=0,k=0;int iL;
   char alph[36]="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    int morse[36]={" . ━ "," ━ . . . "," ━ . ━ . "," ━ . . "," . ",
    " . . ━ . ","━ ━ ."," . . . . "," . . "," . ━ ━ ━ ",
    " ━ . ━ "," . ━ . . "," ━ ━ ","━ ."," ━ ━ ━ "," . ━ ━ . ",
    " ━ ━ . ━ "," . ━ . "," ... "," ━ "," . . ━ ",". . . ━",
    " . ━ ━ ","━ . . ━"," ━ . ━ ━ "," ━ ━ . . "," ━ ━ ━ ━ ━  ",
    ". ━ ━ ━ ━ ",". . ━ ━ ━ ",". . . ━ ━ "," . . . .  ",
    " . . . . .  ","━ . . . . "," ━ ━ . . .  ","━ ━ ━ . . ",
    "━ ━ ━ ━ . "};
    char *str1;
   printf("Please enter an English phrase and then press Enter:\n");
    scanf("%s",str1);
      iL=strlen(str1);
      for(k=0;k<=iL;k++)
       str1[k]=toupper(str1[k]);
     for(i=0;i<=iL;i++)
      {if (str1[i]==' ')
       printf("  ");
        else for(j=0;j<=36;j++)
       { if (str1[i]==alph[j])
         printf("%s ",morse[j]);
       }
        }
        getch();
}
Run in Win-TC
Last edited by LuciWiz : 12-Jul-2007 at 00:25. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #8  
Old 11-Jul-2007, 20:32
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 452
Howard_L has a spectacular aura aboutHoward_L has a spectacular aura about

Re: Convert English phrases to morse code and it‘s reverse process


Please DO use the C++ tags found at the top of the message window to enclose your code!

Well you got some ideas of what you'd like to try.
I assume it wouldn't compile... Actually I KNOW it wouldn't but it would be nice for you to include some comments regarding what YOU think problems might be.
I will say that your arrays seem like a good idea.
The first array will work ok and will have a terminating '\0' (null). (right dave?)
But the second will need some changes before it will work. Suppose we start there.
I think you might want a 2 dimensional string array.
What do you think?

Oh, and I'm pretty sure you should be able to google for morse code.
Howard;
  #9  
Old 12-Jul-2007, 00:28
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,242
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Convert English phrases to morse code and it‘s reverse process


You've actually got a very good start.

One thing to consider is that every ASCII character has a value. 'A'=61, 'B'=62, SPACE=32, and so on. Therefore, you can make 1 single array for the Morse Code, and include punctuation, numbers, upper and lower case values. Any ASCII values that don't have an equivalent Morse Code value (like anything lower than SPACE) just make the array entry an empty string ("").

Now, you can use the current character (str1[k] in your code) as an index into the Morse Code array (morse[str1[k]]) and output the string.

Also, read this, this, and this
__________________

Age is unimportant -- except in cheese
  #10  
Old 12-Jul-2007, 03:23
shalombi shalombi is offline
Junior Member
 
Join Date: Feb 2007
Posts: 47
shalombi is on a distinguished road

Re: Convert English phrases to morse code and it‘s reverse process


I have a quick suggestion to make, just looking at your code it seems simple enough, now considering what walt said and what howard said maybe try something like this.

CPP / C++ / C Code:
int input;

int i;

char Morse_Array[6][36] = {

{" . ━ "},
{" ━ . . . "},
//etc...
};

while( (input = getchar()) != EOF){

input -= 65;

for(i = 0; i < 5; i++)
printf("%c", Morse_Array[i][input];

}

I didn't try to compile I'm sure i made some sort of mistake somewhere but the logic of this should work for letters from A-Z with a few if statements or a switch I'm sure this should work quite well for the rest of the letters too.

I am not 100% sure about my initialization of the multidimensional array any senior want to get back to me on that one?

Enjoy

Max
 
 

Recent GIDBlogFlickr uploads of IA pictures by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:47.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.