i was having an issue earlier with my program displaying garbage but i think i figured out that problem. my program gets 3 pieces of info a "tracking number" a "description" and a "price". my issue is when trying to display the description from my linked list it only displays the first letter of the array. i dont know what im doing wrong.
// Undefined behavior! Even if it did work the syntax could only result in one character being copied
CurrentRecordPointer->Desc[35] = *InitDesc;
You cannot copy strings this way. There are a number of fixes.
1) use std::string and getline. std::string provides built in copy constructor and assignment operator and you don't have to worry about strings that are too large being entered by the user.
2) use strcpy to copy the string. Desc[35] is an out of bounds access. Use a constant to define the size of the array and then use a strcpy to copy the data.
If I were you, I would rewrite the string processing to use std::string. I don't see any reason to mess around with character arrays in that example since it is clearly a C++ program.
now im a total programming newb im not quite sure what you mean. Ive tried to use a string instead of a character array, but i need to be able to have spaces in the description. When i use a string and input a something with a space in it the program crashes and just goes into a loop. any way you can dumb it down a little. and maybe an example? i would rather learn how to do it instead of actually just getting the code tho
Take a look at this example. You need to use getline with std::string. You might be using cin which will stop when it reaches a space where getline will read an entire line. http://www.cplusplus.com/reference/string/getline/
Try copying the examples at those links and I think that you should be able to use them within your code. Repost the latest thing that you are working on if you run into trouble and someone will offer help as long as it looks like you are making progress on your own.
ok I seem to have gotten it working. As i understand it the getline just reads everything from the input stream and ignores any endline characters so my
isnt really necessary. Since im not trying to convert from a string pointer to a char array and just copy a string to a string my InsertItem function works too. Are my thoughts correct?
Read the second link that I showed you completely. You need to skip past the '\n' after using cin to read the integers otherwise getline will not work. It also provides an alternative which is much simpler than what you are doing. Moreover, it shows you how to deal with invalid inputs which is something that you should add to the program regardless. It looks like you are on the right track. You can also pass the string objects to functions by const reference, which will help you to avoid unnecessary copies.