'array -> inverse array manually without library and check if it palindrome
When studying arrays I got a problem.
I'd appreciate if you help me to get output for this code.
I need to
- inverse array in new array
- compare both arrays to check whether input is a palindrome or not
- without using string.h library
# include<stdio.h>
int main(void)
{
char pal[15],palcpy[15];
int slen,i,j;
printf("\t\tpalindrome checker :)\n\nplease input the word you need to check : ");
scanf("%s", pal);
slen = strlen(pal);
for(i=slen ; i>=0 ; i--)
{
for(j=0 ; j<=slen ; j++)
{
palcpy[j] = pal[i];
}
}
printf("%s", pal);
return 0;
}
Solution 1:[1]
In line with https://ericlippert.com/2014/03/21/find-a-simpler-problem/ ( and How do I ask and answer homework questions? ) I recommend:
- Start with a HelloWorld, test
- Extend to read a string and echo, test
- Extend to copy the string to a second array, test
- Modify to echo from copy, test
- Extend to verify that original and copy are identical, test
- Modify to copy in reverse, test
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yunnosch |
