top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to print a string without using header file ‪stdio.h and printf function in C?

+2 votes
801 views
How to print a string without using header file ‪stdio.h and printf function in C?
posted Jul 16, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+3 votes

Your question is to print a string without :

1> including "stdio.h" header file
2> Not using printf function
: If stdio.h is not included, then printf( ) cannot be used.

If the above stated requirement is correct, then you can use 'write' function to print string.

#include "unistd.h" /* Please use < > instead of " " */

int main( )
{
      write(1, "Query Home", 10);
      return 0;
}

write( ) -> Takes 3 argument:

1> The File Descriptor
2> The String to be printed (Buffer)
3> Size of the buffer (Count)

For more information, refer man pages

=> man 2 write

answer Jul 16, 2014 by Deepak D
+1 vote

You can print the string without using stdio.h and printf, but for that you have to use system cal. First close the stdout buffer. See the below program.

main()
{
close(1);
Int fd;
char a[] = "hello friends\n";
fd = open(filename,O_RDWR);
write(fd,a,strlen(a));
}

answer Sep 22, 2014 by anonymous
...