Solved Getline causes program to crash.

May 1, 2012 at 21:03:39
Specs: Windows 7
I solve one problem and hit another. Of course. Ok. In my program, I am trying to get a line from a txt file through fstream with these three lines:

ifstream input("EnglishQuestions.txt");
char * question = "abc";
input.getline(question, 256);

And my program keeps crashing (as in, it says "Project has stopped working. Checking for a solution to the problem" and does that little thing where it pretends to be helping you) I've clicked the debug button there, and it got me nowhere. The problem is the input.getline line, because if I comment it out, the program runs fine. Why would this cause a crash?

Txt file says: Which part of the sentence is incorrect:
My cat has discovered... (etc not important)

See More: Getline causes program to crash.

Report •

May 1, 2012 at 21:15:41
✔ Best Answer
Question: How much space are you reserving on the stack for "quesetion"? (Hint: Probably less than the 256 you're telling getline().)

How To Ask Questions The Smart Way

Report •

May 1, 2012 at 21:19:04
Solved it! I changed char * question to char question[256] to hold the size like you said!

Report •

Related Solutions

Ask Question