d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Iso Programing Help With Hw! > Programming In C
Add Reply New Topic New Poll
Member
Posts: 9,330
Joined: Oct 2 2006
Gold: 0.00
Oct 23 2013 01:31pm
Purpose: Use arrays & strings.

Description:

Write a function that determines if a string contains a
single word palindrome.

Pass a string to the function and have it return true or
false indicating whether the string contains a single
word palindrome.


Okay so here is where i am at.
I have a function to check for palindrome but now I need to have one function that tests a whole phrase instead of just a word which means i need it to ignore spaces and caps.


Below is the code I have that tests for palindrome although it doesnt ignore spaces or caps which is where i guess i need help.
void pal(char *str1)
{
int i;
int x;
x = strlen(str1)-1;
for ( i = 0; i<=x; i++)
{
if(str1[i] == str1[x-i])
{
printf(" Your String is a Palindrome \n");
return 0;
}
else
{
printf(" Your String is not a Palindrome \n");
return 0;
}
}
}



In the end goal is to have one functions that tests a phare for palindrome and ignores spaces and caps.
Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Oct 23 2013 02:26pm
create a function that remove spaces and caps first

create a function that flips word

check if first word = 2nd word

simple shit
Member
Posts: 9,330
Joined: Oct 2 2006
Gold: 0.00
Oct 23 2013 04:07pm
Quote (0n35 @ Oct 23 2013 02:26pm)
create a function that remove spaces and caps first

create a function that flips word

check if first word = 2nd word

simple shit


im pretty sure i need to have it be a single function. thats where i am stuck
Member
Posts: 11,610
Joined: Oct 28 2008
Gold: 1,795.00
Oct 23 2013 04:14pm
Quote (Dragoon427 @ Oct 23 2013 04:07pm)
im pretty sure i need to have it be a single function. thats where i am stuck


Code
function palindrome($word) {
$word = str_replace(" ", "", $word)
$word = strtolower($word)
for(x = 0 to strlen($word)) {
$word2 = $word2 + right($word, $x)
}
if($word = $word2) {
return True
} else {
return False
}
}


convert to c
but that's it
if you can't do this yourself you might consider taking another course
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 23 2013 05:07pm
Quote (Dragoon427 @ Oct 23 2013 06:07pm)
im pretty sure i need to have it be a single function. thats where i am stuck


if that's your only problem, i have good news for you: the solution is simple.

step 1: write your code using multiple helper functions
step 2: copy the code from your helper function, and paste it into the main function replacing your function name
step 3: fix the variable names based on the parameter
step 4: done!
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll