Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4617012
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:03:49+00:00 2026-05-22T02:03:49+00:00

#include usefunc.h #define MY_SIZE 256 int inpArr(char tmp[], int size) { size = -1;

  • 0
#include "usefunc.h"
#define MY_SIZE 256

int inpArr(char tmp[], int size) {
    size = -1;
    while(1) {
        size++;
        if((tmp[size] = getchar()) == '\n') break;
    }
    return size;
}

void revString(char tmp[], int size, char new[]) {
    int i, j;
    for (i = size, j = 0; i >= 0; i--, j++) new[j] = tmp[i];
}

void copy_forw(char tmp[], int size, char new[], int offset) {
    int i, j;
    for (i = offset, j = 0; i <= size; i++, j++) new[j] = tmp[i];
}

void copy_back(char tmp[], int size, char new[], int offset) {
    int i, j;
    for (i = size-offset, j = size; i > -1; i--, j--) new[j] = tmp[i];
}

void cut(char tmp[], int size, char new[]) {

}

int main () {
    char tmp[MY_SIZE] = {0x0}, rev[MY_SIZE] = {0x0}, new[MY_SIZE] = {0x0}, some[MY_SIZE-1];
    int size = inpArr(tmp, size);
    revString(tmp, size, rev);
    copy_forw(rev, size, new, 1); copy_back(tmp, size, some, 1);
    printf("|%s|\n|%s|\n", some, new);
    int is_palindrome = StringEqual(new, some);
    printf("%d\n", is_palindrome);
}

StringEqual is pretty much a function that just compares a char array character by character.
If I input the string yay it should be a palindrome, but doesn’t appear to be. Why is this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:03:50+00:00Added an answer on May 22, 2026 at 2:03 am

    Your problem is with the line that goes:

    if((tmp[size] = getchar()) == '\n') break;
    

    This line will always assign the character the user inputs into the array, even when the user inputs the \n character to indicate that they are done providing input. So for example, when you enter “yay” and then a newline to indicate that you are done, your array looks like:

    {'y', 'a', 'y', '\n'}
    

    and the reverse of that array is:

    {'\n', 'y', 'a', 'y'}
    

    …which will obviously fail a palindrome check. I would suggest revising your code as follows:

    int inpArr(char tmp[], int size) {
        size = -1;
        while(1) {
            size++;
            if((tmp[size] = getchar()) == '\n') break;
        }
        tmp[size] = '\0';  //replace the newline with a null terminator
        return size;
    }
    
    void revString(char tmp[], int size, char new[]) {
        int i, j;
        for (i = size - 1, j = 0; i >= 0; i--, j++) new[j] = tmp[i];
        new[size] = '\0';  //place a null terminator at the end of the reversed string
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include<stdio.h> int main(void) { int i=1,j=-1; if((printf(%d,i))<(printf(%d,j))) printf(%d,i); else printf(%d,j); return 0; } As
#include <vector> std::vector<long int> as; long int a(size_t n){ if(n==1) return 1; if(n==2) return
#include<iostream> using namespace std; class A { int a; int b; public: void eat()
#include<iostream> class name { public: int a; name():a(0){}; }; void add(name * pname) {
#include usefunc.h //don't worry about this -> lib I wrote int main() { int
#include<stdio.h> int main(void) { signed int a=-1; unsigned int b=1; int c= a+b; printf(%d\n,c);
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits
#include <iostream> using namespace std; int main() { double u = 0; double w
include(conn.php); $result = mysql_query(SELECT * FROM sggame); while($row = mysql_fetch_assoc($result)); { $id = $row['id'];
#include iostream class A { private: int a; public : A(): a(-1) {} int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.