Re: C programming Arrays

  • From: "Laura Eaves" <leaves1@xxxxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 9 Oct 2007 21:15:53 -0400

John, perhaps a hint at alternative implementations might help.

If you have an array of strings with user names in it, plus a float array of 
wages, and whatever else, you can do as Dale et al have suggested and create 
arrays for each field and set them up so employee with ID equal to i will 
have the following data:

    name[i] = "Joe Blow";
    wages[i] = 2200.00;
    whatever[i] = "other data goes here";

Then all you need to keep track of is how the array is numbered so you don't 
accidently overrun the size of the array (you definitely need a test for 
that), and also choose a convention of what employee 0 represents -- is 
employee #0 the CEO? Or is that a blank slot for you to put unrelated data,.

Alternatively you can avoid using multiple arrays by defining a struct -- if 
you have seen that concept anywhere.  An example follows:

    struct Employee {
        char* name;
        float wage;
        int whatever;

Then define an array of employee data as follows:

    struct Employeeempdata[100];
    empdata[1].name = "Joe Blow";
    empdata[1].wage = 2200.00;
    /* etc -- and be sure to test for array overflow */

Let me know if this is helpful.
I am trying to simplify the process but may be obfuscating instead... Sorry 
if that's the case.
Happy hacking.

----- Original Message ----- 
From: "John Miller" <n1umj@xxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, October 09, 2007 8:47 PM
Subject: Re: C programming Arrays

I understand the concept of what an array does, I'm just not sure how to use
it. Example, I can get started with them, declaring the variables and all
with the number in brackets, but after that, no matter how many sites I look
at, it's like I'm looking at the same things over again and I'm not getting
it, especially when it comes to adding it in to an already existing program
assignment. If that makes sense, I need something closer to my assignment
figuring out employee wages and all and just an empty example, or an example
when the numbers in the program are already known, instead of like with this
program when I have to enter them, that's where I get stuck. I can get the
idea if I see something closer to actual work.
My main problem is, I went in to this class knowing nothing. I'm getting
there, but I'm not a programmer. I see all the time where that's obvious in
what I miss. I'm trying pretty much to get through the class. At this point
and am with a lot of help. I'm trying to depend less on help and more on
getting things done but getting enough help to at least pass. If I didn't
need the class I'd get rid of it, actually, if it wasn't for the fact I had
to drop a class already that I couldn't take because the program needed for
everything didn't work with a screen reader, I'd drop it and try again on
campus where I might be able to work more with people in the class but I'm
kind of locked in to right now where I have to take and pass it.
----- Original Message ----- 
From: "Dale Leavens" <dleavens@xxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, October 09, 2007 7:02 PM
Subject: Re: C programming Arrays

Hi John,

Arrays come in up to three dimensions. A one dimensional or single
dimensioned array is like a list or a stack of open ended boxes into which
values may be stored. A two dimensional array is like a collection of boxes
or pigeon holes, that is you have rows and columns of boxes into which you
can stuff values. Three dimensional arrays are like layers of pigeon holes
stacked in front of each other into which values may be stuffed and
retrieved. When you want to stick something into a particular array location
you must specify which one. For example:

Pigeon hole [1 down], [two to the right], [three deep]
in the case of a three dimensioned array.

In the case of a single dimension array which is more like a list you might
retrieve the item in list [12].

If you were modeling a checker board it would be a two dimension array,

The various dimensions then are referred to as indexes and may be referred
to using integer variables so you can use a loop to loop through each index
of an array to read from the location or write to it or change it or what
ever. The trick there is to remember which index you are referencing, that
is, to read in sequence you probably want to set x to one then loop through
y then increase x and again loop through y until you have visited all of the
x/y index locations.

Is that the sort of thing you were looking for?

You must specify the sort of variable you are storing, you can have arrays
of strings, integers, doubles and floats but you cannot mix them. You can
however have an array of strings say to hold names and a similar array of
floats to hold wages and index both with the same value so that:

NameString[1] is an employee name and WageFloat[1] is his wage. Different
arrays but linked by their index. Your programme must take care not to
confuse the index or you may be pointing to someone else's wages.

Hope I understood your request and that this was helpful.

Dale Leavens, Cochrane Ontario Canada
Skype DaleLeavens
Come and meet Aurora, Nakita and Nanook at our polar bear habitat.

----- Original Message ----- 
From: "John Miller" <n1umj@xxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, October 09, 2007 5:30 PM
Subject: C programming Arrays

> Hi,
> Is there anyone that can give a good, actually reasonably understandable
> explanation or example of an array in C programming? In my class, the
> book's
> examples are horrible at best and confusing and the teacher should be
> fired
> his is so bad. That or I should drop the class which I was actually about
> to
> do but I looked and there is no other major completely online that holds
> my
> interest so I guess I have to stick it out for another torturous 5 weeks
> or
> what ever it is. I'm getting some of it, but not enough.
> Thanks,
> John Miller N1UMJ
> AIM and yahoo messenger: N1UMJ Skype: n1umjjohn
> home page:
> myspace:
> __________
> View the list's information and change your settings at
> //
View the list's information and change your settings at

View the list's information and change your settings at

View the list's information and change your settings at 

Other related posts: