473,568 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can any one help me?

I went to solve a problem related
to Palindrome

int isPalindrome(ch ar *c);

returns back 1 if the string is a palindrome and returns back zero if
it is not a palindrome.

but without using thr library from( string.h)

who I can test my function that is the problem without using the
above library ?

the function is:

int isPalindrome(ch ar c[])
{
int a, b;
if (a >= b)
return 1;
else if (c[a] != c[b])
return 0;
else
return isPalindrome(c) ;

}

Mar 13 '06 #1
12 2012
join wrote:
I went to solve a problem related
to Palindrome

int isPalindrome(ch ar *c);

returns back 1 if the string is a palindrome and returns back zero if
it is not a palindrome.

but without using thr library from( string.h)

who I can test my function that is the problem without using the
above library ?

the function is:

int isPalindrome(ch ar c[])
{
int a, b;
if (a >= b)
return 1;
else if (c[a] != c[b])
return 0;
else
return isPalindrome(c) ;

}


There are a few issues with your code:

1) a and b are never initialized.
2) recursion has no way to exit

If you want to use recursion, pass in a and b, with the initial values
as 0 and one less than the number of characters in the string
(found using a version of strlen you implement yourself, since
strlen is forbidden by your appparent homework requirements about not
using string.h) respectively. Your recursive call needs to increment
a and decrement b...

As based on the code my impression is that you are still learning
C, you might consider writing an iterative version instead of
or in addition to the recursive one, as it may be more straightforward
for you to debug.

As for testing it, why do you need the string library for that?
stdio to report results perhaps?

-David

Mar 13 '06 #2
h_*******@hotma il-dot-com.no-spam.invalid (join) writes:
who I can test my function that is the problem without using the
above library ?

the function is:

int isPalindrome(ch ar c[])
{
int a, b;
if (a >= b)
return 1;
else if (c[a] != c[b])
return 0;
else
return isPalindrome(c) ;

}


I can already tell you that the function doesn't work. It uses
the values of `a' and `b' without first initializing them.

Also, I don't see why you should avoiding using string functions
in testing your function, even if the function you wrote should
not use them. Constraints on code and on its testing are
related, but separate.
--
"Am I missing something?"
--Dan Pop
Mar 13 '06 #3
On Monday 13 March 2006 19:06, join opined (in
<KI************ ********@gigane ws.com>):
I went to solve a problem related
to Palindrome

int isPalindrome(ch ar *c);

returns back 1 if the string is a palindrome and returns back zero if
it is not a palindrome.

but without using thr library from( string.h)
This sounds remarkably similar to something asked here a few weeks back.
You may want to search the group on Google.

It also sounds like a homework... Why else would you shy from stnandard
library functions? One reason may be that you're using an embedded
implementation, and the <string.h> functions are too expensive, but
then, rare is an embedded system wanting to know whether a string is a
palindrome (an under-5 toy, perhaps).
who I can test my function that is the problem without using the
above library ?
I presume you mean "how I can test?".
the function is:

#include <stdio.h>
int isPalindrome(ch ar c[])
{
int a, b;
if (a >= b)
return 1;
else if (c[a] != c[b])
return 0;
else
return isPalindrome(c) ;

}
int main(void)
{
printf("isPalin drome = %d\n",isPalindr ome("anavolimil ovana"));

return 0;
}

Would be one way of doing it. You'll find that the function does not
work, for the following reasons:
int isPalindrome(ch ar c[])
int isPalindrome(co nst char *c)

Is probably better, although not quite the same.
{
int a, b;
You never initialise `a` and `b`. On every invokation of this function
they assume completely random values (they are uninitialised). Judging
by your approach, you may have wanted `a` to start off pointing to the
last character (you'd want to use `strlen` here, or roll your own), and
`b` to start as 0. You'd also want to exit immediately if the string
was empty (c[0] == '\0', or better strlen(c) == 0) after determining
that pointer to it is not NULL (c != NULL).
if (a >= b)
return 1;
else if (c[a] != c[b])
return 0;
else
In the else branch you prbably wanted to decrement `a` and increment
`b`.
return isPalindrome(c) ;
Also, never in your function you change the values of `a` and `b`.
}


NB, take my suggestions with a grain of salt (i.e. double-check the
logic), as I did not test them.

--
BR, Vladimir

Those of you who think you know everything are very annoying to those
of us who do.

Mar 13 '06 #4

"join" <h_*******@hotm ail-dot-com.no-spam.invalid> wrote in message
news:KI******** ************@gi ganews.com...
but without using thr library from( string.h)


Your problem will be much easier to solve if you write functions to:
1) copy a string
2) reverse a string
3) compare a string
Rod Pemberton

Mar 13 '06 #5
On 2006-03-13, Rod Pemberton <do*********@so rry.bitbuck.cmm > wrote:

"join" <h_*******@hotm ail-dot-com.no-spam.invalid> wrote in message
news:KI******** ************@gi ganews.com...
but without using thr library from( string.h)


Your problem will be much easier to solve if you write functions to:
1) copy a string
2) reverse a string
3) compare a string
Rod Pemberton


True.

Alternatively he could do none of the above and just do a pincer
movement compare from end of potential palindrome and start of
potential palindrome comparing the characters and exiting when the pointers
meet.

For extra bonus assignment points he might want to take into account
that a Palindrome is case insensitive...
Mar 13 '06 #6
Groovy hepcat Rod Pemberton was jivin' on Mon, 13 Mar 2006 15:17:09
-0500 in comp.lang.c.
Re: Can any one help me?'s a cool scene! Dig it!
"join" <h_*******@hotm ail-dot-com.no-spam.invalid> wrote in message
news:KI******* *************@g iganews.com...
but without using thr library from( string.h)


Your problem will be much easier to solve if you write functions to:
1) copy a string
2) reverse a string
3) compare a string


Merely reversing a copy of the string and comparing it to the
original won't work correctly. The problem, as stated, is to determine
whether a string a a palidrome. No definition of palindrome has been
given, so the general meaning is assumed. A palindrome is a sentence
or phrase whose letters spell the same thing forward or reverse.
The function should ignore white space and punctuation. It should
also ignore differences in case. The following is a palandrome, but is
not the same when reversed:

Was it a car or a cat I saw?

Besides, you don't really need to make a copy of the string. You
only have to compare (case insensitively) the first as-yet-uncompared
alphabetic (or alphanumeric) character to the last as-yet-uncompared
alphabetic (or alphanumeric) character. That's trivial (and a clue for
the OP).
Now, if the OP wants to provide a more restrictive definition of
palindrome for the purpose of this project, then it may make things
easier.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technicall y correct" English; but since when was rock & roll "technicall y correct"?
Mar 14 '06 #7
think you for everu body here.

In fact , I am a new student for programming language , and I am
truing to learn it as I can as possible , and I am truing to slove
some problem like this , forget about my function.

int isPalindrome(ch ar c[])
{
int a, b;
if (a >= b)
return 1;
else if (c[a] != c)
return 0;
else
return isPalindrome(c) ;

}
Ignore this function.

Can any one solve this problem to me without using the library
<string.h> and give me the code?

thing you for every body.

Mar 14 '06 #8
join wrote:

Can any one solve this problem to me without using the library
<string.h> and give me the code?

thing you for every body.


People here give hints for homework if you show some code (as you did)
and seem to be making an effort. But generally they don't do it for
you.

-David

Mar 14 '06 #9
join wrote:
think you for everu body here.

In fact , I am a new student for programming language , and I am
truing to learn it as I can as possible , and I am truing to slove
some problem like this , forget about my function. Can any one solve this problem to me without using the library
<string.h> and give me the code?


Basically:

1. Yes, most of us can solve this problem.

2. No, we won't give the code.
It's an obvious student problem, which means its goal is to teach you
something about the C language. If we do your work for you, you don't
learn.

Work out the actual requirements of how the algorithm should work. One
way is to start with a string and do it by hand. Make note of how you
solve it that way. Turn that into a program.


Brian
Mar 14 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11190
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL) on the server because of that. Our site will have an SSL certificate next week, so I would like to use AIM instead of SIM, however, I don't know how...
2
5787
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues to execute the code until the browser send his reply to the header instruction. So an exit(); after each redirection won't hurt at all
3
22980
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which field is completed.
0
8452
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. 354 roberto@ausone:Build/php-4.3.2> ldd /opt/php4/bin/php libsablot.so.0 => /usr/local/lib/libsablot.so.0 libstdc++.so.5 => ...
1
8556
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the column below. The viewer can select states from the drop down lists above the other two columns as well. If the viewer selects only one, only one...
4
18229
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the user comes back to a page where he had a submitted POST data the browser keeps telling that the data has expired and asks if repost. How to avoid...
1
6790
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url http://www.mis.gla.ac.uk/biquery/training/ but each of the courses held have maximum of 8 people that could be
2
31359
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value to :parameter I dont like the idea of making the SQL statement on the fly without binding parameters as I dont want a highly polluted SQL cache.
3
23548
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the results of the picture half the size. The PHP I have installed support 1.62 or higher. And all I would like to do is take and image and make it fit a...
0
7693
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7916
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7962
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.