954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem, plz help

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
#include
#include
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"

matias.germany
Newbie Poster
6 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 
#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.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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

matias.germany
Newbie Poster
6 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

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.

Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

xD sorry, first time posting here

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char texto[200];
int x, y;
/*creamos un vector con todos los caracteres del codigo morse*/
    char *caracteres[49]= { "------",".----", "..---", "...--", "....-",".....",
                            "-....","--...", "---..", "----.", ".-", "-...",
                            "-.-.", "-..", ".","..-", "--.","....", "..",
                            ".---", "-.-", ".-..", "--", "-.", "---",  ".--.",
                            "--.-", ".-.", "...", "-", "..-",  "...-", ".--",
                            "-..-", "-.--", "--..","----", "--.--",".-.-.-",
                            "---...", "--..--", "-.-.-.", ".----.", ".-..-.",
                            "..--..", "-.-.--", "-.--.", "-.--.-", " " }; 
    char *ASCIItoMorse(char *entrada)
/*asignamos la posicion del codigo morse a los respectivos caracteres ASCII*/
    {
         entrada=texto;
         if(entrada[x] >= '0' && entrada[x] <= '9')
         return caracteres[entrada[x] - '0'];
         else if(entrada[x] >= 'A' && entrada[x] <= 'Z')
         return caracteres[entrada[x] - 'A'];
         else if(entrada[x]== 'ñ')
         return caracteres[38];
         else if(entrada[x] >= 'a' && entrada[x] <= 'z')
         return caracteres[entrada[x] - 'a'];
         else if(entrada[x] =='.')
         return caracteres[38];
         else if(entrada[x] ==':')
         return caracteres[39];
         else if(entrada[x] ==',')
         return caracteres[40];
         else if(entrada[x] ==';')
         return caracteres[41];
         else if(entrada[x] =='´')
         return caracteres[42];
         else if(entrada[x] =='"')
         return caracteres[43];
         else if(entrada[x] =='?')
         return caracteres[44];
         else if(entrada[x] =='!')
         return caracteres[45];
         else if(entrada[x] =='(')
         return caracteres[46];
         else if(entrada[x] ==')')
         return caracteres[47];
         else if(entrada[x] =='')
         return caracteres[48];         
         }

int main(void)
{
    char *entrada;
    printf("Ingrese texto ASCII que desea traducir a morse:\n\n");
    entrada= gets(texto);
    y= strlen(texto);
    for(x=0;x<=y-1;x++)
    printf("\n%s", ASCIItoMorse(entrada[x]));
    system("pause");
}


Plz need the answer quick...must get it like in 1 hour =S

matias.germany
Newbie Poster
6 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

Take a look at this snippet

Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

Solve it =D
Thanks...but still need help with the morse to ascii plz xD

matias.germany
Newbie Poster
6 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

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:

char *words = {"Apple", "Banana", "Cherry", "Date", "Eggplant", ...
              };  // Apple is word[0], etc.

...

    int ch;
    ch = getchar();    // accept a character
    printf("%s\n"", words[ch-'A']);    // display the word matching the letter
...

Get the character intoch, say you enter 'C'
ch-'A' gives you 2 ('A'=41, 'C'=43) and you displaywords[2] which is "Cherry".

This should help you write your code much shorter and less complex with a little thought.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You