943,987 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1363
  • C RSS
May 18th, 2007
0

Problem, plz help

Expand Post »
Hi, im starting here with C and im stuck with a little problem...can someone helpme plz.

The program is a ASCII to morse converter


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char text[200];
int x, y;
char *characters[49]= { "------",".----", "..---", "...--", "....-",".....",
"-....","--...", "---..", "----.", ".-", "-...",
"-.-.", "-..", ".","..-", "--.","....", "..",
".---", "-.-", ".-..", "--", "-.", "---", ".--.",
"--.-", ".-.", "...", "-", "..-", "...-", ".--",
"-..-", "-.--", "--..","----", "--.--",".-.-.-",
"---...", "--..--", "-.-.-.", ".----.", ".-..-.",
"..--..", "-.-.--", "-.--.", "-.--.-", " " };
char *ASCIItoMorse(char *enty)
{
entry=text;
if(entry[x] >= '0' && entry[x] <= '9')
return characters[entry[x] - '0'];
else if(enty[x] >= 'A' && entry[x] <= 'Z')
return characters[entry[x] - 'A'];
else if(entry[x]== 'ñ')
return characters[38];
else if(entry[x] >= 'a' && entry[x] <= 'z')
return characters[entry[x] - 'a'];
else if(entry[x] =='.')
return characters[39];
else if(entry[x] ==':')
return characters[40];
else if(entry[x] ==',')
return characters[41];
else if(entry[x] ==';')
return characters[42];
else if(entry[x] =='´')
return characters[43];
else if(entry[x] =='"')
return characters[44];
else if(entry[x] =='?')
return characters[45];
else if(entry[x] =='!')
return characters[46];
else if(entrada[x] =='(')
return characters[47];
else if(entry[x] ==')')
return characters[48];
else if(entry[x] =='')
return characters[49];
}

int main(void)
{
char *entry;
printf("Type your ASCII text:\n\n");
entrada= gets(text);
y= strlen(text);
for(x=0;x<=y-1;x++)
printf("%s\n", ASCIItoMorse(entrada[x]));
system("pause");
}

The error I get is:
[Warning] passing arg 1 of `ASCIItoMorse' makes pointer from integer without a cast

thanks for your time

PD: Any idea on how to do a MorsetoASCII plz help and to solve the spanish characters problems like "Ñ" and "CH"
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
matias.germany is offline Offline
6 posts
since May 2007
May 18th, 2007
0

Re: Problem, plz help

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char text[200];
int x, y;
char *characters[49] = { "------", ".----", "..---", "...--", "....-", ".....",
                         "-....", "--...", "---..", "----.", ".-", "-...",
                         "-.-.", "-..", ".", "..-", "--.", "....", "..",
                         ".---", "-.-", ".-..", "--", "-.", "---", ".--.",
                         "--.-", ".-.", "...", "-", "..-", "...-", ".--",
                         "-..-", "-.--", "--..", "----", "--.--", ".-.-.-",
                         "---...", "--..--", "-.-.-.", ".----.", ".-..-.",
                         "..--..", "-.-.--", "-.--.", "-.--.-", " " };
char *ASCIItoMorse ( char *enty )
{
   entry = text;
   if ( entry[x] >= '0' && entry[x] <= '9' )
      return characters[entry[x] - '0'];
   else if ( enty[x] >= 'A' && entry[x] <= 'Z' )
      return characters[entry[x] - 'A'];
   else if ( entry[x] == 'ñ' )
      return characters[38];
   else if ( entry[x] >= 'a' && entry[x] <= 'z' )
      return characters[entry[x] - 'a'];
   else if ( entry[x] == '.' )
      return characters[39];
   else if ( entry[x] == ':' )
      return characters[40];
   else if ( entry[x] == ',' )
      return characters[41];
   else if ( entry[x] == ';' )
      return characters[42];
   else if ( entry[x] == '´' )
      return characters[43];
   else if ( entry[x] == '"' )
      return characters[44];
   else if ( entry[x] == '?' )
      return characters[45];
   else if ( entry[x] == '!' )
      return characters[46];
   else if ( entrada[x] == '(' )
      return characters[47];
   else if ( entry[x] == ')' )
      return characters[48];
   else if ( entry[x] == '' )
      return characters[49];
}

int main ( void )
{
   char *entry;
   printf ( "Type your ASCII text:\n\n" );
   entrada = gets ( text );
   y = strlen ( text );
   for ( x = 0; x <= y - 1; x++ )
      printf ( "%s\n", ASCIItoMorse ( entrada[x] ) );
   system ( "pause" );
}

>gets and "system pause"
These should be avoided, for starters... If you are unsure about input in c look here for ideas.
Last edited by iamthwee; May 18th, 2007 at 6:34 pm.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
May 18th, 2007
0

Re: Problem, plz help

well, still having problems with it, but I realice that i am over the maximum, it has to be

return characters[38];
else if(entry[x] ==':')
return characters[39];
else if(entry[x] ==',')
return characters[40];
else if(entry[x] ==';')
return characters[41];
else if(entry[x] =='´')
return characters[42];
else if(entry[x] =='"')
return characters[43];
else if(entry[x] =='?')
return characters[44];
else if(entry[x] =='!')
return characters[45];
else if(entrada[x] =='(')
return characters[46];
else if(entry[x] ==')')
return characters[47];
else if(entry[x] =='')
return characters[48];

because i wasn't counting the 0
Reputation Points: 10
Solved Threads: 0
Newbie Poster
matias.germany is offline Offline
6 posts
since May 2007
May 18th, 2007
0

Re: Problem, plz help

Do you see how nice is the code that iamthwee posted for you?. With nice format and easy to read indenting?.
iamthwee is not the only one that can do that. You can do it too.
Learn how to tag by clicking here.
Last edited by Aia; May 18th, 2007 at 9:11 pm.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
May 18th, 2007
0

Re: Problem, plz help

xD sorry, first time posting here

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. char texto[200];
  5. int x, y;
  6. /*creamos un vector con todos los caracteres del codigo morse*/
  7. char *caracteres[49]= { "------",".----", "..---", "...--", "....-",".....",
  8. "-....","--...", "---..", "----.", ".-", "-...",
  9. "-.-.", "-..", ".","..-", "--.","....", "..",
  10. ".---", "-.-", ".-..", "--", "-.", "---", ".--.",
  11. "--.-", ".-.", "...", "-", "..-", "...-", ".--",
  12. "-..-", "-.--", "--..","----", "--.--",".-.-.-",
  13. "---...", "--..--", "-.-.-.", ".----.", ".-..-.",
  14. "..--..", "-.-.--", "-.--.", "-.--.-", " " };
  15. char *ASCIItoMorse(char *entrada)
  16. /*asignamos la posicion del codigo morse a los respectivos caracteres ASCII*/
  17. {
  18. entrada=texto;
  19. if(entrada[x] >= '0' && entrada[x] <= '9')
  20. return caracteres[entrada[x] - '0'];
  21. else if(entrada[x] >= 'A' && entrada[x] <= 'Z')
  22. return caracteres[entrada[x] - 'A'];
  23. else if(entrada[x]== 'ñ')
  24. return caracteres[38];
  25. else if(entrada[x] >= 'a' && entrada[x] <= 'z')
  26. return caracteres[entrada[x] - 'a'];
  27. else if(entrada[x] =='.')
  28. return caracteres[38];
  29. else if(entrada[x] ==':')
  30. return caracteres[39];
  31. else if(entrada[x] ==',')
  32. return caracteres[40];
  33. else if(entrada[x] ==';')
  34. return caracteres[41];
  35. else if(entrada[x] =='´')
  36. return caracteres[42];
  37. else if(entrada[x] =='"')
  38. return caracteres[43];
  39. else if(entrada[x] =='?')
  40. return caracteres[44];
  41. else if(entrada[x] =='!')
  42. return caracteres[45];
  43. else if(entrada[x] =='(')
  44. return caracteres[46];
  45. else if(entrada[x] ==')')
  46. return caracteres[47];
  47. else if(entrada[x] =='')
  48. return caracteres[48];
  49. }
  50.  
  51. int main(void)
  52. {
  53. char *entrada;
  54. printf("Ingrese texto ASCII que desea traducir a morse:\n\n");
  55. entrada= gets(texto);
  56. y= strlen(texto);
  57. for(x=0;x<=y-1;x++)
  58. printf("\n%s", ASCIItoMorse(entrada[x]));
  59. system("pause");
  60. }

Plz need the answer quick...must get it like in 1 hour =S
Reputation Points: 10
Solved Threads: 0
Newbie Poster
matias.germany is offline Offline
6 posts
since May 2007
May 18th, 2007
0

Re: Problem, plz help

Take a look at this snippet
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
May 18th, 2007
0

Re: Problem, plz help

Solve it =D
Thanks...but still need help with the morse to ascii plz xD
Reputation Points: 10
Solved Threads: 0
Newbie Poster
matias.germany is offline Offline
6 posts
since May 2007
May 19th, 2007
0

Re: Problem, plz help

First thing to understand is that each character (letters, numbers, punctuation) all have a specific value. Therefore, the character's value can be used as an index into an array. For example:
  1. char *words = {"Apple", "Banana", "Cherry", "Date", "Eggplant", ...
  2. }; // Apple is word[0], etc.
  3.  
  4. ...
  5.  
  6. int ch;
  7. ch = getchar(); // accept a character
  8. printf("%s\n"", words[ch-'A']); // display the word matching the letter
  9. ...
  10.  
Get the character into ch, say you enter 'C'
ch-'A' gives you 2 ('A'=41, 'C'=43) and you display words[2] which is "Cherry".

This should help you write your code much shorter and less complex with a little thought.
Moderator
Reputation Points: 3278
Solved Threads: 894
Posting Sage
WaltP is offline Offline
7,747 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: When is a return statement mandatory?
Next Thread in C Forum Timeline: Error in string reversal using recursive function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC