|
-
January 30th, 2005, 03:53 PM
#1
pointers
Okay this is really making me mad. I have a pointer to a char(char *filename) and I want to assign that to a buffer(char buffer). I've tried looking around and tried what they put( buffer = &filename, etc..) but it still pops up an error
Code:
error C2440: 'initializing' : cannot convert from 'char **__w64 ' to 'char []'
Please help.
-
January 30th, 2005, 04:04 PM
#2
Re: pointers
Show us some code, someone will help then.
B+!
'There is no cat' - A. Einstein
Use [code] [/code] tags!
Did YOU share your photo with us at CG Members photo gallery ?
-
January 30th, 2005, 05:56 PM
#3
Re: pointers
Something like this:
Code:
char *string;
char buffer = &string
-
January 30th, 2005, 06:07 PM
#4
Re: pointers
 Originally Posted by Notsosuperhero
Something like this:
Code:
char *string;
char buffer = &string
Well, there are two things wrong here: You are taking the address of the pointer (instead of just the pointer itself) and you are trying to assign it to a single character (not a buffer). In order to copy text characters pointed to by a char* to a char array, you should use strncpy().
-
January 30th, 2005, 06:08 PM
#5
Re: pointers
Your terminology is a little difficult to understand.
A character pointer is a pointer to a series of characters in memory.
A character array is storage space for such a series of characters.
You said you have a pointer (possibly a char *) which you would like to assign to buffer (whatever that is).
If you are trying to copy the characters from one place to another, you may need to use something like strcpy to perform a simple string copy. Before doing this, the buffer must be large enough to hold these characters being copied.
Something like this should work...
char *MyPointer = "Hello World";
char MyBuffer[100];
strcpy(MyBuffer, MyPointer);
Hope this helps,
- Nigel
-
January 30th, 2005, 08:50 PM
#6
Re: pointers
... or doing it in the C++ way.
Code:
include <string>
using namespace std;
int main()
{
const char *myString = "Hello world";
string anotherString(myString);
return 0;
}
Last edited by Kheun; January 30th, 2005 at 10:27 PM.
-
January 30th, 2005, 09:56 PM
#7
Re: pointers
Thank you all. I was a little tired(OK really tired) when I was posting this.
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
|