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

  • Home
  • SEARCH
  • 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 8345311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:38:13+00:00 2026-06-09T06:38:13+00:00

I want to write a program that will take substrings from a given string.

  • 0

I want to write a program that will take substrings from a given string.

Then, the program will check if the substrings are palindrome. If palindrome, it will list them anywhere else and then it will sort out the unique palindromes.

But is there any process so that I can put more than one strings in an array individually??

I have written a program that will count, how many of the substrings are palindrome but, I cannot figure out how to count unique palindromes from them.

My code is here below:

#include<stdio.h>
#include<malloc.h>
#include<string.h>
char* substring(char*,int,int);
int is_palindrome(char array[],int length);
int main()
{
    char string[85],*pointer;
    int position,length,temp,string_length,pesky;
    printf("enter a string\n");
    while(gets(string)){
        position=1,length=2;
        temp=string_length=pesky=strlen(string);
        while(position<=string_length){
            while(length<=temp){
                pointer=substring(string,position,length);
                if(is_palindrome(pointer,length)==1){pesky++;puts(pointer);}
                free(pointer);
                length++;
            }
            position++;
            temp--;
            length=2;
        }
        printf("The string '%s' contains %d palindromes.\n",string,pesky);
    }
    return 0;
}
char* substring(char *string,int position,int length)
{
    char *pointer;
    int c;
    pointer=malloc(length+1);
    if(pointer==NULL){
        printf("unable to locate memory.\n");
        exit(EXIT_FAILURE);
    }
    for(c=0;c<position-1;c++){
        string++;
    }
    for(c=0;c<length;c++){
        *(pointer+c)=*string;
        string++;
    }
    *(pointer+c)='\0';
    return pointer;
}
int is_palindrome(char array[],int length)
{
    int k,j,o=0;
    for(k=length-1,j=0;k>j;k--,j++){
        if(array[k]!=array[j]){
        o=1;
        break;
        }
    }
    if (o==0) {return 1;}
    else {return 0;}
}
  • 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-06-09T06:38:15+00:00Added an answer on June 9, 2026 at 6:38 am

    In order to store the various substrings, you will need an array of char pointers. As you separate out your substrings, which you are copying into a malloced memory area, you take the pointer that is returned and store the pointer into your array of char pointers.

    So something like the following will define an array of chars along with a count of the number of char pointers that are currently in the array.

    char *pArrayStrings [100];
    int   iArrayStringsIndex = 0;
    

    At this point you will have an array of char pointers. You can then do a search through the array to determine if the palindrome has already been found. Something like the following.

    {
        int iLoop = 0;
        // search the array to see if this palindrome is already there
        for (iLoop = 0; iLoop < iArrayStringsIndex; iLoop++) {
            if (strcmp (pArrayStrings[iLoop], pointer) == 0) {
                // found a match for this palindrome
                break;
            }
        }
        if (iLoop >= iArrayStringsIndex) {
           // this is a new palindrome that is not in the array
           pArrayStrings[iArrayStringsIndex] = pointer;
           iArrayStringsIndex++;
        }
    }
    

    The above strcmp() function is case sensitive so you might want to use the case insensitive compare.

    I have not tried compiling this code so there may be an error in it however this would be a general approach that should get you close to what you want.

    Once you are done, you can then loop over the array and do a free() to free the malloced memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a program that would take a string, let's say Fox
I want to write a program that will generate random notes and draw them
I want to write a program (preferably in java) that will parse and analyze
I want to write a batch file that will take the contents of a
I need to write a program that will take a existing local windows user,
I'm trying to write a program that will take an HTML file and make
Problem: I want to write a process that will allow a user to take
I am trying to write a program that will take the users input value
I want to write a program that will allow writing plugins for it. The
I want to write a C program that will sample something every second (an

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.