I am a total newbie at programming I understand the fundamentals of how it all works but i don't know a single language. I want to write a program that will convert a sentence into numbers. What I mean is take each letter and output the numerical equivalent. So like
I need help = 07 00 14 05 05 04 00 08 05 12 16
which language should i be looking into learning to write this program by the end of it. Does anyone know of where i can find sample code that I can edit to fit my needs.
Any help or suggestions would be very helpful. I do apologies if I posted in the wrong place or is this is something that has already been answered.
Which Language to use
Started by gbkilpatrick, May 18 2010 07:14 PM
7 replies to this topic
#1
Posted 18 May 2010 - 07:14 PM
|
|
|
#2
Posted 18 May 2010 - 09:11 PM
I would suggest C for this task. And it's quite simple actually. Maybe this works for you
If i understood well. By 'numeral equivalent', you mean ascii code or something custom?
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
char *s = "I need help";
int i;
for (i = 0; i < strlen(s); i++) {
printf("%d ", s[i]);
}
printf("\n");
return 0;
}
If i understood well. By 'numeral equivalent', you mean ascii code or something custom?
// d-_-b+
#3
Posted 18 May 2010 - 11:48 PM
WTF?! 12 lines of code for such an obvious task?
def translate(s: String) = s.toList map (_ toInt) mkString " "Result:
scala> translate("I need help")
res0: String = 73 32 110 101 101 100 32 104 101 108 112
Remember: always use the right tool for the job. C is the worst one for text processing.
#4
Posted 19 May 2010 - 04:45 AM
Thanks guys for you help. I little more info i guess may help but what i mean by numerical equivalent is each letters gets translated to it's count is the alphabet like a =01 b =02 c =03 and so on and spaces and 00.
#5
Posted 19 May 2010 - 11:10 AM
val charMap = (Map() ++ ('a' to 'z' zip (1 to 26)) ++ ('A' to 'Z' zip (1 to 26))).orElse[Char, Int] {case _ => 0}
def translate(s: String) = s.toList map charMap mkString " "
scala> translate("I need help")
res10: String = 9 0 14 5 5 4 0 8 5 12 16
Who can do it in C in 2 lines?
Edited by JCoder, 20 May 2010 - 02:37 AM.
#6
Posted 19 May 2010 - 11:56 AM
#7
Posted 19 May 2010 - 12:35 PM
Thank you all so much for your help I will let you know how it works out. Also any suggestions as to which development environment I should use right now I have Microsoft Visual Studio 2008 & 2010 professional editions. But if there is a better one for a complete newbie it would be helpful to me thank you once again
#8
Posted 20 May 2010 - 02:20 AM
If you are a complete newbe, get a language that has REPL (Read Eval Print Loop). Ruby, Python and Scala are examples of such languages. No need to configure project, create header files or write boilerplate code just to create a hello world program. BTW: C++ is the worst language for a beginner, regardless it had REPL or not.
So it is not a suitable language for writing applications in it, especially for newbies. It's main purpose are device drivers, operating system kernels, embedded software, hard real-time stuff.
Quote
Ok, so you can't do it in C with two lines, so what?
So it is not a suitable language for writing applications in it, especially for newbies. It's main purpose are device drivers, operating system kernels, embedded software, hard real-time stuff.


Sign In
Create Account

Back to top









