Hey, I was working on a program that would ask you a question and you had to put an answer. Well, when I went to compare the answer the user inputs with the right answer, it always comes up wrong and I was wondering if I did these lines of coding right:

LPSTR lpString = "";
					GetDlgItemText(hwndqw2, IDC_ANSQW, lpString, 1000);
					string span = lpString;
					string span2 = rSpnV[i];
					if(span == span2)
						MessageBox(hwndqw2,"You are right!!!", "CORRECT!", MB_OK);
					else
						MessageBox(hwndqw2, "You are wrong!!!", "WRONG!", MB_OK);

Recommended Answers

All 2 Replies

You have to allocate memory for the string because GetDlgItemText() does not do that for you.

char text[255] = {0};
GetDlgItemText(hwndqw2, IDC_ANSQW, text, sizeof(text));

Thanks. It works like a charm now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.