Hello.
Title says it all, i got problem Passing struct intro function to change its values.
(this is just copy from my code if its lacking something i will add it)
here is my code:
struct Students
{
shortint subjects;
std::string subjectName;
shortint subjectGrade;
std::string studentsName;
};
char ReturnInput()
{
char tempCharNameChange[31];
if(!(std::cin >> tempCharNameChange))
{
std::cin.clear();
std::cin.ignore(100, '\n');
}
return *tempCharNameChange;
}
bool LookForStudentAndSetName(int StudentsAmount, char* tempChar, Students *StructStudents)
{
bool qwe = false;
for(int x = 0; x < StudentsAmount; x++)
{
if(tempChar == StructStudents[x]->studentsName)
{
TypeStuff(6);
(StructStudents[x]->studentsName) = ReturnInput(); //This should set my struct student name to ReturnInput
qwe = true;
}
}
return qwe;
}
int main()
{ int StudentsAmount = 0;
char tempChar[63];
bool changeNames = false;
bool didFound = false;
Students StructStudents[StudentsAmount];//Makes struct for each student
//At this point stuff is
//StudentAmount = HowMuchYouPicked.
//tempChar[63] = name of student you are looking for to change its name
//changeNames = true(keaps loop on if you want to change names)NOT INCLUDED IN HERE
//didFound = will print text if pupil is found / else name of pupil = eror404^^
didFound = LookForStudentAndSetName(StudentsAmount, tempChar, StructStudents);
}
Edit: Alredy found out it does change my students name
BUT! if students name was "a" and then i want to change it to "bill" it will change only existing amount of letters there fore changing "a" = "bill" will make "b"
how do i extend the name?
Edit2: Atm i wrecked search. Everything is still up, if you want to help.
Here is a link to project cut the spaces
http: //www. mediafire.com/ download.php?yv4k6837754io20
ReturnInput() is returning a char so only one char will be assigned to studentsName. In this case, you're dereferencing tempCharNameChange, which will give you the first character in the array (or the first character the user enters).
You should make ReturnInput() return a std::string and change it to use a std::string instead of an array of chars.
//StudentAmount = HowMuchYouPicked.
as i said the StudentsAmount cant be less then 1 there for its always positive number.
as for the char problem, yea i will put all that to strings.
//char ReturnInput() im talking about this here
i thought i returned char pointer.(i return char there for i had error thats why i dereferenced it my bad).
Your escenario:
_ Architect: Here are the blueprints, I want a skyrocket of 0m height
_ Gimenez Carlos, Contractor: Ok, the building is done.
_ (Architect alters the blueprints.)
_ Nobody understand why the people are dying in the 42th floor.