I'm reading from a text file and taking in strings and placing them into two separate arrays. Ex: TargetArr[1] and TypoArr[1] are pairs. I need to be able to look at each letter in the strings so I've tried converting them into char arrays. I want two arrays of char arrays. The code I have is giving me a seg fault, it's coming from when im trying to create the char*[] and convert the strings to char arrays. Not sure what im doing wrong here. Im trying to take the first string in my normal array, make it a char array, then place into my array of char arrays.
if (myfile.is_open()){
for(int i=0; i<num; i++){
getline(myfile,targetArr[i]);
getline(myfile,typoArr[i]);
getline(myfile,skip);
}
}
char* targetCArr[num+1];
char* typoCArr[num+1];
for(int i=0; i<num; i++){
strcpy(targetCArr[i], targetArr[i].c_str());
strcpy(typoCArr[i], typoArr[i].c_str());
}