473,385 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Determine if a character string is palindromic

Hello experts,

I write a function named palindrome to determine if a character string
is palindromic, and test it with some example strings. Is it suitable
to add it to a company/project library as a small tool function
according to its quality? I will be very happy to get your suggestion
from every aspect on it: interface design, C language knowledge or
algorithm efficient.

Sincerely,

lovecreatesbeauty
/* Filename : palindrome.c
* Function : bool palindrome(char *s);
* Description: to determine if a character string is palindromic
* Date : 8 May 2006
*/

#include <stdbool.h>
#include <stddef.h>
#include <string.h>

bool palindrome(char *s)
{
bool palindromic = true;
size_t len = strlen(s);

if (len > 1)
{
for (unsigned i = 0; i < len / 2; ++i)
{
if (s[i] != s[len - 1 - i])
{
palindromic = false;
break;
}
}
}

return palindromic;
}
/* test */
#include <stdio.h>

int main()
{
printf("%i\n", palindrome("deed"));
printf("%i\n", palindrome("deeds"));
}

/*
$ gcc -W -Wall -std=c99 -pedantic palindrome.c
$ ./a.out
1
0
$
*/

May 8 '06 #1
25 6490
lovecreatesbeauty said:
Hello experts,

I write a function named palindrome to determine if a character string
is palindromic, and test it with some example strings. Is it suitable
to add it to a company/project library as a small tool function
according to its quality? I will be very happy to get your suggestion
from every aspect on it: interface design, C language knowledge or
algorithm efficient.

You might want to test it with these well-known palindromes:

"Madam, I'm Adam!"
"Able was I, ere I saw Elba."
"A man, a plan, a canal - Panama!"

Does it correctly identify them as palindromes?

(By the way, that question was rhetorical.)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 8 '06 #2
lovecreatesbeauty opined:
Hello experts,

I write a function named palindrome to determine if a character
string is palindromic, and test it with some example strings. Is it
suitable to add it to a company/project library as a small tool
function according to its quality? I will be very happy to get your
suggestion from every aspect on it: interface design, C language
knowledge or algorithm efficient.

Sincerely,

lovecreatesbeauty
/* Filename : palindrome.c
* Function : bool palindrome(char *s);
* Description: to determine if a character string is palindromic
* Date : 8 May 2006
*/

#include <stdbool.h>
#include <stddef.h>
#include <string.h>

bool palindrome(char *s)
{
bool palindromic = true;
size_t len = strlen(s);

if (len > 1)
{
for (unsigned i = 0; i < len / 2; ++i)
{
if (s[i] != s[len - 1 - i])
{
palindromic = false;
break;
}
}
}

return palindromic;
}
/* test */
#include <stdio.h>

int main()
{
printf("%i\n", palindrome("deed"));
printf("%i\n", palindrome("deeds"));
}

/*
$ gcc -W -Wall -std=c99 -pedantic palindrome.c
$ ./a.out
1
0
$
*/


Apart from the fact that it doesn't work, it looks fairly good.
Did you consider upper/lower case? Try: "Ana voli Milovana".
Or, alternatively, you need to define "palindrome" more precisely.

--
Microsoft is not the answer.
Microsoft is the question.
NO (or Linux) is the answer.
(Taken from a .signature from someone from the UK, source unknown)

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

May 8 '06 #3
lovecreatesbeauty wrote:
Hello experts,

I write a function named palindrome to determine if a character string
is palindromic, and test it with some example strings. Is it suitable
to add it to a company/project library as a small tool function
according to its quality? I will be very happy to get your suggestion
from every aspect on it: interface design, C language knowledge or
algorithm efficient.

Sincerely,

lovecreatesbeauty
/* Filename : palindrome.c
* Function : bool palindrome(char *s);
* Description: to determine if a character string is palindromic
* Date : 8 May 2006
*/

#include <stdbool.h>
I am not a fan of stdbool.h but that's just me.
#include <stddef.h>
#include <string.h>

bool palindrome(char *s)
If the function does not modify the string pointed to by s (and it
doesn't, I looked ahead), it would be better to indicate this:

bool palindrome (const char *s)
{
bool palindromic = true;
size_t len = strlen(s);

if (len > 1)
{
for (unsigned i = 0; i < len / 2; ++i)
What happens if len/2 > UINT_MAX but less than SIZE_MAX?
I would declare i as size_t.
{
if (s[i] != s[len - 1 - i])
{
palindromic = false;
That's quite a narrow definition of palindrome you have there. A
generally well-accepted definition of palindrome from wikipedia states:

"A palindrome is a word, phrase, number or other sequence of units
(such as a strand of DNA) that has the property of reading the same in
either direction (the adjustment of punctuation and spaces between
words is generally permitted)"

Your example does not allow things like:
"Aba"
"A, A"
which most people would consider to be palindromic.
break;
}
}
}

return palindromic;
}


Below is my version of the function, the main difference is the fact
that it is much less strict than yours ignoring all non-alphanumeric
characters:

#include <stddef.h>
#include <string.h>
#include <ctype.h>

int palindrome(const char *s)
{
size_t len = strlen(s);
const char *left, *right;

if (len > 1) {
left = s; right = s+(len-1);
while (left < right) {
if (!isalnum(*left)) {
left++;
continue;
}
if (!isalnum(*right)) {
right--;
continue;
}
if (toupper(*left) == toupper(*right)) {
left++, right--;
continue;
} else {
return 1;
}
}
}
return 0;
}

/* test */
#include <stdio.h>
#define BUF_SIZE 80

int main(void)
{
char buf[BUF_SIZE];
while (fgets(buf, 80, stdin) != NULL)
palindrome(buf) ? puts("Palindrome") : puts("Not a palindrome");
return 0;
}

Robert Gamble

May 8 '06 #4

Robert Gamble wrote:
Below is my version of the function, the main difference is the fact
that it is much less strict than yours ignoring all non-alphanumeric
characters:

#include <stddef.h>
#include <string.h>
#include <ctype.h>

int palindrome(const char *s)
{
size_t len = strlen(s);
const char *left, *right;

if (len > 1) {
left = s; right = s+(len-1);
while (left < right) {
if (!isalnum(*left)) {
left++;
continue;
}
if (!isalnum(*right)) {
right--;
continue;
}
if (toupper(*left) == toupper(*right)) {
left++, right--;
continue;
} else {
return 1;
That should be return 0;
}
}
}
return 0;


And that should be return 1;

Robert Gamble

May 8 '06 #5
lovecreatesbeauty wrote:

I write a function named palindrome to determine if a character string
is palindromic, and test it with some example strings. Is it suitable
to add it to a company/project library as a small tool function
according to its quality? I will be very happy to get your suggestion
from every aspect on it: interface design, C language knowledge or
algorithm efficient.

Sincerely,

lovecreatesbeauty

/* Filename : palindrome.c
* Function : bool palindrome(char *s);
* Description: to determine if a character string is palindromic
* Date : 8 May 2006
*/

.... snip code ...

I think you will find the following somewhat simpler. It doesn't
need the C99 stdbool.h include, and guarantees not to modify the
input string. It also handles the silly cases.

#include <stdio.h>
#include <string.h>

/* Returns 1 for palindrome, 0 for non-palindrome */
/* ispalindrome is a reserved function name */
int qpalindrome(const char *s)
{
const char *p;

/* null and empty strings are not palindromes */
if (s && *s) {
p = s + strlen(s) - 1;
while (p > s)
if (*p-- != *s++) return 0;
return 1;
}
return 0;
} /* qpalindrome */

/* It is left as an exercise to allow mixed case. */
/* or to elide blanks */

void check(const char *s)
{
if (s) printf("\"%s\" ", s);
if (qpalindrome(s)) puts("is");
else puts("isn't");
} /* check */

int main(void)
{
puts("Checking palindromes");
check("noon");
check("Noon");
check("dad");
check("Dad");
check(NULL);
check("");
return 0;
} /* main */

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
May 8 '06 #6
Robert Gamble wrote:
Robert Gamble wrote:
return 1;


That should be return 0;
}
}
}
return 0;


And that should be return 1;


Is there any particular reason that functions often behave this way?
If they succeed, they return 0, which in C is false, and vice versa.

Hmm, while I was writing this it occurred to me that it can have
something to do with error reporting. Different return values can
indicate different errors. Is that the reason?
May 8 '06 #7
john opined:
Robert Gamble wrote:
Robert Gamble wrote:
return 1;


That should be return 0;
}
}
}
return 0;


And that should be return 1;


Is there any particular reason that functions often behave this way?
If they succeed, they return 0, which in C is false, and vice versa.

Hmm, while I was writing this it occurred to me that it can have
something to do with error reporting. Different return values can
indicate different errors. Is that the reason?


Probably because returning 0 from `main()` is an indication of
successful program termination.

--
"Besides, I think [Slackware] sounds better than 'Microsoft,' don't
you?"
(By Patrick Volkerding)

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

May 8 '06 #8
"lovecreatesbeauty" <lo***************@gmail.com> writes:
I write a function named palindrome to determine if a character string
is palindromic, and test it with some example strings. Is it suitable
to add it to a company/project library as a small tool function
according to its quality? I will be very happy to get your suggestion
from every aspect on it: interface design, C language knowledge or
algorithm efficient.

/* Filename : palindrome.c
* Function : bool palindrome(char *s);
* Description: to determine if a character string is palindromic
* Date : 8 May 2006
*/

#include <stdbool.h>
#include <stddef.h>
#include <string.h>

bool palindrome(char *s)
{
bool palindromic = true;
size_t len = strlen(s);

if (len > 1)
{
for (unsigned i = 0; i < len / 2; ++i)
{
if (s[i] != s[len - 1 - i])
{
palindromic = false;
break;
}
}
}

return palindromic;
}
/* test */
#include <stdio.h>

int main()
{
printf("%i\n", palindrome("deed"));
printf("%i\n", palindrome("deeds"));
}


Your use of <stdbool.h> and of a declaration within a for loop mean
your program will work only with a C99 implementation, or with an
implementation that provides these features as an extension. Only you
can decide whether that's a problem. Converting the program to C90,
or rather to the common subset of C90 and C99, is straightforward.

You use an unsigned object to iterate through the string, but the
upper bound of the iteration is of type size_t. It's conceivable that
size_t could be bigger than unsigned, and that your loop could fail
for a very long string. You're unlikely to run into this problem
either in practice or in testing, unless you're specifically looking
for it. On many implementations, you'll never see a problem (i.e.,
testing can never reveal the bug). In other words, this bug is
particularly insidious.

The printf statements invoke undefined behavior. Your palindrome()
function returns a bool; printf's "%i" expects an int.

Note that "%i" is equivalent to "%d" in a printf format string; "%d"
is much more common in my experience. Using "%i" is perfectly correct
(if the corresponding argument is an int), but seeing it forces me to
pause and wonder why the author chose to use "%i" rather than "%d".
Perhaps the author thought there was a difference, and is failing to
express something significant. This is a minor style issue; feel free
to ignore it. (Note that "%d" and "%i" do behave differently in
scanf.)

You haven't defined the term "palindromic". The usual definition
ignores whitespace, punctuation, and the distinction between upper and
lower case; for example, "A man, a plan, a canal, Panama!" is
considered to be a palindrome. If you want to use a simpler
definition, that's fine, but you need to state clearly what definition
you're using.

Finally, the only use I've ever seen for a function to determine
whether a string is a palindrome is as an exercise in a programming
class or other tutorial. I can't imagine including such a function,
however well implemented, in a library, or calling it other than in a
test of the function itself.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 8 '06 #9
On 2006-05-08, john <no@email.com> wrote:
Robert Gamble wrote:
Robert Gamble wrote:
return 1;


That should be return 0;
}
}
}
return 0;


And that should be return 1;


Is there any particular reason that functions often behave this way?
If they succeed, they return 0, which in C is false, and vice versa.

Hmm, while I was writing this it occurred to me that it can have
something to do with error reporting. Different return values can
indicate different errors. Is that the reason?


I always assumed that was the basic reason. Occasionally people write
functions that return boolean "true for success", and often functions
that return pointers return NULL for failure, so you always have to be a
bit careful with

if (f())
/* succeeded or failed? */

etc.
May 8 '06 #10
In article <44***************@yahoo.com>,
CBFalconer <cb********@maineline.net> wrote:
/* null and empty strings are not palindromes */


Why on earth would you choose to not call the empty string a
palindrome? That would break such obvious invariants (indeed,
one might say definitions) as

palindrome(s) == (strcmp(s, reverse(s)) == 0)

-- Richard
May 8 '06 #11
On 2006-05-08, Keith Thompson wrote:

Finally, the only use I've ever seen for a function to determine
whether a string is a palindrome is as an exercise in a programming
class or other tutorial. I can't imagine including such a function,
however well implemented, in a library, or calling it other than in a
test of the function itself.


I use one in my work (composing cryptic crosswords).

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
May 8 '06 #12
"Chris F.A. Johnson" <cf********@gmail.com> writes:
On 2006-05-08, Keith Thompson wrote:

Finally, the only use I've ever seen for a function to determine
whether a string is a palindrome is as an exercise in a programming
class or other tutorial. I can't imagine including such a function,
however well implemented, in a library, or calling it other than in a
test of the function itself.


I use one in my work (composing cryptic crosswords).


Ok, sometimes my imagination fails me.

(Chris, just out of curiosity, why do you always indent everything you
write? Indentation like that is sometimes used to denote blocks of
quoted text. IMHO it would be clearer if your text were
left-justified like everyone else's.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 8 '06 #13
On 2006-05-08, Keith Thompson wrote:
"Chris F.A. Johnson" <cf********@gmail.com> writes:
On 2006-05-08, Keith Thompson wrote:

Finally, the only use I've ever seen for a function to determine
whether a string is a palindrome is as an exercise in a programming
class or other tutorial. I can't imagine including such a function,
however well implemented, in a library, or calling it other than in a
test of the function itself.
I use one in my work (composing cryptic crosswords).


Ok, sometimes my imagination fails me.

(Chris, just out of curiosity, why do you always indent everything you
write?


For the same reason that books have margins, and better books wider
margins.

Actaully, I started doing it in order to distinguish between my
text and (shell) code. I like code set flush left so that no
fiddling is necessary when cutting and pasting it.
Indentation like that is sometimes used to denote blocks of
quoted text.
Newsreaders, IME, generally do not recognize indentation as
quoting.
IMHO it would be clearer if your text were left-justified like
everyone else's.)


Left-justified? You mean flush-left and/or ragged right.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
May 8 '06 #14
Richard Tobin wrote:
CBFalconer <cb********@maineline.net> wrote:
/* null and empty strings are not palindromes */


Why on earth would you choose to not call the empty string a
palindrome? That would break such obvious invariants (indeed,
one might say definitions) as

palindrome(s) == (strcmp(s, reverse(s)) == 0)


All I can say is I documented it. That has been lying about in my
junk directory for four years. To alter that, simply change 0 to 1
in one location.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
May 8 '06 #15
Chris F.A. Johnson wrote:
On 2006-05-08, Keith Thompson wrote:
"Chris F.A. Johnson" <cf********@gmail.com> writes:
On 2006-05-08, Keith Thompson wrote:
Finally, the only use I've ever seen for a function to determine
whether a string is a palindrome is as an exercise in a programming
class or other tutorial. I can't imagine including such a function,
however well implemented, in a library, or calling it other than in a
test of the function itself.
I use one in my work (composing cryptic crosswords). Ok, sometimes my imagination fails me.

(Chris, just out of curiosity, why do you always indent everything you
write?


For the same reason that books have margins, and better books wider
margins.


My news reader provides such indentation sufficient unto my needs. I
could probably configure it to provide more if I so desired. This does
not require that you indent your text.
Actaully, I started doing it in order to distinguish between my
text and (shell) code. I like code set flush left so that no
fiddling is necessary when cutting and pasting it.


Personally I find shells don't have a problem with white space before
the commands.
Indentation like that is sometimes used to denote blocks of
quoted text.


Newsreaders, IME, generally do not recognize indentation as
quoting.


Agreed.
IMHO it would be clearer if your text were left-justified like
everyone else's.)


Left-justified? You mean flush-left and/or ragged right.


Yes, the normal is flush-left and ragged right. Since it is the norm
news readers can reformat it as well.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
May 9 '06 #16
"Chris F.A. Johnson" wrote:
On 2006-05-08, Keith Thompson wrote:
.... snip ...
(Chris, just out of curiosity, why do you always indent everything
you write?


For the same reason that books have margins, and better books wider
margins.

Actaully, I started doing it in order to distinguish between my
text and (shell) code. I like code set flush left so that no
fiddling is necessary when cutting and pasting it.
Indentation like that is sometimes used to denote blocks of
quoted text.


Newsreaders, IME, generally do not recognize indentation as
quoting.
IMHO it would be clearer if your text were left-justified like
everyone else's.)


Left-justified? You mean flush-left and/or ragged right.


Flush left. Your technique is fine until it gets requoted, when it
tends to spread out to the right, and be resistant to reformatting.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
May 9 '06 #17
qed
john wrote:
Robert Gamble wrote:
Robert Gamble wrote:
return 1;


That should be return 0;
}
}
}
return 0;


And that should be return 1;


Is there any particular reason that functions often behave this way?
If they succeed, they return 0, which in C is false, and vice versa.

Hmm, while I was writing this it occurred to me that it can have
something to do with error reporting. Different return values can
indicate different errors. Is that the reason?


It follows from a tradition in UNIX, however there is also a sound
reason for it. Very often a function returns with the *quantity* of
something it is trying to count from a complex data structure. However,
the data structure may be detectably corrupted or in an ill-defined
state. So using one int return value you can follow the convention that
all negative values indicate errors, and all positive values means
success -- further that all the positive values indicate each possible
count, while different negative values can correspond to different kinds
of errors.

So for example, how many elements are in a vector? Normally, you would
just want to know the quantity of elements that that vector has -- every
possibility from 0 to INT_MAX (say) makes sense, has meaning and easily
corresponds to a successful return. But if the vector is corrupted
because it has been ininitialized, or if an entry has some bad contents
or something like that you probably want some detail to help you track
down what kind of error you have, so that you can debug it, or avoid
that kind of vector contents. If you are just debugging, its usually
convenient to return -__LINE__. You can still reserve the value -1 for
other kinds of deterministic errors (like out of memory), since its
generally not possible to have source code which can expand the macro
__LINE__ on the first line of your source.

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/
May 10 '06 #18
Richard Heathfield wrote:
lovecreatesbeauty said:

Hello experts,

I write a function named palindrome to determine if a character string
is palindromic, and test it with some example strings. Is it suitable
to add it to a company/project library as a small tool function
according to its quality? I will be very happy to get your suggestion
from every aspect on it: interface design, C language knowledge or
algorithm efficient.


You might want to test it with these well-known palindromes:

"Madam, I'm Adam!"
"Able was I, ere I saw Elba."
"A man, a plan, a canal - Panama!"


They are palindromic sentences, not palindromic strings.

void convert_sentence_to_string(char *destination, const char *source)
{
for(; *source; source++)
{
if(isalpha((unsigned char) *source))
*destination++ = toupper((unsigned char) *source);
}
}

--
Simon.
May 10 '06 #19
Simon Biber said:
Richard Heathfield wrote:

You might want to test it with these well-known palindromes:

"Madam, I'm Adam!"
"Able was I, ere I saw Elba."
"A man, a plan, a canal - Panama!"
They are palindromic sentences, not palindromic strings.


They are palindromes.
void convert_sentence_to_string(char *destination, const char *source)
{
for(; *source; source++)
{
if(isalpha((unsigned char) *source))
*destination++ = toupper((unsigned char) *source);
}
}


And when were you planning on fixing the bug? :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 10 '06 #20
Richard Heathfield wrote:
Simon Biber said:
Richard Heathfield wrote:
You might want to test it with these well-known palindromes:

"Madam, I'm Adam!"
"Able was I, ere I saw Elba."
"A man, a plan, a canal - Panama!"


They are palindromic sentences, not palindromic strings.

They are palindromes.


Sure, but the original program did not claim to detect palindromes. It
claimed to detect palindromic strings. :-)
void convert_sentence_to_string(char *destination, const char *source)
{
for(; *source; source++)
{
if(isalpha((unsigned char) *source))
*destination++ = toupper((unsigned char) *source);
}
}


And when were you planning on fixing the bug? :-)


Apart from the failure to include <ctype.h>, was there a bug in my code?

Simon.
May 10 '06 #21
Simon Biber said:
Richard Heathfield wrote:
Simon Biber said:

void convert_sentence_to_string(char *destination, const char *source)
{
for(; *source; source++)
{
if(isalpha((unsigned char) *source))
*destination++ = toupper((unsigned char) *source);
}
}


And when were you planning on fixing the bug? :-)


Apart from the failure to include <ctype.h>, was there a bug in my code?


Yep. Here's a hint. The name of the function gives the intent, but the code
does not meet that intent. You have forgotten something rather important,
as a result of which disaster could well strike. In fact, it's a terminal
error!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
May 10 '06 #22
Richard Heathfield wrote:
Simon Biber said:

Richard Heathfield wrote:
Simon Biber said:

void convert_sentence_to_string(char *destination, const char *source)
{
for(; *source; source++)
{
if(isalpha((unsigned char) *source))
*destination++ = toupper((unsigned char) *source);
}
}

And when were you planning on fixing the bug? :-)


Apart from the failure to include <ctype.h>, was there a bug in my code?

Yep. Here's a hint. The name of the function gives the intent, but the code
does not meet that intent. You have forgotten something rather important,
as a result of which disaster could well strike. In fact, it's a terminal
error!


Ah, yes. I am getting sloppy!

Insert a line
*destination = 0;
as the last line of the function.

I will admit that I had not tested the function the first time I posted
it. I did test it after your comment about a bug, but unfortunately it
worked fine. There must have been a serendipitous null byte in my array.

--
Simon.
May 10 '06 #23
On 2006-05-09, Flash Gordon wrote:
Chris F.A. Johnson wrote:
On 2006-05-08, Keith Thompson wrote:

(Chris, just out of curiosity, why do you always indent everything you
write?


For the same reason that books have margins, and better books wider
margins.


My news reader provides such indentation sufficient unto my needs. I
could probably configure it to provide more if I so desired. This does
not require that you indent your text.
Actaully, I started doing it in order to distinguish between my
text and (shell) code. I like code set flush left so that no
fiddling is necessary when cutting and pasting it.


Personally I find shells don't have a problem with white space before
the commands.


It would if the command, intending IFS to contain a single newline,
is:

IFS='
'

I have the same problem if I have my newsreader do the indentation.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
May 10 '06 #24
"Chris F.A. Johnson" <cf********@gmail.com> writes:
On 2006-05-09, Flash Gordon wrote:
Chris F.A. Johnson wrote:
On 2006-05-08, Keith Thompson wrote:

(Chris, just out of curiosity, why do you always indent everything you
write?

For the same reason that books have margins, and better books wider
margins.


My news reader provides such indentation sufficient unto my needs. I
could probably configure it to provide more if I so desired. This does
not require that you indent your text.
Actaully, I started doing it in order to distinguish between my
text and (shell) code. I like code set flush left so that no
fiddling is necessary when cutting and pasting it.


Personally I find shells don't have a problem with white space before
the commands.


It would if the command, intending IFS to contain a single newline,
is:

IFS='
'

I have the same problem if I have my newsreader do the indentation.


Since you're the only person I know of who does this, it makes your
posts, and posts that quote them, slightly more difficult to read.
I suggest not indenting your text and finding some other way to mark
code.

It's not a huge deal, and I don't plan to bring it up again. Sorry
for the digression.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
May 10 '06 #25
Vladimir Oka wrote:

Apart from the fact that it doesn't work, it looks fairly good.
Did you consider upper/lower case? Try: "Ana voli Milovana".
Or, alternatively, you need to define "palindrome" more precisely.


After seeing this example, I'm curious; where are you from?

May 10 '06 #26

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

Similar topics

1
by: Ren? M?hle | last post by:
I have a psp script with a procedure just to run an update on one table. The Problem occurs when I try to compile this script with pspload: ORA-20006: "frsys_updatereport.psp": compilation...
1
by: rusttree | last post by:
I'm working on a program that manipulates bmp files. I know the offset location of each piece of relevent data within the bmp file. For example, I know the 18th through 21st byte is an integer...
2
by: jt | last post by:
Looking for an example how to convert and CString to an ASCII character string. Any examples on how to do this? Thank you, jt
0
by: MLH | last post by:
Is an apostrophe a character of special significance to MySQL in a way that would cause "Bob's dog" to become translated into a 12-character string when typed into a MySQL memo field? If I type...
2
by: Roy Rodsson via .NET 247 | last post by:
Hi all! I am using a stored procedure in SQL2000 for retrieving fileinformations from a db. the table as an uniqueidentifier for the file information. The stored procedure has a variable...
7
by: Justin | last post by:
i need to build the unsigned character string: "PR0N\0Spam\0G1RLS\0Other\0Items\0\0\0" from the signed character string: "PR0N Spam G1RLS Other Items" Tokeninzing the character string is not...
5
by: Karthik | last post by:
Hello! I am not a wizard in this area! Just need some help out in this. I am trying to convert bstr string to new character string. Here is the snippet of my code. **** Code Start**** ...
5
by: Paul Aspinall | last post by:
Hi I want to send an ASCII character string / stream to an IP address. I basically have 6 barcode printers, and a web interface. Depending on what is entered on the web page, will determine...
8
by: Brand Bogard | last post by:
Does the C standard include a library function to convert an 8 bit character string to a 16 bit character string?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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 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.