Can any one write a simple C Program 4 this??

This is a discussion on Can any one write a simple C Program 4 this?? within the C Programming forums, part of the General Programming Boards category; He guys can any one write a simple C program 2 print a character without using any output statements in ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    12

    Question Can any one write a simple C Program 4 this??

    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 02:40 AM. Reason: Snip font colour / size abuse.

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    12
    Visit www.lern2hack.blogspot.com & see C programming section

  3. #3
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105
    Whoa, man. Use a different font.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    and the program they show won't compile for me:

    Code:
    #include<stdio.h>
    void main()
    {
    char far *p=0xb8000000;
    *p='A';
    getch();
    }
    getch() is not included in stdio.h, probably means getchar().
    "Cannot initialize char far * to unsigned long".

    Looks like it's designed to write directly to video memory, however.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    And that is potentially very bad.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,336
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,525
    Well, the solution that seemed obvious to me was to invoke the echo command.

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    12
    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

  10. #10
    Registered User
    Join Date
    Dec 2007
    Posts
    12
    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

  11. #11
    Registered User
    Join Date
    Dec 2007
    Posts
    12
    Definetely base address of monochrome is different it starts from
    0xB000

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by sriki View Post
    Hey use "conio.h" header file man,the program will definitely execute on any comp.
    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 05: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.

  13. #13
    Registered User
    Join Date
    Dec 2007
    Posts
    12
    I hav written a Program in C to to make XP genuine.
    Even i'll b posting this on my blog sooon.

  14. #14
    Registered User
    Join Date
    Dec 2007
    Posts
    12
    It Will Work Even In windows Vista

  15. #15
    Registered User
    Join Date
    Dec 2007
    Posts
    12
    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

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-30-2007, 09:08 AM
  2. need a simple program
    By Peter Griffin in forum C++ Programming
    Replies: 7
    Last Post: 12-04-2005, 03:23 PM
  3. Need help with simple, simple program.
    By LightsOut06 in forum C Programming
    Replies: 5
    Last Post: 09-01-2005, 08:31 PM
  4. Problem with simple XOR program
    By spike_ in forum C++ Programming
    Replies: 8
    Last Post: 08-17-2005, 12:09 AM
  5. simple frontend program problem
    By gandalf_bar in forum Linux Programming
    Replies: 16
    Last Post: 04-22-2004, 06:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21