All of lore.kernel.org
 help / color / mirror / Atom feed
From: prabhum@msys-tech.com (Prabhu)
To: kernelnewbies@lists.kernelnewbies.org
Subject: how setbuf is working in c program
Date: Mon, 06 Jun 2011 20:05:31 +0530	[thread overview]
Message-ID: <4DECE5B3.3030801@msys-tech.com> (raw)

Hi all,

I am writing user- space driver. My intention is to print whatever 
string i am enter into terminal.

Here i am using setbuf function to sent the data to the print after some 
fixed string length.

I wrote below program for understand setbuf functionality. But i am 
getting unpredictable result for some output . can any one explain the 
why i am getting these result.

root at desktop:/home/prabhu# cat a.c
#include <stdio.h>
main()
{
char buff2[]= "hello world";
char buf1[6]="";
setbuf(stdin, buf1);
getchar();
printf ("%s",buf1);
}


root at desktop:/home/prabhu# cc a.c
root at desktop:/home/prabhu# ./a.out
a
a
root at desktop:/home/prabhu# ./a.out
aa
aa
root at desktop:/home/prabhu# ./a.out
aaa
aaa
root at desktop:/home/prabhu# ./a.out
aaaa
aaaa
root at desktop:/home/prabhu# ./a.out
aaaaa
aaaaa
hello worldroot at desktop:/home/prabhu# ./a.out
aaaaaa
aaaaaa
ello worldroot at desktop:/home/prabhu# ./a.out
aaaaaaa
aaaaaaa
llo worldroot at desktop:/home/prabhu# ./a.out
aaaaaaaa
aaaaaaaa
lo worldroot at desktop:/home/prabhu# ./a.out
aaaaaaaaa
aaaaaaaaa
o worldroot at desktop:/home/prabhu# ./a.out
aaaaaaaaaa
aaaaaaaaaa
  worldroot at desktop:/home/prabhu# ./a.out
aaaaaaaaaaa
aaaaaaaaaaa


Thanks,
Prabhu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110606/1ce1dc0c/attachment.html 

             reply	other threads:[~2011-06-06 14:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-06 14:35 Prabhu [this message]
2011-06-06 15:24 ` how setbuf is working in c program Jonathan Neuschäfer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DECE5B3.3030801@msys-tech.com \
    --to=prabhum@msys-tech.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.