Jump to content

Which Language to use

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
gbkilpatrick

gbkilpatrick

    Newbie

  • Members
  • Pip
  • 3 posts
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.

#2
ksemeks

ksemeks

    Learning Programmer

  • Members
  • PipPipPip
  • 57 posts
I would suggest C for this task. And it's quite simple actually. Maybe this works for you

#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
JCoder

JCoder

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 245 posts
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
gbkilpatrick

gbkilpatrick

    Newbie

  • Members
  • Pip
  • 3 posts
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
JCoder

JCoder

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 245 posts
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
ksemeks

ksemeks

    Learning Programmer

  • Members
  • PipPipPip
  • 57 posts
Ok, so you can't do it in C with two lines, so what?
// d-_-b+

#7
gbkilpatrick

gbkilpatrick

    Newbie

  • Members
  • Pip
  • 3 posts
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
JCoder

JCoder

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 245 posts
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.

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.