Replacing specific chars with different and more chars - c++

I'm trying to do an interesting exercise from a book with the following question:
For our dynamically allocated strings, create a function replaceString that takes
three parameters, each of type arrayString: source, target, and replaceText.
The function replaces every occurrence of target in source with replaceText.
For example, if source points to an array containing abcdabee, target points to
ab, and replaceText points to xyz, then when the function ends, source should
point to an array containing xyzcdxyzee.
I replace every occurence of target, in this case ab, with replaceText, in this case xyz in char *.
For this exercise the book uses a 0 to mark char * termination and uses a typedef for char *. I've written the following function to test replaceString out.
arrayString being typedef char *arrayString
void replaceStringTester() {
arrayString test = new char[8];
test[0] = 'a';
test[1] = 'b';
test[2] = 'c';
test[3] = 'd';
test[4] = 'a';
test[5] = 'b';
test[6] = 'e';
test[7] = 'e';
test[8] = 0;
arrayString target = new char[3];
target[0] = 'a';
target[1] = 'b';
target[3] = 0;
arrayString replaceText = new char[4];
replaceText[0] = 'x';
replaceText[1] = 'y';
replaceText[2] = 'z';
replaceText[3] = 0;
replaceString(test, target, replaceText);
cout << test;
}
As well as the following function to find the length of an arrayString
int length(arrayString as) {
int count = 0;
while (as[count] != 0) {
++count;
}
return count;
}
My idea up until now has been, iterate over the source arrayString, check does the source start with the first char of target? If it does, iterate over target and check if the rest lines up. I've written following function for it, however im uncertain if it does exactly what I drafted up.
void replaceString(arrayString &source, arrayString target, arrayString replaceText) {
int sourceLength = length(source);
int targetLength = length(target);
int replaceTextLength = length(replaceText);
int targetPresent = 0;
for (int i = 0; i < sourceLength; ++i) {
if (source[i] == target[0]) {
int count = 0;
for (int k = 0; k < targetLength; ++k) {
if (target[k] == source[i + k]) {
++count;
}
}
if (count == targetLength) {
++targetPresent;
}
}
}
int newStringLength = sourceLength + (replaceTextLength - targetLength) * targetPresent + 1;
arrayString newString = new char[newStringLength];
newString[newStringLength] = 0;
int j = 0;
int i = 0;
while (j < newStringLength) {
if (source[j] == target[0]) {
bool targetAcquired = false;
for (int k = 0; k < targetLength; ++k) {
if (target[k] == source[j + k]) {
targetAcquired = true;
} else {
targetAcquired = false;
break;
}
}
if (targetAcquired) {
for(int k = 0; k < replaceTextLength; ++k) {
newString[i] = replaceText[k];
++i;
}
j += targetLength;
}
if (!targetAcquired) {
newString[i] = source[j];
++j;
++i;
}
} else {
newString[i] = source[j];
++j;
++i;
}
}
delete[] source;
source = newString;
}
Edit:
I've solved it by implementing two trackers for our positions in each respective stringArray and then filtering with a boolean what is in where. Thank you for your help.

For starters using this typedef
typedef char *arrayString;
is a bad idea. For example if you need to declare a pointer to a constant string then this declaration
const arrayString p;
will not denote
const char *p;
It means
char * const p;
that is not the same as the above declaration..
And the second and the third parameters of your function should be declared as having the type const char * because they are not changed within the function,
The function should be declared the following way
char * replaceString( char * &source, const char *target, const char *replaceText );
Within the function you need at first to count how many times the string target is found in the string source. When using this information and the length of the string replaceText you need to allocate dynamically a new character array if it is required. When just copy the source string into the dynamically allocated array substituting the target string for the replacing string.
After that you should delete the source string and assign its pointer with the newly formed string.
Pat attention to that there is standard C string function strstr declared in the header <cstring> that can simplify your code. Also to find the length of a string you can use another standard C string function strlen. Otherwise you should write them yourself.

Count how many elements you've assigned:
test[0] = 'a'; // 1
test[1] = 'b'; // 2
test[2] = 'c'; // 3
test[3] = 'd'; // 4
test[4] = 'a'; // 5
test[5] = 'b'; // 6
test[6] = 'e'; // 7
test[7] = 'e'; // 8
test[8] = 0; // 9
You've assigned 9 elements. Are there 9 elements in the array?
arrayString test = new char[8];
No. There aren't 9 elements in the array. There are 8. You access outside the bounds of the array and the behaviour of the program is undefined.
arrayString being typedef char *arrayString
Don't use obfuscation like this. It reduces readability and provides no advantages.

Related

Recursion loses solution in array while unwinding

I am trying to design a recursive solution to Lewis Carroll's 'Word Ladder' game
The game attempts to link a starting word, for example 'WET' to an ending word, e.g. 'DRY' using a chain of words where between any 2 words just 1 letter is different. There is a limit on how many words can be used to make the chain.
For example for WET - DRY the solution is WET - bet - bat - bay - day - DRY
I am using the below recursive C function
exit condition: word is 1 step away from the 'target word' - i.e. if it sees DAY (= 1 step away from DRY), it returns true
It finds the solution, however, the problem is: it does not pass the solution back to original function. With each return call, the chain shaves off one word - i.e. the function's innermost call correctly solves 'bet - bat - bay - day' and stores it in the answer_chain - however once calls unwind - this array somehow gets passed as 'bet - bat - bay' (=loses 1 word), and so on, and as a result the original outermost function call gets no information about the solution.
I've tried:
Copying 'by value' by creating a c-style string first, assigning it back later
Copying the array item-by-item only when the first return is reached, and just assigning one array to the other otherwise (answer_chain = answer_chain_temp)
I've unfortunately not been able to figure out what the issue actually is.
Any help would be greatly appreciated.
bool find_chain(const char* start_word, const char* target_word, const char* answer_chain[], int max_steps){
if (answer_chain[0] == NULL) {} // This is to zero out incoming answer_chain
else if (!valid_step(start_word,answer_chain[0])){
delete[] answer_chain;
for (unsigned int i = 0; i < sizeof(answer_chain)/sizeof(answer_chain[0]);++i){
answer_chain[i] = NULL;
}
}
int filled_words = find_sz_of_char_arrays(answer_chain); // Looks for null-terminator
string previous_word, try_new_word;
bool is_solved = false;
if (valid_chain(answer_chain) && valid_step(answer_chain[filled_words-1],target_word) ) {
is_solved = true;
}
if (is_solved) {return true;}
if (max_steps == 0 && !is_solved) {return false;}
if (filled_words > 0) { previous_word = answer_chain[filled_words-1];} else {previous_word = start_word;}
for (unsigned int j = 0; j < strlen(start_word); ++j){
try_new_word = previous_word;
for (unsigned int i = 0; i < 26; ++i){
char new_char = i + 'A';
if (try_new_word.at(j) != new_char) { // has to be different from character already in place
try_new_word.at(j) = new_char;
if (valid_step(previous_word.c_str(),try_new_word.c_str()) && !is_word_already_in_chain(try_new_word.c_str(),answer_chain) ) {
const char** answer_chain_temp = new const char*[15]; // append 'try' word to answer array
for (int k = 0; k < filled_words;++k){
answer_chain_temp[k] = answer_chain[k];}
answer_chain_temp[filled_words] = try_new_word.c_str();
answer_chain_temp[filled_words+1] = NULL;
if (find_chain(start_word,target_word,answer_chain_temp,max_steps-1)){
delete[] answer_chain;
answer_chain = new const char*[15];
for (int kk = 0; kk < 15;++kk) {
if (answer_chain_temp[kk]!=NULL){
answer_chain[kk] = answer_chain_temp[kk];
}
}
delete[] answer_chain_temp;
return true;
} // if successful - append the word
} // if valid step
} // if letter is differerent
} // for i
} // for j
return false;
}
EDIT:
I've now changed the middle part to copy the .s_str() by value, however the issue still seems to persist. I believe something is off with how I am copying and deleting after the solution has been found:
const char** answer_chain_temp = new const char*[15]; // append 'try' word to answer array
for (int k = 0; k < filled_words;++k){answer_chain_temp[k] = answer_chain[k];}
char * writable = new char[try_new_word.size() + 1];
std::copy(try_new_word.begin(), try_new_word.end(), writable);
writable[try_new_word.size()] = '\0';
answer_chain_temp[filled_words] = writable;
answer_chain_temp[filled_words+1] = NULL;
if (find_chain(start_word,target_word,answer_chain_temp,max_steps-1)){
delete[] answer_chain;
answer_chain = new const char*[15];
for (int kk = 0; kk < 15;++kk) {
if (answer_chain_temp[kk] != NULL){
answer_chain[kk] = answer_chain_temp[kk]; // <<<<<< I believe the problem is here
}
}
display_chain(answer_chain,cout); cout << endl;
delete[] answer_chain_temp;
return true;```

In arrays, see if last four elements of 1st array match last 4 elements of 2nd array?

How is it possible to see if the last four elements of an array match the last four elements of the second array?
For instance, I'm writing a password program. First, the user is asked their birth date. Then they are asked to input a password.
for the birth date array, the user enters '05/14/1984'
for the password array, the user enters 'coke_1984'
I'm trying to see if the last four of birth date are the same as the last four of the password, if all four match, then add 1 to score.
I'm completely stuck! The code I have now has an "invalid conversion from 'char' to 'const char*'"
for(i = len; i <= len; i--)
{
if(strcmp(birthdate, password[i]) == 0)
{
dateCMP = true;
}else{dateCMP = false;}
}
if(dateCMP = true)
{
score += 1;
cout << "Your date of birth should not be the last four characters";
}
Make your life easier and take advantage of the already provided STL facilities like std::string.
Below is a function that takes as entries 2 strings and returns true if their last 4 characters are equal and false otherwise:
bool
compare_last_4_characters(std::string const &str1, std::string const &str2) {
std::size_t sz1 = str1.size();
std::size_t sz2 = str2.size();
if(sz1 > 3 && sz2 > 3) {
return str1.substr(sz1 - 4, sz1) == str2.substr(sz2 - 4, sz2);
}
return false;
}
LIVE DEMO
If you can't use std::string below is a version that works without them:
bool
compare_last_4_characters(char const *str1, char const *str2) {
int sz1 = strlen(str1) - 4;
int sz2 = strlen(str2) - 4;
if(sz1 >= 0 && sz2 >= 0) return !strcmp(str1 + sz1, str2 + sz2);
return false;
}
LIVE DEMO
#include <iostream>
#include <utility>
#include <algorithm>
//size_t literal: see http://stackoverflow.com/questions/22346369/initialize-integer-literal-to-stdsize-t
constexpr std::size_t operator "" _z(unsigned long long n)
{
return n;
}
bool lastFourEquals(const char* str1, size_t strlen1, const char* str2, size_t strlen2)
{
//variant 1: do not allow shorter strings
//if(strlen1 < 4 || strlen2 < 4) return false;
//Variant 2: maximum of last for equals (e.g. "123"=="0123")
size_t maxLen =std::min(std::max(strlen1, strlen2), 4_z);
for (int i = 1; i <= maxLen; i++)
{
size_t pos1 = strlen1 - i;
size_t pos2 = strlen2 - i;
if (str1[pos1] != str2[pos2]) return false; //Found difference
}
return true;
}
int main()
{
const char* test1 = "05/14/1984";
const char* test2 = "coke_1984";
bool eq = lastFourEquals(test1, strlen(test1), test2, strlen(test2));
std::cout << (eq ? "true" : "false") << std::endl;
}
I figured it out by using another array. I just made an array called compare to store values of password if password[i] == birthdate[i]... then used an if to strcmp(compare, birthdate)...
for(i = len-4; i < len; i++)
{
if(birthdate[i] == password[i])
{
compare[i] = password[i];
}
}
if(strcmp(compare, birthdate))
{
score += 1;
}
Thanks for your attempts to help!
I think this works! I finally got it. It's a pain in the ass not being able to use the string library. Please let me know! You guys have been so much help. Don't worry about my other arguments in the function, I'm not using those quite yet.
//this function runs to see if the first letter of last name matched
//first letter of password, if the birthdate
int checkStrength(char password[SIZE], char lastName[SIZE], char
birthdate[SIZE], char carMake[SIZE], int favNum)
{
//array and variables for use through the checks
char compareDate[SIZE];
int weakness = 0;
int len = strlen(password) - 4;
int i;
int c = 0;
//this for loop compares arrays, if comparison is found, adds element to
//compareDate and then uses an if statement to strcmp compare and birthdate
//if compare and birthdate are then the same, add weakness
for(i = 0; i < len; i++)
{
if(birthdate[c] == password[len])
{
compareDate[c] = password[i];
c += 1;
}
}
if(strcmp(compareDate, birthdate) == 1)
{
weakness += 1;
cout << "Your birth year should not be the last four character of your
password.";
cout << compareDate;
}
//this checks to see if the car make array is used in order through password,
//if it is, add weakness
return weakness;
}

Insert symbol into string C++

I need to insert symbol '+' into string after its each five symbol.
st - the member of class String of type string
int i = 1;
int original_size = st.size;
int count = 0;
int j;
for (j = 0; j < st.size; j++)
{
if (i % 5)
count++;
}
while (st.size < original_size + count)
{
if (i % 5)
{
st.insert(i + 1, 1, '+');
st.size++;
}
i++;
}
return st;
I got an error in this part of code. I think it is connected with conditions of of the while-cycle. Can you help me please how to do this right?
If I've understood you correctly then you want to insert a '+' character every 5 chars in the original string. One way to do this would be to create a temporary string and then reassign the original string:
std::string st("A test string with some chars");
std::string temp;
for (int i = 1; i <= st.size(); ++i)
{
temp += st[i - 1];
if (i % 5 == 0)
{
temp += '+';
}
}
st = temp;
You'll notice I've started the loop at 1, this is to avoid the '+' being inserted on the first iteration (0%5==0).
#AlexB's answer shows how to generate a new string with the resulting text.
That said, if your problem is to perform in-place insertions your code should look similar to this:
std::string st{ "abcdefghijk" };
for(auto i = 4; i != st.size(); i += 5)
st.insert(i+1, 1, '+'); // insert 1 character = '+' at position i
assert(st == "abcde+fghij+k");
std::string InsertEveryNSymbols(const std::string & st, size_t n, char c)
{
const size_t size(st.size());
std::string result;
result.reserve(size + size / n);
for (size_t i(0); i != size; ++i)
{
result.push_back(st[i]);
if (i % n == n - 1)
result.push_back(c);
}
return result;
}
You don't need a loop to calculate the length of the resulting string. It's going to be simply size + size / 5. And doing multiple inserts makes it a quadratic-complexity algorithm when you can just as easily keep it linear.
Nothing no one else has done, but eliminates the string resizing and the modulus and takes advantage of a few new and fun language features.
std::string temp(st.length() + st.length()/5, '\0');
// preallocate string to eliminate need for resizing.
auto loc = temp.begin(); // iterator for temp string
size_t count = 0;
for (char ch: st) // iterate through source string
{
*loc++ = ch;
if (--count == 0) // decrement and test for zero much faster than
// modulus and test for zero
{
*loc++ = '+';
count = 5; // even with this assignment
}
}
st = temp;

I Am Able To Go Outside Array Bounds

Given two strings, write a method to decide if one is an anagram/permutation of the other. This is my approach:
I wrote this function to check if 2 strings are anagrams (such as dog and god).
In ascii, a to z is 97 - 122.
Basically I have an array of bools that are all initially false. Everytime I encounter a char in string1, it marks it as true.
To check if its an anagram, I check if any chars of string2 are false (should be true if encountered in string1).
I'm not sure how but this works too: arr[num] = true; (shouldnt work because I dont take into account that ascii starts at 97 and thus goes out of bounds).
(Side note: is there a better approach than mine?)
EDIT: Thanks for all the responses! Will be carefully reading each one. By the way: not an assignment. This is a problem from a coding interview practice book
bool permutation(const string &str1, const string &str2)
{
// Cannot be anagrams if sizes are different
if (str1.size() != str2.size())
return false;
bool arr[25] = { false };
for (int i = 0; i < str1.size(); i++) // string 1
{
char ch = (char)tolower(str1[i]); // convert each char to lower
int num = ch; // get ascii
arr[num-97] = true;
}
for (int i = 0; i < str2.size(); i++) // string 2
{
char ch = (char)tolower(str2[i]); // convert char to lower
int num = ch; // get ascii
if (arr[num-97] == false)
return false;
}
return true;
}
There is nothing inherent in C++ arrays that prevents you from writing beyond the end of them. But, in doing so, you violate the contract you have with the compiler and it is therefore free to do what it wishes (undefined behaviour).
You can get bounds checking on "arrays" by using the vector class, if that's what you need.
As for a better approach, it's probably better if your array is big enough to cover every possible character (so you don't have to worry about bounds checking) and it shouldn't so much be a truth value as a count, so as to handle duplicate characters within the strings. If it's just a truth value, then here and her would be considered anagrams.
Even though you state it's not an assignment, you'll still learn more if you implement it yourself, so it's pseudo-code only from me. The basic idea would be:
def isAnagram (str1, str2):
# Different lengths means no anagram.
if len(str1) not equal to len(str2):
return false
# Initialise character counts to zero.
create array[0..255] (assumes 8-bit char)
for each index 0..255:
set count[index] to zero
# Add 1 for all characters in string 1.
for each char in string1:
increment array[char]
# Subtract 1 for all characters in string 2.
for each char in string2:
decrement array[char]
# Counts will be all zero for an anagram.
for each index 0..255:
if count[index] not equal to 0:
return false
return true
Working approach : with zero additional cost.
bool permutation(const std::string &str1, const std::string &str2)
{
// Cannot be anagrams if sizes are different
if (str1.size() != str2.size())
return false;
int arr[25] = {0 };
for (int i = 0; i < str1.size(); i++) // string 1
{
char ch = (char)tolower(str1[i]); // convert each char to lower
int num = ch; // get ascii
arr[num-97] = arr[num-97] + 1 ;
}
for (int i = 0; i < str2.size(); i++) // string 2
{
char ch = (char)tolower(str2[i]); // convert char to lower
int num = ch; // get ascii
arr[num-97] = arr[num-97] - 1 ;
}
for (int i =0; i< 25; i++) {
if (arr[i] != 0) {
return false;
}
}
return true;
}
Yes, C and C++ both doesn't carry out the index-out-of-bounds.
It is the duty of the programmer to make sure that the program logic doesn't cross the legitimate limits. It is the programmer who need to make checks for the violations.
Improved Code:
bool permutation(const string &str1, const string &str2)
{
// Cannot be anagrams if sizes are different
if (str1.size() != str2.size())
return false;
int arr[25] = { 0 }; //<-------- Changed
for (int i = 0; i < str1.size(); i++) // string 1
{
char ch = (char)tolower(str1[i]); // convert each char to lower
int num = ch; // get ascii
arr[num-97] += 1; //<-------- Changed
}
for (int i = 0; i < str2.size(); i++) // string 2
{
char ch = (char)tolower(str2[i]); // convert char to lower
int num = ch; // get ascii
arr[num-97] = arr[num-97] - 1 ; //<-------- Changed
}
for (int i =0; i< 25; i++) { //<-------- Changed
if (arr[i] != 0) { //<-------- Changed
return false; //<-------- Changed
}
}
return true;
}

remove commas from string

I created a program in C++ that remove commas (,) from a given integer. i.e. 2,00,00 would return 20000. I am not using any new space. Here is the program I created:
void removeCommas(string& str1, int len)
{
int j = 0;
for (int i = 0; i < len; i++)
{
if (str1[i] == ',')
{
continue;
}
else
{
str1[j] = str1[i];
j++;
}
}
str1[j] = '\0';
}
void main()
{
string str1;
getline(cin, str1);
int i = str1.length();
removeCommas(str1, i);
cout << "the new string " << str1 << endl;
}
Here is the result I get:
Input : 2,000,00
String length =8
Output = 200000 0
Length = 8
My question is that why does it show the length has 8 in output and shows the rest of string when I did put a null character. It should show output as 200000 and length has 6.
Let the standard library do the work for you:
#include <algorithm>
str1.erase(std::remove(str1.begin(), str1.end(), ','), str1.end());
If you don't want to modify the original string, that's easy too:
std::string str2(str1.size(), '0');
str2.erase(std::remove_copy(str1.begin(), str1.end(), str2.begin(), ','), str2.end());
You need to do a resize instead at the end.
Contrary to popular belief an std::string CAN contain binary data including 0s. An std::string 's .size() is not related to the string containing a NULL termination.
std::string s("\0\0", 2);
assert(s.size() == 2);
The answer is probably that std::strings aren't NUL-terminated. Instead of setting the end+1'th character to '\0', you should use str.resize(new_length);.
Edit: Also consider that, if your source string has no commas in it, then your '\0' will be written one past the end of the string (which will probably just happen to work, but is incorrect).
The std::srting does not terminate with \0, you are mixing this with char* in C. So you should use resize.
The solution has already been posted by Fred L.
In a "procedural fashion" (without "algorithm")
your program would look like:
void removeStuff(string& str, char character)
{
size_t pos;
while( (pos=str.find(character)) != string::npos )
str.erase(pos, 1);
}
void main()
{
string str1;
getline(cin, str1);
removeStuff(str1, ',');
cout<<"the new string "<<str1<<endl;
}
then.
Regards
rbo
EDIT / Addendum:
In order to adress some efficiency concerns of readers,
I tried to come up with the fastest solution possible.
Of course, this should kick in on string sizes over
about 10^5 characters with some characters to-be-removed
included:
void fastRemoveStuff(string& str, char character)
{
size_t len = str.length();
char *t, *buffer = new char[len];
const char *p, *q;
t = buffer, p = q = str.data();
while( p=(const char*)memchr(q, character, len-(p-q)) ) {
memcpy(t, q, p-q);
t += p-q, q = p+1;
}
if( q-str.data() != len ) {
size_t tail = len - (q-str.data());
memcpy(t, q, tail);
t += tail;
}
str.assign(buffer, t-buffer);
delete [] buffer;
}
void main()
{
string str1 = "56,4,44,55,5,55"; // should be large, 10^6 is good
// getline(cin, str1);
cout<<"the old string " << str1 << endl;
fastRemoveStuff(str1, ',');
cout<<"the new string " << str1 << endl;
}
My own procedural version:
#include <string>
#include <cassert>
using namespace std;
string Remove( const string & s, char c ) {
string r;
r.reserve( s.size() );
for ( unsigned int i = 0; i < s.size(); i++ ) {
if ( s[i] != c ) {
r += s[i];
}
}
return r;
}
int main() {
assert( Remove( "Foo,Bar,Zod", ',' ) == "FooBarZod" );
}
Here is the program:
void main()
{
int i ;
char n[20] ;
clrscr() ;
printf("Enter a number. ") ;
gets(n) ;
printf("Number without comma is:") ;
for(i=0 ; n[i]!='\0' ; i++)
if(n[i] != ',')
putchar(n[i]) ;
getch();
}
For detailed description you can refer this blog: http://tutorialsschool.com/c-programming/c-programs/remove-comma-from-string.php
The same has been discussed in this post: How to remove commas from a string in C
Well, if youre planing to read from a file using c++. I found a method, while I dont think thats the best method though, but after I came to these forums to search for help before, I think its time to contribute with my effort aswell.
Look, here is the catch, what I'm going to present you is part of the source code of the map editor Im building on right now, that map editor obviously has the purpose to create maps for a 2D RPG game, the same style as the classic Pokemon games for example. But this code was more towards the development of the world map editor.
`int strStartPos = 0;
int strSize = 0;
int arrayPointInfoDepth = 0;
for (int x = 0; x < (m_wMapWidth / (TileSize / 2)); x++) {
for (int y = 0; y < (m_wMapHeight / (TileSize / 2)); y++) {
if (ss >> str) {
for (int strIterator = 0; strIterator < str.length(); strIterator++) {
if (str[strIterator] == ',') {`
Here we need to define the size of the string we want to extract after the previous comma and before the next comma
`strSize = strIterator - strStartPos;`
And here, we do the actual transformation, we give to the vector that is a 3D vector btw the string we want to extract at that moment
`m_wMapPointInfo[x][y][arrayPointInfoDepth] = str.substr(strStartPos, strSize);`
And here, we just define that starting position for the next small piece of the string we want to extract, so the +1 means that after the comma we just passed
strStartPos = strIterator + 1;
Here, well since my vector has only 6 postions that is defined by WorldMapPointInfos we need to increment the third dimension of the array and finally do a check point where if the info has arrived the number 6 then break the loop
arrayPointInfoDepth++;
if (arrayPointInfoDepth == WorldMapPointInfos) {
strStartPos = 0;
arrayPointInfoDepth = 0;
break;
}
}
}
}
}
}
Either way on my code, think abt that the vector is just a string, thats all you need to know, hope this helps though :/
Full view:
int strStartPos = 0;
int strSize = 0;
int arrayPointInfoDepth = 0;
for (int x = 0; x < (m_wMapWidth / (TileSize / 2)); x++) {
for (int y = 0; y < (m_wMapHeight / (TileSize / 2)); y++) {
if (ss >> str) {
for (int strIterator = 0; strIterator < str.length(); strIterator++) {
if (str[strIterator] == ',') {
strSize = strIterator - strStartPos;
m_wMapPointInfo[x][y][arrayPointInfoDepth] = str.substr(strStartPos, strSize);
strStartPos = strIterator + 1;
arrayPointInfoDepth++;
if (arrayPointInfoDepth == WorldMapPointInfos) {
strStartPos = 0;
arrayPointInfoDepth = 0;
break;
}
}
}
}
}
}