He guys can any one write a simple C program 2 print a character without using any output statements in C.Also try 2 print a string without usig any output statemets.
He guys can any one write a simple C program 2 print a character without using any output statements in C.Also try 2 print a string without usig any output statemets.
Last edited by Salem; 12-03-2007 at 03:40 AM. Reason: Snip font colour / size abuse.
Visit www.lern2hack.blogspot.com & see C programming section
Whoa, man. Use a different font.
and the program they show won't compile for me:
getch() is not included in stdio.h, probably means getchar().Code:#include<stdio.h> void main() { char far *p=0xb8000000; *p='A'; getch(); }
"Cannot initialize char far * to unsigned long".
Looks like it's designed to write directly to video memory, however.
And that is potentially very bad.
Well, it's certainly possiblet to print a string without using any "standard" output statements. Many different ways, here's a few examples...
Windows "TextOut" would perhaps qualify?
Or I could define a bitmap font and draw it myself to the screen in Windows or Linux using WxWidgets?
I have written graphcis drivers for Windows, and I worked with the "DrawText" function that is the backend of TextOut. Does that qualify?
Or do we have to use machine-dependant "poking directly to the hardware"?
Yes, you can write text to the console in DOS and DOS-mode [or even in protected mode, as long as you don't have an OS in the way to prevent that]. I did a complete library for clrscr, clreol, printxy, savescreen, restorescreen, box, saveregion, restoreregion, in assembler, circa 1985.
And by the way, if you have a monochrome graphics card, the code posted above won't work, as the base-address of the graphics card is different there. If I remmeber right, there's a register in the std vga IO registers to check for monochrome or colour display adapters. Not that anyone uses monochrome these days.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Wow, void main, using gets(), and other copious dependencies on specific compilers.
Now that's a good site to learn from
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Well, the solution that seemed obvious to me was to invoke the echo command.
Hey use "conio.h" header file man,the program will definitely execute on any comp.
I'll also update it on my Blog
4
more programs
visit
www.lern2hack.blogspot.com
use c compiler
if u use c++ compiler
make sure u hav set the CPP Ext in OPTIONS>COMPILER>C++ OPTIONS
program will definitel work
Definetely base address of monochrome is different it starts from
0xB000
It will not execute correctly "on any computer". It will only work in DOS if the graphcis adapter is a colour graphics adapter [or in Windows in a DOS-box] - in fact, it needs to be compiled by a 16-bit compiler, which probably means some old version of Turbo/Borland C.
If we completely ignore the "getch()" part that is unportable, we still have the problem that the code accesses hardware directly on a hard-coded physical address, and that it uses far pointer [a concept that only really makes sense in a segmented memory model]. Physical address 0xB8000 is not described as 0xB8000000 in 32-bit mode, so even if you run on a 32-bit OS that uses direct memory mapping [not virtual address mapping], it would not do the right thing. And it certainly won't "run on any OS".
Do you ACTUALLY understand what the code does, and how it depends on the hardware architecture, or did you just copy it from somewhere without actually understanding at all what it does?
--
Mats
Last edited by matsp; 12-03-2007 at 06:35 AM. Reason: Reduce unnecessary quoting.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I hav written a Program in C to to make XP genuine.
Even i'll b posting this on my blog sooon.
It Will Work Even In windows Vista
I am the first 2 write dis code
u can check it out
type "c program to print without using any output statements" in google & my site is the top one u see