hi friends,
i am new to this can any one help me regarding this issue
my aim is to Write a program which computes the largest palindrome substring of a string using pointers
Input: The input is the string whose largest palindrome substring should be found.
Output: The output displays the largest palindrome substring.
Sample Input:
Enter the string: Habitat
Sample Output:
The longest palindrome substring of Habitat is: tat
----------------------------------------------------------------------------------------------------------------
i am able to write the code with out using pointers can any one help me regarding this how can i write this using pointers
code with out pointers is -
#include<stdio.h>
-
#include<conio.h>
-
#include<string.h>
-
main()
-
{
-
char s[20],x[20],y[10],t[10];
-
int i,j,l,k,l1=0;
-
printf("Enter the string");
-
gets(s);
-
l=strlen(s);
-
s[l]='\0';
-
for(i=0;i<l;i++)
-
{
-
j=0;
-
x[j]=s[i]; //taking the first character into X
-
j++;
-
x[j]='\0';
-
for(k=i+1;k<l;k++)
-
{
-
x[j]=s[k];
-
j++;
-
x[j]='\0';
-
strcpy(t,x);
-
if(strcmp(t,strrev(x))==0) //comparing the substring as if palindrome
-
{
-
if(l1<strlen(x)) //if palindrome compare the length wih previous paindrome
-
{
-
strcpy(y,t);
-
puts(y); //print the longer palindrome
-
l1=strlen(y);
-
}
-
}
-
-
strrev(x);
-
}
-
-
}
-
getch();
-
}
3 1544
hi friends,
i am new to this can any one help me regarding this issue
my aim is to Write a program which computes the largest palindrome substring of a string using pointers
Input: The input is the string whose largest palindrome substring should be found.
Output: The output displays the largest palindrome substring.
Sample Input:
Enter the string: Habitat
Sample Output:
The longest palindrome substring of Habitat is: tat
----------------------------------------------------------------------------------------------------------------
i am able to write the code with out using pointers can any one help me regarding this how can i write this using pointers
code with out pointers is
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char s[20],x[20],y[10],t[10];
int i,j,l,k,l1=0;
printf("Enter the string");
gets(s);
l=strlen(s);
s[l]='\0';
for(i=0;i<l;i++)
{
j=0;
x[j]=s[i]; //taking the first character into X
j++;
x[j]='\0';
for(k=i+1;k<l;k++)
{
x[j]=s[k];
j++;
x[j]='\0';
strcpy(t,x);
if(strcmp(t,strrev(x))==0) //comparing the substring as if palindrome
{
if(l1<strlen(x)) //if palindrome compare the length wih previous paindrome
{
strcpy(y,t);
puts(y); //print the longer palindrome
l1=strlen(y);
}
}
strrev(x);
}
}
getch();
}
Hi,
You can use array of char like char * x = new char[]; instead of char x[n]. I am not able to find anything else in this code where you can use pointers.
Regards
hi friends,
i am new to this can any one help me regarding this issue
my aim is to Write a program which computes the largest palindrome substring of a string using pointers
Input: The input is the string whose largest palindrome substring should be found.
Output: The output displays the largest palindrome substring.
Sample Input:
Enter the string: Habitat
Sample Output:
The longest palindrome substring of Habitat is: tat
----------------------------------------------------------------------------------------------------------------
i am able to write the code with out using pointers can any one help me regarding this how can i write this using pointers
code with out pointers is
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char s[20],x[20],y[10],t[10];
int i,j,l,k,l1=0;
printf("Enter the string");
gets(s);
l=strlen(s);
s[l]='\0';
for(i=0;i<l;i++)
{
j=0;
x[j]=s[i]; //taking the first character into X
j++;
x[j]='\0';
for(k=i+1;k<l;k++)
{
x[j]=s[k];
j++;
x[j]='\0';
strcpy(t,x);
if(strcmp(t,strrev(x))==0) //comparing the substring as if palindrome
{
if(l1<strlen(x)) //if palindrome compare the length wih previous paindrome
{
strcpy(y,t);
puts(y); //print the longer palindrome
l1=strlen(y);
}
}
strrev(x);
}
}
getch();
}
Maybe you could use pointers to iterate over the string: -
char test[] = "Hello World";
-
char *p;
-
for (p = test; *p != '\0'; p++;)
-
{
-
// here use "*p" to get the char instead of "test[i]"
-
}
-
It looks like you are going to a lot of unnecessary work. A palindrome is a word or phrase that reads the saem in both directions.
So, you create two pointers A and B. Start A with the the address of element 0 and start B with the address of the element returned by strlen().
Compare the characters pointed at by the two pointers. If they are equal advance A by 1 and reduce B by 1 and repeat the compare.
You have a palindrome when the addresses in A and B are the same.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tommy Lang |
last post by:
I am working on this project and I need some help/pointers/comments to
get me started, I am stuck.
The program will be used to store information in an array while it is
running.
I need to store...
|
by: Simon |
last post by:
Hi,
if I have a structure like...
struct sMyPointers{
ClassA *m_pPointerA;
ClassB *m_pPointerB;
void *m_pPointerToSomethingElse;
};
|
by: rokuingh |
last post by:
ok, so i've been working on this one for quite a while, and the code is very big so i'm just going to give the relevant parts. this is a program that builds polymers (chemical structures of repeated...
|
by: ArcInversion |
last post by:
Hi, I've been using a javascript script to create a dragon that flies across the page. Anyways, I'd like to make it so when you click the dragon it takes you to a new page. Was wondering if anyone...
|
by: vinod.bhavnani |
last post by:
Hello all,
I need desperate help
Here is the problem:
My problem today is with multidimensional arrays.
Lets say i have an array A this is a 4 dimensional
static array.
|
by: sarathy |
last post by:
Hi,
I have been using C++ for a while. I am not entirely clear with
the concepts of reference in C++.
- Why was there a need for introducing a concept called "Reference" in
C++ when everything...
|
by: Y2J |
last post by:
I am working through this book on C++ programming, the author is
speaking of using linked lists. He gave and example which I found
confusing to say the least. So I rewrote the example in a way that...
|
by: Martin Jørgensen |
last post by:
Hi,
I'm reading a number of double values from a file. It's a 2D-array:
1 2 3 4 5 6 7
-------------
1 3.2
2 0 2.1
3 9.3
4
|
by: DDP3000 |
last post by:
void F(int **A, int N)
{
int i,j;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
A=((i+j)%2==0)?1:-1;
}
I have never used such a thing before, so it might be a really stupid
question but I cannot find...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |