Compressed Strings

Hi,

I need to compress a string to find out if a word is a palindrome (same as reversed like race car). So I also need to do the reverse of it. I only missed one class and the notes are online and she never went over this and I can't find it in the book. When I search it on google I get something completely different.

example:
Enter a sentence to check:
Ten animals I slam in a net.
compressed: tenanimalsislaminanet
reversed: tenanimalsislaminanet
===> Palindrome!!!

The things I need help with is compressing a sentence, taking out the punctuation, and reversing it. The only problem is I have to use only what we've learned so far so be as basic as possible please.

Thanks in advance.
pseudocode
string input
string compressed := ""
for each char c in input
   if c != ' ' and c != ',' and c != '.' end etc. then
      append c to compressed

If you're working with arrays of characters, to append you'll need a variable j to mark the end of compressed. Write compressed[j] = c; j++;. Don't forget to append a 0 after the loop.
How do I append c to compressed?

Would anybody be able to skype about this? It would make the whole thing faster
Last edited on
1
2
3
4
5
6
7
char compressed[80];
int j = 0;
...
compressed[j] = c;
j++;
...
compressed[j] = 0;
Topic archived. No new replies allowed.