how setbuf is working in c program

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@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@desktop:/home/prabhu# cc a.c
root@desktop:/home/prabhu# ./a.out
a
a
root@desktop:/home/prabhu# ./a.out
aa
aa
root@desktop:/home/prabhu# ./a.out
aaa
aaa
root@desktop:/home/prabhu# ./a.out
aaaa
aaaa
root@desktop:/home/prabhu# ./a.out
aaaaa
aaaaa
hello worldroot@desktop:/home/prabhu# ./a.out
aaaaaa
aaaaaa
ello worldroot@desktop:/home/prabhu# ./a.out
aaaaaaa
aaaaaaa
llo worldroot@desktop:/home/prabhu# ./a.out
aaaaaaaa
aaaaaaaa
lo worldroot@desktop:/home/prabhu# ./a.out
aaaaaaaaa
aaaaaaaaa
o worldroot@desktop:/home/prabhu# ./a.out
aaaaaaaaaa
aaaaaaaaaa
 worldroot@desktop:/home/prabhu# ./a.out
aaaaaaaaaaa
aaaaaaaaaaa


Thanks,
Prabhu
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux