string subscript out of range - string bubble sort The 2019 Stack Overflow Developer Survey Results Are InHow do I iterate over the words of a string?How do you convert a byte array to a hexadecimal string, and vice versa?Sorting an array of JavaScript objects by propertySort array of objects by string property valueHow to Sort Multi-dimensional Array by Value?Converting 'ArrayList<String> to 'String[]' in JavaConvert ArrayList<String> to String[] arrayEasiest way to convert int to string in C++Loop through an array of strings in Bash?Why is it faster to process a sorted array than an unsorted array?
Does a dangling wire really electrocute me if I'm standing in water?
Inversion Puzzle
Monty Hall variation
Should I use my personal or workplace e-mail when registering to external websites for work purpose?
Are USB sockets on wall outlets live all the time, even when the switch is off?
Lethal sonic weapons
Where does the "burst of radiance" from Holy Weapon originate?
If a poisoned arrow's piercing damage is reduced to 0, do you still get poisoned?
Can distinct morphisms between curves induce the same morphism on singular cohomology?
What do the Banks children have against barley water?
How can I create a character who can assume the widest possible range of creature sizes?
Access elements in std::string where positon of string is greater than its size
How to manage monthly salary
Landlord wants to switch my lease to a "Land contract" to "get back at the city"
Inflated grade on resume at previous job, might former employer tell new employer?
How to make payment on the internet without leaving a money trail?
Understanding the implication of what "well-defined" means for the operation in quotient group
Dual Citizen. Exited the US on Italian passport recently
How are circuits which use complex ICs normally simulated?
Confusion about non-derivable continuous functions
Can't find the latex code for the ⍎ (down tack jot) symbol
How was Skylab's orbit inclination chosen?
In microwave frequencies, do you use a circulator when you need a (near) perfect diode?
Which Sci-Fi work first showed weapon of galactic-scale mass destruction?
string subscript out of range - string bubble sort
The 2019 Stack Overflow Developer Survey Results Are InHow do I iterate over the words of a string?How do you convert a byte array to a hexadecimal string, and vice versa?Sorting an array of JavaScript objects by propertySort array of objects by string property valueHow to Sort Multi-dimensional Array by Value?Converting 'ArrayList<String> to 'String[]' in JavaConvert ArrayList<String> to String[] arrayEasiest way to convert int to string in C++Loop through an array of strings in Bash?Why is it faster to process a sorted array than an unsorted array?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
First post here but I've been digging around for a solution to this bug.
I am getting an error "string subscript out of range"
PhoneBook is an array of class Contact object pointers.
static const int maxSize = 10;
Contact* phoneBook[maxSize]; //array of contact pointers
where Contact is defined as
class Contact
public:
Contact();
std::string firstName;
std::string lastName;
std::string name; //lName + fName
std::string phoneNumber;
std::string address;
;
Here is my bubble sort function.
void AddressBook::bubbleSort(Contact phoneBook[], int length)
Contact temp;
for (int i = 0; i < length; i++)//for n-1 passes
for (int j = 0; j < length - 1; j++)
if (phoneBook->name[j] > phoneBook->name[j + 1])
temp = phoneBook[j];
phoneBook[j] = phoneBook[j + 1];
phoneBook[j + 1] = temp;
here is addContact
void AddressBook::addContact(std::string fName, std::string lName, std::string pNumber, std::string addr)
if (isFull())
std::cout << "Is full" << std::endl;
return;
Contact *contact = new Contact;
contact->firstName = fName;
contact->lastName = lName;
contact->name = lName + ", " + fName;
contact->phoneNumber = pNumber;
contact->address = addr;
std::cout << contact->name + " has been added!" << std::endl;
phoneBook[length] = contact;
length++;
bubbleSort(phoneBook[maxSize], length);
and lastly, where i use it (source.cpp)
switch (choice)
{
case 1:
addrBook.addContact("Ty", "Le", "6191231234", "1234 State Street");
addrBook.addContact("Zak", "Zachary", "6191231234", "1234 Avenue Drive");
I know for a fact that the problem originates from the bubbleSort function because it'll work fine when I comment it out of addContact().
Here's a picture of my error
(too long to copy and paste)
FULL CODE
.h
https://pastebin.com/TrtQW8Tc
.cpp
https://pastebin.com/EaGBUe9e
source
https://pastebin.com/1BR5pXZE
c++ arrays bubble-sort
add a comment |
First post here but I've been digging around for a solution to this bug.
I am getting an error "string subscript out of range"
PhoneBook is an array of class Contact object pointers.
static const int maxSize = 10;
Contact* phoneBook[maxSize]; //array of contact pointers
where Contact is defined as
class Contact
public:
Contact();
std::string firstName;
std::string lastName;
std::string name; //lName + fName
std::string phoneNumber;
std::string address;
;
Here is my bubble sort function.
void AddressBook::bubbleSort(Contact phoneBook[], int length)
Contact temp;
for (int i = 0; i < length; i++)//for n-1 passes
for (int j = 0; j < length - 1; j++)
if (phoneBook->name[j] > phoneBook->name[j + 1])
temp = phoneBook[j];
phoneBook[j] = phoneBook[j + 1];
phoneBook[j + 1] = temp;
here is addContact
void AddressBook::addContact(std::string fName, std::string lName, std::string pNumber, std::string addr)
if (isFull())
std::cout << "Is full" << std::endl;
return;
Contact *contact = new Contact;
contact->firstName = fName;
contact->lastName = lName;
contact->name = lName + ", " + fName;
contact->phoneNumber = pNumber;
contact->address = addr;
std::cout << contact->name + " has been added!" << std::endl;
phoneBook[length] = contact;
length++;
bubbleSort(phoneBook[maxSize], length);
and lastly, where i use it (source.cpp)
switch (choice)
{
case 1:
addrBook.addContact("Ty", "Le", "6191231234", "1234 State Street");
addrBook.addContact("Zak", "Zachary", "6191231234", "1234 Avenue Drive");
I know for a fact that the problem originates from the bubbleSort function because it'll work fine when I comment it out of addContact().
Here's a picture of my error
(too long to copy and paste)
FULL CODE
.h
https://pastebin.com/TrtQW8Tc
.cpp
https://pastebin.com/EaGBUe9e
source
https://pastebin.com/1BR5pXZE
c++ arrays bubble-sort
add a comment |
First post here but I've been digging around for a solution to this bug.
I am getting an error "string subscript out of range"
PhoneBook is an array of class Contact object pointers.
static const int maxSize = 10;
Contact* phoneBook[maxSize]; //array of contact pointers
where Contact is defined as
class Contact
public:
Contact();
std::string firstName;
std::string lastName;
std::string name; //lName + fName
std::string phoneNumber;
std::string address;
;
Here is my bubble sort function.
void AddressBook::bubbleSort(Contact phoneBook[], int length)
Contact temp;
for (int i = 0; i < length; i++)//for n-1 passes
for (int j = 0; j < length - 1; j++)
if (phoneBook->name[j] > phoneBook->name[j + 1])
temp = phoneBook[j];
phoneBook[j] = phoneBook[j + 1];
phoneBook[j + 1] = temp;
here is addContact
void AddressBook::addContact(std::string fName, std::string lName, std::string pNumber, std::string addr)
if (isFull())
std::cout << "Is full" << std::endl;
return;
Contact *contact = new Contact;
contact->firstName = fName;
contact->lastName = lName;
contact->name = lName + ", " + fName;
contact->phoneNumber = pNumber;
contact->address = addr;
std::cout << contact->name + " has been added!" << std::endl;
phoneBook[length] = contact;
length++;
bubbleSort(phoneBook[maxSize], length);
and lastly, where i use it (source.cpp)
switch (choice)
{
case 1:
addrBook.addContact("Ty", "Le", "6191231234", "1234 State Street");
addrBook.addContact("Zak", "Zachary", "6191231234", "1234 Avenue Drive");
I know for a fact that the problem originates from the bubbleSort function because it'll work fine when I comment it out of addContact().
Here's a picture of my error
(too long to copy and paste)
FULL CODE
.h
https://pastebin.com/TrtQW8Tc
.cpp
https://pastebin.com/EaGBUe9e
source
https://pastebin.com/1BR5pXZE
c++ arrays bubble-sort
First post here but I've been digging around for a solution to this bug.
I am getting an error "string subscript out of range"
PhoneBook is an array of class Contact object pointers.
static const int maxSize = 10;
Contact* phoneBook[maxSize]; //array of contact pointers
where Contact is defined as
class Contact
public:
Contact();
std::string firstName;
std::string lastName;
std::string name; //lName + fName
std::string phoneNumber;
std::string address;
;
Here is my bubble sort function.
void AddressBook::bubbleSort(Contact phoneBook[], int length)
Contact temp;
for (int i = 0; i < length; i++)//for n-1 passes
for (int j = 0; j < length - 1; j++)
if (phoneBook->name[j] > phoneBook->name[j + 1])
temp = phoneBook[j];
phoneBook[j] = phoneBook[j + 1];
phoneBook[j + 1] = temp;
here is addContact
void AddressBook::addContact(std::string fName, std::string lName, std::string pNumber, std::string addr)
if (isFull())
std::cout << "Is full" << std::endl;
return;
Contact *contact = new Contact;
contact->firstName = fName;
contact->lastName = lName;
contact->name = lName + ", " + fName;
contact->phoneNumber = pNumber;
contact->address = addr;
std::cout << contact->name + " has been added!" << std::endl;
phoneBook[length] = contact;
length++;
bubbleSort(phoneBook[maxSize], length);
and lastly, where i use it (source.cpp)
switch (choice)
{
case 1:
addrBook.addContact("Ty", "Le", "6191231234", "1234 State Street");
addrBook.addContact("Zak", "Zachary", "6191231234", "1234 Avenue Drive");
I know for a fact that the problem originates from the bubbleSort function because it'll work fine when I comment it out of addContact().
Here's a picture of my error
(too long to copy and paste)
FULL CODE
.h
https://pastebin.com/TrtQW8Tc
.cpp
https://pastebin.com/EaGBUe9e
source
https://pastebin.com/1BR5pXZE
c++ arrays bubble-sort
c++ arrays bubble-sort
edited Mar 22 at 6:46
Tyler Le
asked Mar 22 at 2:44
Tyler LeTyler Le
72
72
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
This is almost a typo. Instead of indexing the name string in
if (phoneBook->name[j] > phoneBook->name[j + 1])
you want to index phonebook
if (phoneBook[j].name > phoneBook[j + 1].name)
Shoot.. so close. Thanks! I do get another error though, this time, Unhandled exception thrown: read access violation. _Right_data was 0xCCCCCD04. (Error and bubbleSort updated in post)
– Tyler Le
Mar 22 at 3:12
@TylerLe 0xCCCCCD04 looks a lot like uninitialized memory (see Wikipedia's list of common debugging codes) plus an offset of a member variable in a structure. Odds are you ran off the end of the stack somewhere and tried to access a pointer.
– user4581301
Mar 22 at 3:19
1
I just looked at your edit to the question and I'm going to roll it back in a few seconds. It is bad form to change a question in such a way that it renders existing answers invalid. When one solution exposes a new problem, you are better off debugging a while to see if you can solve it, and asking a new question if you cannot.
– user4581301
Mar 22 at 3:22
Oh I'm sorry, I didn't know.
– Tyler Le
Mar 22 at 3:40
No worries. Got distracted before I could finish my thought. Your new error crashes the program somewhere insidestd::string. The odds of the error being instd::stringare pretty close to zero due to the sheer number of people using it every day without a problem. If you look down at the bottom of Visual Studio, you'll find a Call Stack tab. Click that and you'll see how the program got to the crash site. Work your way back until you find where the 0xCCCCCCCC came from. Then you may have to do a bit more work to find out how it got there. Probably be an out-of-bounds array access.
– user4581301
Mar 22 at 4:38
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55292156%2fstring-subscript-out-of-range-string-bubble-sort%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is almost a typo. Instead of indexing the name string in
if (phoneBook->name[j] > phoneBook->name[j + 1])
you want to index phonebook
if (phoneBook[j].name > phoneBook[j + 1].name)
Shoot.. so close. Thanks! I do get another error though, this time, Unhandled exception thrown: read access violation. _Right_data was 0xCCCCCD04. (Error and bubbleSort updated in post)
– Tyler Le
Mar 22 at 3:12
@TylerLe 0xCCCCCD04 looks a lot like uninitialized memory (see Wikipedia's list of common debugging codes) plus an offset of a member variable in a structure. Odds are you ran off the end of the stack somewhere and tried to access a pointer.
– user4581301
Mar 22 at 3:19
1
I just looked at your edit to the question and I'm going to roll it back in a few seconds. It is bad form to change a question in such a way that it renders existing answers invalid. When one solution exposes a new problem, you are better off debugging a while to see if you can solve it, and asking a new question if you cannot.
– user4581301
Mar 22 at 3:22
Oh I'm sorry, I didn't know.
– Tyler Le
Mar 22 at 3:40
No worries. Got distracted before I could finish my thought. Your new error crashes the program somewhere insidestd::string. The odds of the error being instd::stringare pretty close to zero due to the sheer number of people using it every day without a problem. If you look down at the bottom of Visual Studio, you'll find a Call Stack tab. Click that and you'll see how the program got to the crash site. Work your way back until you find where the 0xCCCCCCCC came from. Then you may have to do a bit more work to find out how it got there. Probably be an out-of-bounds array access.
– user4581301
Mar 22 at 4:38
|
show 1 more comment
This is almost a typo. Instead of indexing the name string in
if (phoneBook->name[j] > phoneBook->name[j + 1])
you want to index phonebook
if (phoneBook[j].name > phoneBook[j + 1].name)
Shoot.. so close. Thanks! I do get another error though, this time, Unhandled exception thrown: read access violation. _Right_data was 0xCCCCCD04. (Error and bubbleSort updated in post)
– Tyler Le
Mar 22 at 3:12
@TylerLe 0xCCCCCD04 looks a lot like uninitialized memory (see Wikipedia's list of common debugging codes) plus an offset of a member variable in a structure. Odds are you ran off the end of the stack somewhere and tried to access a pointer.
– user4581301
Mar 22 at 3:19
1
I just looked at your edit to the question and I'm going to roll it back in a few seconds. It is bad form to change a question in such a way that it renders existing answers invalid. When one solution exposes a new problem, you are better off debugging a while to see if you can solve it, and asking a new question if you cannot.
– user4581301
Mar 22 at 3:22
Oh I'm sorry, I didn't know.
– Tyler Le
Mar 22 at 3:40
No worries. Got distracted before I could finish my thought. Your new error crashes the program somewhere insidestd::string. The odds of the error being instd::stringare pretty close to zero due to the sheer number of people using it every day without a problem. If you look down at the bottom of Visual Studio, you'll find a Call Stack tab. Click that and you'll see how the program got to the crash site. Work your way back until you find where the 0xCCCCCCCC came from. Then you may have to do a bit more work to find out how it got there. Probably be an out-of-bounds array access.
– user4581301
Mar 22 at 4:38
|
show 1 more comment
This is almost a typo. Instead of indexing the name string in
if (phoneBook->name[j] > phoneBook->name[j + 1])
you want to index phonebook
if (phoneBook[j].name > phoneBook[j + 1].name)
This is almost a typo. Instead of indexing the name string in
if (phoneBook->name[j] > phoneBook->name[j + 1])
you want to index phonebook
if (phoneBook[j].name > phoneBook[j + 1].name)
answered Mar 22 at 2:56
user4581301user4581301
21.1k52034
21.1k52034
Shoot.. so close. Thanks! I do get another error though, this time, Unhandled exception thrown: read access violation. _Right_data was 0xCCCCCD04. (Error and bubbleSort updated in post)
– Tyler Le
Mar 22 at 3:12
@TylerLe 0xCCCCCD04 looks a lot like uninitialized memory (see Wikipedia's list of common debugging codes) plus an offset of a member variable in a structure. Odds are you ran off the end of the stack somewhere and tried to access a pointer.
– user4581301
Mar 22 at 3:19
1
I just looked at your edit to the question and I'm going to roll it back in a few seconds. It is bad form to change a question in such a way that it renders existing answers invalid. When one solution exposes a new problem, you are better off debugging a while to see if you can solve it, and asking a new question if you cannot.
– user4581301
Mar 22 at 3:22
Oh I'm sorry, I didn't know.
– Tyler Le
Mar 22 at 3:40
No worries. Got distracted before I could finish my thought. Your new error crashes the program somewhere insidestd::string. The odds of the error being instd::stringare pretty close to zero due to the sheer number of people using it every day without a problem. If you look down at the bottom of Visual Studio, you'll find a Call Stack tab. Click that and you'll see how the program got to the crash site. Work your way back until you find where the 0xCCCCCCCC came from. Then you may have to do a bit more work to find out how it got there. Probably be an out-of-bounds array access.
– user4581301
Mar 22 at 4:38
|
show 1 more comment
Shoot.. so close. Thanks! I do get another error though, this time, Unhandled exception thrown: read access violation. _Right_data was 0xCCCCCD04. (Error and bubbleSort updated in post)
– Tyler Le
Mar 22 at 3:12
@TylerLe 0xCCCCCD04 looks a lot like uninitialized memory (see Wikipedia's list of common debugging codes) plus an offset of a member variable in a structure. Odds are you ran off the end of the stack somewhere and tried to access a pointer.
– user4581301
Mar 22 at 3:19
1
I just looked at your edit to the question and I'm going to roll it back in a few seconds. It is bad form to change a question in such a way that it renders existing answers invalid. When one solution exposes a new problem, you are better off debugging a while to see if you can solve it, and asking a new question if you cannot.
– user4581301
Mar 22 at 3:22
Oh I'm sorry, I didn't know.
– Tyler Le
Mar 22 at 3:40
No worries. Got distracted before I could finish my thought. Your new error crashes the program somewhere insidestd::string. The odds of the error being instd::stringare pretty close to zero due to the sheer number of people using it every day without a problem. If you look down at the bottom of Visual Studio, you'll find a Call Stack tab. Click that and you'll see how the program got to the crash site. Work your way back until you find where the 0xCCCCCCCC came from. Then you may have to do a bit more work to find out how it got there. Probably be an out-of-bounds array access.
– user4581301
Mar 22 at 4:38
Shoot.. so close. Thanks! I do get another error though, this time, Unhandled exception thrown: read access violation. _Right_data was 0xCCCCCD04. (Error and bubbleSort updated in post)
– Tyler Le
Mar 22 at 3:12
Shoot.. so close. Thanks! I do get another error though, this time, Unhandled exception thrown: read access violation. _Right_data was 0xCCCCCD04. (Error and bubbleSort updated in post)
– Tyler Le
Mar 22 at 3:12
@TylerLe 0xCCCCCD04 looks a lot like uninitialized memory (see Wikipedia's list of common debugging codes) plus an offset of a member variable in a structure. Odds are you ran off the end of the stack somewhere and tried to access a pointer.
– user4581301
Mar 22 at 3:19
@TylerLe 0xCCCCCD04 looks a lot like uninitialized memory (see Wikipedia's list of common debugging codes) plus an offset of a member variable in a structure. Odds are you ran off the end of the stack somewhere and tried to access a pointer.
– user4581301
Mar 22 at 3:19
1
1
I just looked at your edit to the question and I'm going to roll it back in a few seconds. It is bad form to change a question in such a way that it renders existing answers invalid. When one solution exposes a new problem, you are better off debugging a while to see if you can solve it, and asking a new question if you cannot.
– user4581301
Mar 22 at 3:22
I just looked at your edit to the question and I'm going to roll it back in a few seconds. It is bad form to change a question in such a way that it renders existing answers invalid. When one solution exposes a new problem, you are better off debugging a while to see if you can solve it, and asking a new question if you cannot.
– user4581301
Mar 22 at 3:22
Oh I'm sorry, I didn't know.
– Tyler Le
Mar 22 at 3:40
Oh I'm sorry, I didn't know.
– Tyler Le
Mar 22 at 3:40
No worries. Got distracted before I could finish my thought. Your new error crashes the program somewhere inside
std::string. The odds of the error being in std::string are pretty close to zero due to the sheer number of people using it every day without a problem. If you look down at the bottom of Visual Studio, you'll find a Call Stack tab. Click that and you'll see how the program got to the crash site. Work your way back until you find where the 0xCCCCCCCC came from. Then you may have to do a bit more work to find out how it got there. Probably be an out-of-bounds array access.– user4581301
Mar 22 at 4:38
No worries. Got distracted before I could finish my thought. Your new error crashes the program somewhere inside
std::string. The odds of the error being in std::string are pretty close to zero due to the sheer number of people using it every day without a problem. If you look down at the bottom of Visual Studio, you'll find a Call Stack tab. Click that and you'll see how the program got to the crash site. Work your way back until you find where the 0xCCCCCCCC came from. Then you may have to do a bit more work to find out how it got there. Probably be an out-of-bounds array access.– user4581301
Mar 22 at 4:38
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55292156%2fstring-subscript-out-of-range-string-bubble-sort%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown