Hello Everybody,

For a sorting project I'm working on, I have a string array, with 50 values. I need to convert each string in the array to a two dimensional char array.

For example, Let's say there is a string array[50]. Each position in the array has a name in it. Like say,
array[0] == david, array[1] == robert, etcetera
There's also a char array2[50][32].
array2[0][0] == d, array2[0][1] == a, array2[0][2] == vand so on

Well, from the example above, the string array[50] exists. It contains 50 distinct names (as a matter of interest, the names are from star wars). The very needed char array2[50][32] does not exist. I need that char array[50][32], and it should be pretty much full. If I have that char array, I can do things like convert to ascii/unicode , sort the values, and all sorts of fun stuff like that.

Again, I'm trying to convert a string array[50] into a char array2[50][32]. Some code:

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream myfile("names.dat");
int count = 0;
string names[50];
char array2[50][32]; // this is the data I need
int ascii[50][32]; //this should hold converted strings
while (count < 50) { //read the data from 'names.dat'
myfile >> names[count]; // and store it in names array
count++; //this loop works fine.
}
count = 0;
//right here should be a loop that converts
//one by one the array 'names[50]' into the
//char array 'array2[50][32]

//right here should be a conversion array,
//taking the charr array[50][32] and
//converting it to ascii, but I don't need
//any help with this

//right here should be a selection sort array,
//using the converted asciis, but I don't need
//any help with this
myfile.close();
}

Please help me! I need help very badly! :icon_cry:

Thanks, I think... But is there a good way to break a string down into individual letters?

Did you read the link? c_str() returns a c-style string which is char*stringName[].

All you have to do is store that return then use stringName[x] to access the xth character in the string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.