Need guidance, please.

Discuss PocketC for Palm OS (including Desktop Edition)

Postby Maria on Thu May 11, 2006 7:00 am

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;

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

Any help would be greatly appreciated.

Posts: 3
Joined: Thu May 11, 2006 4:45 am
Location: Singapore

Postby ramstrong on Mon May 15, 2006 10:02 pm

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.

Posts: 2
Joined: Fri May 12, 2006 11:14 pm

Postby Maria on Wed May 17, 2006 2:25 am

Thanks, Ramstrong. It worked! I like PocketC :)
Posts: 3
Joined: Thu May 11, 2006 4:45 am
Location: Singapore

Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 1 guest