- #1
SnakeDoc
- 27
- 1
Homework Statement
I am to write a program that has its user enter 100 character or less and determine if the line is a palindrome or not. I must use pointers one that starts at the beginning and one at the end of the array that must work their way in until they meet.(I'm also having trouble with this not sure how to keep them from going past each other.) As of now the program seems to be working just fine. When I compile the code I get the following warnings though.
:45:5: warning: passing argument 2 of 'is_palindrome' makes pointer from integer without a cast [enabled by default]
k = is_palindrome(j, letters[N]);
^
:20:6: note: expected 'char *' but argument is of type 'char'
bool is_palindrome(int n, char array[n]);
^
In function 'is_palindrome':
hw27.c:61:19: warning: assignment makes pointer from integer without a cast [enabled by default] while(arrayp1 =! arrayp2)
^
:65:25: warning: assignment makes pointer from integer without a cast [enabled by default]
if( arrayp1 =! arrayp2)
^
Homework Equations
The Attempt at a Solution
C:
//Preprocessor Directives
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
//define constants
#define N 101
//declare prototype
bool is_palindrome(int n, char array[n]);
//call main function
int main(void)
{
// Declare variables
char letters[N]={'\0'};
int i=0;
int j;
bool k;
printf("Enter a message: ");
while ((letters[I]=getchar()) != '\n')
{
[INDENT] //if the array element is a letter then make it upper case
if (isalpha(letters[I]))
{
[INDENT] letters[I]= toupper(letters[I]);
i++;
j++;[/INDENT]
}[/INDENT]
}
k = is_palindrome(j, letters[N]);
if (k == false)
[INDENT] printf("The line is not a palindrome.");[/INDENT]
else if(k == true)
[INDENT] printf("The line is a palindrome.");[/INDENT]
exit(EXIT_SUCCESS);
}
bool is_palindrome(int n, char array[n])
{
int i=0;
int len = n;
char *arrayp1 = &array[I];
char *arrayp2 = &array[n-1];
while(arrayp1 =! arrayp2)
{
[INDENT] for(i=0; i<len; i++)
{
[INDENT] if( arrayp1 =! arrayp2)
{
[INDENT] return false;[/INDENT]
}
n--;[/INDENT]
}[/INDENT]
}
return true;
}
Last edited: