473,404 Members | 2,187 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,404 software developers and data experts.

How to left pad a string with spaces?

If I have a string say:

myvar[128] = "This is a string";

How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:

" This is a string";
Thanks!
Jun 27 '08 #1
41 12381
nospam <no@spam.comwrites:
If I have a string say:

myvar[128] = "This is a string";

How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:

" This is a string";
If you mean "in place" -- the result ending up in the same array -- then
you can't do it directly because sprintf is undefined if used with
overlapping objects.

Using memmove and memset is, IMO, the simplest way to do this.

--
Ben.
Jun 27 '08 #2
nospam <no@spam.comwrote:
If I have a string say:
myvar[128] = "This is a string";
I guess that's supposed to be

char myvar[128] = "This is a string";
How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:
" This is a string";
sprint() doesn't convert strings, it prints into a string.
It looks as if you would like to use sprintf() with 'myvar'
as both the source and the destination and that's not pos-
sible. The C standard says about this specifically:

If copying takes place between objects that overlap,
the behavior is undefined.

which exactly addresses this situation. So there's no way
you can do this reliably with sprintf().

I guess in the end you want to do something more complicated
but for what you describe you want to do a simple

memmove( myvar + 4, myvar, strlen( myvar ) + 1 );
memset( myvar, ' ', 4 );

will do. Note the use of memmove() instead of memcpy() which
is required since source and destination overlap.

Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Jun 27 '08 #3
On Mon, 09 Jun 2008 23:28:17 +0000, Jens Thoms Toerring wrote:
nospam <no@spam.comwrote:
>If I have a string say:
>myvar[128] = "This is a string";

I guess that's supposed to be

char myvar[128] = "This is a string";
>How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:
>" This is a string";

sprint() doesn't convert strings, it prints into a string.
It looks as if you would like to use sprintf() with 'myvar'
as both the source and the destination and that's not pos-
sible. The C standard says about this specifically:

If copying takes place between objects that overlap,
the behavior is undefined.

which exactly addresses this situation. So there's no way
you can do this reliably with sprintf().

I guess in the end you want to do something more complicated
but for what you describe you want to do a simple

memmove( myvar + 4, myvar, strlen( myvar ) + 1 );
memset( myvar, ' ', 4 );

will do. Note the use of memmove() instead of memcpy() which
is required since source and destination overlap.

Regards, Jens

I need to use sprintf, similar to the legacy code I'm working with.
Something like this:

strncpy(fname,tmp+21,9); fname[9] = '\0';
strncpy(mname,tmp+31,1); mname[1] = '\0';

sprintf(tmp,"%4s%-20s%-20s%-32s%-4s",
" ",fname,mname,lname," ");

Jun 27 '08 #4
On Tue, 10 Jun 2008 00:17:45 +0100, Ben Bacarisse wrote:
nospam <no@spam.comwrites:
>If I have a string say:

myvar[128] = "This is a string";

How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:

" This is a string";

If you mean "in place" -- the result ending up in the same array -- then
you can't do it directly because sprintf is undefined if used with
overlapping objects.

Using memmove and memset is, IMO, the simplest way to do this.


I need to use sprintf, similar to the legacy code I'm working with.
Something like this:

strncpy(fname,tmp+21,9); fname[9] = '\0';
strncpy(mname,tmp+31,1); mname[1] = '\0';

sprintf(tmp,"%4s%-20s%-20s%-32s%-4s",
" ",fname,mname,lname," ");

Jun 27 '08 #5
nospam wrote:
>
If I have a string say:

myvar[128] = "This is a string";

How do I use sprintf to convert the string so it has 4 spaces
padded on the left like:

" This is a string";
For example, assuming you know s has space for the extra chars:

void sstretch(char *s, int amount) {
char *p1, *p2;

if (amount) {
pi = strchr(s, '\0');
if ((p1 s) && amount) {
p2 = p1 + amount;
do { /* move the string */
*p2-- = *p1--;
} while {p1 s);
}
while (amount) { /* inject the blanks */
*s++ = ' ';
amount--;
}
}
} /* untested */

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #6
nospam <no@spam.comwrites:
On Tue, 10 Jun 2008 00:17:45 +0100, Ben Bacarisse wrote:
>nospam <no@spam.comwrites:
>>If I have a string say:

myvar[128] = "This is a string";

How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:

" This is a string";

If you mean "in place" -- the result ending up in the same array -- then
you can't do it directly because sprintf is undefined if used with
overlapping objects.

Using memmove and memset is, IMO, the simplest way to do this.

I need to use sprintf, similar to the legacy code I'm working with.
Something like this:
Why do you *need* to do it any particular way? I suspect we mean
different things by "need".
strncpy(fname,tmp+21,9); fname[9] = '\0';
strncpy(mname,tmp+31,1); mname[1] = '\0';

sprintf(tmp,"%4s%-20s%-20s%-32s%-4s",
" ",fname,mname,lname," ");
If you *must* use sprintf, what would constitute use of sprintf?
Would this count?

memmove(myvar + 4, myvar, strlen(myvar) + 1);
sprintf(myvar, " ");
myvar[3] = ' ';

what about:

memmove(myvar + 4, myvar, strlen(myvar) + 1);
memset(myvar, ' ', 4);
sprintf(myvar + strlen(myvar), "");

?

All of this assumes that you need it done in-place. It is just
possible that what you are asking for is:

sprintf(tmp, " %s", myvar);

but that seems so obvious as to be an unlikely question.

--
Ben.
Jun 27 '08 #7
CBFalconer <cb********@yahoo.comwrites:
nospam wrote:
>>
If I have a string say:

myvar[128] = "This is a string";

How do I use sprintf to convert the string so it has 4 spaces
padded on the left like:

" This is a string";

For example, assuming you know s has space for the extra chars:

void sstretch(char *s, int amount) {
char *p1, *p2;

if (amount) {
pi = strchr(s, '\0');
if ((p1 s) && amount) {
p2 = p1 + amount;
do { /* move the string */
*p2-- = *p1--;
} while {p1 s);
}
while (amount) { /* inject the blanks */
*s++ = ' ';
amount--;
}
}
} /* untested */
Yuck. Two typos and two logic errors. You complain about not posting
corrections, so the correction is:

void sstretch(char *s, size_t amount)
{
memmove(s + amount, s, strlen(s) + 1);
memset(s, ' ', amount);
}

Why would you do all those gymnastics with the potential (so well
demonstrated) for errors?

--
Ben.
Jun 27 '08 #8
Ben Bacarisse <be********@bsb.me.ukwrites:
CBFalconer <cb********@yahoo.comwrites:
>nospam wrote:
>>>
If I have a string say:

myvar[128] = "This is a string";

How do I use sprintf to convert the string so it has 4 spaces
padded on the left like:

" This is a string";

For example, assuming you know s has space for the extra chars:

void sstretch(char *s, int amount) {
char *p1, *p2;

if (amount) {
pi = strchr(s, '\0');
if ((p1 s) && amount) {
p2 = p1 + amount;
do { /* move the string */
*p2-- = *p1--;
} while {p1 s);
}
while (amount) { /* inject the blanks */
*s++ = ' ';
amount--;
}
}
} /* untested */

Yuck. Two typos and two logic errors. You complain about not posting
corrections, so the correction is:

void sstretch(char *s, size_t amount)
{
memmove(s + amount, s, strlen(s) + 1);
memset(s, ' ', amount);
}

Why would you do all those gymnastics with the potential (so well
demonstrated) for errors?
I would also point out to the beginner, and "Chuck", to read the man
pages and to see why memmove is better than memcpy in this and other
situations. What the hell is that horrific mess above the correct
solution?!?!
Jun 27 '08 #9
Richard<rg****@gmail.comwrites:
Ben Bacarisse <be********@bsb.me.ukwrites:
<snip>
>void sstretch(char *s, size_t amount)
{
memmove(s + amount, s, strlen(s) + 1);
memset(s, ' ', amount);
}

I would also point out to the beginner, and "Chuck", to read the man
pages and to see why memmove is better than memcpy in this and other
situations.
That is an odd way of putting it. memmove is *essential* in this
situation. In other situations memcpy may be better. I did not
explain because someone else has already done so.

--
Ben.
Jun 27 '08 #10
Ben Bacarisse <be********@bsb.me.ukwrites:
Richard<rg****@gmail.comwrites:
>Ben Bacarisse <be********@bsb.me.ukwrites:
<snip>
>>void sstretch(char *s, size_t amount)
{
memmove(s + amount, s, strlen(s) + 1);
memset(s, ' ', amount);
}

I would also point out to the beginner, and "Chuck", to read the man
pages and to see why memmove is better than memcpy in this and other
situations.

That is an odd way of putting it. memmove is *essential* in this
situation. In other situations memcpy may be better. I did not
explain because someone else has already done so.
I didnt see any other post on the matter. "better" is mentioned to get
people to read the man pages. Self help and all that. I see nothing odd
at all in mentioning it as "better".
Jun 27 '08 #11
Richard<rg****@gmail.comwrites:
Ben Bacarisse <be********@bsb.me.ukwrites:
>Richard<rg****@gmail.comwrites:
>>Ben Bacarisse <be********@bsb.me.ukwrites:
<snip>
>>>void sstretch(char *s, size_t amount)
{
memmove(s + amount, s, strlen(s) + 1);
memset(s, ' ', amount);
}
I would also point out to the beginner, and "Chuck", to read the man
pages and to see why memmove is better than memcpy in this and other
situations.

That is an odd way of putting it. memmove is *essential* in this
situation. In other situations memcpy may be better. I did not
explain because someone else has already done so.

I didnt see any other post on the matter.
Message ID: <6b*************@mid.uni-berlin.de Jens Thoms Toerring:

"Note the use of memmove() instead of memcpy() which is required
since source and destination overlap."

--
Ben.
Jun 27 '08 #12
nospam wrote:
If I have a string say:

myvar[128] = "This is a string";

How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:

" This is a string";

/* BEGIN new.c */

#include <stdio.h>

int main(void)
{
char myvar[128] = "This is a string";

sprintf(myvar, "%20s", "This is a string");
puts(myvar);
return 0;
}

/* END new.c */

--
pete
Jun 27 '08 #13
On Jun 10, 7:57 am, Richard<rgr...@gmail.comwrote:
Ben Bacarisse <ben.use...@bsb.me.ukwrites:
CBFalconer <cbfalco...@yahoo.comwrites:
nospam wrote:
>If I have a string say:
>myvar[128] = "This is a string";
>How do I use sprintf to convert the string so it has 4 spaces
padded on the left like:
>" This is a string";
For example, assuming you know s has space for the extra chars:
void sstretch(char *s, int amount) {
char *p1, *p2;
if (amount) {
pi = strchr(s, '\0');
if ((p1 s) && amount) {
p2 = p1 + amount;
do { /* move the string */
*p2-- = *p1--;
} while {p1 s);
}
while (amount) { /* inject the blanks */
*s++ = ' ';
amount--;
}
}
} /* untested */
Yuck. Two typos and two logic errors. You complain about not posting
corrections, so the correction is:
void sstretch(char *s, size_t amount)
{
memmove(s + amount, s, strlen(s) + 1);
memset(s, ' ', amount);
}
Why would you do all those gymnastics with the potential (so well
demonstrated) for errors?

I would also point out to the beginner, and "Chuck", to read the man
pages and to see why memmove is better than memcpy in this and other
situations. What the hell is that horrific mess above the correct
solution?!?!
Other than the overlapping memory case, how is memmove supposed to be
better than memcpy?
I am unaware of any other scenario in which memmove is better than
memcpy.
Jun 27 '08 #14
Ben Bacarisse wrote:
CBFalconer <cb********@yahoo.comwrites:
.... snip ...
>
> void sstretch(char *s, int amount) {
char *p1, *p2;

if (amount) {
pi = strchr(s, '\0');
if ((p1 s) && amount) {
p2 = p1 + amount;
do { /* move the string */
*p2-- = *p1--;
} while {p1 s);
}
while (amount) { /* inject the blanks */
*s++ = ' ';
amount--;
}
}
} /* untested */

Yuck. Two typos and two logic errors. You complain about not posting
corrections, so the correction is:

void sstretch(char *s, size_t amount)
{
memmove(s + amount, s, strlen(s) + 1);
memset(s, ' ', amount);
}
One does it for the exercise. I see only one typo [while {p1 >
s)]] and one unnecessary test [&& amount]. A compilation may well
show up more. What did you see?

Incidentally, a speed comparison would be interesting. I don't
think your version allows for amount == 0 and for an empty original
string. I would have to check the specs for memove and memset with
care.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #15
Ben Bacarisse wrote:
Richard<rg****@gmail.comwrites:
>Ben Bacarisse <be********@bsb.me.ukwrites:
<snip>
>>void sstretch(char *s, size_t amount)
{
memmove(s + amount, s, strlen(s) + 1);
memset(s, ' ', amount);
}

I would also point out to the beginner, and "Chuck", to read the
man pages and to see why memmove is better than memcpy in this
and other situations.

That is an odd way of putting it. memmove is *essential* in this
situation. In other situations memcpy may be better. I did not
explain because someone else has already done so.
Richard is a troll. I didn't use memmove, but did the move coding
directly.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

** Posted from http://www.teranews.com **
Jun 27 '08 #16
Ben Bacarisse said:
Richard<rg****@gmail.comwrites:
>Ben Bacarisse <be********@bsb.me.ukwrites:
<snip>
>>void sstretch(char *s, size_t amount)
{
memmove(s + amount, s, strlen(s) + 1);
memset(s, ' ', amount);
}

I would also point out to the beginner, and "Chuck", to read the man
pages and to see why memmove is better than memcpy in this and other
situations.

That is an odd way of putting it. memmove is *essential* in this
situation.
Um, no, it isn't. You /can/ bully the bytes around by hand if you prefer
(but if you do so, you need to push them *just so*, or they'll turn on
you). If you just meant that memcpy is a non-starter here, then of course
I agree.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #17
rio

"nospam" <no@spam.comha scritto nel messaggio
news:co******************************@comcast.com. ..
If I have a string say:

myvar[128] = "This is a string";

How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:
>
" This is a string";
Thanks!
it not use sprint not tested

/* return the string if ok
0 if error
using like:
char *pc;
char *s="This is a string"

if((pc=the4spaces(s))==0) Error();
use(pc);
....
free(pc);
*/
char* the4spaces(char* s)
{char *p1, *p2, p;
unsigned c, sz;
/********************/
if(s==0) return 0;
if( (int) (sz=strlen(s)) < 0) return 0;
p=p2=malloc(sz+8);
if(p2==0) return 0;
p1=s;
while( *p1 && (*p1==' '||*p1=='\t')) ++p1;
*p2++=' '; *p2++=' '; *p2++=' '; *p2++=' ';
while(*p2++=*p1++);
return p;
}

Jun 27 '08 #18
pete <pf*****@mindspring.comwrites:
nospam wrote:
>If I have a string say:
myvar[128] = "This is a string";
How do I use sprintf to convert the string so it has 4 spaces padded
on
the left like:
" This is a string";


/* BEGIN new.c */

#include <stdio.h>

int main(void)
{
char myvar[128] = "This is a string";

sprintf(myvar, "%20s", "This is a string");
puts(myvar);
return 0;
}

/* END new.c */
And what if the declaration is changed to:

char myvar[128] = "This is a string too";

? The requirement is to insert 4 spaces, not to deal just with that
one particular string. If it were, the sprintf call could be changed
to:

strcpy(myvar, " This is a string");

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #19
On 10 Jun, 02:48, nospam <n...@spam.comwrote:
On Mon, 09 Jun 2008 23:28:17 +0000, Jens Thoms Toerring wrote:
nospam <n...@spam.comwrote:
If I have a string say:
myvar[128] = "This is a string";
I guess that's supposed to be
char myvar[128] = "This is a string";
How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:
" * *This is a string";
sprint() doesn't convert strings, it prints into a string.
It looks as if you would like to use sprintf() with 'myvar'
as both the source and the destination and that's not pos-
sible. The C standard says about this specifically:
* If copying takes place between objects that overlap,
* the behavior is undefined.
which exactly addresses this situation. So there's no way
you can do this reliably with sprintf().
I guess in the end you want to do something more complicated
but for what you describe you want to do a simple
memmove( myvar + 4, myvar, strlen( myvar ) + 1 );
memset( myvar, ' ', 4 );
will do. Note the use of memmove() instead of memcpy() which
is required since source and destination overlap.
* * * * * * * * * * * * * * Regards, Jens

I need to use sprintf, similar to the legacy code I'm working with.
Something like this:

strncpy(fname,tmp+21,9); fname[9] = '\0';
strncpy(mname,tmp+31,1); mname[1] = '\0';

sprintf(tmp,"%4s%-20s%-20s%-32s%-4s",
* * * * * * " ",fname,mname,lname," ");- Hide quoted text -
why do you need to use sprintf()?
(several other people have asked you this but you didn't reply)

--
Nick Keighley


Jun 27 '08 #20
rio

"rio" <a@b.cha scritto nel messaggio
news:48***********************@reader2.news.tin.it ...
>
"nospam" <no@spam.comha scritto nel messaggio
news:co******************************@comcast.com. ..
>If I have a string say:

myvar[128] = "This is a string";

How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:
>>
" This is a string";
Thanks!

it not use sprint not tested

/* return the string if ok
0 if error
using like:
char *pc;
char *s="This is a string"

if((pc=the4spaces(s))==0) Error();
use(pc);
....
free(pc);
*/
char* the4spaces(char* s)
{char *p1, *p2, p;
unsigned c, sz;
/********************/
if(s==0) return 0;
if( (int) (sz=strlen(s)) < 0) return 0;
p=p2=malloc(sz+8);
if(p2==0) return 0;
p1=s;
while( *p1 && (*p1==' '||*p1=='\t')) ++p1;
*p2++=' '; *p2++=' '; *p2++=' '; *p2++=' ';
while(*p2++=*p1++);
return p;
}
the CBFalconer way

/*
sz is the space memory size
not tested
*/

unsigned the4spaces(char* s, unsigned sz)
{char *p1, *p2;
unsigned c;
/********************/
if(s==0) return 1; /* nothing error */
if((int)sz<=4) return 2; /* error */
c=strlen(s);
if(c<0 || c+4>=sz) return 3;
p1=s+c+4; p2=s+c;
while(p2>=s) {*p1=*p2; --p1; --p2;}
s[0]=' '; s[1]=' '; s[2]=' '; s[3]=' ';
return 0; /* ok */
}

/*
one better version?
d should be mallocched or 0
e.g.
char *d=0;
unsigned sz=0;
----
if((sz=the4spaces(&d, sz, string))==0) error();
free(*d);
----------
*/

unsigned the4spaces(char** d, unsigned sz, char* s)
{char *p1, *p2, p;
unsigned c, sz, r;
/********************/
if(s==0) goto l0;
if( (int) (c=strlen(s)) < 0)
goto l0;
r=sz;
if(c+4+1<sz)
{if( p=realloc(*d, c+8)==0)
{l0:;
free(*d); *d=0; return 0;
}
r=c+8;
}
p1=s; p2=p; *d=p;
while( *p1 && (*p1==' '||*p1=='\t')) ++p1;
*p2++=' '; *p2++=' '; *p2++=' '; *p2++=' ';
while(*p2++=*p1++);
return r;
}

Jun 27 '08 #21
rio

"rio" <a@b.cha scritto nel messaggio news:484e3100$0$18150/*
one better version?
d should be mallocched or 0
e.g.
char *d=0;
unsigned sz=0;
----
if((sz=the4spaces(&d, sz, string))==0) error();
free(*d);
----------
*/

unsigned the4spaces(char** d, unsigned sz, char* s)
{char *p1, *p2, p;
unsigned c, sz, r;
/********************/
if(s==0) goto l0;
if( (int) (c=strlen(s)) < 0)
goto l0;
r=sz;
p=*d;
if(c+4+1<sz)
{if( p=realloc(*d, c+8)==0)
{l0:;
free(*d); *d=0; return 0;
}
r=c+8;
*d=p
}
p1=s; p2=p; *d=p;
^^^^^^^not
p1=s; p2=p;
while( *p1 && (*p1==' '||*p1=='\t')) ++p1;
*p2++=' '; *p2++=' '; *p2++=' '; *p2++=' ';
while(*p2++=*p1++);
return r;
}


Jun 27 '08 #22
rio

"rio" <a@b.cha scritto nel messaggio
news:48***********************@reader5.news.tin.it ...
>
"rio" <a@b.cha scritto nel messaggio news:484e3100$0$18150/*
> one better version?
d should be mallocched or 0
e.g.
char *d=0;
unsigned sz=0;
----
if((sz=the4spaces(&d, sz, string))==0) error();
free(*d);
----------
*/

unsigned the4spaces(char** d, unsigned sz, char* s)
{char *p1, *p2, p;
unsigned c, sz, r;
/********************/
if(s==0) goto l0;
if( (int) (c=strlen(s)) < 0)
goto l0;
r=sz;
p=*d;
> if(c+4+1<sz)
{if( p=realloc(*d, c+8)==0)
arrrrrrrrrrrrrhhgjgjg ^^^^^^^^^^^^^^
if( (p=realloc(*d, c+8))==0)
> {l0:;
free(*d); *d=0; return 0;
}
r=c+8;
*d=p
> }
p1=s; p2=p; *d=p;
^^^^^^^not
p1=s; p2=p;
>while( *p1 && (*p1==' '||*p1=='\t')) ++p1;
*p2++=' '; *p2++=' '; *p2++=' '; *p2++=' ';
while(*p2++=*p1++);
return r;
}
this seems good
not know if compile

Jun 27 '08 #23
rio

"CBFalconer" <cb********@yahoo.comha scritto nel messaggio
news:48***************@yahoo.com...
Ben Bacarisse wrote:
>CBFalconer <cb********@yahoo.comwrites:
... snip ...
>>
>> void sstretch(char *s, int amount) {
char *p1, *p2;

if (amount) {
pi = strchr(s, '\0');
if ((p1 s) && amount) {
p2 = p1 + amount;
do { /* move the string */
*p2-- = *p1--;
} while {p1 s);
}
while (amount) { /* inject the blanks */
*s++ = ' ';
amount--;
}
}
} /* untested */

Yuck. Two typos and two logic errors. You complain about not posting
corrections, so the correction is:

void sstretch(char *s, size_t amount)
{
memmove(s + amount, s, strlen(s) + 1);
memset(s, ' ', amount);
}

One does it for the exercise. I see only one typo [while {p1 >
s)]] and one unnecessary test [&& amount]. A compilation may well
show up more. What did you see?
>> pi = strchr(s, '\0');
seems an error; should be p1= strchr(s, '\0');?
Incidentally, a speed comparison would be interesting. I don't
think your version allows for amount == 0 and for an empty original
string. I would have to check the specs for memove and memset with
care.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **

Jun 27 '08 #24
nospam <no@spam.comwrote:
On Mon, 09 Jun 2008 23:28:17 +0000, Jens Thoms Toerring wrote:
nospam <no@spam.comwrote:
If I have a string say:
myvar[128] = "This is a string";
I guess that's supposed to be

char myvar[128] = "This is a string";
How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:
" This is a string";
I need to use sprintf, similar to the legacy code I'm working with.
Something like this:
strncpy(fname,tmp+21,9); fname[9] = '\0';
strncpy(mname,tmp+31,1); mname[1] = '\0';
sprintf(tmp,"%4s%-20s%-20s%-32s%-4s",
" ",fname,mname,lname," ");
This one is fine since before your print into tmp you
obviously copy the bits from tmp you still need to some
other place. And then you write something completely
new into tmp, using what you had copied to a safe place.

So if you would have a second array to store what myvar
holds, then of course you can print into myvar afterwards
with sprintf() like in

char myvar[ 128 ] = "This is a string";
char buf[ 124 ];

strncpy( buf, myvar, 123 );
buf[ 123 ] = '\0';

sprintf( myvar, " %s", buf );

Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Jun 27 '08 #25
On 10 Jun 2008 at 0:04, CBFalconer wrote:
if (amount) {
pi = strchr(s, '\0');
if ((p1 s) && amount) {
Got to love this. A condition as redundant as it is ugly.

Jun 27 '08 #26
Richard Heathfield <rj*@see.sig.invalidwrites:
Ben Bacarisse said:
>Richard<rg****@gmail.comwrites:
>>Ben Bacarisse <be********@bsb.me.ukwrites:
<snip>
>>>void sstretch(char *s, size_t amount)
{
memmove(s + amount, s, strlen(s) + 1);
memset(s, ' ', amount);
}
I would also point out to the beginner, and "Chuck", to read the man
pages and to see why memmove is better than memcpy in this and other
situations.

That is an odd way of putting it. memmove is *essential* in this
situation.

Um, no, it isn't. You /can/ bully the bytes around by hand if you prefer
(but if you do so, you need to push them *just so*, or they'll turn on
you). If you just meant that memcpy is a non-starter here, then of course
I agree.
What do you think, seriously? Did you think I had forgotten, for a
moment, that one could just move the data about "by hand"? Were you
worried that people new to C would take that remark and think that
there was absolutely only one function that can be used here[1]? It was
in a direct reply to "memmove is better than memcpy".

Does every statement have to true when clipped out of context? If I
had instead used your phrase "memcpy is a non-starter here" would you
have come back with "Um, no. You /can/ use an auxiliary array."?

[1] OK, so you can tell I am little annoyed by this level of nit-
picking so here is a related story to lighten the tone: When I was
about six and I heard a pipe band was playing "Scotland the Brave".
It seemed they always played that, so I asked my father if this is the
only tune the bagpipes can play. He replied, voice no doubt dripping
with sarcasm, "Yes, it's a musical instrument that can only play one
tune". The sarcasm went right over my six year old head and I for
years, whenever I head the pipes I used to think "that must be another
part of Scotland the Brave I don't know". Logic forced me to assume
it was the longest tune ever written.

So, yes, beginners can be thrown by authoritative statements taken out
of context, but I dispute that that was a real and present danger in
this case.

--
Ben.
Jun 27 '08 #27
"rio" <a@b.cwrites:

<lost of code snipped>
this seems good
not know if compile
Despite the almost deliberate attempt to obscure the code I spotted
errors in all the versions you posted. Why not take a little more
time, think about the solution, and do some testing?

--
Ben.
Jun 27 '08 #28
Ben Bacarisse said:
Richard Heathfield <rj*@see.sig.invalidwrites:
>Ben Bacarisse said:
<snip>
>>>
That is an odd way of putting it. memmove is *essential* in this
situation.

Um, no, it isn't. You /can/ bully the bytes around by hand if you prefer
(but if you do so, you need to push them *just so*, or they'll turn on
you). If you just meant that memcpy is a non-starter here, then of
course I agree.

What do you think, seriously?
That your (previous) reply was composed and posted swiftly.
Did you think I had forgotten, for a
moment, that one could just move the data about "by hand"?
No.
Were you
worried that people new to C would take that remark and think that
there was absolutely only one function that can be used here[1]?
Yes.
It was in a direct reply to "memmove is better than memcpy".
Yes, I know, but it was also rather poorly worded.
Does every statement have to true when clipped out of context?
I left the context in place, but I still think that "essential" is a
sufficiently forceful word that there was a risk of its overwhelming that
context, which is why I replied as I did.
If I
had instead used your phrase "memcpy is a non-starter here" would you
have come back with "Um, no. You /can/ use an auxiliary array."?
I don't think so, no - memcpy /is/ a non-starter because you have to do the
byte shuffle - into temp, then back into the original array - and whilst
that's doable, it's a bit lame.
[1] OK, so you can tell I am little annoyed by this level of nit-
picking
You might want to pick up a slightly thicker skin from Tesco or Sears or
wherever. I've been nitpicked a lot worse than that, and lived to tell the
tale. :-)
so here is a related story to lighten the tone: When I was
about six and I heard a pipe band was playing "Scotland the Brave".
It seemed they always played that, so I asked my father if this is the
only tune the bagpipes can play. He replied, voice no doubt dripping
with sarcasm, "Yes, it's a musical instrument that can only play one
tune". The sarcasm went right over my six year old head
Parents really can be [********] sometimes, can't they?

<snip>
So, yes, beginners can be thrown by authoritative statements taken out
of context, but I dispute that that was a real and present danger in
this case.
I think you'd have been right to dispute it, say, ten years ago, or maybe
even five.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #29
Ben Bacarisse wrote:
"rio" <a@b.cwrites:

<lost of code snipped>
>this seems good
not know if compile

Despite the almost deliberate attempt to obscure the code I spotted
errors in all the versions you posted. Why not take a little more
time, think about the solution, and do some testing?
This guy is notorious for obscuring _all_ of his code, not just C. You
should look at his custom x86 assembler language is alt.lang.asm
sometime. No amount of argument over the years has seemed to convince
him of the benefits of legible code.

Jun 27 '08 #30
rio

"Ben Bacarisse" <be********@bsb.me.ukha scritto nel messaggio
news:87************@bsb.me.uk...
"rio" <a@b.cwrites:

<lost of code snipped>
>this seems good
not know if compile

Despite the almost deliberate attempt to obscure the code I spotted
errors in all the versions you posted. Why not take a little more
time, think about the solution, and do some testing?
????
i miss all your post in my server news that correct myself
the only one that answe me that i see is this one above

have you not good news server? :)

anyway the last one should be correct if i add
if(d==0) goto l0;

--
Ben.


Jun 27 '08 #31
CBFalconer <cb********@yahoo.comwrites:
Ben Bacarisse wrote:
>CBFalconer <cb********@yahoo.comwrites:
... snip ...
>>
>> void sstretch(char *s, int amount) {
char *p1, *p2;

if (amount) {
pi = strchr(s, '\0');
if ((p1 s) && amount) {
p2 = p1 + amount;
do { /* move the string */
*p2-- = *p1--;
} while {p1 s);
}
while (amount) { /* inject the blanks */
*s++ = ' ';
amount--;
}
}
} /* untested */

Yuck. Two typos and two logic errors. You complain about not posting
corrections, so the correction is:

void sstretch(char *s, size_t amount)
{
memmove(s + amount, s, strlen(s) + 1);
memset(s, ' ', amount);
}

One does it for the exercise.
But if you don't test it (or think about it enough) you get only the
illusion of exercising your C brain whereas, in fact, you are just
putting on "bug flab".
I see only one typo [while {p1 >
s)]] and one unnecessary test [&& amount]. A compilation may well
show up more. What did you see?
pi in place of p1. The two logic bugs are:

(1) the loop does not run to the end -- you leave an un-copied
character. Note that this is slightly trick to correct.

(2) when the original string is empty (and amount 0) you just write
spaces over the null.
Incidentally, a speed comparison would be interesting. I don't
think your version allows for amount == 0
I disagree, but if you think there is a problem, please quote C&V --
it seem fine by my reading. While we are being incidental, your code
does not check for amount < 0 but I decided that was not a bug but an
undocumented contract with the caller.
and for an empty original
string.
How ironic. You code breaks in that case. What problem do you see in
my version? As I say, it seems fine by my reading of the standard but
I am open to wiser interpretations.
I would have to check the specs for memove and memset with
care.
That would seem to be a staring point, not something to leave until
after you've suggested someone else is wrong.

--
Ben.
Jun 27 '08 #32
On Mon, 09 Jun 2008 18:57:04 -0400, nospam <no@spam.comwrote:
>If I have a string say:

myvar[128] = "This is a string";

How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:

" This is a string";
Thanks!
As long as your array is at least twice as long as (your string plus
the number of spaces to insert):
sprintf(myvar+64, "%s", myvar);
sprintf(myvar, " %s", myvar+64);
Remove del for email
Jun 27 '08 #33
rio

"rio" <a@b.cha scritto nel messaggio
news:48***********************@reader1.news.tin.it ...
>
"Ben Bacarisse" <be********@bsb.me.ukha scritto nel messaggio
news:87************@bsb.me.uk...
>"rio" <a@b.cwrites:

<lost of code snipped>
>>this seems good
not know if compile

Despite the almost deliberate attempt to obscure the code I spotted
errors in all the versions you posted. Why not take a little more
time, think about the solution, and do some testing?
I have not the C compiler here under my hands
so i write code without testing
????
i miss all your post in my server news that correct myself
the only one that answe me that i see is this one above

have you not good news server? :)

anyway the last one should be correct if i add
if(d==0) goto l0;
better if(d==0) return 0;

Don't you like my last creation? it will be not much fast

/*
d should be mallocched or 0
e.g.
char *d=0;
unsigned sz=0;
----
if((sz=the4spaces(&d, sz, string))==0) error();
free(*d);
----------
*/
%define SPAZI 4

unsigned the4spaces(char** d, unsigned sz, char* s)
{char *p1, *p2, p;
unsigned c, r;
/********************/
if(d==0||SPAZI<0) return 0;
if(s==0) goto l0;
if( (int) (c=strlen(s)) < 0) goto l0;
r=sz; p=*d;
if(c+SPAZI +1<sz)
{if( (p=realloc(*d, c+8))==0 )
{l0:; free(*d); *d=0; return 0;}
r=c+8; *d=p;}
p1=s; p2=p;
while( *p1 && (*p1==' '||*p1=='\t')) ++p1;
for(c=0; c<SPAZI ; ++c, ++p2) *p2=' '
while(*p2++=*p1++);
return r;}


Jun 27 '08 #34
rio

"rio" <a@b.cha scritto nel messaggio
news:48***********************@reader4.news.tin.it ...
>"Ben Bacarisse" <be********@bsb.me.ukha scritto nel messaggio
news:87************@bsb.me.uk...
>>"rio" <a@b.cwrites:
So how many errors do you see?
[whithout use the compiler and with the use of the compiler]
/*
d should be mallocched or 0
e.g.
char *d=0;
unsigned sz=0;
----
if((sz=the4spaces(&d, sz, string))==0) error();
free(*d);
----------
*/
%define SPAZI 4

unsigned the4spaces(char** d, unsigned sz, char* s)
{char *p1, *p2, p;
unsigned c, r;
/********************/
if(d==0||SPAZI<0) return 0;
if(s==0) goto l0;
if( (int) (c=strlen(s)) < 0) goto l0;
r=sz; p=*d;
if(c+SPAZI +1<sz)
{if( (p=realloc(*d, c+ SPAZI+8))==0 )
{l0:; free(*d); *d=0; return 0;}
r=c+ SPAZI +8; *d=p;}
p1=s; p2=p;
while( *p1 && (*p1==' '||*p1=='\t')) ++p1;
for(c=0; c<SPAZI ; ++c, ++p2) *p2=' '
while(*p2++=*p1++);
return r;}


Jun 27 '08 #35
Barry Schwarz <sc******@dqel.comwrites:
On Mon, 09 Jun 2008 18:57:04 -0400, nospam <no@spam.comwrote:
>>If I have a string say:

myvar[128] = "This is a string";

How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:

" This is a string";

As long as your array is at least twice as long as (your string plus
the number of spaces to insert):
sprintf(myvar+64, "%s", myvar);
sprintf(myvar, " %s", myvar+64);
I don't think that is permitted:

7.19.6.6 The sprintf function

... If copying takes place between objects that overlap, the
behavior is undefined.

It does not say "between /regions/ of objects that overlap". It seems
any overlap is enough to render it undefined.

--
Ben.
Jun 27 '08 #36
rio wrote:
"rio" <a@b.cha scritto nel messaggio
news:48***********************@reader4.news.tin.it ...
>>"Ben Bacarisse" <be********@bsb.me.ukha scritto nel messaggio
news:87************@bsb.me.uk...
"rio" <a@b.cwrites:

So how many errors do you see?
[whithout use the compiler and with the use of the compiler]
That's the problem with code and coding style: without running it thru a
compiler it is next to impossibe to detect the bugs.
Your code is just not writte for human consumption, and even you have
problems with it, hence the multiple versions you post to correct yourself.

Bye, Jojo
Jun 27 '08 #37
Ben Bacarisse wrote:
CBFalconer <cb********@yahoo.comwrites:
>Ben Bacarisse wrote:
>>CBFalconer <cb********@yahoo.comwrites:
... snip ...
>>>
void sstretch(char *s, int amount) {
char *p1, *p2;

if (amount) {
pi = strchr(s, '\0');
if ((p1 s) && amount) {
p2 = p1 + amount;
do { /* move the string */
*p2-- = *p1--;
} while {p1 s);
}
while (amount) { /* inject the blanks */
*s++ = ' ';
amount--;
}
}
} /* untested */

Yuck. Two typos and two logic errors. You complain about not
posting corrections, so the correction is:
.... snip ...
>>
One does it for the exercise.

But if you don't test it (or think about it enough) you get only the
illusion of exercising your C brain whereas, in fact, you are just
putting on "bug flab".
>I see only one typo [while {p1 s)]] and one unnecessary test
[&& amount]. A compilation may well show up more. What did you see?

pi in place of p1. The two logic bugs are:

(1) the loop does not run to the end -- you leave an un-copied
character. Note that this is slightly trick to correct.

(2) when the original string is empty (and amount 0) you just
write spaces over the null.
More than I expected. I guess I am getting sloppy. Well, I did
mark it 'untested', and say 'something like this'. :-)

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #38
On Tue, 10 Jun 2008 19:27:31 +0100, Ben Bacarisse
<be********@bsb.me.ukwrote:
>Barry Schwarz <sc******@dqel.comwrites:
>On Mon, 09 Jun 2008 18:57:04 -0400, nospam <no@spam.comwrote:
>>>If I have a string say:

myvar[128] = "This is a string";

How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:

" This is a string";

As long as your array is at least twice as long as (your string plus
the number of spaces to insert):
sprintf(myvar+64, "%s", myvar);
sprintf(myvar, " %s", myvar+64);

I don't think that is permitted:

7.19.6.6 The sprintf function

... If copying takes place between objects that overlap, the
behavior is undefined.

It does not say "between /regions/ of objects that overlap". It seems
any overlap is enough to render it undefined.
It seems that the term "object" is not used with great precision here.

What would happen if myvar were defined as
char myvar[2][64] = {"This ..."};
and in the calls to sprintf each use of myvar was cast to char*?
myvar[0] and [1] are objects that do not overlap but both are part of
the object myvar. Is this overlap? Would it be overlap if the
arguments were changed to myvar[0] and myvar[1]?

What about
char *myvar = malloc(128);
strcpy(myvar, "This ...");
There are no objects here so no objects can overlap.

The compiler will probably generate the same code for the three sets
of calls to sprintf. It doesn't seem right (tm) that the same code
generated from essentially identical source statements should be
undefined, questionable, and well defined, respectively.

I will assert that the intent of the word object in this section is
meant to refer to the source and destination strings and therefore
under the conditions I postulated there is no overlap.
Remove del for email
Jun 27 '08 #39
Barry Schwarz <sc******@dqel.comwrites:
On Tue, 10 Jun 2008 19:27:31 +0100, Ben Bacarisse
<be********@bsb.me.ukwrote:
>>Barry Schwarz <sc******@dqel.comwrites:
>>On Mon, 09 Jun 2008 18:57:04 -0400, nospam <no@spam.comwrote:

If I have a string say:

myvar[128] = "This is a string";

How do I use sprintf to convert the string so it has 4 spaces padded on
the left like:

" This is a string";

As long as your array is at least twice as long as (your string plus
the number of spaces to insert):
sprintf(myvar+64, "%s", myvar);
sprintf(myvar, " %s", myvar+64);

I don't think that is permitted:

7.19.6.6 The sprintf function

... If copying takes place between objects that overlap, the
behavior is undefined.

It does not say "between /regions/ of objects that overlap". It seems
any overlap is enough to render it undefined.

It seems that the term "object" is not used with great precision here.

What would happen if myvar were defined as
char myvar[2][64] = {"This ..."};
and in the calls to sprintf each use of myvar was cast to char*?
myvar[0] and [1] are objects that do not overlap but both are part of
the object myvar. Is this overlap? Would it be overlap if the
arguments were changed to myvar[0] and myvar[1]?

What about
char *myvar = malloc(128);
strcpy(myvar, "This ...");
There are no objects here so no objects can overlap.

The compiler will probably generate the same code for the three sets
of calls to sprintf. It doesn't seem right (tm) that the same code
generated from essentially identical source statements should be
undefined, questionable, and well defined, respectively.

I will assert that the intent of the word object in this section is
meant to refer to the source and destination strings and therefore
under the conditions I postulated there is no overlap.
These are good points, but I think the wording is clear that the
behaviour is undefined. The intent may not be this wide, but the word
"object" must mean the whole object, surely?

The same wording is used for memcpy, so if it is generally agreed that
memcpy can be used to copy from one place to another non-overlapping
place /within/ a single object, then I agree your solution is OK.

--
Ben.
Jun 27 '08 #40
CBFalconer said:

<snip>
I guess I am getting sloppy.
It's been happening for some time.
Well, I did
mark it 'untested', and say 'something like this'. :-)
In future, please mark it "tested", and say "exactly like this", and try to
ensure that those claims will stand up to expert scrutiny.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #41
Ben Bacarisse <be********@bsb.me.ukwrites:
Barry Schwarz <sc******@dqel.comwrites:
>On Tue, 10 Jun 2008 19:27:31 +0100, Ben Bacarisse
<be********@bsb.me.ukwrote:
>>>Barry Schwarz <sc******@dqel.comwrites:
<snip>
>>>As long as your array is at least twice as long as (your string plus
the number of spaces to insert):
sprintf(myvar+64, "%s", myvar);
sprintf(myvar, " %s", myvar+64);

I don't think that is permitted:

7.19.6.6 The sprintf function

... If copying takes place between objects that overlap, the
behavior is undefined.

It does not say "between /regions/ of objects that overlap". It seems
any overlap is enough to render it undefined.

It seems that the term "object" is not used with great precision
here.
I have to think that may be deliberate. See below...
>What would happen if myvar were defined as
char myvar[2][64] = {"This ..."};
and in the calls to sprintf each use of myvar was cast to char*?
myvar[0] and [1] are objects that do not overlap but both are part of
the object myvar. Is this overlap? Would it be overlap if the
arguments were changed to myvar[0] and myvar[1]?
<snip>
>I will assert that the intent of the word object in this section is
meant to refer to the source and destination strings and therefore
under the conditions I postulated there is no overlap.
And I now agree.
These are good points, but I think the wording is clear that the
behaviour is undefined. The intent may not be this wide, but the word
"object" must mean the whole object, surely?
The definition of "object" is very loose: "region of data storage in
the execution environment, the contents of which can represent
values". Thus within an object declared: 'char obj[128];' there
are many other objects. Each char is an object as well as the whole
thing, but the region from obj[3] too obj[30] (inclusive) is also an
object. In deciding if "objects overlap" there are therefore two ways
to go: define "the objects" as the smallest ones involved in the copy,
or define them as the largest. Anything else is rather arbitrary.

It seems obvious to me, now, that the intent is that the smallest
objects be the ones that need to be overlap-free. So, in short,
forget my objection!

--
Ben.
Jun 27 '08 #42

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

Similar topics

3
by: Uttam | last post by:
Hello, Using ADO I have created a table and have also created fields. To create fields, I have used the following: ..Columns.Append "Field_Name", adWChar, 6 I load records into this...
4
by: mhw | last post by:
I don't found function! ThanksŁˇ
1
by: Anonieko Ramos | last post by:
> > > How to display multiple spaces in a dropdownlist webform1.aspx <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
3
by: Sam | last post by:
I want to divide character into 2 section. Example, 200412 divided into 2004 in A block and 12 in B block. Please advise how to use left(string, length) or right(string, length) for above...
3
by: NathanC | last post by:
Left('ironman',4) Result - 'iron' Is there anyway to excute this task in VB.NET? Currently, I am determing the value of the 4th character, splitting on that, then grabbing the value of the...
2
by: Reny | last post by:
Hi, I came across a doubt on the String.PadLeft Method.The doubt is this -- What's difference it make if the argument to this function carries an integer whose value is less than the length of...
2
by: akoymakoy | last post by:
is there a function to remove leading and trailing spaces on strings? example: word = " THE QUICK BROWN FOX " output: word = "THE QUICK BROWN FOX"
3
by: AWW | last post by:
RichTextBox.Text = string & vbCR works but if I extract a substring with microsoft.visualbasic.left then vbCR stops working. I can do F5 executes with/without the Left and the vbCr does/doesNot...
5
by: =?Utf-8?B?Qm9iQWNoZ2lsbA==?= | last post by:
I need a function (or code) that will physically change the words in a text string to make the first word be last, second word next to last, etc. but maintain the same position of the letters in...
3
by: Elohim | last post by:
Hi to everybody, I'm a learner of C++. I'll really appreciate if you can help me or teach me something. Thank you in advance. #include<iostream> #include<string> int main() { ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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
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...
0
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...
0
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...
0
agi2029
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,...
0
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...

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.