Dear All,
I have a code as below. First I call the readFile in here I can read the value into the name variable which I have declared as string. The problem now as I run the loop I want to put each of the name into an array of names which is the clientName. Here is where I am stuck char *isName = new char;*isName = name;strcpy(clientName[clientCount],isName);? Any help please? Thank you.

#include <iostream>
#include <string>
#include <fstream>

using namespace std;
void readFile(char* [],int []);
void caclulateInterest(char * [],int [],int []);
int main()
{
	int totalClient = 10;
	char *clientName[10];
	int clientSavings[10],clientInterest[10];
	
    readFile(clientName,clientSavings);
	//caclulateInterest(clientName,clientSavings,clientInterest);
}

void readFile(char *clientName[],int clientSavings[])
{
	int clientCount=0;
	ifstream inFile;
	inFile.open("example.txt");
	 
 
	if(inFile.is_open())
	{   
	    
		while(!inFile.eof()) 
		{
		 string name="";
		 double salary = 0.00;	
         getline(inFile,name,'#');
		 inFile>>salary;
		 char *isName = new char[20];
		 *isName = name;
		 strcpy(clientName[clientCount],isName);
         //cout<<"\nName"<<name;
		 //cout<<"\nSalary"<<salary;
		 clientCount++;
		}
		//system("pause");
	}
	else
	{
	  cout<<"Failed to open";	
	}
   
}
void caclulateInterest(char *clientName[],int clientSavings[],int clientInterest[])
{
   for(int i=0; i<2; i++)
   {
	   cout<<"Name is : "<<*clientName[i];
   }
   system("pause");
}

Dear Jonsa,
I should put like this is it std::string name="";. Can you tell me which one to pick I am quite confuse too ?

This article has been dead for over six months. Start a new discussion instead.