TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [TCLUG:580] Another Newbie



Just to be correct, since only 1 statement is being used, the { } is   
optional.  The real problem is that in C you can't do a string comparison   
with the == operator.  A small criticism is that you probably wouldn't   
want to pass a struct by value.  Also, you're showing DOS origins; in   
Unix the prototype for main() is "int  main(int argc, char** argv, char**   
env);"  So, with corrections and embelishments (details of   
get_book_info(), buy(), and pshaw() are left to the imagination):


#include <string.h>
#include <stdio.h>

struct tmoney
{
    int dollars;
    int cents;
};

typedef  struct tmoney t_money;

struct tbook
{
    char    title[64];
    char    author[64];
    char    publisher[64];
    t_money  MSRP;
};

typedef struct tbook t_book;

struct terror
{
    int    errno;
    char  message[128];
    int    severity;
};

typedef struct terror t_error;

t_error  get_book_info(t_book*  book);
void  buy(t_book*  book);
void  pshaw(t_book*  book);

int
main(int argc, char** argv, char** env)
{
t_book  book;

    get_book_info(&book);

    if (strcmp(book.publisher, "oreilly") == 0)
        buy(&book);
    else
        pshaw(&book);

    return 0;
}


 ----------
From:  Ben Kochie
Sent:  Wednesday, July 08, 1998 11:59 PM
To:  tclug-list@listserv.real-time.com; Brad DeJong
Subject:  Re: [TCLUG:580] Another Newbie

   

just to be pickey

void main (void) {
        if (book.publisher == "oreilly") {
                buy(book);
        } else {
                pshaw(book);
        }
        return;
}

hehe.. if someone wants to write the rest of the program for this.. i bet   
it
would be a nice sub-page off of the tclug web page

On 08-Jul-98 Christopher Reid Palmer wrote:
> On Wed, 8 Jul 1998, Clark Whiting wrote:
>
>> Does anyone know of a good book (manual) that discusses these setups   
in
>> detail so that I can work through these problems.
>
> *Running Linux*, by Lar Kauffman and Matt Welsh, is the book you want.
>
> main () {
>       if (book == oreilly)
>               buy;
>       else
>               pshaw;
> }
>
>   
__________________________________________________________________________  
___
> Christopher Reid Palmer : jaymz@acm.cs.umn.edu : innerFire on IRC   
(EFNet)
>
> Free Software Special Interest Group : acm.cs.umn.edu/~jaymz/sigfs/
> Digital Media Center : www.umn.edu/dmc/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tclug-list-unsubscribe@listserv.real-time.com
> For additional commands, e-mail: tclug-list-help@listserv.real-time.com
> Try our website: http://tclug.real-time.com

TTYL,
        Ben Kochie (ben@intexp.com)

[{(-----------------------------------------------------------)}]
You can never underestimate the stupidity of the general public.
                                        -Scott Adams

To the engineer, the world is a toy box full of sub-optimized and
feature-poor toys.
                                        -How to tell an Engineer
[{(-----------------------------------------------------------)}]


 ---------------------------------------------------------------------
To unsubscribe, e-mail: tclug-list-unsubscribe@listserv.real-time.com
For additional commands, e-mail: tclug-list-help@listserv.real-time.com
Try our website: http://tclug.real-time.com