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"

Member Avatar for iamthwee
#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.

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

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.

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

Take a look at this snippet

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

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 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.