Welcome to Coding : Sécurité Programmation Réseaux

Search   in  

 Create an Account Home | Submit News Your Account Content | Topics | Top 10  


Accueil
· Home
· Listing des Articles
· Top 10
· Repository des Exploits

Les sujets / parties
· C / C ++
· Visual Basic
· Asm
· Reseaux
· Java
· Securite
· Divers

Utile
· Listing des Articles

· Telecharger
· Le Forum
· Liens
· Proposer un article

Top20 des Downloads
· 1: Etude des reseaux generalites et protocoles
· 2: Cheval de troie en VB avec sources
· 3: Netcat 1.1
· 4: Keylogger
· 5: Etudes des reseaux hauts debits architectures et protocoles
· 6: Ecoute de port
· 7: Etude du Smart Spoofing
· 8: Win Packet Capture Utils
· 9: Tutorial on Traffic Interception on Switched Lan using ARP spoofing
· 10: Cours de C

User Info
Welcome, Anonymous
Nickname
Password
(Register)
Membership:
Latest: trapcodien
New Today: 1
New Yesterday: 0
Overall: 2207

People Online:
Visitors: 42
Members: 1
Total: 43

Online Now:
01: trapcodien

  
Coding : Sécurité Programmation Réseaux: Forums

Coding :: View topic - Why do I get an extra return in thie following case?
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Why do I get an extra return in thie following case?

 
Post new topic   Reply to topic    Coding Forum Index -> Scripting
View previous topic :: View next topic  
Author Message
K-mart Cashier
Guest





PostPosted: Sat Jul 05, 2008 4:10 am    Post subject: Why do I get an extra return in thie following case? Reply with quote

I just don't spend enough time "tinkering" with *nix. Anyhow when I
read from an unbuffered input and type something in, I get two prompts
after I hit return.

m-net% more tty.c
#include <stdio.h>

int main(void)
{
char c;

return(read(0, &c, 1) == 1) ? (unsigned char)c : EOF;

return 0;
}
m-net% ./tty
c
m-net%
m-net%

Now when I buffer the input, and type something in, I only get one
prompt after I hit return.

m-net% more tty2.c
#include <stdio.h>

int main(void)
{
static char buf[BUFSIZ];
static char *bufp = buf;
static int n = 0;

if(n == 0) {
n = read(0,buf, sizeof buf);
bufp = buf;
}
return (--n >= 0) ? (unsigned char) *bufp++ : EOF;
}
m-net% ./tty2
c h a d
m-net%


Why is this?


Chad
Back to top
Chad
Guest





PostPosted: Sat Jul 05, 2008 8:11 am    Post subject: Re: Why do I get an extra return in thie following case? Reply with quote

On Jul 4, 9:10 am, K-mart Cashier <cdal...@gmail.com> wrote:
Quote:
I just don't spend enough time "tinkering" with *nix. Anyhow when I
read from an unbuffered input and type something in, I get two prompts
after I hit return.

m-net% more tty.c
#include <stdio.h

int main(void)
{
 char c;

 return(read(0, &c, 1) == 1) ? (unsigned char)c : EOF;

 return 0;}

m-net% ./tty
c
m-net%
m-net%

Now when I buffer the input, and type something in, I only get one
prompt after I hit return.

m-net% more tty2.c
#include <stdio.h

int main(void)
{
 static char buf[BUFSIZ];
 static char *bufp = buf;
 static int n = 0;

 if(n == 0) {
  n = read(0,buf, sizeof buf);
  bufp = buf;
 }
 return (--n >= 0) ? (unsigned char) *bufp++ : EOF;}

m-net% ./tty2
c h a d
m-net%

Why is this?

Chad

Never mind. I thought about it and realized that in the latter,
newline is stored in buf..
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Coding Forum Index -> Scripting All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group
PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.36 Seconds