Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URGENT Morse Code - Code errors I need help, program in previous note.

Status
Not open for further replies.

Row

Technical User
Feb 21, 2000
4
0
0
US
I have gotten it down to three error message. I am getting the following message when I build:<br>
<br>
(109) : error c2099: intializer is not a constant<br>
(110) : error c2099: intializer is not a constant<br>
(118) : error c2059: syntax error : 'while'<br>
<br>
Could you please help me with this I have been working on this program forever and still cannot get it to run. And after I get it to run I have to redo the main and work it a second way. My time is short.<br>
<br>
Thanks.<br>

 
Hi i copyed your code and the compile errors i got were in the function convert to alpha. From what i saw you declare four char pointers, char *in;char *out;char *pszCurrIn;char *pszCurrOut;<br>
The errors i received were on these lines of code, i think what you did is you declared these two pointers equal to each other without putting address in them<br>
pszCurrIn = in;<br>
pszCurrOut = out;<br>
<br>
this also gave an error<br>
i = 0;<br>
<br>
also this while loop while(i &lt; (size - 1) ¦¦ !blDone)<br>
you may have a logic error in the !blDone<br>
try commenting the line 1 = 0 out and put that in you variable statement<br>
The other thing that i noticied in your two first global variables<br>
char *MorseDigits[10]<br>
char *MorseAlphabet[26]<br>
You declared an array of pointers but in c that does not make room for the strings. as of right now you are &quot;stepping&quot; on other memory and you will get really weird errors. The best way is to declare char MorseDigits[10] as a normal array. This i think will solve some of your problems. I had the same problem in my last project. hope i helped, you can reach me at <A HREF="mailto:tmoses@iname.com">tmoses@iname.com</A> if you want.
 
Other errors are:<br>
<br>
<br>
The function prototype:<br>
int ConvertToAlpha(char *in, char *out, int size);<br>
<br>
Doesn't match the function:<br>
<br>
int ConvertToAlpha();char *in; /* Pointer to input buffer (contains alpha, digit, spaces) */<br>
char *out; /* Pointer to output buffer (will contain morse code) */<br>
int size; /* Size of the output buffer */<br>
<br>
Also, the enclosing braces {} of the function body appear to be missing.....<br>
<br>
Another error:<br>
<br>
/* Signify we found the token match.*/<br>
blFound = 0;<br>
<br>
should probably read (based on other code samples):<br>
<br>
/* Signify we found a token match.*/<br>
blFound = 1;<br>
<br>
This is a VERY good argument for using #defines:<br>
<br>
#define TOKEN_FOUND 1<br>
#define TOKEN_NOT_FOUND 0<br>
<br>
And writing:<br>
<br>
/* Signify we found a token match.*/<br>
blFound = TOKEN_FOUND;<br>
<br>
This makes these silly typos much easier to catch!<br>
<br>
Another error:<br>
<br>
/* Is this an alphabetical morse code token?*/<br>
for(iIndex = 0; iIndex &lt; 26 && !blFound; iIndex++)<br>
{<br>
--&gt; if(!strncmp(*pszCurrIn, MorseAlphabet[iIndex],<br>
strlen(MorseAlphabet[iIndex])))<br>
<br>
Take the * out..... You want to pass the address of the string to strncmp NOT the value it is pointing to!<br>
<br>
I did actually finally get your code to compile after fixing these and other errors, but it would only decode the first character of your morse string. Another problem is that your code has lost it's formatting by being posted on a Web page in HTML and has lost its readability... (Spaces have been truciated)<br>
Anyways.... I hope this helps you out. The best way to learn coding is to debug & debug & debug & debug & debug.... ;)<br>
<br>
<br>
<p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href= Page</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top