tags:

views:

131

answers:

6

How do I print #include<conio.h> in C

#include<stdio.h>
#include<conio.h>
void main()
{
printf("#include<conio.h>");

}

How to get the output as

#include<conio.h>

you have to put getch(); and press Ctrl+f9 instead of alt+f5

+2  A: 

I don't think you need to do anything else. You have written the solution yourself. All you have to do is just Compile and Run......... :)

Night Shade
no it shows me a blank screen
subanki
If you get a blank screen, then the problem is probably in somewhere else. The characters you are printing are perfectly valid to be printed using printf function in C. You don't have to add any escape characters or anything else. The problem is probably in your IDE settings or somewhere else. Can you print anything other than that? Try printing "Hello World" and see if it prints.
Night Shade
try removing the "conio.h" header, because it is not in ANSI C standard specification. Also have main return integer rather than void, write "void" as argument to the main, and return "0" from main. See if that works. Also, could you tell us which IDE/Compiler you are using?
Night Shade
@Archangel still not working
subanki
then try adding a "getch();" after calling "printf" and see what is exactly happening here. Also try to debug the program.
Night Shade
@subanki: Check out my answer ---- I think you're problem's with the IDE, not the code.
Jacob
A: 

It works fine for me, but I suppose it's remotely possible that your STDOUT stream is not being flushed automatically. Try adding

fflush(stdout);

after the printf.

Evgeny
`stdout` should be flushed automatically at program termination.
Billy ONeal
Yeah, I'd have thought so too - and it is for me. Just throwing out the only possibility I can think of, based on the info given.
Evgeny
@Evgeny fflush(stdout); gives me a more darker blank screen, not working
subanki
+2  A: 

If you are running it from an IDE, you might need to look at the output console or something, and maybe it closes when your program quits before you get a chance to see what it has printed.

If you are running it from the command line, maybe (because it doesn't print a newline after the string) your prompt is clobbering the output.

Matt Curtis
assuming u r right , how to make it display the output for a longer time, i am using borland turbo C
subanki
Looks like (from your question amendment) I was right - it was printing after all, and the issue was (presumably) your IDE closing the output window too quickly. Feel free to mark this answer as "accepted" :)
Matt Curtis
I think Matt is right (he often is). If you run your executable from the command-line, the output should persist.
Johnsyweb
A: 

Sometimes the shell will overwrite the last printed line if it doesn't end in a newline; try adding a \n to the end of the printf

Michael Mrozek
+1  A: 

If I remember Turbo C++ right (could be the same), you need to go to the Output window to see the result. So go to Window on the menu bar and select Output --- you should see your string there.

If that doesn't work add getch(); to the end of your program. This will ensure that the program will wait for a keystroke from the user before exit.

Jacob
i tried both methods still no output
subanki
A: 

What if you replace the 'printf' call with

fprintf(stderr, "#include<conio.h>");

Or, try this:

_cprintf("#include<conio.h>");

Any luck?

dacris