user2966767
user2966767

Reputation: 1

issue with char TypeDef

When I try to copy the data from a string into this typdef char by char, the debugger shows everything going in properly, but when it ouputs, it outputs the data plus garbage data. When I tried to see the length of the items each instance of scores, the size is over 700, when it should be 30. Anyone know whats going on?

const int NUMBEROFQUESTIONS= 30;
typedef char answerSet[NUMBEROFQUESTIONS];

getline(testResults, x, '\n');
        testResults.getline(scores[count],'\n');

        for(int j=0; j< 25; j++){
            for(int i =0; i < 30;i++){
                scores[j][i] = x[i];
            }
        }

Upvotes: 0

Views: 70

Answers (1)

dnk
dnk

Reputation: 661

You should put trailing '\0' at the end of your array if you want to see output as string.

Upvotes: 1

Related Questions