RE: this C program any better?

  • From: "Ken Perry" <whistler@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sun, 28 Oct 2007 08:10:54 -0700


Well if you would try to compile it the compiler would tell you where you
made mistakes.  You do not seem to be trying it has nothing to do with being
smart or not.  The compiler will show you where your errors are you just
have to learn what the errors mean.  Right now your sending the code to this
list asking what's wrong when what you should be doing is compiling it and
seeing what the compiler says.   The errors you had in that last one would
have shown up bright as a neon light in a dark basement if you ran a
compiler on it.  

Ken 

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of John Miller
Sent: Sunday, October 28, 2007 5:27 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: this C program any better?

Normally I do run it, but this time I didn't because I wanted to see if I
was on the right track before I went and finished it so I knew it wouldn't
run as it was. I'm not the smartest person there is by a long shot but I did
know that wouldn't run as was.
----- Original Message -----
From: "Jackie McBride" <abletec@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Saturday, October 27, 2007 11:51 PM
Subject: Re: this C program any better?


> John, I, like Ken, am curious whether u actually run your code 
> because, if u did, I think you'd see that it wouldn't fly.
>
> Let's discuss a few points.
> 1)  A struct is a data type.  As such, u do stuff like:
> struct employee{
> int employeeNumber;
> float hours_worked;
> float gross_pay;
> float overtime;
> } emp;
>
> Or u can declare it later by saying struct employee emp;
>
> Employee is a tag, while emp is an instance of the structure & is used 
> to reference it.  If u want 5 employees, then, it's declared as 
> }emp[5]; or later in the program as struct employee emp[5];
>
> U reference variables of a structure by saying stuff like 
> emp.hours_worked;  the period or dot is called the struct operator.
> If u wanna reference the 3rd employee in an array of structures of 
> instance emp, then you'd say emp[2].hoursWorked (arrays are 0-based, 
> remember).
>
> 2)  This is a really hard concept for beginner C programmers to grasp 
> (believe me, I know this!), but in the C programming language, with 
> regard to functions, the right hand literally does not know what the 
> left hand doeth.  U can, for example, do the following:
>
> void change_i();
>
> main()
> {
> int i;
> char ch;
>
> i = 10;
> change_i();
> printf("in main, i = " "%d\n",i);
> ch = getche();
> return 0;
> }
>
> void change_i(void)
> {
> int i;
> i = 20;
> printf("in change_i, i = " "%d\n",i);
> }
>
> In main, i=10, even after the code goes to change_i.  I in main & i in 
> change_i, though the name is identical, are 2 entirely different 
> kettles of fish.  Run the code & see for yourself.
>
> In order to make the above function actually change the value of i in 
> main, a statement at the end of change_i would say return i; & main 
> would say i = change_i();  that way the value is passed back to main.
>
> To initialize your data, u could do something like:
> float initialize(void)
> int i;
> float hours_worked[5] = { 40, 52, 37, 45, 40 };;; return hours_worked; 
> }
>
> I recommend u download & have a look at sam's teach yourself c in 21 
> days, available from:
> http://ftp.build.bg/Books_and_Help/Books/_programming/
>
> But u really do need 2 start running your code & checking its output.
>
> On 10/27/07, John Miller <n1umj@xxxxxxxxxxx> wrote:
>> Yeah, I know, I sent it in another email. That's what I get for not 
>> sleeping last night. I forget to include things in emails. Someday 
>> I'll start sleeping well again. When is the question. Hopefully in 2 
>> or 3 weeks when this class is over though I think there's more to it 
>> than that.
>> ----- Original Message -----
>> From: "Jackie McBride" <abletec@xxxxxxxxx>
>> To: <programmingblind@xxxxxxxxxxxxx>
>> Sent: Saturday, October 27, 2007 5:00 PM
>> Subject: Re: this C program any better?
>>
>>
>> > Couldn't tell u.  It's not there.
>> >
>> > On 10/27/07, John Miller <n1umj@xxxxxxxxxxx> wrote:
>> >> I'm wondering if this code is any better than the last one? I 
>> >> guess I'm at the point where I have to send it in no matter what 
>> >> but I figured I'd get any help I could before I do.
>> >>
>> >>
>> >> __________
>> >> View the list's information and change your settings at 
>> >> //www.freelists.org/list/programmingblind
>> >>
>> >>
>> >
>> >
>> > --
>> > Jackie McBride
>> > Please join my fight against breast cancer 
>> > <http://teamacs.acsevents.org/site/TR?px=1790196&pg=personal&fr_id=
>> > 3489>
>> > & Check out my homepage at:
>> > www.abletec.serverheaven.net
>> > __________
>> > View the list's information and change your settings at 
>> > //www.freelists.org/list/programmingblind
>> >
>>
>> __________
>> View the list's information and change your settings at 
>> //www.freelists.org/list/programmingblind
>>
>>
>
>
> --
> Jackie McBride
> Please join my fight against breast cancer 
> <http://teamacs.acsevents.org/site/TR?px=1790196&pg=personal&fr_id=348
> 9>
> & Check out my homepage at:
> www.abletec.serverheaven.net
> __________
> View the list's information and change your settings at 
> //www.freelists.org/list/programmingblind
> 

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: