Read-only archive of the All About Symbian forum (2001–2013) · About this archive

symbian S60 Application

6 replies · 1,059 views · Started 25 October 2006

Hi
I have curiosity for knowing how would be programmed an application that will reverse given text. Thank you

What do you mean with "reverse given text"?

Simply writing it backwards like this? ?siht ekil sdrawkcab ti gnitirw ylpmiS

Or do you mean something else?

Is this a perhaps some sort of a school project you want someone else to do for you?

Sure, but I'm not going to write it for you, but you can use Google to find string reverse examples:
http://www.google.com/codesearch

With even the most basic programming skills, you should be able to figure this out on your own (create a new string or byte/character array to hold the reversed string, and then go through the string/array you want to reverse from the end to the beginning and copy each byte/character one by one to the new string/array).

What you should do is following:

void reverse(char* str)
{
size_t len = strlen(str);
int i = 0;
char* copy = malloc((len+1) * sizeof(char)); // In case char is not 1 byte

while(i < len)
{
copy[i] = str[len-1 - i]; // Copying in reverse order
i++; advance through the string
}

copy[i] = '\0'; // Null terminate string

strcpy(str, copy); // Store the result in the original string

free(copy); // Release memory

return; // Exit
}

if you need to store the original string you just do the memory allocation before calling the routine and routine should look like
void reverse(char* str, cahr* copy) - everything else is the same

Now this is the code you just need to add it to your application

Greetings,
elgrande 😃