Problem, plz help

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2007
Posts: 6
Reputation: matias.germany is an unknown quantity at this point 
Solved Threads: 0
matias.germany matias.germany is offline Offline
Newbie Poster

Problem, plz help

 
0
  #1
May 18th, 2007
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"
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Problem, plz help

 
0
  #2
May 18th, 2007
#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.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 6
Reputation: matias.germany is an unknown quantity at this point 
Solved Threads: 0
matias.germany matias.germany is offline Offline
Newbie Poster

Re: Problem, plz help

 
0
  #3
May 18th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,033
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Problem, plz help

 
0
  #4
May 18th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 6
Reputation: matias.germany is an unknown quantity at this point 
Solved Threads: 0
matias.germany matias.germany is offline Offline
Newbie Poster

Re: Problem, plz help

 
0
  #5
May 18th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,033
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Problem, plz help

 
0
  #6
May 18th, 2007
Take a look at this snippet
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 6
Reputation: matias.germany is an unknown quantity at this point 
Solved Threads: 0
matias.germany matias.germany is offline Offline
Newbie Poster

Re: Problem, plz help

 
0
  #7
May 18th, 2007
Solve it =D
Thanks...but still need help with the morse to ascii plz xD
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Problem, plz help

 
0
  #8
May 19th, 2007
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.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC