PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > the difference between \r and \n
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
the difference between \r and \n

Réponse
 
LinkBack Outils de la discussion
Vieux 29/05/2008, 14h02   #1
YarvinG Liu
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut the difference between \r and \n

i write two codes:
printf("123\r");
printf("123\n");
the lattar. as we all know. the output will be:
123
press any key to continue

but the formmer will be:
press any key to continue

which means data:123 has lost.
Y?
  Réponse avec citation
Vieux 29/05/2008, 14h19   #2
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: the difference between \r and \n

YarvinG Liu said:

> i write two codes:
> printf("123\r");
> printf("123\n");
> the lattar. as we all know. the output will be:
> 123
> press any key to continue
>
> but the formmer will be:
> press any key to continue
>
> which means data:123 has lost.


Right.

> Y?


I don't understand. If you mean "Why?", however, the answer is that writing
a '\r' character to the standard output stream moves the active position
to the initial position of the current line. It would seem that your IDE
then writes "press any key to continue" to the standard output stream,
starting at that position, and therefore overwriting your "123" text.

--
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
  Réponse avec citation
Vieux 01/06/2008, 02h00   #3
Dan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: the difference between \r and \n


"YarvinG Liu" <yarving@gmail.com> wrote in message
news:be73985c-a476-44a2-b1b0-51d01458e6b0@h1g2000prh.googlegroups.com...
>i write two codes:
> printf("123\r");
> printf("123\n");
> the lattar. as we all know. the output will be:
> 123
> press any key to continue
>
> but the formmer will be:
> press any key to continue
>
> which means data:123 has lost.
> Y?


\r move the cursor back to the start of the line, the "press any key.." is
then written over the top of 123. Its probably safest to always go \r\n if
you are on windows systems.


  Réponse avec citation
Vieux 01/06/2008, 02h50   #4
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: the difference between \r and \n

Dan said:

<snip>

> \r move the cursor back to the start of the line, the "press any key.."
> is then written over the top of 123. Its probably safest to always go
> \r\n if you are on windows systems.


No, that's pointless - \n is perfectly adequate on *all* systems, including
Windows. The stdout stream is a text stream. Like all text streams, if you
write a '\n' to it, any necessary conversions *will* be done by the
implementation.

--
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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h22.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11547 seconds with 12 queries