User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 426,200 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,853 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 744 | Replies: 7
Reply
Join Date: May 2007
Posts: 6
Reputation: matias.germany is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
matias.germany matias.germany is offline Offline
Newbie Poster

Help Problem, plz help

  #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"
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,782
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 319
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: Problem, plz help

  #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 5:34 pm.
I'm not a programmer. My attitude starts with ignorance, holds steady at conversation, and ends with a trip to the hospital. Get used to it.
Reply With Quote  
Join Date: May 2007
Posts: 6
Reputation: matias.germany is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
matias.germany matias.germany is offline Offline
Newbie Poster

Re: Problem, plz help

  #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  
Join Date: Dec 2006
Posts: 1,419
Reputation: Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all 
Rep Power: 10
Solved Threads: 98
Aia's Avatar
Aia Aia is offline Offline
Nearly a Posting Virtuoso

Re: Problem, plz help

  #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 8:11 pm.
"No man's life, liberty, or property is safe while the legislature is in session." ~ Mark Twain
Reply With Quote  
Join Date: May 2007
Posts: 6
Reputation: matias.germany is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
matias.germany matias.germany is offline Offline
Newbie Poster

Re: Problem, plz help

  #5  
May 18th, 2007
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
Reply With Quote  
Join Date: Dec 2006
Posts: 1,419
Reputation: Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all 
Rep Power: 10
Solved Threads: 98
Aia's Avatar
Aia Aia is offline Offline
Nearly a Posting Virtuoso

Re: Problem, plz help

  #6  
May 18th, 2007
Take a look at this snippet
"No man's life, liberty, or property is safe while the legislature is in session." ~ Mark Twain
Reply With Quote  
Join Date: May 2007
Posts: 6
Reputation: matias.germany is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
matias.germany matias.germany is offline Offline
Newbie Poster

Re: Problem, plz help

  #7  
May 18th, 2007
Solve it =D
Thanks...but still need help with the morse to ascii plz xD
Reply With Quote  
Join Date: May 2006
Posts: 2,723
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 15
Solved Threads: 222
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: Problem, plz help

  #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.
Age is unimportant -- except in cheese
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 7:04 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC