Hi,
I am trying to convert a char pointer to a normal char(somehow copy the strings from the pointer and pass it to the char)

Here is a piece of example on what i want to do

#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
    char *namen="Test";
   char test[255];

    test=namen;
    cout<<test<<endl;

    return 0;
}

If i run that code i get the following error : "invalid conversion from char** to char"

I know you cant just copy a char pointer to a char but is there a way or a technique to do it?
Thanks in advanced.

Recommended Answers

All 3 Replies

Nope. What you did makes no sense. A char can only contain 1 char.
Use std::string instead.

Ok i replaced it to something better, but is it possible to do what i want to do?

You actually did it in reverse.

int main()
{
    char *namen;
   char test[255] = "Test";

    namen = test;
    cout << test << endl;
    cout << namen << endl;

    return 0;
}

The pointer can receive the address of the array. Not the other way around.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.