[Solved] strcpy a reference to a pointer function


I’ve made small changes in your source code in order to test it and fix it. I’ve created a method called SetfileName in Frame class and also changed the char *fileName to char fileName[40], so that Frame class holds the value of fileName instead of the pointer.

 #include <iostream>
 #include <string.h>

 using namespace std;

 class Frame {
        char fileName[40];
        Frame *pNext;

    public:
        Frame() {}
        ~Frame() {}
        const char *GetfileName () { return fileName; }
        const Frame *GetpNext () { return pNext; };

        void SetfileName(const char *name) { strncpy(fileName, name, sizeof(fileName)); }

        void printFileName() { cout << fileName << endl;  }
};


void InsertFrame() {
        Frame* frame = new Frame; //used to hold the frames
        char* firstName = new char[40];

        cout << "Please enter the Frame filename :";

        cin.getline(firstName, 40); //enter a filename
        frame->SetfileName(firstName);
        frame->printFileName();
}

int main() {

    InsertFrame();

    return 0;
}

solved strcpy a reference to a pointer function