Hey guys,
I was working on a program where I had to convert an old C program into a C++ program.
I am supposed to create a ciphertext class and use it to output a ciphertext that I get from a file. So far, I have written:
Code:
class Ciphertext{
private:
char file_name[20];
char *ciphertext[10];
public:
Ciphertext(char file_input[20])
{
FILE *fp;
char input[MAX_LENGTH+1];
int m=0;
strcpy(file_name,file_input);
fp=fopen(file_name, "r");
while((fgets(input,80,fp))!=NULL)
{
ciphertext[m]=malloc(strlen(input)+1);
strcpy(ciphertext[m],input); /**** ERROR HERE*****/
m++;
}
~Ciphertext(){}
int main(void)
{
printf("Please enter file name where the encoded text is found:");
scanf("%s",file_name);
while(getchar()!='\n');
Ciphertext my_ciphertext(file_name);
}
where the member function ciphertext is my constructor function. When I try to compile my code, I am getting an error: "c2440: cannot conver from void* to char*" and it says this error occurs at the line above marked error here. This is very confusing to me because the code above worked perfectly when I was to write the program in regular C. Please help me understand where I am going wrong.
Thanks,
Andy