1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Shortest Hello G4EF | 8 Sep 2009

Discussion in '$1 Daily Competition' started by shabbir, Sep 8, 2009.

  1. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    Write a C Program which has least number of characters and prints "Hello G4EF" without quotes.

    This is not first submission winner but would wait for all submission and then the shortest would win.
    Criteria would be least number of characters and it should be a C Program
     
  2. Mridula

    Mridula New Member

    Joined:
    Mar 5, 2008
    Messages:
    316
    Likes Received:
    19
    Trophy Points:
    0
    Occupation:
    S/w proffessional
    Location:
    Bangalore
    #include<stdio.h>
    main()
    {puts("Hello G4EF");}
     
  3. Kshiteej

    Kshiteej New Member

    Joined:
    Jul 6, 2009
    Messages:
    79
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Mumbai
    char*_="Hello G4EF\n";
     
  4. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    I googled and found this as the shortest possible. As, the source file is only 1 byte !

    Steps :
    (1) Create a new empty file named : "void main(){puts(Hello, World!);}c.c"
    (2) Open the file with any text editor and write only one char "A" to the file and save it.
    ##That's our program ;) Only 1 char content !
    (3) To compile it, use gcc with flags "-DA=__FILE__ -Dc=// -istdio.h void*.c".

    Not sure if it works. I'll test and post. :)
     
  5. Seema786

    Seema786 New Member

    Joined:
    Jul 29, 2009
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    IT Professional
    Location:
    Banglore
    char*_="Hello G4EF";
     
  6. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    @ Shabbir,

    Are you consider character in file or size of the file ?
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    Can you explain the difference.
     
  8. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    1. Charater

    #include<stdio.h>
    main()
    {puts("Hello G4EF");}

    Total Character = 48

    2.

    #include<stdio.h>
    main()
    {puts("Hello G4EF");}

    Save It = 4 KB
     
  9. Raj08

    Raj08 New Member

    Joined:
    Aug 1, 2009
    Messages:
    39
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Agent 420
    Location:
    India
    Hello G4EF

    Output of C Program.
     
  10. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    That's because the file is stored in blocks, and the smallest block size is 4KB. Select the file and press Alt-Enter and you'll see the actual file size displayed.

    Very good. And what is the source code of that C program? It's true Shabbir didn't actually say "and post the code here", but that could reasonably be implied, also how is he going to judge your code if he can't see it?
     
  11. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    :lol:
     
  12. Kshiteej

    Kshiteej New Member

    Joined:
    Jul 6, 2009
    Messages:
    79
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Mumbai
    Hi Shabbir,

    What is the answer of this question?
     
  13. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    Looks like Saswat but I am not on Linux and so is not able to verify what he said.
     
  14. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
  15. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    I haven't said anything because I don't think it would work. But I don't have a Linux or MinGW installation handy to try it.

    Saswat, to convince me* you should post a screen shot that shows it working. Use four commands:
    ls
    cat <filename>
    <the gcc command>
    <invoke the executable so we can see the output>

    *Not that it's me that needs convincing. But I think this would convince anyone.
     
  16. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    So, what's the final answer for this ?
     
  17. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    Saswat's
     
  18. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Thanx for accepting my answer :happy:
    But ...
    As I mentioned, "Not sure if it works".
    And as xpi0t0s thinks it won't work, it might not. I just read it here : http://everything2.com/title/The+World%27s+Shortest+Hello+World

    Anyway, one thing is clear from the code that it is not according to the latest ANSI C specs, 'cuz it still uses void main() and not int main().

    Anyway, the shortest working (confirmed) "Hello G4EF" program in ANSI C will be :
    Code:
    main(){puts("Hello G4EF");}
    which is still the shortest (29 bytes) even if my previous answer is rejected ;)

    NOTE that you don't need to do these :
    (*) #include <stdio.h>
    (*) int in-front of main.
    (*) return 0
    (*) New lines at end of statements
    They reduce the code length further.
     
  19. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    I think it won't work because there are missing quotes:
    Code:
    puts(Hello, World!)
    
    Apart from that though the principle of putting one character in the C file and using a -D to place the code is absolutely fine, in fact this is what one of the IOCCC winners did (although his file was 3 characters long: A;<eof>).
     
  20. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,046
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth
    Congrs SP :D
     

Share This Page