Try this out, then compare the two programs and see what changes I made. And just so that I don't get complaints, void main is not standard and therefore you shouldn't do it. The standard dictates that int main(void) should be used.
Code:
#include <fstream>
#include <stdlib.h>
#include <cstring>
#include <iostream>
using namespace std;
void main()
{
char name[256];
char *namearray[50];
int a = -1;
ifstream new_name("names.txt");
if (!new_name){
cout << "Error opening file.\n";
exit(1);
}
while (!new_name.eof()){
a++;
new_name.getline (name, 255, '\n');
namearray[a] = new char[255];
strcpy(namearray[a], name);
}
for (int v=0; v < a; v++)
cout << namearray [v] << " " << endl;
new_name.close();
}
p.s. I had to create my own data file to test this, but it works quite well.
-Prelude