I am trying to write a program that stores char arrays of names.
This is my code
#include <iostream>
#include <string.h>
using namespace std;
char **names;
char *input_name;
int main() {
names = new char*[10];
for(int i=0; i<10; i++){
names = new char[60];
cout << "Input name" << i << ": \n";
cin >> input_name;
strcpy(names[i],input_name);
cout << names[i] << "\n";
}
return 0;
}
Firstly I am getting the cannot convert ‘char*’ to ‘char**’ in assignment
names = new char[60]; error.
Also, getting the invalid conversion from ‘char’ to ‘const char*’ [-fpermissive]
strcpy(names[i],input_name); error
I would greatly appreciate it if someone could modify my code and help me out
Thanks
names = new char[60];benames[i] = new char[60];? The other errors are side-effect of the previous error.input_nameuninitialized. In your case, it will be easier just to make it a simple string instead of a pointer.char input_names[60];.std::string?