Page 1 of 1

PostPosted: Thu May 11, 2006 7:00 am
by Maria
Hi
I just started on Andy Harris' Palm programming book and am stuck at Chapter 2, challenge no. 3, "Ask the user for a word and convert that word into pig latin by extracting the first letter and adding it to the end of the word with "ay". For example, if the user enters "PocketC", the program shoudl return "ocketCPay". Don't worry about words that begin with vowels.

My problem is :-

1. Extracting a letter - I can only do so if I know the number of letters in the word the user chooses. If my number is more than the number of letters, it doesn't work.

2. Adding to the end of the word - I am completely stumped. I tried various codes but nothing seem to work.

Don't laugh too hard - here's what I have so far :-

string str;
main();
clear();

puts("StringLibrary\n");
while(str=gets("Please enter a word:")){
puts("nRight10=" + strright(str.10));
wait();
}
} //end main

Any help would be greatly appreciated.


Thanks!

PostPosted: Mon May 15, 2006 10:02 pm
by ramstrong
Use strlen() to find out string length. The rest is trivial. You can even use substr() to do it: substr(str,1,strlen(str)-1)+substr(str,0,1)+"ay"
I'll have to check whether strlen(str)-1 is correct, but I think so.

Alternatively, strright(str,strlen(str)-1)+strleft(str,1)+"ay", BTW. Same thing. Oh, and please check that you use comma, instead of period.

HTH

PostPosted: Wed May 17, 2006 2:25 am
by Maria
Thanks, Ramstrong. It worked! I like PocketC :)