[OT] Hello-Program

Thomas 'Balu' Walter tw at itreff.de
Thu Oct 12 05:41:49 PDT 2000


Here is an example of what can happen to you on #lfs.

I was complaining that I am not a real coder anymore - just a scripter
(html, php and such). 
Peter de Freitas <Ghovs@#LFS> read that and told me that I am not dead
yet, I still have a chance to be reactivated - to start coding again.

He told me to do that _right now_ and I did it...

I created a simple Hello-World-Program and he told me to include
ANSII-Colors, which I did.
Then he told me to make it ask for a user name, which I did.

Attached is the final result ;)

     Ba-coder.again-lu

-------------- next part --------------
/* Hello.c 
 * Copyright (C) 2000 Thomas "Balu" Walter <hello at b-a-l-u.de>
 *
 * Thanks to Peter de Freitas <Ghovs@#LFS> for suggesting me to write
 * this.
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * The GNU General Public License is not included into this C-File
 * but you can get it at http://www.gnu.org/copyleft/gpl.html
 * or write to the Free Software Foundation, Inc., 
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */


/* Discontinued color-support */
// #include "colors.h"

/* ANSII-C Headers */
#include <stdio.h>
#include <stdlib.h>

/* Print the usage information */
int usage(char *program)
{
        printf("Usage: %s [Name]\n", program);
        printf("This program says hello to a given name. If you don\'t ");
        printf("give a name at\nstartup it displays this usage ");
        printf("information ;).\n");
}

/* Main program part */
int main(int argc, char *argv[])
{

        /* first check if the name was given as an argument */
        if (argc!=2) {

                /* if not print an error and usage information
                 * and stop 
                 */
                printf("ERROR: Please provide _exact_ one ");
                printf("argument to %s.\n\n", argv[0]);
                usage(argv[0]);
                exit(EXIT_FAILURE);
        }

        /* print the hello finally */
        /* discontinued color-support */
        // printf(RED"H"GREEN"e"YELLOW"l"BLUE"l"MAGENTA"o"CYAN" world!\33[0m\n");
        printf("Hello %s!\n", argv[1]); 

        exit(EXIT_SUCCESS);
}



More information about the lfs-dev mailing list