Hey guys, I am trying to take chars from a file, and place them into 2 different dynamically allocated arrays.
An example of the file would be
name:John Doe&id:1448&phone:98765
One array stores name, id, and phone, and another should store each value.
I have gone ahead and taken the string and converted it into a char array, past that, I am at a loss for how to take the chars and use strcpy to get them into the arrays. Thanks for your help!
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
string fileName, line;
fstream accountInfo;
char *entireString = new char[0];
char **keys= new char*[0];
char **values = new char*[0];
cout << "Please enter the name of the file you wish to use." <<endl;
cin >> fileName;
accountInfo.open(fileName.c_str());
if(!accountInfo)
{
cout << "Unable to open file!";
exit(1);
}
while(getline(accountInfo,line))
{
int count = 0;
int columnCount = 0;
entireString[line.length()+1];
strcpy(entireString,line.c_str());
for(int i = 0; i < line.length(); i++)
{
if(entireString[i] == ':')
{
for(int i = entireString.length() + 1; i < count ; i++)
{
}
count = 0;
columnCount++;
}
if(entireString[i] == '&')
{
count = 0;
}
if(entireString[i] == ':')
{
count = 0;
}
if(entireString[i] == '&')
{
count = 0;
}
if(entireString[i] == ':')
{
count = 0;
}
if(entireString[i] == '&')
{
count = 0;
}
if(entireString[i] != ':' || entireString[i] != '&')
{
count++;
}
}
}
accountInfo.close();
}
The if statements were an idea of mine to gradually progress through the array, find out where I am in the array, and strcpy the values behind it somehow into the array, thus the counters.
And I realize my statement in the for loop is wrong. Working on that problem too :)