Question

Part I Write a program palind.c that reads a message, then checks whether its palindrome (the letters in the message are the same from left to right as from right to left): Enter a message He lived as a devil, eh? Palindrome Enter a message Madam, I am Adam Not a palindrome Ignore all characters that arent letters. Use integer variables to keep track ofpositions in the array. Hint: Read the message one character at a time sing getchar and store the characters in an array. Stop Reading when the array is full or the character read is Mn. Part II: Revise the program in Part I to use a pointer instead of an integer to keep track of positions in the array. Name the new C program a palindP.c.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for you:

#include <stdio.h>
#include <ctype.h>
#include <string.h>
int isLinePalindrome(char *line)
{
    int length = strlen(line);
    int i = 0, j = length-1;
    while(i <= j)
    {
       //printf("%c\t%c\n", *(line + i), *(line + j));
       if(!isalpha(*(line + i)))
           i++;
          
       else if(!isalpha(*(line + j)))
           j--;
       else if(tolower(*(line + i)) != tolower(*(line + j)))
           return 0;
       else
       {
          i++;
           j--;  
       }  
    }
    return 1;
}
int main()
{
    char line[50];
    printf("Enter a message: ");
    scanf("%[^\n]s", line);
    printf("You entered %s\n", line);
    if(isLinePalindrome(line))
        printf("Palindrome\n");
    else
        printf("Not a palindrome\n");  
}

And the output screenshot is:

Add a comment
Know the answer?
Add Answer to:
Write a program palind.c that reads a message, then checks whether it's palindrome (the letters in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help programming this program in C. 1.) Write a program that reads a message,...

    I need help programming this program in C. 1.) Write a program that reads a message, then checks whether it's a palindrome (the letters in the message are the same from left to right as from right to left), example is shown below: Enter a message: He lived as a devil, eh? Palindrome Enter a message: Madam, I am Adam. Not a Palindrome 2.) Ignore all characters that aren't letters. Use integer variables to keep track of positions in the...

  • Write a python program that contains a hardcoded string and checks whether it is a palindrome...

    Write a python program that contains a hardcoded string and checks whether it is a palindrome (the same forwards as backwards). If it is then display “It is a palindrome”, otherwise display “It is not a palindrome”. A hardcoded string is simply a string defined in your program, for example: my_string = “Hello” Some sample palindromes to use are: A car, a man, a maraca Desserts, I stressed Madam, I’m Adam You will need to strip out any punctuation such...

  • Write a program that reads each word from A1.txt and check if it's a palindrome or...

    Write a program that reads each word from A1.txt and check if it's a palindrome or not. Show your output in the file Bl.txt. The total number of words in the file can change. You must use c-string or character arrays. Using String datatype and strrev() function are not allowed in this problem. "A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward." (Wikipedia) Sample Input: series madam Sample Output: yes

  • 1. DOES A DIGIT APPEAR IN AN INTEGER, Write a recursive function appears(n,i) that returns true...

    1. DOES A DIGIT APPEAR IN AN INTEGER, Write a recursive function appears(n,i) that returns true if the digit i appears in the positive (base 10) integer n, false if it does not in c++. ex. Enter a positive integer: 54321 Enter a digit: 7 The digit 7 does NOT appear in the integer 54321. 2. IS AN INPUT STRING A PALINDROME? A palindrome is a string in which the letters are the same in both directions, disregarding capitalization and...

  • Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward...

    Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for...

  • A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here...

    A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for the user input....

  • Write a Python Program Write a program which reads a word, lower-cases all its letters, then...

    Write a Python Program Write a program which reads a word, lower-cases all its letters, then prints out a square array where the first row contains the word, and each subsequent line is the previous line circular-shifted one place to the left. Example for entered word word == "MoXiE": moxie oxiem xiemo iemox emoxi Try doing this any way you can. Hint 1: lower-case word, then repeat the following len(word)times: (a) print word, (b) move first char of word to...

  • Please Code in Java and follow the directions given Thanks Program required Directions .A palindrome is a str...

    Please Code in Java and follow the directions given Thanks Program required Directions .A palindrome is a string that reads the same forward and backward, i.e., the letters are the same whether you read them from right to left or from left to right. Examples: 3 a) radar à is a palindrome b)Able was I ere I saw Elba à is a palindrome e good à not a palindrome Write java program to read a line of text and tell...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • This is for C++ Write a program that reads in a sequence of characters entered by...

    This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT