|
-
Oct 22nd, 2002, 11:59 AM
#1
Thread Starter
Junior Member
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.
-
Oct 22nd, 2002, 12:18 PM
#2
Stuck in the 80s
The tag is [code]code[/code]
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.
-
Oct 22nd, 2002, 12:21 PM
#3
Stuck in the 80s
oh yeah...
2. You can't convert char * to char. One is a pointer, the other is a character variable.
-
Oct 22nd, 2002, 12:22 PM
#4
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.
-
Oct 22nd, 2002, 12:25 PM
#5
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.
-
Oct 22nd, 2002, 12:28 PM
#6
Stuck in the 80s
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 }
-
Oct 22nd, 2002, 04:01 PM
#7
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.
-
Oct 22nd, 2002, 05:59 PM
#8
Stuck in the 80s
Originally posted by CornedBee
Preprocessor directives are not C or C++ commands...
Sorry. I didn't meant to upset you...
-
Oct 23rd, 2002, 03:04 AM
#9
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.
-
Oct 23rd, 2002, 01:03 PM
#10
Thread Starter
Junior Member
YEAH
My book says "Now u have compled Week 1, and u can now program and understand advanced programs"
-
Oct 23rd, 2002, 02:33 PM
#11
Monday Morning Lunatic
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
-
Oct 23rd, 2002, 02:48 PM
#12
"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.
-
Oct 23rd, 2002, 02:50 PM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|