newbie...please help!

C

cj

Hello! I need some major help! I took this computer programming class
to learn more about computers. Picked this class because it had a
section to learn web page design but now I have to complete the section
about the c language and I have no clue! I'm totally stressing out
because it is blowing my mind and if I don't complete all the lessons I
don't receive a certificate of completion. Please someone help me! Here
are a few questions:

What is the length returned by the "strlen()" function?
char dog[80]

strcpy (dog,"I am a dog");
strlen (dog);

Which animal will be replaced with "fly" in the following code
fragment?
char animals [ ] [3][6] = {
"cow","pig","dog","rat","bat","hen","eel","ant","cat","ox","owl","yak","ram","bee","doe"}
strcpy(animals [2] [1] , "fly");

What is the difference between the 7's in thse two statements?
long cat [7];
cat[7] = 5L


I will only ask 3 for now until I see the response I get from anyone
willing to help. I appreciate any help! Thanks
 
S

Sandeep

hmm ... I would be surprised if you get answers to these questions
here. My suggestion would be to fire up your friendly compiler and type
simple programs to see what answers you get for your queries.

This can get you started.
#include<iostream>

using namespace std;

int main()
{
char dog[80];

strcpy(dog,"someone is a dog");
cout<<"Length of dog is: "<<strlen(dog)<<endl;

return 0;
}
 
A

Alf P. Steinbach

* cj:
Hello! I need some major help! I took this computer programming class
to learn more about computers. Picked this class because it had a
section to learn web page design but now I have to complete the section
about the c language

This group is concerned with C++, not C: you're off-topic, post in
[comp.lang.c].

and I have no clue! I'm totally stressing out
because it is blowing my mind and if I don't complete all the lessons I
don't receive a certificate of completion. Please someone help me!

Homework is off-topic also in [comp.lang.c].
 
O

osmium

cj said:
Hello! I need some major help! I took this computer programming class
to learn more about computers. Picked this class because it had a
section to learn web page design but now I have to complete the section
about the c language and I have no clue! I'm totally stressing out
because it is blowing my mind and if I don't complete all the lessons I
don't receive a certificate of completion. Please someone help me! Here
are a few questions:
What is the difference between the 7's in thse two statements?
long cat [7];
cat[7] = 5L

The first one creates an array with space to store 7 long ints.

The second attempts to write the value 5, which is specified as being a long
int by the L, into an array named cat. Since the array elements of *this*
cat are numbered 0 to 6 inclusive, there is no legitimate place to put the
5. If you are lucky the program will bomb, if it doesn't fail now you may
be in for some nasty surprises at a later time. The C language is perfectly
willing to do what it's told, as here. That was part of its early quirky
charm contributing to its success..

Now that you are in the course, read the syllabus again. Is it an honest
description of what is happening in class? Sounds fishy to me. Or else your
reading of the syllabus when you signed up was kind of a skim instead of a
read.
 
M

Mike Wahler

cj said:
Hello! I need some major help! I took this computer programming class
to learn more about computers. Picked this class because it had a
section to learn web page design but now I have to complete the section
about the c language and I have no clue! I'm totally stressing out
because it is blowing my mind and if I don't complete all the lessons I
don't receive a certificate of completion. Please someone help me! Here
are a few questions:

What is the length returned by the "strlen()" function?
char dog[80]

strcpy (dog,"I am a dog");
strlen (dog);

Which animal will be replaced with "fly" in the following code
fragment?
char animals [ ] [3][6] = {
"cow","pig","dog","rat","bat","hen","eel","ant","cat","ox","owl","yak","ram","bee","doe"}
strcpy(animals [2] [1] , "fly");

What is the difference between the 7's in thse two statements?
long cat [7];
cat[7] = 5L


I will only ask 3 for now until I see the response I get from anyone
willing to help. I appreciate any help! Thanks

You'll find the answers in your textbook.

Note that this newsgroup is about C++, not C. However,
all the constructs above are common to both C and C++.

Yes, we're very willing to *help*, but *help* means
that *you* are doing something too. So review your
book, come back (or visit comp.lang.c or alt.comp.lang.learn.c-c++)
and post your attempts at answers, and we'll tell you if they're
correct, and if they're not, we'll help you make them correct.

-Mike
 
C

cj

Sorry to bother you! I did post in the comp.lang.c group but thought it
wouldn't hurt to post here also...excuse me ...it won't happen again
 
C

cj

The textbook is confusing me compared to my workbook. And I am trying,
that's why I am so stressed. But hey Mike thanks for taking time to
reply! I think I can get help from others that aren't so rude and fyi:
I did post in the comp.lang.c group so I'm not all that stupid. Just
didn't think it would hurt to post here too but I guess I was wrong.
 
P

Phlip

cj said:
The textbook is confusing me compared to my workbook. And I am trying,
that's why I am so stressed. But hey Mike thanks for taking time to
reply! I think I can get help from others that aren't so rude and fyi:
I did post in the comp.lang.c group so I'm not all that stupid. Just
didn't think it would hurt to post here too but I guess I was wrong.

I suspect that the C group will be much more grumpy than this one.

What I did for my first C class was simple: I sat down one weekend and read
the friggin textbook, from near the beginning until after the middle,
straight through.

Only after this fun did I try to write programs, and hence try to use the
tutorial as a reference for quick lookups. And I got to use a lot of
features, such as strlen(), right away without looking them up.
 
A

Alan Johnson

osmium said:
cj said:
What is the difference between the 7's in thse two statements?
long cat [7];
cat[7] = 5L


The first one creates an array with space to store 7 long ints.

The second attempts to write the value 5, which is specified as being a long
int by the L, into an array named cat.

I prefer a more literal interpretation of the question.

7 - 7 = 0

Therefore, the answer is 0.
 
J

JustBoo

On Wed, 11 Jan 2006 03:14:12 GMT, "Mike Wahler"

"Soca, his eyes open!" "Mirab, with sails unfurled."
Yes, we're very willing to *help*, but *help* means
that *you* are doing something too. So review your
book, come back (or visit comp.lang.c or alt.comp.lang.learn.c-c++)
and post your attempts at answers, and we'll tell you if they're
correct, and if they're not, we'll help you make them correct.
-Mike

This should be in the FAQ. :-D (Okay, it probably already is...
somewhere... worded differently... under a nebulous title...
somewhere... in the FAQ.)

You da' man! Um, sorry Mike, I'm a plonked outcast so I apologize for
the trouble my compliment might cause you. :)

[In a quiet humble voice]
'Flatter me, and I may not believe you. Criticize me, and I may not
like you. Ignore me, and I may not forgive you. Encourage me, and I
will not forget you.' -- William Arthur Ward
 
D

Default User

cj said:
Sorry to bother you! I did post in the comp.lang.c group but thought
it wouldn't hurt to post here also...excuse me ...it won't happen
again


Yes, and you can imagine how well the post went over there.

If you are going to post to more than one group, learn how to
crosspost. However, usually you should not be posting to more than one.
Also read the information below.



Brian
 
D

Default User

Phlip said:
I suspect that the C group will be much more grumpy than this one.
:)

What I did for my first C class was simple: I sat down one weekend
and read the friggin textbook, from near the beginning until after
the middle, straight through.

Pretty much what I did. I also took reading notes. That was the most
motivated I ever was for a class, but I was taking it because I really
wanted to learn C, it was my first return to school after several years
out. I still have that book of reading notes.


Brian
 
J

Jim Langston

cj said:
Hello! I need some major help! I took this computer programming class
to learn more about computers. Picked this class because it had a
section to learn web page design but now I have to complete the section
about the c language and I have no clue! I'm totally stressing out
because it is blowing my mind and if I don't complete all the lessons I
don't receive a certificate of completion. Please someone help me! Here
are a few questions:

What is the length returned by the "strlen()" function?
char dog[80]

strcpy (dog,"I am a dog");
strlen (dog);

Since this is kinda like homework I'll make you think a little.

strcpy(dog, "woof");
strlen(dog);
this strlen would return 4.

strcpy(dog, "woof woof");
strlen(dog);
this strnlen would return 9.

So what do you think
strcpy(dog, "I am a dog");
would return? strlen counts the characters until the first null terminator,
which is simply the value 0. A c-style string is terminated with a 0 byte.
"woof" contains 5 bytes. 'w' 'o' 'o' 'f' '\0'. '\0' is a way of making a
character 0, which can also just be 0.
 
C

cj

Thanks to all who replied! Some of the info was very helpful which is
what I was looking for. Thanks again!
 

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

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top