Results 1 to 13 of 13

Thread: some things from a new bie

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    28

    some things from a new bie

    i finally got my book! now i can basic-basic-basic c++!

    some question

    1. whats the diff betwen char and char* ?

    2. how to conv a char* to a char

    the task:
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    
    time_t tempchar;
    tempchar = time(NULL);
    
    char* timetemp
    timetemp=ctime(&tempchar);  // whats that '&' sybol doing anyway?
    
    char timestr
    // nows the error
    timestr=timetemp
    // how to do? i know there are diff of types...
    
    cout << timestr
    
    {
    PLZ HELP!

    ***! Why doesnt this stupid tag work?
    Last edited by Chs; Oct 23rd, 2002 at 01:02 PM.

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    The tag is &#91;code&#93;code&#91;/code&#93;

    1. char * is a pointer, not a character variable. It holds the memory address of a character variable. If you're just starting with C++, you might want to stay away from that until you get a better handle.

    The & is the 'address of' operator. It sets the pointer equal to the address of a variable. Ie:

    Code:
    char money = '\0';
    char *pmoney = NULL;
    
    money = '$'; 
    pmoney = &money; //pmoney = address of money
    Last edited by The Hobo; Oct 22nd, 2002 at 12:22 PM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    oh yeah...

    2. You can't convert char * to char. One is a pointer, the other is a character variable.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    As The Hobo said: stay away from pointers, they don't belong to the basic-basic-basic C++ part. Actually they don't even belong to the basic-basic C++ parts, and only the special uses of char * (pointers to characters) belong to the basic C++ part.

    For now if you need strings use the string class, which is defined in the <string> header:
    Code:
    #include <string>
    using namespace std;
    The & (address-of) operator belongs to pointers.
    There is another meaning of &, but it isn't basic either.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    There are a few additional things you should remember.
    a) Use [ code] ... [/ code] tags to wrap your C++ code when posting here. We all hate you if you don't

    b) Watch your semicolons. You must terminate every command in C++ with a ;
    if you don't the compiler assumes the command continues in the next line. It's like the opposite of the _ at the end of a line in VB.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by CornedBee
    There are a few additional things you should remember.
    a) Use [ code] ... [/ code] tags to wrap your C++ code when posting here. We all hate you if you don't

    b) Watch your semicolons. You must terminate every command in C++ with a ;
    if you don't the compiler assumes the command continues in the next line. It's like the opposite of the _ at the end of a line in VB.
    Unless it's a directive or ends in a brace { or }
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Preprocessor directives are not C or C++ commands...

    Yeah, some statements, like if, while, for, ... (every condition or loop statement) usually aren't terminated by ;, else they woud behave incorrectly.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by CornedBee
    Preprocessor directives are not C or C++ commands...
    Sorry. I didn't meant to upset you...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Why do you think I am upset? I just corrected you.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    May 2002
    Posts
    28

    YEAH

    My book says "Now u have compled Week 1, and u can now program and understand advanced programs"

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Heh. Unlikely.

    It takes years to understand advanced programs
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    "Advanced" from the first week's point of view.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The interesting thing about programming is that it's usually easier to write advanced programs than understanding them. At least for code like that written by most programmers, only rarely is code written so well and commented so thoroughly that it is easier to understand than to read.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width