| | |
Problem, plz help
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2007
Posts: 6
Reputation:
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 6:34 pm.
*Voted best profile in the world*
•
•
Join Date: May 2007
Posts: 6
Reputation:
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 9:11 pm.
•
•
Join Date: May 2007
Posts: 6
Reputation:
Solved Threads: 0
xD sorry, first time posting here
Plz need the answer quick...must get it like in 1 hour =S
C Syntax (Toggle Plain Text)
#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
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.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- 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)
- 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
| Thread Tools | Search this Thread |
adobe api array arrays binarysearch calculate char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators initialization iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list lists locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql odf open opensource openwebfoundation owf pattern pdf performance pointer pointers posix power probleminc program programming pyramidusingturboccodes read recursion recv recvblocked repetition research scanf scheduling scripting segmentationfault send shape socketprograming socketprogramming stack standard string suggestions systemcall test testautomation unix urboc user voidmain() wab win32api windows.h






