Invalid Conversion from...
Ok I'm gettin the "Invalid convertion from 'char*' to 'char'" thing. This is different from yer usual error because I'm actually working with pointers.
Here is a boiled down verstuon: #includes char* LOC = new char[501]; //This line had no errors char ret[501]="This is 501 charecters in my program"; *LOC = ret; //This is where the error is End code Well anyone? The heap data is deleted at the end of the program. |
It would be better if you posted your code in [code][/code] tags from now on; it puts code in a box with a monospaced font:
Code:
#include <stdio.h> it looks to me like you're trying to assign the pointer to the first element of ret as the first element of LOC, not the elements themselves. i.e.: char* LOC = new char[501]; dynamically allocates 501 bytes of memory and assigns it to the pointer LOC. char ret[501]="This is 501 charecters in my program"; allocates 501 bytes of memory on the heap and fills them with the values of the string "This is 501 charecters in my program". *LOC = ret; is attempting to assign the pointer to the ret array as the dereferenced value of (i.e. the first element of) the LOC array, so you're implicitly converting from char* to char. I think what you want to do is strcpy the contents of ret into where LOC points to. Something like: Code:
char* LOC = new char[501]; (…awaits abrasive correction from other, more knowledgable members…) |
Are you using C or C++? I didn't think new was a keyword in C. If you're using C++, is there any reason you're not using C++ strings?
Edit: Also, is there any reason you don't have spell checking enabled in your browser? A lot of your posts contain typos. |
I thought there wernt any poi ters in c. Well Using C++. I do have spell check and that's the problem; when you see me posting from a Mac I'm really posting from my iPod Touch (see! See! It will automatically capitalize any of it's products).
I need to use c-style strigns to work with filenames, using a normal string gets me an error. Thanks peeps ya got the anwnswer! Edit: I had no idea that the code tags existed in this forum. |
If you need a C string, you can always use C++ strings to do any manipulation (e.g. concatenation) and then call the c_str() method. See this for a list of string's member functions.
|
All times are GMT -5. The time now is 10:21 AM. |