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 21-Dec-2005, 09:46
hello2001 hello2001 is offline
New Member
 
Join Date: Dec 2005
Posts: 7
hello2001 is on a distinguished road

Microsoft Visual Studio .NET Morse Code


hi,

CPP / C++ / C Code:
char MorseData[] = “.- -...-.-.-.. . ..-.--. ...... .----.- .-..-- -. --- .--.--.-.-. ... - ..- ...-.-- -..--.----..”

i have four space for each morse code for e.g. A is ".- "

The program must use one of the character strings above and should include a function to accept a letter and return the equivalent Morse code for the letter.

i need to use pointers to get each morse all the morse code will be same size four space..


i try to use this functions :

CPP / C++ / C Code:
strcpy(string1, string2) the prototypes are held in string.h

i try to converted into its integer ASCI code by a simple arithmetic operation.

but still i can't it to work.. please help with this i real need help..

thank's
Last edited by hello2001 : 21-Dec-2005 at 09:57. Reason: Please insert your C code between [c] & [/c] tags
  #2  
Old 21-Dec-2005, 10:02
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 961
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: Microsoft Visual Studio .NET Morse Code


Hi, hello2001.

I tried to edit your post (to use code tags) and I think you were editing it at the same time too.
In case there is anything missing from your post, it might be my fault. Please let me know if that happened.

Best regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #3  
Old 21-Dec-2005, 11:14
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,793
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Microsoft Visual Studio .NET Morse Code


Quote:
Originally Posted by hello2001
hi,

CPP / C++ / C Code:
char MorseData[] = “.- -...-.-.-.. . ..-.--. ...... .----.- .-..-- -. --- .--.--.-.-. ... - ..- ...-.-- -..--.----..”

i have four space for each morse code for e.g. A is ".- "

First of all, your array is incorrect. Here is one that has the proper number of characters in the proper order:

CPP / C++ / C Code:
  char MorseData[] = ".-  -...-.-.-.. .   ..-."\
                     "--. ......  .----.- .-.."\
                     "--  -.  --- .--.--.-.-. "\
                     "... -   ..- ...-.-- -..-"\
                     "-.----.. ";

Note that by breaking it up into smaller groups, it is easier to troubleshoot (easier for me, that is).


Quote:
Originally Posted by hello2001
i try to use this functions :

CPP / C++ / C Code:
strcpy(string1, string2) the prototypes are held in string.h

In order to use strcpy, string2 must be a zero-terminated sequence of characters. There is only one string, and each 4-char sequence is not zero-terminated, so I don't see how strcpy is useful with the array that you gave.

Quote:
Originally Posted by hello2001
i try to converted into its integer ASCI code by a simple arithmetic operation.

That would have been my choice. How did you try it?

Assuming array index 0 is for the first morse dit for 'A', then array index 4 will be for the first morse dah for 'B', array index 8 will be for 'C', etc.

So for a given character from 'A' to 'Z', what will be the index?

I got (character - 'A') * 4.

You can copy the four characters starting into that index into your output string, one at a time. Don't forget to put an extra '0' at the end if you want to make a "string" out of the answer. Maybe you want to eliminate trailing space characters?

For example is 'A' represented by
Code:
".= "
or is it
Code:
".-"
?

Regards,

Dave
  #4  
Old 22-Dec-2005, 07:55
hello2001 hello2001 is offline
New Member
 
Join Date: Dec 2005
Posts: 7
hello2001 is on a distinguished road

Re: Microsoft Visual Studio .NET Morse Code


i try to use pointers to get each morse.. i try to convert letters into ascii, but still i can't do it..

i have the morse code.. i went user to type in letter and program should returns morse code..

regards
maj
  #5  
Old 22-Dec-2005, 08:45
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,793
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Microsoft Visual Studio .NET Morse Code


Quote:
Originally Posted by hello2001
i try to use pointers to get each morse.. i try to convert letters into ascii, but still i can't do it..

i have the morse code.. i went user to type in letter and program should returns morse code..

regards
maj

I showed you a correct array of Morse characters ( correct according to your description in your original post). I showed how to calculate the location of any Morse character in the array for ASCII chars 'A' through 'Z'. Did you try to implement any of it?

In your first post you said that

"i try to converted into its integer ASCI code by a simple arithmetic operation. but still i can't it to work."

Show us what you tried. If someone wants to help you, then it would definitely help if he/she could know what you know and what you don't know. In other words, what do you know about pointers and arrays before you ran into this problem? For all we know, your program was correct but you just had a bad array. Ask specific questions and show your work on the problem so far.

Regards,

Dave
  #6  
Old 22-Dec-2005, 09:26
hello2001 hello2001 is offline
New Member
 
Join Date: Dec 2005
Posts: 7
hello2001 is on a distinguished road

Re: Microsoft Visual Studio .NET Morse Code


CPP / C++ / C Code:
#include "stdafx.h"
using namespace std;

  char MorseData[] = ".-  -...-.-.-.. .   ..-."\
                     "--. ......  .----.- .-.."\
                     "--  -.  --- .--.--.-.-. "\
                     "... -   ..- ...-.-- -..-"\
                     "-.----.. ";

int main()
{
char ascii[27];
	char temp = '\0';
	int cntr = 0;

	ascii[0] = 'a';
	for(cntr = 1; cntr < 26; cntr++) {
		temp = ascii[cntr - 1];
		temp++;
		ascii[cntr] = temp;
	}

	for(cntr = 0; cntr < 26; cntr++) {
		cout << "Position " << cntr << " = " << ascii[cntr] << endl;
	}

	return 0;

}

from ascii to letters but i dont how to assign them to morse code
Last edited by LuciWiz : 22-Dec-2005 at 09:38. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #7  
Old 22-Dec-2005, 09:57
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,793
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Microsoft Visual Studio .NET Morse Code


Quote:
Originally Posted by hello2001

from ascii to letters but i dont how to assign them to morse code

You are looking for a way to locate the Morse dits and dahs for an ascii char (looking for the position of the first Morse element corresponding to the ascii char). Once you know where to start, then you just copy the following elements to your output string.

How about what I suggested previously (but now, I see that you are using ascii 'a' through 'z', not 'A' through 'Z)'?

Here is how you can get the first Morse dit or dah for each ascii character:
CPP / C++ / C Code:
int index;
char asciichar;
.
.
	for (asciichar = 'a'; asciichar <= 'z'; asciichar++) {
			position = (asciichar - 'a') * 4;
			cout << asciichar << ": " << MorseData[position] << endl;
	}


Now, if you can get the first Morse dit/dah, you can copy the successive Morse elements into your output string, right?

Regards,

Dave
  #8  
Old 23-Dec-2005, 09:59
hello2001 hello2001 is offline
New Member
 
Join Date: Dec 2005
Posts: 7
hello2001 is on a distinguished road

Re: Microsoft Visual Studio .NET Morse Code


CPP / C++ / C Code:
int main()

{
char ascii[27];
	char temp = '\0';
	int cntr = 0;

	ascii[0] = 'a';
	for(cntr = 1; cntr < 26; cntr++) {
		temp = ascii[cntr - 1];
		temp++;
		ascii[cntr] = temp;
	}

	for(cntr = 0; cntr < 26; cntr++) {
		cout << "Position " << cntr << " = " << ascii[cntr] << endl;
	}

to show all the letters a-z


int position;
	int index;
	char asciichar;

	for (asciichar = 'a'; asciichar <= 'z'; asciichar++) {
			position = (asciichar - 'a') * 4;			
			cout << asciichar << ": " << MorseData[position] << endl;
	}

is to locate the firt position of morse code.. which is locating.. i need to use index to display other morse code dit/dah..

also i went the user to type in the letter and then display the morse code..


thanks for help

best Regards
Last edited by LuciWiz : 24-Dec-2005 at 10:32. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #9  
Old 24-Dec-2005, 10:17
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,793
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Microsoft Visual Studio .NET Morse Code


Quote:
Originally Posted by hello2001
is to locate the firt position of morse code.. which is locating.. i need to use index to display other morse code dit/dah..

also i went the user to type in the letter and then display the morse code..

First I will give you a lecture (If you want to skip that and go directly to the example, it's OK, and I concede that the statments in the lecture are only an opinion. YMMV --- Your Mileage May Vary)

[/begin lecture]

Here's the thing: in order to create interesting programs in C (or any other language), you usually have to know something about the language and its library funcitons.

If I give you an index value for a specific char in an array, and you can't tell me how to retrieve the values of that char and the following three, then you really need to learn something about the language, specifically arrays. Since you referred to "pointers" in your first post, you might have to learn something about pointers and their relationship to arrays.

If you don't know how to get user input into a variable, then I suggest that you need to learn something about standard library I/O functions and make sure that you can apply them.

For programs of this nature, I would recommend that you make the ASCII-to-Morse translation scheme be a separate function, but maybe you don't need to do this for your first pass at making it work.

[/end lecture]



On the other hand, sometimes when we know a little about the language and reading a book seems kind of boring and way too abstract, one way to learn is to find a seemingly simple problem that is interesting to us and dig into the language far enough to solve the problem. Fair enough.

Here is an example of obtaining user input from the keyboard. I have indicated the place where you could put the translation procedure.

Now, this isn't the first program that I would write as an example for someone who didn't have any exposure to the language at all, but you are far enough along to know about arrays and at least have been exposed to some terminology about pointers. This little example does show how to use standard C library functions to obtain and display user input, using an array of chars.

"But," you say, "I wanted C++, not C." Well here's a clue: this is a perfectly valid guaranteed Standard C++ program as well as a perfectly valid guaranteed Standard C program. If you want to use getline() and cout rather than fgets() and printf() so that it is "real" C++, then I say: go for it! You will still be indexing through an array of chars, and that's the key.

If you have any problems, then please post the entire program that you are trying.

1. Tell us what you did (what input did you give it).

2. Tell us what the output was (compiler errors?, compiled OK but bombed when executed? executed but gave wrong answer? or what???)

3. Tell us what you don't understand about what you expected to get and what you got.

It wouldn't hurt to mention the compiler and operating system you are using. Sometimes it makes a difference for people trying to help.

CPP / C++ / C Code:
#include <stdio.h>

int main()
{
  int i;
  char buffer[10];

  printf("Enter a line of characters a-z (ctrl-c or EOF to exit the program):\n");
  printf(":  ");
  while (fgets(buffer, sizeof(buffer), stdin)) {
    printf("Here are the contents of the buffer <%s>\n\n", buffer);
    printf("Here are the contents, a character at a time:\n");
    for (i = 0; buffer[i] != 0; i++) {
      printf("buffer[%d] = %c:  ", i, buffer[i]);
      if ((buffer[i] < 'a') || (buffer[i] > 'z')) {
        printf("Invalid character; must be a through z\n");
      }
      else { 
        printf("Here's where you translate the ASCII character to Morse\n");
      }
    }
    printf("Enter a line of characters a-z (ctrl-c or EOF to exit the program):\n");
    printf(":  ");

  }
  return 0;
}

Now, if you just want a program to translate ASCII to Morse, you can probably find examples on the web for all kinds of interfaces. If you are using this as a vehicle and motivation for learning C, you have to put some effort into learning C.


Regards,

Dave
  #10  
Old 12-Jan-2006, 06:17
hello2001 hello2001 is offline
New Member
 
Join Date: Dec 2005
Posts: 7
hello2001 is on a distinguished road

Re: Microsoft Visual Studio .NET Morse Code


i try to show all the morse from index but i coundn't show it..
 
 

Recent GIDBlogWriting a book 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Introduction to .NET LuciWiz .NET Forum 5 09-Aug-2007 05:53
Visual Studio .NET 2003 problem in executing C source files Debugger1 C Programming Language 14 04-Jun-2005 03:51
What is "Ambigious symbol" ??*( a compilation error) small_ticket C++ Forum 2 07-Jan-2005 22:10
Problem with int mixed with char,... leitz C++ Forum 17 07-Dec-2004 21:56
Help! Some basal questions about MFC xutingnjupt MS Visual C++ / MFC Forum 1 05-Dec-2004 04:38

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

All times are GMT -6. The time now is 11:29.


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