Thread: C program

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    32

    Lightbulb C program

    Code:
    need answ & expl of following question
    
    main()
    {
    printf("\nab");
    printf("\bsi");
    printf("\rha");
    }

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Google printf and read its documentation.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    10
    hai

    would be the output!
    \n is newline-takes cursor to new/next line on console;
    \b is backspace-does the same work as the backspace key on keyboard;
    \r is carriage return-brings the cursor to beginning of current line on console;

    try interpreting the arguments provided to 'printf',u ll understand hw it prints 'hai'.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Still teaching stupid programming tricks in Southern Asia, amirite?

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    10
    Has nothing to do with real time programming however if you execute this you still get an answer!

  6. #6
    Registered User
    Join Date
    Sep 2010
    Posts
    32
    Quote Originally Posted by avee137 View Post
    hai

    would be the output!
    \n is newline-takes cursor to new/next line on console;
    \b is backspace-does the same work as the backspace key on keyboard;
    \r is carriage return-brings the cursor to beginning of current line on console;

    try interpreting the arguments provided to 'printf',u ll understand hw it prints 'hai'.
    Hi,
    I run this program using eclipse, it throws the output

    absi
    ha

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Look carefully at the box character - see the numbers?

    Now go here
    Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion

    Then read your C book for what \b means.

    Do you see it now?

    Also, you would have gotten a much better answer if you'd posted both code AND output in the same post, instead of the terse "what's this code do" you started with.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM