Monday, April 25, 2016

printf, fprintf, sprintf and printk..... whats the difference ?

There are basically 3 standard "streams"

  1. stdin - standard input stream
  2. stdout - standard output stream
  3. stderr - standard error stream
fprintf(standard stream, "message");  //message is sent to the mentioned stream

printf("message"); //message is sent to stdout. so it is as good as writing fprintf(stdout, "message")

#define BUFFER_SIZE 50
char *ch_arr = (char *)malloc(sizeof(char) * BUFFER_SIZE);
sprintf(ch_arr,  "message"); //message is sent to char buffer whose pointer is passed as argument

printk(KERN_IMERG "message");  
//used to print message to kernel log file. Hence it can only be called from kernel only

No comments:

Post a Comment

PROFILE

My photo
India
Design Engineer ( IFM Engineering Private Limited )

Followers