structs

  • Thread starter Bill Cunningham
  • Start date
B

Bill Cunningham

I am understanding here that cat is a sort of template but it has been
suggested that I can use an array instead of in this case k1, k2, k3 for
each of my cats. Can I use k1 for all of them? How would I implement an
array here.

#include <stdio.h>

struct cat {
char *name;
char *color;
};

int main(void)
{
struct cat k1 = { "striper", "striped" };
struct cat k2 = { "spooky", "black" };
struct cat k3 = { "smokey", "gray" };
printf("%s %s/n", k1.name, k1.color);
printf("%s %s/n", k2.name, k2.color);
printf("%s %s/n", k3.name, k3.color);
}

Bill
 
K

Keith Thompson

Bill Cunningham said:
I am understanding here that cat is a sort of template but it has been
suggested that I can use an array instead of in this case k1, k2, k3 for
each of my cats. Can I use k1 for all of them? How would I implement an
array here.

#include <stdio.h>

struct cat {
char *name;
char *color;
};

int main(void)
{
struct cat k1 = { "striper", "striped" };
struct cat k2 = { "spooky", "black" };
struct cat k3 = { "smokey", "gray" };
printf("%s %s/n", k1.name, k1.color);
printf("%s %s/n", k2.name, k2.color);
printf("%s %s/n", k3.name, k3.color);
}

I guess you could call it a "template" (<OT>C++ uses that term with a
very different meaning</OT>), but it's clearer to say that it's a
type.

Usually I try not to just give you the answer, but in this case it's
so trivial that I don't know how to break it down:

struct cat cats[3];

Why are you using "/n" in your printf calls? Did you re-type the code
rather than copy-and-pasting it? Or did you see the output all on one
line when you ran the code and decide it wasn't worth worrying about?
Or did you not bother running it?

Here's something for you to chew on:

#include <stdio.h>

#define ARRAY_LENGTH(a) ( sizeof (a) / sizeof (a)[0] )

struct cat {
char *name;
char *color;
};

int main(void)
{
struct cat cats[] = {
{ "striper", "striped" },
{ "spooky", "black" },
{ "smokey", "gray" }
};
size_t i;
for (i = 0; i < ARRAY_LENGTH(cats); i ++) {
printf("%s %s\n", cats.name, cats.color);
}
return 0;
}
 
O

osmium

"Bill Cunningham"
I am understanding here that cat is a sort of template but it has been
suggested that I can use an array instead of in this case k1, k2, k3 for
each of my cats. Can I use k1 for all of them? How would I implement an
array here.

#include <stdio.h>

struct cat {
char *name;
char *color;
};

int main(void)
{
struct cat k1 = { "striper", "striped" };
struct cat k2 = { "spooky", "black" };
struct cat k3 = { "smokey", "gray" };

If you read what you posted, you will see that it is not an English
sentence, you say: "... can I use an array instead of _____ in this case
...." If you mean instead of a struct the answer is that you shouldn't do
that. A struct is used to indicate a "binding" of the various properties of
an entity. There is also a technique called parallel arrays which may be
what you or your friend are proposing. See if you can find anything about
parallel arrays using Google. The proper way to do what I think you want is
an array of structures, that is, each element of the array is a structure.

By "binding" I mean that the name and color are "bound" to a certain
particular cat, In theory you could reach out and touch *that* cat.
 
R

ray

The powers that be have banned Linux useage at my high school and also
at the college because they claim it is responsible for the hacking
virus that we get all the time.

I like Linux and while others think it sucks, I don't. Can I do anything
to get Linux back on the apporved list? Thank You.
Hon

I'd call the local newspaper. And maybe 'Chicita', or Dole.
 
K

Keith Thompson

osmium said:
"Bill Cunningham"

If you read what you posted, you will see that it is not an English
sentence, you say: "... can I use an array instead of _____ in this case
..."
[...]

Actually I think the only problem is a couple of missing commas:
... that I can use an array instead of, in this case, k1, k2, k3
for each of my cats.
or
... that I can use an array instead of (in this case) k1, k2, k3
for each of my cats.
 
J

J.O. Aho

Hon said:
The powers that be have banned Linux useage at my high school and also at
the college because they claim it is responsible for the hacking virus
that we get all the time.

I like Linux and while others think it sucks, I don't.
Can I do anything to get Linux back on the apporved list?

You should contact MIIT, I think they can help you to get Linux as the
approved operating system at your high school, just give them your head
masters office number and they may be calling him before you have
managed to hangup.
 
B

Bill Cunningham

Why are you using "/n" in your printf calls? Did you re-type the code
rather than copy-and-pasting it? Or did you see the output all on one
line when you ran the code and decide it wasn't worth worrying about?
Or did you not bother running it?

<snip>

I pasted this code and before that it compiled and I used \n before /n.
Everything was printed on one line when it was executed. Then I changed it
to /n thinking maybe I did something backwards and I still got one line with
"n"s between each cat name. I have overlooked what has happened and I don't
know why \n didn't work in the format string of printf. Isn't

printf("%s %s\n",k1.name.... and so on correct?


Bill
 
R

Richard

Bill Cunningham said:
<snip>

I pasted this code and before that it compiled and I used \n before /n.
Everything was printed on one line when it was executed. Then I changed it
to /n thinking maybe I did something backwards and I still got one line with
"n"s between each cat name. I have overlooked what has happened and I don't
know why \n didn't work in the format string of printf. Isn't

printf("%s %s\n",k1.name.... and so on correct?


Bill

6/10
 
K

Keith Thompson

Bill Cunningham said:
<snip>

I pasted this code and before that it compiled and I used \n before /n.
Everything was printed on one line when it was executed. Then I changed it
to /n thinking maybe I did something backwards and I still got one line with
"n"s between each cat name. I have overlooked what has happened and I don't
know why \n didn't work in the format string of printf. Isn't

printf("%s %s\n",k1.name.... and so on correct?

Yes, "\n" should work. Change all the "/n"s to "\n"s, recompile, and
try again. If it still doesn't work, post your code and your output.
(Don't even think about trying "/n" again, unless you want to print a
'/' character followed by an 'n' character.)
 
J

jameskuyper

Scott said:
Sorry, I thought it was clear that (since I have seen neither
Summerfield's book nor code) I was explaining the character of
testing that you might see if you did not have access to epsilon
and friends. That test can solve some problems, and I have no
idea what the test in the unquoted code actually was trying to
discover.

In case it wasn't obvious, that message was posted in response to a
message posted by our local village idiot to comp.lang.python, with
follow-ups redirected here.
 
B

Bill Cunningham

Yes, "\n" should work. Change all the "/n"s to "\n"s, recompile, and
try again. If it still doesn't work, post your code and your output.
(Don't even think about trying "/n" again, unless you want to print a
'/' character followed by an 'n' character.)

That's the way I've been doing it and I tried again and the compiler
compiled without any warnings. The output was as I expected. I must've had
an error of some kind in the first try. I was getting some kind of warning
and the code compiled but displayed this:

striper n striped spooky n black

That was when I used \n. When I used /n that was of course what was
displayed:

striper /n striped /n spooky /n black.

Bill
 
A

Aragorn

/
You should contact MIIT, I think they can help you to get Linux as the
approved operating system at your high school, just give them your head
masters office number and they may be calling him before you have
managed to hangup.

And should that fail, then give /us/ a call. We'll show up at your school
as penguins dressed in fatigues, armed with paintball guns, and we'll splat
every Windows-infected computer on the compound until the perimeter is
secured. :p
 
S

Spiros Bousbouras

In case it wasn't obvious, that message was posted in response to a
message posted by our local village idiot to comp.lang.python, with
follow-ups redirected here.

How does he manage to insert his threads in the
middle of an ongoing thread on comp.lang.c ? I've
read the above as part of
< http://groups.google.co.uk/group/comp.lang.c/browse_thread/thread/760276cb07f1e7a4#which has the title "structs". What confuses
me is how posts belonging to a thread started
in a different group end up interspersed with
posts of a thread started on comp.lang.c Or is
what I'm seeing simply an artefact of how
Google does things?
 
M

Man-wai Chang ToDie (33.6k)

The powers that be have banned Linux useage at my high school and also at
the college because they claim it is responsible for the hacking virus
that we get all the time.

Nobles' school? Only nobles could afford Micro$oft stuff... :)
I like Linux and while others think it sucks, I don't.
Can I do anything to get Linux back on the apporved list?

Does your school check each student's operating system? If not, then
just keep using your Linux. All you need are TCP ports to surf the
net.... :)

The real problem is whether your school supports only Internet Explorer
rather than web standards ....

--
@~@ Might, Courage, Vision, SINCERITY.
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Xubuntu 8.04.2) Linux 2.6.28.3
^ ^ 12:44:01 up 1 day 16:23 0 users load average: 1.00 1.00 1.00
¤£­É¶U! ¤£¶BÄF! ¤£´©¥æ! ¤£¥´¥æ! ¤£¥´§T! ¤£¦Û±þ! ½Ð¦Ò¼{ºî´© (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa
 
P

Paul

Spiros said:
How does he manage to insert his threads in the
middle of an ongoing thread on comp.lang.c ? I've
read the above as part of
< http://groups.google.co.uk/group/comp.lang.c/browse_thread/thread/760276cb07f1e7a4#
which has the title "structs". What confuses
me is how posts belonging to a thread started
in a different group end up interspersed with
posts of a thread started on comp.lang.c Or is
what I'm seeing simply an artefact of how
Google does things?

Try this. This is one of his thread bombing runs.

http://groups.google.ca/groups/search?q=Linux+Bananed+At+My+School&qt_s=Search+Groups

Now, look at the message header of the originating post in alt.os.linux.

Subject: Linux Bananed At My School
Followup-To: comp.lang.c
References: <[email protected]> <----- artificially inserted!
From: Hon from China - Master Troll <[email protected]>
Message-ID: <[email protected]>

The insertion of an unrelated Reference, plus the followup,
allows any respondent to be suckered into posting into comp.lang.c,
when they reply to "Linux Bananed At My School".

An original posting (start of a thread) would not normally
have a reference entry.

Paul
 
H

High Plains Thumper

Aragorn said:
And should that fail, then give /us/ a call. We'll show up at
your school as penguins dressed in fatigues, armed with
paintball guns, and we'll splat every Windows-infected
computer on the compound until the perimeter is secured. :p

Rather, do like Indiana Schools. Remove all hard drives. Ghost
with Linux image and apps. Reinstall hard drives. Problem
solved. :)

Oh, and I forgot. Run all Microsoft software licenses and CD's
through a media shredder.
 
M

Man-wai Chang ToDie (33.6k)

The powers that be have banned Linux useage at my high school
and also at

Nobles' school? Only nobles could afford Micro$oft stuff... :)

Does your school check each student's operating system? If not, then
just keep using your Linux. All you need are TCP ports to surf the
net.... :)

The real problem is whether your school supports only Internet Explorer
rather than web standards ....

--
@~@ Might, Courage, Vision, SINCERITY.
/ v \ Simplicity is Beauty! May the Force and Farce be with you!
/( _ )\ (Xubuntu 8.04.2) Linux 2.6.28.3
^ ^ 20:43:01 up 2 days 22 min 2 users load average: 1.01 1.01 1.00
¤£­É¶U! ¤£¶BÄF! ¤£´©¥æ! ¤£¥´¥æ! ¤£¥´§T! ¤£¦Û±þ! ½Ð¦Ò¼{ºî´© (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_addressesa
 
R

Rex Ballard

The powers that be have banned Linux useage at my high school and also at
the college because they claim it is responsible for the hacking virus
that we get all the time.

You could point out that Linux is used by several government agencies
BECAUSE of it's security, including the Chinese government.

You could also point out that has many of the same security features
as UNIX, which is used widely to run everything from the telephone
system to the trains and the air traffic control systems all around
the world.

You could point out that there has not been a successful hack of Linux
systems in over 15 years, and the last major virus to attack Linux
"infected" 8,000 out of 8 million attempted servers., and most of
those servers were vulnerable because they were improperly configured
- newer Linux systems are configured to be more secure by default.

You might also want to stress the importants of learning the
technology used by these various resources and servers.
I like Linux and while others think it sucks, I don't.
Can I do anything to get Linux back on the apporved list?

I suspect that the ban has more to do with the knowledg that Linux is
TOO SECURE and as a result it's harder for government agencies to
monitor what you are doing with your PC. In the United States,
SELinux can be used, in combination with other Open Source Software to
create "spy-proof" communications used by the intelligence community,
the military during combat operations, and other places where material
being viewed is "Top Secret".

The school also knows that you can use Linux systems as unmonitored
servers and can set up levels of security with Stunnel and self-
generated SSL certificates that can be used by dissidents.

In the United States, there was an attempt to ban Unix, Linux, and 128
bit DES encryption for communication, because it was to hard to
crack. Microsoft was able to offer a comprimise by having Verisign, a
private company 25% owned by Microsoft (to avoid regulation) issue
private key certificatets which would be used to encrypt and pass the
DES keys. Tthe RSA public key certificates could be passed to the
intelligence community or a 3rd party monitoring service which could
intercept or "fake" the DES keys and monitor the encrypted
transmissions as needed.

To circumvent the need for court warrants, the intelligence community
made sure that ONLY private companies who were willing to voluntarily
provide the keys on request of an authorized agent was all that was
required to get the information needed.

Windows machines, of course, can be hacked very easily using any
signed ActiveX control, and the signatures can be purchased from
Microsoft for a nominal fee. Since all PCs are pre-configured to
trust Microsoft's Certificate Authority, the Microsoft sold
certificates can be used to hack any PC running Windews.

The "Official" story being given by your school is bogus. The REAL
justification for a ban on Linux is probably a bit more sinister.
 
A

Aragorn

/
Rather, do like Indiana Schools. Remove all hard drives. Ghost
with Linux image and apps. Reinstall hard drives. Problem
solved. :)

Oh, and I forgot. Run all Microsoft software licenses and CD's
through a media shredder.

That would be a terrible waste of those Microsoft CDs, considering that they
make excellent skeet shooting targets. :)

As for the Microsoft licenses, I haven't tried this myself but a little bird
whispered that they make for good toilet paper. Hey, I'm thinking of the
environment! :)
 
H

High Plains Thumper

Aragorn said:
That would be a terrible waste of those Microsoft CDs,
considering that they make excellent skeet shooting targets.
:)

As for the Microsoft licenses, I haven't tried this myself but
a little bird whispered that they make for good toilet paper.
Hey, I'm thinking of the environment! :)

I am thinking of the environment too! The rough paper surface of
those licenses are abrasive enough for our potty mouth COLA
trolls. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Array of structs function pointer 10
structs 12
Command Line Arguments 0
struct problems 71
HELP:function at c returning (null) 4
structs 29
Finding a word inside a string 35
packing and structs 5

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top