•
•
•
•
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
![]() |
•
•
Join Date: May 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
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"
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"
#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.
•
•
Join Date: May 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
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
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.
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
•
•
Join Date: May 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
xD sorry, first time posting here
Plz need the answer quick...must get it like in 1 hour =S
#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
"No man's life, liberty, or property is safe while the legislature is in session." ~ Mark Twain
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:
Get the character into ch, say you enter 'C'
This should help you write your code much shorter and less complex with a little thought.
c Syntax (Toggle Plain Text)
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 ...
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- i not understand how i do this problem (C++)
- Problem with newly bought MSI Radeon 9800pro. (Monitors, Displays and Video Cards)
- public pathroom problem (plz help) (Java)
- How can fix the problem? (JavaScript / DHTML / AJAX)
- problem with connection to sql server (ASP.NET)
- Page Cannot Be Displayed/... PLZ HELP? (Windows NT / 2000 / XP / 2003)
- weird problem (Troubleshooting Dead Machines)
- A Small Problem ....plz Help Me Out.... (C)
Other Threads in the C Forum
- Previous Thread: When is a return statement mandatory?
- Next Thread: Error in string reversal using recursive function



Linear Mode