By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,436 Members | 1,344 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,436 IT Pros & Developers. It's quick & easy.

Print a string to console without using any print command.

P: 1
Hello experts,

I heard there is a way to print a string in console without using any print statement.
(e.g printf, cout, clog, cerr, puts and similar commands)

I got a hint to use if statement.


Any inputs?
May 28 '07 #1
Share this Question
Share on Google+
10 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
I haven't a clue.

Send me your final solution.
May 28 '07 #2

P: 79
I've never heard of this...I'm interested in knowing how this works.
May 28 '07 #3

kky2k
P: 34
i believe that its not possible to print without using any system calls..

if u find the solution plz post it
May 29 '07 #4

Banfa
Expert Mod 5K+
P: 8,916
How about

Expand|Select|Wrap|Line Numbers
  1. #include "stdlib.h"
  2.  
  3. int main(int argc, char **argp)
  4. {
  5.     system("echo Hello World");
  6.  
  7.     return 0;
  8. }
  9.  
Only calls 1 function which isn't a printing related function.
May 29 '07 #5

Savage
Expert 100+
P: 1,764
How about

Expand|Select|Wrap|Line Numbers
  1. #include "stdlib.h"
  2.  
  3. int main(int argc, char **argp)
  4. {
  5.     system("echo Hello World");
  6.  
  7.     return 0;
  8. }
  9.  
Only calls 1 function which isn't a printing related function.
I don't know why,but it looks like a cheating to me.

Savage
May 29 '07 #6

Banfa
Expert Mod 5K+
P: 8,916
I don't know why,but it looks like a cheating to me.
That is a reasonable sentiment, I felt the same thing as I wrote it :D
May 29 '07 #7

Savage
Expert 100+
P: 1,764
That is a reasonable sentiment, I felt the same thing as I wrote it :D
LOL

Savage
May 29 '07 #8

AdrianH
Expert 100+
P: 1,251
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.   char msg[] = "Hello world!\n";
  4.   write(1, msg, sizeof(msg));
  5.   return 0;
  6. }
  7.  
Not using a print statement. Dunno about how to use an if statement to print though.


Adrian
May 29 '07 #9

Banfa
Expert Mod 5K+
P: 8,916
Not using a print statement. Dunno about how to use an if statement to print though.
Is that a POSIX function?
May 29 '07 #10

AdrianH
Expert 100+
P: 1,251
Is that a POSIX function?
It is part of the C standard low level IO system. It is not used often as it is unbuffered and doesn't have stuff that the stdio has like formatted output and such.

file descriptors
0 stdin
1 stdout
2 stderr

Look at my "How to Parse in C" article, it mentions them briefly.



Adrian
May 29 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.