473,509 Members | 3,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reverse a string

This one question is asked modally in most Microsoft interviews. I
started to contemplate various implementations for it. This was what I
got.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* StrReverse(char*);
char* StrReverse1(char*);
char* StrReverse2(char*);
void StrReverse3(char*);
void StrReverse4(char*);

int main(void)
{

char str[50];
int temp=0;

printf("Enter a string: ");
scanf("%s", str);
printf("The reverse of the string is: %s\n", StrReverse(str));
printf("The reverse of the string is: %s\n", StrReverse1(str));
printf("The reverse of the string is: %s\n", StrReverse2(str));

StrReverse3(str);
printf("The reverse of the string is: %s\n", str);

//Get back the original string
StrReverse3(str);

//Reverse it again
printf("The reverse of the string is: ");
StrReverse4(str);
printf("\n");

scanf("%d", &temp);

}
char* StrReverse(char* str)
{
char *temp, *ptr;
int len, i;

temp=str;
for(len=0; *temp !='\0';temp++, len++);

ptr=malloc(sizeof(char)*(len+1));

for(i=len-1; i>=0; i--)
ptr[len-i-1]=str[i];

ptr[len]='\0';
return ptr;
}

char* StrReverse1(char* str)
{
char *temp, *ptr;
int len, i;

temp=str;
for(len=0; *temp !='\0';temp++, len++);

ptr=malloc(sizeof(char)*(len+1));

for(i=len-1; i>=0; i--)
*(ptr+len-i-1)=*(str+i);

*(ptr+len)='\0';
return ptr;
}

char* StrReverse2(char* str)
{
int i, j, len;
char temp;
char *ptr=NULL;
i=j=len=temp=0;

len=strlen(str);
ptr=malloc(sizeof(char)*(len+1));
ptr=strcpy(ptr,str);
for (i=0, j=len-1; i<=j; i++, j--)
{
temp=ptr[i];
ptr[i]=ptr[j];
ptr[j]=temp;
}
return ptr;
}

void StrReverse3(char* str)
{
int i, j, len;
char temp;
i=j=len=temp=0;

len=strlen(str);
for (i=0, j=len-1; i<=j; i++, j--)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
}
}

/*A coooooooooool way of reversing a string by recursion. I found it
at this web address
http://www.geocities.com/cyberkabila...ersestring.htm
*/

void StrReverse4(char *str)
{
if(*str)
{
StrReverse4(str+1);
putchar(*str);
}
}

Then, I read one guy saying a string could be reversed in one single
sweep with the exclusive OR operator. Since then I've been itching to
know how. If someone can please share with me, the code to reverse a
string with the XOR operator, I'll be grateful.

Regards,
Sathyaish
Nov 14 '05 #1
24 3231
Sathyaish wrote:

[much snippage]

Then, I read one guy saying a string could be reversed in one single
sweep with the exclusive OR operator. Since then I've been itching to
know how. If someone can please share with me, the code to reverse a
string with the XOR operator, I'll be grateful.


You can swap to chars, a and b, with:

*a ^= *b;
*b ^= *a;
*a ^= *b;

Worry about what happens in the middle of the string, when a and b have
the same address.

--
rh
Nov 14 '05 #2
Sathyaish wrote:

This one question is asked modally in most Microsoft interviews. I
started to contemplate various implementations for it. This was what I
got.

/*A coooooooooool way of reversing a string by recursion. I found it
at this web address
http://www.geocities.com/cyberkabila...ersestring.htm
*/

void StrReverse4(char *str)
{
if(*str)
{
StrReverse4(str+1);
putchar(*str);
}
}

Then, I read one guy saying a string could be reversed in one single
sweep with the exclusive OR operator. Since then I've been itching to
know how. If someone can please share with me, the code to reverse a
string with the XOR operator, I'll be grateful.

Regards,
Sathyaish


String reversal by recursion uses O(n^2) time. You can do it in O(n)
time by keeping pointers L and U to the ends. In pseudocode,

while L<U
swap( s[L], s[u] );
L = L+1;
U = U-1;
repeat
--
Julian V. Noble
Professor Emeritus of Physics
jv*@lessspamformother.virginia.edu
^^^^^^^^^^^^^^^^^^
http://galileo.phys.virginia.edu/~jvn/

"For there was never yet philosopher that could endure the toothache
patiently." -- Wm. Shakespeare, Much Ado about Nothing. Act v. Sc. 1.
Nov 14 '05 #3

On Wed, 21 Jul 2004, Julian V. Noble wrote:

Sathyaish wrote:
/*A coooooooooool way of reversing a string by recursion. I found it
at this web address
http://www.geocities.com/cyberkabila...ersestring.htm
*/

void StrReverse4(char *str)
{
if(*str)
{
StrReverse4(str+1);
putchar(*str);
}
}
String reversal by recursion uses O(n^2) time.


Not the way Sathyaish is doing it; that's O(n) right there (even
though it prints out something, rather than reversing the string).
You can do it in O(n)
time by keeping pointers L and U to the ends. In pseudocode,

while L<U
swap( s[L], s[u] );
L = L+1;
U = U-1;
repeat


Or, transforming the loop into tail-recursion,

void revmem(char *s, int L, int U)
{
if (L < U) {
swap(s[L], s[U-1]);
revmem(s, L+1, U-1);
}
}

(Note the change in meaning of U. :)

Then, I read one guy saying a string could be reversed in one single
sweep with the exclusive OR operator. Since then I've been itching to
know how. If someone can please share with me, the code to reverse a
string with the XOR operator, I'll be grateful.


The guy was probably thinking of the old chestnut

x ^= y ^= x ^= y;

which is not only invalid C code, but doesn't work if &x == &y.
And that just swaps two values (assuming it does what the guy obviously
expected it to do); while swapping is a big part of string reversal,
it's not exactly the same thing. And it has nothing to do with
"sweeps."

-Arthur
Nov 14 '05 #4


Sathyaish wrote:
This one question is asked modally in most Microsoft interviews. I
started to contemplate various implementations for it. This was what I
got.

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

char* StrReverse(char*);
char* StrReverse1(char*);
char* StrReverse2(char*);
void StrReverse3(char*);
void StrReverse4(char*);

int main(void)
{

char str[50];
int temp=0;

printf("Enter a string: ");
scanf("%s", str);
printf("The reverse of the string is: %s\n", StrReverse(str));
printf("The reverse of the string is: %s\n", StrReverse1(str));
printf("The reverse of the string is: %s\n", StrReverse2(str));

StrReverse3(str);
printf("The reverse of the string is: %s\n", str);

//Get back the original string
StrReverse3(str);

//Reverse it again
printf("The reverse of the string is: ");
StrReverse4(str);
printf("\n");

scanf("%d", &temp);

}

char* StrReverse(char* str)
{
char *temp, *ptr;
int len, i;

temp=str;
for(len=0; *temp !='\0';temp++, len++);

ptr=malloc(sizeof(char)*(len+1));

for(i=len-1; i>=0; i--)
ptr[len-i-1]=str[i];

ptr[len]='\0';
return ptr;
}

char* StrReverse1(char* str)
{
char *temp, *ptr;
int len, i;

temp=str;
for(len=0; *temp !='\0';temp++, len++);

ptr=malloc(sizeof(char)*(len+1));

for(i=len-1; i>=0; i--)
*(ptr+len-i-1)=*(str+i);

*(ptr+len)='\0';
return ptr;
}

char* StrReverse2(char* str)
{
int i, j, len;
char temp;
char *ptr=NULL;
i=j=len=temp=0;

len=strlen(str);
ptr=malloc(sizeof(char)*(len+1));
ptr=strcpy(ptr,str);
for (i=0, j=len-1; i<=j; i++, j--)
{
temp=ptr[i];
ptr[i]=ptr[j];
ptr[j]=temp;
}
return ptr;
}

void StrReverse3(char* str)
{
int i, j, len;
char temp;
i=j=len=temp=0;

len=strlen(str);
for (i=0, j=len-1; i<=j; i++, j--)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
}
}

/*A coooooooooool way of reversing a string by recursion. I found it
at this web address
http://www.geocities.com/cyberkabila...ersestring.htm
*/

void StrReverse4(char *str)
{
if(*str)
{
StrReverse4(str+1);
putchar(*str);
}
}

Then, I read one guy saying a string could be reversed in one single
sweep with the exclusive OR operator. Since then I've been itching to
know how. If someone can please share with me, the code to reverse a
string with the XOR operator, I'll be grateful.

Regards,
Sathyaish


What's wrong with the good old push/pop stack method of string reversal?
Nov 14 '05 #5
Sathyaish wrote:
void StrReverse3(char* str)
{
int i, j, len;
char temp;
i=j=len=temp=0;

len=strlen(str);
for (i=0, j=len-1; i<=j; i++, j--)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
}
}


Here's a pointier version of the same algorithm:

char *str_rev(char *s)
{
char *p, *q, swap;

if (*s != '\0') {
q = p = s;
q += strlen(q);
while (--q > p) {
swap = *q;
*q = *p;
*p++ = swap;
}
}
return s;
}

--
pete
Nov 14 '05 #6
Richard Harnden wrote:
You can swap to chars, a and b, with:


[stupid XOR trick removed]
NEVER post this crap in answer to a question unless the question is
"What is the most frequent stupidity posted to a C newsgroup."
Nov 14 '05 #7
Richard Harnden wrote:
You can swap to chars, a and b, with:

*a ^= *b;
*b ^= *a;
*a ^= *b;
aah, the crazily named "stupid XOR trick"
Worry about what happens in the middle of the string, when a and b have
the same address.


theoretically, it should just waste a few cpu cycles, but do nothing. if you
abstract yourself from C for a second and think about XOR as being an
associative (i think it is also commutative) binary operation (in the
mathematical sense) with the identity element 1. and using the following rule:

x XOR x = 1

then you can look at your code in the following manner. let a_1, b_1 be the
initial registers a and b. let a_2. b_2 be their final states. by following the
code through, we have the following equalities (brackets not needed due to
associativity, but left in for clarity with the order of the code):

b_2 = (a_1 XOR b_1) XOR b_1
a_2 = ((a_1 XOR b_1) XOR b_1) XOR (a_1 XOR b_1)

using the rule, we get

b_2 = a_1
a_2 = b_1

there is no theoretical reason why you cannot have (a_1 = b_1). in fact, i'd be
very worried if this broke, as it means the C XOR operator is not associative!

this method, although IMHO a cute little trick (and not stupid like most people
say) is actually slower than the more obvious way on most modern optimising
compilers) try the following code:

int a, b;
#ifndef STUPID_XOR
int tmp;
tmp = a;
a = b;
b = tmp;
#else
a ^= b;
b ^= a;
a ^= b;
#endif

and see what your C compiler outputs in assembly to see what i mean. or you
could just make up a simple C program to time a million string reverses using
each algorithm. on my G4 PPC, the "stupid XOR trick" takes about 140% as long as
the obvious solution, with the following assembly created for each:

obvious solution:
stwu 1,-48(1)
stw 31,44(1)
mr 31,1
lwz 0,8(31)
stw 0,16(31)
lwz 0,12(31)
stw 0,8(31)
lwz 0,16(31)
stw 0,12(31)
lwz 11,0(1)
lwz 31,-4(11)
mr 1,11
blr

"stupid XOR trick":
stwu 1,-32(1)
stw 31,28(1)
mr 31,1
lwz 9,8(31)
lwz 0,12(31)
xor 0,9,0
stw 0,8(31)
lwz 9,12(31)
lwz 0,8(31)
xor 0,9,0
stw 0,12(31)
lwz 9,8(31)
lwz 0,12(31)
xor 0,9,0
stw 0,8(31)
lwz 11,0(1)
lwz 31,-4(11)
mr 1,11
blr
Nov 14 '05 #8
Sam Halliday wrote:

Richard Harnden wrote:
You can swap to chars, a and b, with:

*a ^= *b;
*b ^= *a;
*a ^= *b;


aah, the crazily named "stupid XOR trick"
Worry about what happens in the middle of the string,
when a and b have the same address.


theoretically, it should just waste a few cpu cycles,
but do nothing. if you abstract yourself from C for a
second and think about XOR as being an
associative (i think it is also commutative) binary operation (in the
mathematical sense) with the identity element 1.
and using the following rule:

x XOR x = 1


That's the opposite of what XOR means.

The result of an XOR operation is 1,
when the operands are logically different and

the result of an XOR operation is 0,
when the operands are logically the same.

--
pete
Nov 14 '05 #9
pete wrote:
Sam Halliday wrote:

Richard Harnden wrote:
You can swap to chars, a and b, with:

*a ^= *b;
*b ^= *a;
*a ^= *b;


aah, the crazily named "stupid XOR trick"
Worry about what happens in the middle of the string,
when a and b have the same address.


theoretically, it should just waste a few cpu cycles,
but do nothing. if you abstract yourself from C for a
second and think about XOR as being an
associative (i think it is also commutative) binary operation (in the
mathematical sense) with the identity element 1.
and using the following rule:

x XOR x = 1


That's the opposite of what XOR means.


no is not... here 1 means "the identity"; the identity acted on anything does
nothing. everything i wrote is abstrated to mathematics. in fact you do not even
need to know *what* XOR does to understand why the "stupid CXOR trick" works.
Nov 14 '05 #10
Sam Halliday wrote:
there is no theoretical reason why you cannot have (a_1 = b_1). in fact, i'd
be very worried if this broke, as it means the C XOR operator is not
associative!


hold on... brain freeze. there is no reason why you cannot have (a_1 = b_1), but
the problem is when they share the same address (&a_1 = &b_1). in that case,
things would break and we would be left with the identity 1... which is all
zeros.
Nov 14 '05 #11

On Thu, 22 Jul 2004, Sam Halliday wrote:

Sam Halliday wrote:
there is no theoretical reason why you cannot have (a_1 = b_1). in fact, i'd
be very worried if this broke, as it means the C XOR operator is not
associative!


hold on... brain freeze. there is no reason why you cannot have (a_1 = b_1),
but the problem is when they share the same address (&a_1 = &b_1). in that
case, things would break and we would be left with the identity 1... which
is all zeros.


Your lines are a little long; 75 characters, please. And I hope you're
not going to keep using your own personal terminology in which "the
identity 1" is "all zeros." That's just going to confuse and annoy
people. Better use the term "1" to mean "the number 1," which to a
computer person is about as far from "zero" as you can get.

A programmer would have said,

x XOR x = 0

which is absolutely correct, no matter if we're talking bits or
bytes or long-leggedy beasties. x XOR x is always zero.

-Arthur,
one-bit mind
Nov 14 '05 #12
Arthur J. O'Dwyer wrote:
Your lines are a little long; 75 characters, please.
its generally personal preference. on todays modern screens, i find 82 is much
better. if you have a problem with line wrapping, fix it at your end; most good
email clients are advanced enough to pre-process emails in this fashion. i just
live with it. lets face it... no matter how anyone formats their mail, it will
annoy somebody.
And I hope you're
not going to keep using your own personal terminology in which "the
identity 1" is "all zeros." That's just going to confuse and annoy
people.
yes, perhaps i should have used 'i' to mean the identity. in mathematics, it is
quite common to use 1 to mean the identity. 0 would generally be the null set;
and it is good practise to separate them as they are not always the same. it is
hardly "my own personal terminology"... perhaps foreign to most programmers,
admittedly.
Better use the term "1" to mean "the number 1," which to a
computer person is about as far from "zero" as you can get.

A programmer would have said,

x XOR x = 0

which is absolutely correct, no matter if we're talking bits or
bytes or long-leggedy beasties. x XOR x is always zero.


my point was that you can understand why the "stupid XOR trick" works without
even needing to know what XOR does... just a little about its algebra. in doing
that, it is best to abstract away from 1s and 0s altogether. but, i still should
have used a symbol rather than 1 (or 0) to represent the identity.
Nov 14 '05 #13
On Thu, 22 Jul 2004 15:19:21 +0100, Sam Halliday <em***@example.com>
wrote:
Arthur J. O'Dwyer wrote:
Your lines are a little long; 75 characters, please.


its generally personal preference. on todays modern screens, i find 82 is much
better. if you have a problem with line wrapping, fix it at your end; most good
email clients are advanced enough to pre-process emails in this fashion. i just
live with it. lets face it... no matter how anyone formats their mail, it will
annoy somebody.


Not likely. If you follow the conventions, no one will object. While
we're critiquing you posting style, please get a keyboard with a
working shift key.

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 14 '05 #14
In <20040722151921.78978932@noss> Sam Halliday <em***@example.com> writes:
Arthur J. O'Dwyer wrote:
Your lines are a little long; 75 characters, please.
its generally personal preference.


Bullshit: it's basic Usenet netiquette.
on todays modern screens, i find 82 is much better.
And someone with a larger screen than yours might find 150 much better.
The point is that most alphanumeric terminals are still 80 columns and
some people are still using them, for reasons of their own.
if you have a problem with line wrapping, fix it at your end;
A text line that doesn't fit on a terminal line can't be fixed at the
receiver end: there is no way to compress it to fit. And posts with
wrapped around lines are ugly and less readable.
most good
email clients are advanced enough to pre-process emails in this fashion.
In your stupidity, you have failed to realise that this is not a mailing
list. What email clients do or don't is entirely irrelevant to Usenet.

The last thing you'd want a Usenet client to do is to reformat a
"paragraph" containing C source code.
i just
live with it. lets face it... no matter how anyone formats their mail, it will
annoy somebody.


It doesn't matter, as long as the lines do not exceed 72-75 characters and
are not ludicrously narrow. And, again, we're not talking about mail,
but this aspect seems to be above your understanding capabilities.

If your badly formatted posts don't have some other redeeming quality
(and they don't, unless you consider a combination of arrogance and
stupidity as redeeming quality ;-) most people will start ignoring you
completely.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #15
Sam Halliday wrote:

Arthur J. O'Dwyer wrote:
Your lines are a little long; 75 characters, please.


its generally personal preference. on todays modern screens, i find 82 is much
better. if you have a problem with line wrapping, fix it at your end; most good
email clients are advanced enough to pre-process emails in this fashion. i just
live with it. lets face it... no matter how anyone formats their mail, it will
annoy somebody.

Many people still use 80 width screens. Even though I use a windows
reader on a large screen, I still have the courtesy to set my outgoing
width to 72. This provides room for some reasonable quoting without
screwing up other people for no good reason.

Is it your goal to become irrelevant on this newsgroup?


Brian Rodenborn
Nov 14 '05 #16
Dan Pop wrote:
[flame flame flame]

dan, shut up and stop turning every thread into a flamewar. get back on topic...
which was a discussion about the "stupid XOR trick" and reversing of a string.
if it hasn't already ended.

jesus... if this is what you're like to your peers, i'd hate to think what
computer users at DESY think of you... i'm sure you cause more frustration than
you fix.
Nov 14 '05 #17
Sam Halliday <em***@example.com> writes:
yes, perhaps i should have used 'i' to mean the identity. in mathematics, it is
quite common to use 1 to mean the identity. 0 would generally be the null set;


Perhaps this is a disagreement over fonts. I haven't often seen
zero used as the null set, but a zero with a slash through it is
common. Which one appears as "0" on your screen depends on your
font.
--
"To get the best out of this book, I strongly recommend that you read it."
--Richard Heathfield
Nov 14 '05 #18
Ben Pfaff wrote:
Sam Halliday writes:
yes, perhaps i should have used 'i' to mean the identity. in
mathematics, it is quite common to use 1 to mean the identity. 0 would
generally be the null set;


Perhaps this is a disagreement over fonts. I haven't often seen
zero used as the null set, but a zero with a slash through it is
common. Which one appears as "0" on your screen depends on your
font.


i believe you are correct... and also; it is not really 1 for the identity,
but a "blackboard 1". its a 1 but has 2, very close, vertical lines. i
believe you can get it by using \bbmath{1} in LaTeX. neither seem to be in
the iso-8859-15 character set anyway. maths is always difficult to portray
correctly in plain text.
Nov 14 '05 #19
Sam Halliday <em***@example.com> writes:
Arthur J. O'Dwyer wrote:
Your lines are a little long; 75 characters, please.


its generally personal preference. on todays modern screens, i find
82 is much better. if you have a problem with line wrapping, fix it
at your end; most good email clients are advanced enough to
pre-process emails in this fashion. i just live with it. lets face
it... no matter how anyone formats their mail, it will annoy
somebody.


You'll annoy all of the people some of the time, and some of the
people all of the time -- but if you continue posting 82-column text,
you'll annoy all of the people all of the time.

Ok, that's a slight exaggeration, but trust me on this. Many, perhaps
most, Usenet users use a terminal or emulator configured to display 80
columns, simply because of long tradition. Most, perhaps all, Usenet
client programs do not automatically reformat text to fit the window;
if they did, sample code would become illegible (and I frankly don't
want my newsreader to be smart enough to tell the difference).

If you keep your lines down to 72 to 75 columns, your articles will be
significantly easier to read. Persistently failing to do so is
considered rude. (You might also consider using the occasional upper
case letter, but that's not nearly as annoying as the long lines.)

A quick look at groups.google.com indicates that you're fairly new
here, so I can understand your not knowing all this before -- but now
you do.

Speaking of rudeness, I see you've been the recipient of some abuse in
this thread. I recommend ignoring the abuse, though the technical
points in that response are basically correct.
And I hope you're
not going to keep using your own personal terminology in which "the
identity 1" is "all zeros." That's just going to confuse and annoy
people.


yes, perhaps i should have used 'i' to mean the identity. in
mathematics, it is quite common to use 1 to mean the identity. 0
would generally be the null set; and it is good practise to separate
them as they are not always the same. it is hardly "my own personal
terminology"... perhaps foreign to most programmers, admittedly.


Since C already has an extremely well-defined meaning for the symbol 1,
it seems ill-advised to use it to refer to something else.

--
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.
Nov 14 '05 #20
Keith Thompson wrote:
Sam Halliday writes:
Arthur J. O'Dwyer wrote:
Your lines are a little long; 75 characters, please. its generally personal preference. on todays modern screens, i find
82 is much better. if you have a problem with line wrapping, fix it
at your end; most good email clients are advanced enough to
pre-process emails in this fashion. i just live with it. lets face
it... no matter how anyone formats their mail, it will annoy
somebody.


You'll annoy all of the people some of the time, and some of the
people all of the time -- but if you continue posting 82-column text,
you'll annoy all of the people all of the time.

Ok, that's a slight exaggeration, but trust me on this. Many, perhaps
most, Usenet users use a terminal or emulator configured to display 80
columns, simply because of long tradition.


for the record, my posts were all 80 characters (i forgot 82 is my emacs
setting). however, to appease those trapped in 1984, i have reduced it to
75 [despite most usenet etiquette pages stating 64-70 lines... so 75 is
even crossing the boat]
Since C already has an extremely well-defined meaning for the symbol 1,
it seems ill-advised to use it to refer to something else.
oh yes, that was a mistake. i am sure there are even branches of
mathematics which would have scolded me for such notation. i should have
used 'i' for sure, or at least renamed XOR to something else... possibly
'.' as in that notation, the reason why i chose 1 would have been obvious.
the message was to show, algebraically, why the "stupid XOR trick" works...
i thought it was a cute trick, and not stupid at all; from a mathematical
point of view.
Speaking of rudeness, I see you've been the recipient of some abuse in
this thread. I recommend ignoring the abuse, though the technical
points in that response are basically correct.


thats why i now send in 75 characters... i am prepared to accept advice,
however personal abuse is not called for. it amazes me how many people on
usenet forget that recipients are real people. its childish. however, after
checking the credentials of the people calling me an "idiot" i find it
laughable that they should say such a thing. really. it is also quite
amusing to see that all the threads which go off topic and flamey quickly,
are all 100% guided into it by regulars.

happy Pi approximation day! (yesterday for some, including myself)
http://en.wikipedia.org/wiki/Pi_day
Nov 14 '05 #21
Sam Halliday <em***@example.com> writes:
[...]
for the record, my posts were all 80 characters (i forgot 82 is my emacs
setting). however, to appease those trapped in 1984, i have reduced it to
75 [despite most usenet etiquette pages stating 64-70 lines... so 75 is
even crossing the boat]
Thanks. Keep in mind that if your posts are 80 characters, any
responses quoting them will be 81 or 82, depending on whether the
poster uses ">" or "> " (unless the person posting the followup
reformats the quoted text but not everyone bothers).

[...] thats why i now send in 75 characters... i am prepared to accept advice,
however personal abuse is not called for. it amazes me how many people on
usenet forget that recipients are real people.

[...]

Agreed.

--
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.
Nov 14 '05 #22
In <ln************@nuthaus.mib.org> Keith Thompson <ks***@mib.org> writes:
Thanks. Keep in mind that if your posts are 80 characters, any
responses quoting them will be 81 or 82, depending on whether the
poster uses ">" or "> " (unless the person posting the followup
reformats the quoted text but not everyone bothers).

^^^^^^^^^^^^^^^^^^^^^^^^^
If the quotation marks are automatically added by your client (which is
current practice), it's too late for reformatting the quoted text, unless
you're prepared to do all the extra work of removing the old marks (now
spread all over the reformatted text) and reinserting them where they
belong. Are you willing to do that?

If the client has a builtin editor (e.g. PINE), this editor might be
aware of the special meaning of the quotation marks and preserve them
during the reformatting operation (provided that everybody uses the same
quotation marks). However, this is the exception, rather than the rule
(most Unix text based clients use an external editor).

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #23
Dan Pop wrote on 23/07/04 :
If the quotation marks are automatically added by your client (which is
current practice), it's too late for reformatting the quoted text, unless
you're prepared to do all the extra work of removing the old marks (now
spread all over the reformatted text) and reinserting them where they
belong. Are you willing to do that?


The idiomatic answer is 'get a better client', like XNews...
(PC/Windows)

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

"C is a sharp tool"

Nov 14 '05 #24
Da*****@cern.ch (Dan Pop) writes:
In <ln************@nuthaus.mib.org> Keith Thompson <ks***@mib.org> writes:
Thanks. Keep in mind that if your posts are 80 characters, any
responses quoting them will be 81 or 82, depending on whether the
poster uses ">" or "> " (unless the person posting the followup
reformats the quoted text but not everyone bothers). ^^^^^^^^^^^^^^^^^^^^^^^^^
If the quotation marks are automatically added
by your client (which is current practice),
it's too late for reformatting the quoted text,
unless you're prepared to do all the extra
work of removing the old marks (now spread all
over the reformatted text) and reinserting them
where they belong. Are you willing to do that?


Since you ask, yes, I am, but I don't expect everyone to do so. (Just
for demonstration purposes, I've reformatted the above paragraph to 50
colums while keeping the "> " prefixes.)

The newsreader I use is Gnus, which runs under, and is provided with,
GNU Emacs. The Emacs commands "fill-paragraph" (esc-q) and
"fill-region" handle multiple ">" prefixes correctly in most cases
(though they can get a bit confused if some lines are prefixed with
"> " and some with "> > "). Or I can always pipe a region of text
through "fmt -p'>'".
If the client has a builtin editor (e.g. PINE), this editor might be
aware of the special meaning of the quotation marks and preserve them
during the reformatting operation (provided that everybody uses the same
quotation marks). However, this is the exception, rather than the rule
(most Unix text based clients use an external editor).


Agreed, but any decent text editor under Unix should be able to pipe a
region of text through an external command.

--
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.
Nov 14 '05 #25

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

Similar topics

59
4243
by: Raymond Hettinger | last post by:
Please comment on the new PEP for reverse iteration methods. Basically, the idea looks like this: for i in xrange(10).iter_backwards(): # 9,8,7,6,5,4,3,2,1,0 <do something with i> The...
8
3624
by: Jim Langston | last post by:
I have a class I designed that stores text chat in a std::vector<sd::string>. This class has a few methods to retrieve these strings to be displayed on the screen. void ResetRead( bool Reverse,...
21
3959
by: google | last post by:
I'm trying to implement something that would speed up data entry. I'd like to be able to take a string, and increment ONLY the right-most numerical characters by one. The type structure of the...
20
32995
by: sahukar praveen | last post by:
Hello, I have a question. I try to print a ascii file in reverse order( bottom-top). Here is the logic. 1. Go to the botton of the file fseek(). move one character back to avoid the EOF. 2....
47
4956
by: sudharsan | last post by:
could any one please give me a code to reverse a string of more than 1MB .??? Thanks in advance
41
3337
by: rick | last post by:
Why can't Python have a reverse() function/method like Ruby? Python: x = 'a_string' # Reverse the string print x Ruby: x = 'a_string' # Reverse the string
15
6243
by: rajash | last post by:
Thanks for the additional comments. Here is a solution to an exercise I had problems with. I still don't think it's really what's wanted as it uses a "state variable" n - but I can't see how to...
1
10743
by: sunnyluthra1 | last post by:
Hi, I was creating an Application in MS Access for Geocoding a particular Address from Google to get the Lat & Long. I successfully able to did that. Here is the code:...
38
2672
by: ssecorp | last post by:
char* reverse(char* str) { int length = strlen(str); char* acc; int i; for (i=0; i<=length-1; i++){ acc = str; } return acc; }
0
7234
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,...
0
7136
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...
0
7344
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,...
0
7412
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...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
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 ...
0
441
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...

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.