newbie...please help!

Discussion in 'C++' started by cj, Jan 11, 2006.

  1. cj

    cj Guest

    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
    cj, Jan 11, 2006
    #1
    1. Advertising

  2. cj

    Sandeep Guest

    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;
    }


    cj wrote:
    > 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
    Sandeep, Jan 11, 2006
    #2
    1. Advertising

  3. * 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].

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Jan 11, 2006
    #3
  4. cj

    osmium Guest

    "cj" wrote:

    > 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:

    <snip>

    > 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.
    osmium, Jan 11, 2006
    #4
  5. cj

    Mike Wahler Guest

    "cj" <> wrote in message
    news:...
    > 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
    Mike Wahler, Jan 11, 2006
    #5
  6. cj

    cj Guest

    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
    cj, Jan 11, 2006
    #6
  7. cj

    cj Guest

    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.
    cj, Jan 11, 2006
    #7
  8. cj

    Phlip Guest

    cj wrote:

    > 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.

    --
    Phlip
    http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
    Phlip, Jan 11, 2006
    #8
  9. cj

    Alan Johnson Guest

    osmium wrote:
    > "cj" wrote:
    >>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.
    Alan Johnson, Jan 11, 2006
    #9
  10. cj

    JustBoo Guest

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

    "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
    JustBoo, Jan 11, 2006
    #10
  11. cj

    Default User Guest

    cj wrote:

    > 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

    --
    Please quote enough of the previous message for context. To do so from
    Google, click "show options" and use the Reply shown in the expanded
    header.
    Default User, Jan 11, 2006
    #11
  12. cj

    Default User Guest

    Phlip wrote:

    > cj wrote:
    >
    > > 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.


    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
    Default User, Jan 11, 2006
    #12
  13. cj

    Jim Langston Guest

    "cj" <> wrote in message
    news:...
    > 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.
    Jim Langston, Jan 12, 2006
    #13
  14. cj

    cj Guest

    Thanks to all who replied! Some of the info was very helpful which is
    what I was looking for. Thanks again!
    cj, Jan 19, 2006
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JC
    Replies:
    4
    Views:
    7,949
    Jeff C
    Jul 8, 2004
  2. Replies:
    4
    Views:
    491
    Chris Uppal
    May 5, 2005
  3. KK
    Replies:
    2
    Views:
    523
    Big Brian
    Oct 14, 2003
  4. MuZZy
    Replies:
    7
    Views:
    1,719
    Mike Hewson
    Jan 7, 2005
  5. mera
    Replies:
    7
    Views:
    1,079
Loading...

Share This Page